From e288fe4b930339f201222b2821df975fe8a3975f Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Sat, 26 Jan 2019 22:04:22 +0200 Subject: [PATCH] Fix makefile not recompiling on header change We currently do not keep track of header files in our Makefile so if one is changed it can lead to multiple incompatible binary files being linked. Instead we now create dependency lists for each source file and recompile them if the need arises. Fixes #594 --- .gitignore | 1 + Makefile | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 5fe5061..dc85941 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ *.o +*.d *.gcda *.gcno *.gcov diff --git a/Makefile b/Makefile index 9737a64..43d0d76 100644 --- a/Makefile +++ b/Makefile @@ -42,13 +42,15 @@ $(error "$(PKG_CONFIG) failed!") endif endif -CFLAGS := ${DEFAULT_CPPFLAGS} ${CPPFLAGS} ${DEFAULT_CFLAGS} ${CFLAGS} ${INCS} +CFLAGS := ${DEFAULT_CPPFLAGS} ${CPPFLAGS} ${DEFAULT_CFLAGS} ${CFLAGS} ${INCS} -MMD -MP LDFLAGS := ${DEFAULT_LDFLAGS} ${LDFLAGS} ${LIBS} SRC := $(sort $(shell find src/ -name '*.c')) OBJ := ${SRC:.c=.o} TEST_SRC := $(sort $(shell find test/ -name '*.c')) TEST_OBJ := $(TEST_SRC:.c=.o) +DEPS := ${SRC:.c=.d} ${TEST_SRC:.c=.d} + .PHONY: all debug all: doc dunst service @@ -58,11 +60,13 @@ debug: LDFLAGS += ${LDFLAGS_DEBUG} debug: CPPFLAGS += ${CPPFLAGS_DEBUG} debug: all +-include $(DEPS) + +${OBJ} ${TEST_OBJ}: Makefile config.mk + %.o: %.c ${CC} -o $@ -c $< ${CFLAGS} -${OBJ}: config.mk - dunst: ${OBJ} main.o ${CC} -o ${@} ${OBJ} main.o ${CFLAGS} ${LDFLAGS} @@ -122,7 +126,7 @@ endif clean: clean-dunst clean-dunstify clean-doc clean-tests clean-coverage clean-coverage-run clean-dunst: - rm -f dunst ${OBJ} main.o + rm -f dunst ${OBJ} main.o main.d ${DEPS} rm -f org.knopwob.dunst.service rm -f dunst.systemd.service @@ -136,7 +140,7 @@ clean-doc: rm -fr docs/internal/coverage clean-tests: - rm -f test/test test/*.o + rm -f test/test test/*.o test/*.d clean-coverage: clean-coverage-run find . -type f -name '*.gcno' -delete