(Emacs)~Makefile autoinsert now does dependency tracking

Figured this out during stack-vm.c development: a way for Makefiles to
do proper dependency tracking using gcc's option -MMD.
This commit is contained in:
2023-09-29 17:07:21 +01:00
parent b23acc3bbe
commit 7c09c2c22c

View File

@@ -2520,25 +2520,41 @@ change it for C++.
(("[mM]akefile\\'" . "Makefile skeleton") (("[mM]akefile\\'" . "Makefile skeleton")
"" ""
"CC=gcc "CC=gcc
CFLAGS=-Wall -Wextra -Wpedantic -ggdb -fsanitize=address -std=c11 CFLAGS=-Wall -Wextra -Werror -Wswitch-enum -ggdb -fsanitize=address -std=c11
LIBS= LIBS=
OBJECTS=main.o
OUT=main
ARGS= ARGS=
OUT=main.out
%.o: %.c SRC=src
$(CC) $(CFLAGS) -c $^ -o $@ $(LIBS) DIST=build
$(OUT): $(OBJECTS) CODE=$(addprefix $(SRC)/, main.c)
OBJECTS=$(CODE:$(SRC)/%.c=$(DIST)/%.o)
DEPS=$(OBJECTS:%.o=%.d)
.PHONY: all
all: $(OUT)
$(OUT): $(DIST)/$(OUT)
$(DIST)/$(OUT): $(OBJECTS)
mkdir -p $(DIST)
$(CC) $(CFLAGS) $^ -o $@ $(LIBS) $(CC) $(CFLAGS) $^ -o $@ $(LIBS)
-include $(DEPS)
$(DIST)/%.o: $(SRC)/%.c
mkdir -p $(DIST)
$(CC) $(CFLAGS) -MMD -c $< -o $@ $(LIBS)
.PHONY: run
run: $(DIST)/$(OUT)
./$^ $(ARGS)
.PHONY: .PHONY:
clean: clean:
rm -rfv $(OUT) $(OBJECTS) rm -rfv $(DIST)/*
"
.PHONY: run
run: $(OUT)
./$^ $(ARGS)"
_)) _))
#+end_src #+end_src
* Org mode * Org mode