-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
117 lines (83 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
108
109
110
111
112
113
114
115
116
117
-include Makefile.inc
LIBRARY_NAME=d2x
BASE_DIR=$(shell pwd)
SRC_DIR=$(BASE_DIR)/src
SAMPLES_DIR=$(BASE_DIR)/samples
BUILD_DIR?=$(BASE_DIR)/build
INCLUDE_DIR=$(BASE_DIR)/include
INCLUDES=$(wildcard $(INCLUDE_DIR)/*.h) $(wildcard $(INCLUDE_DIR)/*/*.h)
INCLUDES+=$(wildcard $(BUILDIT_DIR)/include/*.h) $(wildcard $(BUILDIT_DIR)/include/*/*.h)
INCLUDES+=$(BUILDIT_DIR)/build/gen_headers/gen/compiler_headers.h
DEBUG ?= 0
# Config is ready, check if config is consistent
CHECK_CONFIG=1
ifeq ($(MAKECMDGOALS), compile-flags)
CHECK_CONFIG=0
endif
ifeq ($(MAKECMDGOALS), linker-flags)
CHECK_CONFIG=0
endif
ifeq ($(MAKECMDGOALS), gdb-command)
CHECK_CONFIG=0
endif
ifeq ($(CHECK_CONFIG), 1)
CONFIG_STR=DEBUG=$(DEBUG)
CONFIG_FILE=$(BUILD_DIR)/build.config
$(shell mkdir -p $(BUILD_DIR))
$(shell touch $(CONFIG_FILE))
ifneq ($(shell cat $(CONFIG_FILE)), $(CONFIG_STR))
$(warning Previous config and current config does not match! Rebuilding)
$(shell rm -rf $(BUILD_DIR))
$(shell mkdir -p $(BUILD_DIR))
$(shell echo $(CONFIG_STR) > $(CONFIG_FILE))
endif
endif
$(shell mkdir -p $(BUILD_DIR))
$(shell mkdir -p $(BUILD_DIR)/samples)
$(shell mkdir -p $(BUILD_DIR)/runtime)
CFLAGS_INTERNAL=-std=c++11
CFLAGS=
LINKER_FLAGS=
INCLUDE_FLAGS=
ifeq ($(DEBUG),1)
CFLAGS+=-g
LINKER_FLAGS+=-l$(LIBRARY_NAME) -g
else
CFLAGS_INTERNAL+=-O3
LINKER_FLAGS+=-l$(LIBRARY_NAME)
endif
BUILDIT_CFLAGS=$(shell make --no-print-directory -C $(BUILDIT_DIR) compile-flags)
BUILDIT_LINK_FLAGS=$(shell make --no-print-directory -C $(BUILDIT_DIR) linker-flags)
CFLAGS_INTERNAL+=-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wmissing-declarations -Woverloaded-virtual -Wno-deprecated -Wdelete-non-virtual-dtor -Werror -Wno-vla
INCLUDE_FLAGS=-I$(INCLUDE_DIR) $(BUILDIT_CFLAGS)
CFLAGS_INTERNAL+=-pedantic-errors
LINKER_FLAGS+=-L$(BUILD_DIR)/ $(BUILDIT_LINK_FLAGS)
SRC=$(wildcard $(SRC_DIR)/*.cpp)
SAMPLE_SRC=$(wildcard $(SAMPLES_DIR)/*.cpp)
OBJS=$(subst $(SRC_DIR),$(BUILD_DIR),$(SRC:.cpp=.o))
SAMPLE_OBJS=$(subst $(SAMPLES_DIR),$(BUILD_DIR)/samples,$(SAMPLE_SRC:.cpp=.o))
SAMPLES=$(subst $(SAMPLES_DIR),$(BUILD_DIR),$(SAMPLE_SRC:.cpp=))
LIBRARY_OBJS=$(OBJS)
LIBRARY=$(BUILD_DIR)/lib$(LIBRARY_NAME).a
all: $(LIBRARY) executables
lib: $(LIBRARY)
.PRECIOUS: $(BUILD_DIR)/%.o $(BUILD_DIR)/samples/%.o
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(INCLUDES)
$(CXX) $(CFLAGS_INTERNAL) $(CFLAGS) $< -o $@ $(INCLUDE_FLAGS) -c
$(BUILD_DIR)/samples/%.o: $(SAMPLES_DIR)/%.cpp $(INCLUDES)
$(CXX) $(CFLAGS) $< -o $@ $(INCLUDE_FLAGS) -c -DBASE_DIR_X=$(BASE_DIR)
$(LIBRARY): $(LIBRARY_OBJS)
ar rv $(LIBRARY) $(LIBRARY_OBJS)
$(BUILD_DIR)/sample%: $(BUILD_DIR)/samples/sample%.o $(LIBRARY)
$(CXX) -o $@ $< $(LINKER_FLAGS)
.PHONY: executables
executables: $(SAMPLES)
clean:
- rm -rf $(BUILD_DIR)
.PHONY: compile-flags linker-flags
compile-flags:
@echo $(CFLAGS) $(INCLUDE_FLAGS)
linker-flags:
@echo $(LINKER_FLAGS)
gdb-command:
@echo gdb --command=$(BASE_DIR)/helpers/gdb/d2x-gdb.init