From 38f90d7bd6669bd6f48be178669a6186e40b30de Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 20:36:14 +0100 Subject: Makefile: Use a more complete dependency graph Use the compiler to generate make-compatible dependency files and include them to ensure targets are recompiled when a header file changes. Also make objects depend on the Makefile explicitly to ensure objects are re-built when the makefile changes. --- Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 242e93f..9176f4d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TARGET := stem SRCEXT := c SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT)) OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o)) -CFLAGS := +CFLAGS := -MMD -MP LIB := -L lib -lm INC := -I include @@ -13,7 +13,7 @@ $(TARGET): $(OBJECTS) @echo " Linking..." @echo " $(CC) $^ -o $(TARGET) $(LIB)"; $(CC) $^ -o $(TARGET) $(LIB) -O3 -$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) +$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) Makefile @echo " Building..." @mkdir -p $(BUILDDIR) @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $< -save-temps -O3 @@ -33,3 +33,5 @@ doc: site: doxygen rsync -uvrP --delete-after "html/" root@nullring.xyz:/var/www/stemdoc + +-include $(OBJECTS:.o=.d) -- cgit From 476044b4947632ba2b03bc368a513cba55cb1103 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 2 May 2024 21:04:36 +0100 Subject: Makefile: Add support for generating compile_flags.txt This helps tools like clangd understand where the header files are such that they can be used to navigate the codebase quickly and easily. --- Makefile | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 9176f4d..9ee2833 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,9 @@ $(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT) Makefile @mkdir -p $(BUILDDIR) @echo " $(CC) $(CFLAGS) $(INC) -c -o $@ $<"; $(CC) $(CFLAGS) $(INC) -c -o $@ $< -save-temps -O3 +compile_flags.txt: Makefile + printf "%s\n" $(CFLAGS) $(INC) >$@ + clean: @echo " Cleaning..."; @echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET) -- cgit