From 59b01f044c8e8e9c522fc5017cf25d6a2299ae66 Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Wed, 8 Apr 2015 21:24:42 +0100 Subject: makefile: updated the dependencies handling method the makefile now generates .d files and is more robust Signed-off-by: Olivier Gayot --- Makefile | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'Makefile') diff --git a/Makefile b/Makefile index e01cd74..6c561a4 100644 --- a/Makefile +++ b/Makefile @@ -1,30 +1,35 @@ -CC ?= gcc -CFLAGS += -W -Wall -std=c99 -Wextra $(shell sdl-config --cflags) -LDFLAGS += $(shell sdl-config --libs) -lSDL_image -lSDL_ttf -NAME = rpg -SRC = $(wildcard *.c) +NAME = rpg +SRC = $(wildcard *.c) -all: depend $(NAME) +CPPFLAGS += $(shell sdl-config --cflags) +LDFLAGS += $(shell sdl-config --libs) -lSDL_image -lSDL_ttf +CFLAGS += -W -Wall -Wextra -std=gnu99 -depend: .depend +CC = gcc -.depend: $(SRC) - @$(RM) .depend - @$(CC) $(CFLAGS) -MM $^ > .depend +OBJ = $(SRC:.c=.o) +DEP = $(SRC:.c=.d) -include .depend - -OBJ = $(SRC:.c=.o) +all: $(NAME) $(NAME): $(OBJ) $(CC) -o $@ $^ $(LDFLAGS) +-include $(DEP) + +%.d: %.c + $(CC) -MM $(CPPFLAGS) $(CFLAGS) $< -MF $@ -MT "$*.o $@" + clean: $(RM) $(OBJ) - -fclean: clean $(RM) $(NAME) -re: fclean all +mrproper: clean + $(RM) $(DEP) + +distclean: mrproper + $(RM) $(addsuffix ~,$(SRC)) + $(RM) $(wildcard $(addsuffix .sw*,$(addprefix .,$(SRC)))) + +.PHONY: all clean mrproper distclean -.PHONY: all depend clean fclean all re -- cgit v1.2.3