Reputation: 618
I'm trying to set a Makefile which does auto-dependency generation. I red this page http://make.paulandlesley.org/autodep.html and write my own Makefile :
Edit : I made some changes following Beta comments. Now, all files and the makefile are at the same level. But not more luck.
CC = gcc
LD = gcc
RM = rm -rf
MAKEDEPEND = gcc -M $(CFLAGS) $(INCLUDE) -o $*.d $<
CFLAGS = -Wall -g
INCLUDE = -I/usr/include/CUnit
LIB = -llibcunit
SRC = lib_dac.c
SRC += main.c
OBJS = $(SRC:.c=.o)
PROG = tests
all: $(OBJS)
%.o : %.c
$(MAKEDEPEND); \
cp $*.d $*.P; \
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $*.d >> $*.P; \
rm -f $*.d
$(CC) -c $(CFLAGS) $(INCLUDE) -o $@ $<
-include $(SRCS:.c=.P)
PHONY: clean
clean:
$(RM) *.o *.exe
$(RM) *.P
But I can not get it worked. When I touch lib_dac.h, on which depends lib_dac.c nothing happen. Am I missing something ?
Thanks for your help.
Upvotes: 1
Views: 947
Reputation: 99084
MAKEDEPEND
is giving you the dependencies for lib_dac.o
, not for src/lib_dac.o
. When Make tries to build src/lib_dac.o
, it doesn't know that lib_doc.h
is involved.
There are several ways to fix this, but the choice depends on how you want to handle the object files (e.g. lib_dac.o
). I notice that you define a BIN_PATH
, but don't use it; instead you build the objects in src
. Is that your intention?
EDIT:
Here is a quick fix to put the object files in bin/
. (Make is good at using files there to build files here, but not the other way around.)
OBJS = $(patsubst %.c,bin/%.o,$(SRC))
bin/%.o : %.c
...
vpath %.c src
Upvotes: 1
Reputation: 618
Ok, I find a typo in my makefile. In the include I wrote $SRCS
instead of $SRC
. Damned copy/paste.
It works well now, but currently all files are in the same directory and I don't really like that.
But the dependency generation works, so problem solved.
Upvotes: 0