-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (73 loc) · 2.75 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
# set project directory one level above the Makefile directory. $(CURDIR) is a
# GNU make variable containing the path to the current working directory
PROJDIR := $(realpath $(CURDIR)/..)
SOURCEDIR := $(realpath $(CURDIR)/code)
BUILDDIR := $(PROJDIR)/build
# executable name
TARGET = together
# show commands?
VERBOSE = FALSE
# create the list of directories. update this when new source files are added
DIRS = main characters engine editor levels menus sound states graphics objects utils
SOURCEDIRS = $(foreach dir, $(DIRS), $(addprefix $(SOURCEDIR)/src/, $(dir)))
TARGETDIRS = $(foreach dir, $(DIRS), $(addprefix $(BUILDDIR)/object-files/, $(dir)))
# Generate the GCC includes parameters by adding -I before each source folder
INCLUDES = $(addsuffix /include, $(SOURCEDIR))
# add this list to VPATH, the place make will look for the source files
VPATH = $(SOURCEDIRS)
# Create a list of *.c sources in DIRS
SOURCES = $(foreach dir,$(SOURCEDIRS),$(wildcard $(dir)/*.c*))
# Define objects for all sources
OBJS := $(subst $(SOURCEDIR),$(BUILDDIR),$(subst /src/,/object-files/,$(SOURCES:%=%.o)))
# Name the compiler
CC = g++
# compiler flags
CFLAGS = -lstdc++ -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf -lGLEW -framework OpenGL
# OS specific part
ifeq ($(OS),Windows_NT)
RM = del /F /Q
RMDIR = -RMDIR /S /Q
MKDIR = -mkdir
ERRIGNORE = 2>NUL || true
SEP=\\
else
RM = rm -rf
RMDIR = rm -rf
MKDIR = mkdir -p
ERRIGNORE = 2>/dev/null
SEP=/
endif
# Remove space after separator
PSEP = $(strip $(SEP))
# Hide or not the calls depending of VERBOSE
ifeq ($(VERBOSE),TRUE)
HIDE =
else
HIDE = @
endif
# Define the function that will generate each rule
define generateRules
$(1)/%.cpp.o: %.cpp
@echo Building $$(subst $$(SOURCEDIR)/src/,,$$<)
$(HIDE)$(CC) -x c++ -c -g -I$$(INCLUDES) -I/usr/local/include -o $$(subst /,$$(PSEP),$$@) $$(subst /,$$(PSEP),$$<) -MMD
$(1)/%.c.o: %.c
@echo Building $$(subst $$(SOURCEDIR)/src/,,$$<)
$(HIDE)$(CC) -x c -c -g -I$$(INCLUDES) -I/usr/local/include -o $$(subst /,$$(PSEP),$$@) $$(subst /,$$(PSEP),$$<) -MMD
endef
# indicate to make which targets are not files
.PHONY: all ../build/resources resources clean directories
all: directories $(BUILDDIR)/$(TARGET) ../build/resources
$(BUILDDIR)/$(TARGET): $(OBJS)
$(HIDE)echo Linking $(subst $(BUILDDIR)/,build/,$@)
$(HIDE)$(CC) $(OBJS) -o $@ $(CFLAGS)
# Generate rules
$(foreach targetdir, $(TARGETDIRS), $(eval $(call generateRules, $(targetdir))))
directories:
$(HIDE)$(MKDIR) $(subst /,$(PSEP),$(TARGETDIRS)) $(ERRIGNORE)
../build/resources: resources
$(HIDE)rsync -rupE resources ../build/
# Remove all objects, dependencies and executable files generated during the build
clean:
$(HIDE)$(RMDIR) $(subst /,$(PSEP),$(TARGETDIRS)) $(ERRIGNORE)
$(HIDE)$(RM) $(TARGET) $(ERRIGNORE)
@echo Cleaning done!