+ 3

How can I make a makefile in C detects the modifications in header files ?

6th Jan 2021, 2:17 AM
Abdelhaq El Amraoui
Abdelhaq El Amraoui - avatar
4 Answers
+ 3
List used header files as dependencies for the object files that use them, that way when a header is modified the objects that use it get rebuilt.
6th Jan 2021, 3:43 AM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar
+ 2
The problem is that the compiler generate other files when I do this
6th Jan 2021, 3:44 AM
Abdelhaq El Amraoui
Abdelhaq El Amraoui - avatar
+ 2
Abdelhaq El Amraoui What kind of other files? What i meant was just to have an explicit recipe for each object file - like module1.o: module1.c header1.h header2.h $(CC) $(CFLAGS) -c
lt; -o $@ (c file should be the first dependency in the list so that
lt; becomes it)
6th Jan 2021, 3:51 AM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar
+ 2
Also you can try using -MMD gcc option: https://codereview.stackexchange.com/questions/2547/makefile-dependency-generation/11109#11109 (never done it myself, but maybe that's what you need)
6th Jan 2021, 4:05 AM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar