From 3748fa7d7a977f4e31c52ec8b4e66aa9e736342b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 18 Jun 2015 23:58:14 -0400 Subject: Makefile: Auto-generate dependencies. --- Makefile | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index 2a115a4..77da3e5 100644 --- a/Makefile +++ b/Makefile @@ -10,19 +10,27 @@ ##################################################################### CC ?= gcc -CFLAGS ?= -std=c99 -g -Og -Wall -D_DEFAULT_SOURCE +CFLAGS ?= -g -Og -Wall LDFLAGS ?= +DEPFLAGS ?= -MD -MP -MF $(@:.o=.d) RM ?= rm -f -DEPS := bftw.h +LOCAL_CPPFLAGS := -D_DEFAULT_SOURCE +LOCAL_CFLAGS := -std=c99 + +ALL_CPPFLAGS = $(LOCAL_CPPFLAGS) $(CPPFLAGS) +ALL_CFLAGS = $(ALL_CPPFLAGS) $(LOCAL_CFLAGS) $(CFLAGS) $(DEPFLAGS) +ALL_LDFLAGS = $(LDFLAGS) bfs: bfs.o bftw.o - $(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ + $(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $^ -o $@ -%.o: %.c $(DEPS) - $(CC) $(CFLAGS) -c $< -o $@ +%.o: %.c + $(CC) $(ALL_CFLAGS) -c $< -o $@ clean: - $(RM) bfs *.o + $(RM) bfs *.o *.d .PHONY: clean + +-include $(wildcard *.d) -- cgit v1.2.3