Makefiles

Talk about development tools here

Moderator: BigEvilCorporation

Post Reply
Zontar
Very interested
Posts: 55
Joined: Fri Oct 21, 2011 8:58 pm

Makefiles

Post by Zontar » Sun Oct 23, 2011 12:00 am

Using ChillyWilly's linux toolkit and Stef's libraries from SDGK, I'm now attempting to compile this simple helloworld:
#include <genesis.h>

int main()
{
VDP_drawText("Hello Genny World!", 10, 13);

while(1)
{
//read input
//move sprite
//update score
//draw current screen (logo, start screen, settings, game, gameover, credits...)

//wait for screen refresh
VDP_waitVSync();
}
return (0);
}
However, the makefile is downright mystifying. I didn't understand the one that came with the toolkit (it needed to be modified as it was pre-configured for windows but was very, very long), so I attempted to make my own but to little avail. This is the error I get:
m68k-elf-gcc -m68000 -Wall -O1 -fomit-frame-pointer -I/opt/toolchains/gen/include -I/opt/toolchains/gen/m68k-elf/include -I/opt/toolchains/gen/m68k-elf/m68k-elf/include-c main.c -o main.o
In file included from /opt/toolchains/gen/include/genesis.h:12:0,
from main.c:1:
/opt/toolchains/gen/include/memory.h:75:6: warning: conflicting types for built-in function ‘memset’
/opt/toolchains/gen/include/memory.h:78:6: warning: conflicting types for built-in function ‘memcpy’
/opt/toolchains/gen/m68k-elf/lib/gcc/m68k-elf/4.5.2/../../../../m68k-elf/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000080000080
/tmp/ccV8Fz7q.o: In function `main':
main.c:(.text+0x12): undefined reference to `VDP_drawText'
main.c:(.text+0x1c): undefined reference to `VDP_waitVSync'
collect2: ld returned 1 exit status
make: *** [main.o] Error 1
I'm not sure, but I might have something out of order or something. It doesn't appear to be acknowledging any of the genesis functions. I understand very little of the build process, so I'm not even entirely sure what's supposed to be done before what for the genesis.

So, I guess I'll start here. Let's say I wanted to compile this manually without make. What is the proper ordering of commands and files needed?

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Sun Oct 23, 2011 4:34 pm

Sounds like your makefile isn't linking the lib, or linking it in the wrong order. You might want to post the makefile. Makefiles can get really complicated, but they don't NEED to be. Look over my article on making a makefile.

http://www.sega-16.com/forum/showthread.php?16692

Zontar
Very interested
Posts: 55
Joined: Fri Oct 21, 2011 8:58 pm

Post by Zontar » Sun Oct 23, 2011 9:06 pm

To start with, I'm currently attempting to use a makefile modified from an earlier libmd that I did have fully working (compiled and ran but had fewer features and includes than stef's SDK).
# C source
SRC_C= main.c

#Name of the project
NAME= zontar_test

# Avoid default system CFLAGS
CFLAGS:=

# Include mdg system makefile
include ${GENDEV}/share/md.mk

(-----and here's the default makefile that was included-------)

PREFIX= /opt/toolchains/gen
CC= m68k-elf-gcc
AS= m68k-elf-as
LD= m68k-elf-ld
OBJC= m68k-elf-objcopy
AR= m68k-elf-ar -rcs
RM= rm -f

OBJ:= ${SRC_C:.c=.o}
OBJ+= ${SRC_S:.s=.o}

CFLAGS+= -m68000 -Wall -Werror -O1 -fomit-frame-pointer -ffreestanding -I${PREFIX}/include/ -Wa,--register-prefix-optional
LINK= -T${PREFIX}/ldscripts/md.ld

${NAME}.bin: ${OBJ}
${LD} ${OBJ} -o ${NAME}.elf -Map ${NAME}.map ${LINK}
${OBJC} -O binary --pad-to=131072 --gap-fill=0 ${NAME}.elf ${NAME}.bin

clean:
${RM} ${OBJ} ${NAME}.bin ${NAME}.elf ${NAME}.map *~

re: clean ${NAME}.bin

.PHONY: clean re

.SUFFIXES: .s .c .o
This relatively simple makefile doesn't give me the memcpy conflicting errors, however, it does provide the same VDP errors as the last one I tried to use (which I've since overwritten.) The main.c file does include genesis.h from /opt/toolchains/gen, and also builds the main.c into main.o, but errors when beginning to link md.ld.

Should I also check and see if the library was built properly? I suspect that could be another cause of the issue.

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Mon Oct 24, 2011 8:15 pm

Look at these three lines:

Code: Select all

OBJ:= ${SRC_C:.c=.o}
OBJ+= ${SRC_S:.s=.o} 


${LD} ${OBJ} -o ${NAME}.elf -Map ${NAME}.map ${LINK}
The ${LD} line links the file, but it only links ${OBJ} - the list of objects, which from the first two lines above is merely your source. There's no libraries or anything there. The objects to link should be

Code: Select all

${LD} md.o ${OBJ} ${LIBS} -o ${NAME}.elf -Map ${NAME}.map ${LINK}
in that order. You either need to put md.o and the libs in the same directory, or set paths to them in the link line. Be sure LIBS has -lmd as one of the libs. LIBS will probably be something like this

Code: Select all

LIBS:= -L${PREFIX}/m68k-elf/lib -L${PREFIX}/m68k-elf/m68k-elf/lib -lmd -lc -lgcc -lnosys
Any -L's set the library path, while -l's specify the library.

Post Reply