Reputation: 2809
My makefile doesn't detect changes in header files. How can i add this functionality to my makefile? Here is my makefile:
CPP = g++
CC = gcc
RES =
OBJ = obj/main.o obj/customfunc1.o obj/customfunc2.o $(RES)
LINKOBJ = obj/main.o obj/customfunc1.o obj/customfunc2.o $(RES)
LIBS =
INCS = -I"lib1/inc" -I"lib2/inc"
CXXINCS = -I"lib1/inc" -I"lib2/inc"
BIN = out
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)
obj/main.o: main.c
$(CC) -c main.c -o obj/main.o $(CFLAGS)
obj/customfunc1.o: lib1/customfunc1.c
$(CC) -c lib1/customfunc1.c -o obj/customfunc1.o $(CFLAGS)
obj/customfunc2.o: lib2/customfunc2.c
$(CC) -c lib2/customfunc2.c -o obj/customfunc2.o $(CFLAGS)
Upvotes: 0
Views: 172
Reputation: 4317
Header files must be listed together with other dependencies. E.g.:
CPP = g++
CC = gcc
RES =
OBJ = obj/main.o obj/customfunc1.o obj/customfunc2.o $(RES)
LINKOBJ = obj/main.o obj/customfunc1.o obj/customfunc2.o $(RES)
LIBS =
INCS = -I"lib1/inc" -I"lib2/inc"
CXXINCS = -I"lib1/inc" -I"lib2/inc"
BIN = out
CXXFLAGS = $(CXXINCS)
CFLAGS = $(INCS)
RM = rm -f
.PHONY: all all-before all-after clean clean-custom
all: all-before $(BIN) all-after
clean: clean-custom
${RM} $(OBJ) $(BIN)
$(BIN): $(OBJ)
$(CC) $(LINKOBJ) -o $(BIN) $(LIBS)
obj/main.o: main.c header1.h header2.h
$(CC) -c main.c -o obj/main.o $(CFLAGS)
obj/customfunc1.o: lib1/customfunc1.c lib1/header.h
$(CC) -c lib1/customfunc1.c -o obj/customfunc1.o $(CFLAGS)
obj/customfunc2.o: lib2/customfunc2.c lib2/header.h
$(CC) -c lib2/customfunc2.c -o obj/customfunc2.o $(CFLAGS)
Upvotes: 2