summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-04-08 21:24:42 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-05-16 03:19:13 +0100
commit59b01f044c8e8e9c522fc5017cf25d6a2299ae66 (patch)
tree2caaf074121a1baa5a4afc8c4c82ca6f6f2b9151
parenta24bd78428f2a8aa3ffda7d3f3d8dbd143cbfcbb (diff)
makefile: updated the dependencies handling method
the makefile now generates .d files and is more robust Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r--Makefile39
1 files changed, 22 insertions, 17 deletions
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