-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMAKEFILE
88 lines (67 loc) · 1.89 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
PROJ_DIR := $(realpath $(CURDIR)/.)
SOURCE_DIR := $(PROJ_DIR)
BUILD_DIR := $(PROJ_DIR)/Build
# Name of the file
ifdef target_file
TARGET = $(target_file)
else
TARGET = ${PROJ_DIR}/YetAnotherChessGame
endif
# Enable Verbose-Mode
ifdef verbose
VERBOSE = TRUE
else
VERBOSE = FALSE
endif
# List of directories in project
DIR_LIST = gui helper model model/figures model/moves
SOURCE_DIRS = $(foreach dir, $(DIR_LIST), $(addprefix $(SOURCE_DIR)/, $(dir)))
TARGET_DIRS = $(foreach dir, $(DIR_LIST), $(addprefix $(BUILD_DIR)/, $(dir)))
INCLUDES = $(foreach dir, $(SOURCE_DIRS), $(addprefix -I, $(dir)))
VPATH = $(SOURCE_DIRS)
SOURCES = $(foreach dir, $(SOURCE_DIRS), $(wildcard $(dir)/*.cpp))
OBJECTS := $(subst $(SOURCE_DIR), $(BUILD_DIR), $(SOURCES:.cpp=.o))
DEPS := $(OBJECTS:.o=.d)
CC = g++
ifeq ($(OS),Windows_NT)
RM = del /F /Q
RMDIR = -RMDIR /S /Q
MKDIR = -mkdir
ERRIGNORE = 2>nul
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)/%.o: %.cpp
@echo Building $$@
$(HIDE)$(CC) -std=c++11 -c $$(INCLUDES) -o $$(subst /,$$(PSEP),$$@) $$(subst /,$$(PSEP),$$<) -MMD
endef
.PHONY: all clean directories
all: directories $(TARGET)
$(TARGET): $(OBJECTS)
$(HIDE)echo Linking $@
$(HIDE)$(CC) -std=c++11 $(OBJECTS) -o $(TARGET)
# Include dependencies
-include $(DEPS)
# Generate rules
$(foreach targetdir, $(TARGET_DIRS), $(eval $(call generateRules, $(targetdir))))
directories:
$(HIDE)$(MKDIR) $(subst /,$(PSEP),$(TARGET_DIRS))
# Remove all objects, dependencies and executable files generated during the build
clean:
$(HIDE)$(RMDIR) $(subst /,$(PSEP),$(TARGET_DIRS)) $(ERRIGNORE)
@echo Cleaning done !