From f735120b97f74e44c7339068cfe256abc2879f86 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Tue, 16 Apr 2024 22:03:52 +0630 Subject: (Emacs/config)~Makefile auto insert now generates dependencies Using -M* options in gcc and clang we can generate dependencies for C files which can be used by make to rebuild files based on other files. --- Emacs/.config/emacs/config.org | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Emacs/.config/emacs/config.org b/Emacs/.config/emacs/config.org index f46344d..7f9e924 100644 --- a/Emacs/.config/emacs/config.org +++ b/Emacs/.config/emacs/config.org @@ -1081,30 +1081,28 @@ change it for C++. "CC=gcc CFLAGS=-Wall -Wextra -Werror -Wswitch-enum -ggdb -fsanitize=address -std=c11 LIBS= + ARGS= OUT=main.out SRC=src DIST=build - -CODE=$(addprefix $(SRC)/, main.c) +CODE=$(addprefix $(SRC)/, ) # add source files here OBJECTS=$(CODE:$(SRC)/%.c=$(DIST)/%.o) -DEPS=$(OBJECTS:%.o=%.d) +DEPDIR:=$(DIST)/dependencies +DEPFLAGS=-MT $@ -MMD -MP -MF +DEPS:=$(CODE:$(SRC)/%.c=$(DEPDIR):%.d) $(DEPDIR)/main.d .PHONY: all all: $(OUT) $(OUT): $(DIST)/$(OUT) -$(DIST)/$(OUT): $(OBJECTS) - mkdir -p $(DIST) +$(DIST)/$(OUT): $(OBJECTS) $(SRC)/main.o | $(DIST) $(CC) $(CFLAGS) $^ -o $@ $(LIBS) --include $(DEPS) - -$(DIST)/%.o: $(SRC)/%.c - mkdir -p $(DIST) - $(CC) $(CFLAGS) -MMD -c $< -o $@ $(LIBS) +$(DIST)/%.o: $(SRC)/%.c | $(DIST) $(DEPDIR) + $(CC) $(CFLAGS) $(DEPFLAGS) $(DEPDIR)/$*.d -c $< -o $@ $(LIBS) .PHONY: run run: $(DIST)/$(OUT) @@ -1113,6 +1111,14 @@ run: $(DIST)/$(OUT) .PHONY: clean: rm -rfv $(DIST)/* + +$(DIST): + mkdir -p $(DIST) + +$(DEPDIR): + mkdir -p $(DEPDIR) + +-include $(DEPS) " _)) #+end_src -- cgit v1.2.3-13-gbd6f