Files available:
src1.c
src1. h
src2.c
src3.c
src4.c
src4. h
It is worth paying attention that NOT for all .c files there are own .h files.
The current makefile works, but with the proviso: when changing any .h file, ALL .c files are rebuilt:
SRCS = $(wildcard *.c) HDRS = $(wildcard *.h) %.o: %.c $(HDRS) @$(CC) -c -o $@ $< If you expand the contents of the $ (HDRS) variable, the automatic build will look like this:
%.o: %.c src1.h src4.h @$(CC) -c -o $@ $< That is why if only one src4.h file is changed, then all * .c files will be re-assembled.
In another case, an attempt to do so as indicated in the example below will lead to an error, because the src2.h files src3.h do not exist:
%.o: %.c %.h @$(CC) -c -o $@ $< Be kind, tell me, please, how to make the right Makefile so that when src4.h changes, only src4.c is reassembled, but not the rest.
All my independent attempts to find the answer to this question were unsuccessful.
Thank you in advance for your advice.