making source in subfolder question
I have makefile that compiles all *.c files in subfolder:
objects := $(patsubst %.c,%.o,$开发者_如何学运维(wildcard *.c))
cobj: $(objects)
$(objects): %.o: %.c
$(CC) -c $< -o $@
I am having trouble trying to do the same from parent folder. Lets say my .c files are in the folder 'csrc'
objects := $(addprefix, csrc/, $(patsubst %.c,%.o,$(wildcard *.c)))
cobj: $(objects)
$(objects): csrc/%.o: %.c
$(CC) -c $< -o $@
i always see "nothing to do for cobj... Any ideas?
Your pattern rule csrc/%.o: %.c
translates e.g. csrc/foo.o
into foo.c
, not csrc/foo.c
. Presumably, that is not what you want.
Why not just %.o: %.c
?
What Oli Charlesworth said is correct, but there's another mistake. The wildcard function only checks the current directory. As it is now, $(objects)
will be empty (I assume there are no source files in the current, parent directory). You will have to specify the path: $(wildcard csrc/*.c)
精彩评论