-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
108 lines (86 loc) · 2.91 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# @author clemedon (Clément Vidon)
####################################### BEG_5 ####
NAME := roguelike
#------------------------------------------------#
# INGREDIENTS #
#------------------------------------------------#
# LIBS libraries to be used
# LIBS_TARGET libraries to be built
#
# INCS header file locations
#
# SRC_DIR source directory
# SRCS source files
#
# BUILD_DIR build directory
# OBJS object files
# DEPS dependency files
#
# CC compiler
# CFLAGS compiler flags
# CPPFLAGS preprocessor flags
# LDFLAGS linker flags
# LDLIBS libraries name
LIBS := m uncursed glib-2.0 dijkstra rlsmenu flecs
LIBS_TARGET := lib/rlsmenu/rlsmenu.a lib/flecs/flecs.a lib/DijkstraMap/dijkstra.a
INCS := include lib/rlsmenu/ lib/flecs/include lib/DijkstraMap/include
SRC_DIR := $(shell realpath src)
SRCS := ai.c component.c gui.c input.c item.c log.c main.c map.c \
monster.c observer.c player.c religion.c render.c systems.c
SRCS := $(SRCS:%=$(SRC_DIR)/%)
BUILD_DIR := $(shell realpath build)
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
CC := gcc
CFLAGS := -g3 $(shell pkg-config --cflags glib-2.0) -Wall -Wextra -Werror -std=gnu11
CFLAGS += $(addprefix -I,$(INCS)) -MMD -MP
LDFLAGS := $(addprefix -L,$(dir $(LIBS_TARGET)))
LDFLAGS += -fsanitize=undefined -fno-sanitize-recover
LDLIBS := $(addprefix -l,$(LIBS))
#------------------------------------------------#
# UTILITIES #
#------------------------------------------------#
# RM force remove
# MAKEFLAGS make flags
# DIR_DUP duplicate directory tree
RM := rm -f
MAKEFLAGS += --silent --no-print-directory
DIR_DUP = mkdir -p $(@D)
#------------------------------------------------#
# RECIPES #
#------------------------------------------------#
# all default goal
# $(NAME) link .o -> archive
# $(LIBS) build libraries
# %.o compilation .c -> .o
# clean remove .o
# fclean remove .o + binary
# re remake default goal
# run run the program
# info print the default goal recipe
all: $(NAME)
$(NAME): $(OBJS) $(LIBS_TARGET)
$(CC) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $(NAME)
$(info CREATED $(NAME))
$(LIBS_TARGET):
$(MAKE) -C $(@D)
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(DIR_DUP)
$(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
$(info CREATED $@)
-include $(DEPS)
clean:
$(RM) $(OBJS) $(DEPS)
$(RM) $(NAME)
fclean: clean
for f in $(dir $(LIBS_TARGET)); do $(MAKE) -C $$f clean; done
re:
$(MAKE) fclean
$(MAKE) all
info-%:
$(MAKE) --dry-run --always-make $* | grep -v "info"
#------------------------------------------------#
# SPEC #
#------------------------------------------------#
.PHONY: clean fclean re
.SILENT: