Wednesday, 7 August 2013

make/makefile: realize that there is a new (not changed) source file

make/makefile: realize that there is a new (not changed) source file

In general my makefile works. Since people will ask, here it is for
reference:
HEADERS = *.h
OBJS = *.o
MYFORWARDS = *.c
WARNS = -Wall
CC = gcc
CFLAGS = -mwindows -Wall
LDFLAGS = -mwindows -lkernel32 -luser32
all : my.exe
my.exe : ${OBJS}
${CC} -o "$@" ${OBJS} ${LDFLAGS}
%.o : %.c ${HEADERS}
${CC} ${CFLAGS} -c $< -o $@
Make generally works backwards: For each target look if one of its sources
changed, if so rebuild.
I dont want to change that since it's the whole point of make, however
there's an exception.
I generally like the *.o and *.c so i dont have to edit the makefile each
time a .c is added.
The problem is, that when i create a new .c file then there exists no .o
file yet and thus (make working backwards from the .o's) it does not even
realize that there is a new .c.
What i have done up to now is each time i create a new .c i manually
create the new .o file.
Is there a better way? Thanks in advance.

No comments:

Post a Comment