We can add pattern rules such as %.c
or %.o
which mimics *.c
or *.o
in bash (it searches for all files that have extension .c
or .o
. This is very useful if you have several targets, so you don't have to write all rules. I would like to know how to use this trick if your target files (.c
or .o
) are in the previous directory. In bash, one can write ../*.c
, but ../%.c
does not work in makefile as I tested. How do you do such thing in makefile?
My second question: sometimes one would like to add header dependencies like this:
HEADER=factorial.h
%.o: %.c $(HEADERS)
gcc -o program $%
It is a good idea to add a header dependency because sometimes you don't know whether or not the included libraries have some change.
Here we have to manually type the file names for HEADER
.
How do I make it so it can scan the target file's included headers?
For example: my main.c
has #include "dog.h"
How do I make it so it detects main.c
has included dog.h
.