Keroronsk Keroronsk - 1 year ago 103
C Question

GNU Make ignore all rules except first

I have a project with a bunch of source file, some of them (but not all) must be rebuilded after one specific *.h file is changed (currtype.h). I have explicit rule for this in my makefile:

%.obj: %.c
$(COMPILE)

main.obj: main.c currtype.h
$(COMPILE)
CustomHTTPApp.obj: CustomHTTPApp.c currtype.h
$(COMPILE)
CustomSNMPApp.obj: CustomSNMPApp.c currtype.h
$(COMPILE)

COMPILE = -"$(CC)" -C $< $(CFLAGS) $(INCLUDE_STACK)


But than I change my currtype.h I see only main.c being recompiled. If I put CustomHTTPApp on the first line and main.c on second, then only CustomHTTPApp is recompiled etc. How this can be fixed?

Answer Source

If you just run "make", the first non-implicit rule gets executed, which just builds main.obj. You need to add another target building all output files, e.g. called "all":

all: main.obj CustomHTTPApp.obj CustomSNMPApp.obj

%.obj: %.c
    $(COMPILE)

main.obj: main.c currtype.h
    $(COMPILE)
CustomHTTPApp.obj: CustomHTTPApp.c currtype.h
    $(COMPILE)
CustomSNMPApp.obj: CustomSNMPApp.c currtype.h
    $(COMPILE)

COMPILE = "$(CC)" -C $< $(CFLAGS) $(INCLUDE_STACK)