-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
makefile-compile
230 lines (190 loc) · 13.1 KB
/
makefile-compile
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# Clean plugin name by stripping out everything up to (and including) the last slash
BASENAME = $(shell echo $(NAME) | sed -e "s@.*/@@")
# Engine name
override ENGINE_NAME = core
# Engine's home
override ENGINE_HOME = $(ENGINE_FOLDER)
# Small data sections' usage
MSDA_SIZE = 0
MEMORY_POOL_SECTION =
NON_INITIALIZED_GLOBAL_DATA_SECTION =
INITIALIZED_GLOBAL_DATA_SECTION =
STATIC_SINGLETONS_DATA_SECTION =
VIRTUAL_TABLES_DATA_SECTION =
MEMORY_POOL_SECTION_ATTRIBUTE = __MEMORY_POOL_SECTION_ATTRIBUTE=
NON_INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE = __NON_INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE=
INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE = __INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE=
STATIC_SINGLETONS_DATA_SECTION_ATTRIBUTE = __STATIC_SINGLETONS_DATA_SECTION_ATTRIBUTE=
VIRTUAL_TABLES_DATA_SECTION_ATTRIBUTE = __VIRTUAL_TABLES_DATA_SECTION_ATTRIBUTE=
include $(ENGINE_HOME)/makefile-compiler
-include $(GAME_CONFIG_MAKE_FILE)
-include $(PLUGIN_CONFIG_MAKE_FILE)
OPTIMIZATION_OPTION = -O0
ifneq ($(OPTIMIZATION),)
OPTIMIZATION_OPTION = -$(OPTIMIZATION)
endif
PEDANTIC_WARNINGS_FLAG =
ifeq ($(PRINT_PEDANTIC_WARNINGS), 1)
PEDANTIC_WARNINGS_FLAG = -pedantic
endif
STORE_SUFFIX =
PROLOG_FUNCTIONS_FLAG = -mno-prolog-function
ifeq ($(USE_PROLOG_FUNCTIONS), 1)
PROLOG_FUNCTIONS_FLAG = -mprolog-function
STORE_SUFFIX = -pf
endif
FRAME_POINTER_USAGE_FLAG = -fomit-frame-pointer
ifeq ($(USE_FRAME_POINTER), 1)
FRAME_POINTER_USAGE_FLAG = -fno-omit-frame-pointer
endif
USE_CUSTOM_LINKER_SCRIPT =
ifneq ($(MEMORY_POOL_SECTION),)
MEMORY_POOL_SECTION_ATTRIBUTE = __MEMORY_POOL_SECTION_ATTRIBUTE="__attribute__((section(\"$(MEMORY_POOL_SECTION)\")))"
USE_CUSTOM_LINKER_SCRIPT = 1
endif
ifneq ($(NON_INITIALIZED_GLOBAL_DATA_SECTION),)
NON_INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE = __NON_INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE="__attribute__((section(\"$(NON_INITIALIZED_GLOBAL_DATA_SECTION)\")))"
USE_CUSTOM_LINKER_SCRIPT = 1
endif
ifneq ($(INITIALIZED_GLOBAL_DATA_SECTION),)
INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE = __INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE="__attribute__((section(\"$(INITIALIZED_GLOBAL_DATA_SECTION)\")))"
USE_CUSTOM_LINKER_SCRIPT = 1
endif
ifneq ($(STATIC_SINGLETONS_DATA_SECTION),)
STATIC_SINGLETONS_DATA_SECTION_ATTRIBUTE = __STATIC_SINGLETONS_DATA_SECTION_ATTRIBUTE="__attribute__((section(\"$(STATIC_SINGLETONS_DATA_SECTION)\")))"
USE_CUSTOM_LINKER_SCRIPT = 1
endif
ifneq ($(VIRTUAL_TABLES_DATA_SECTION),)
VIRTUAL_TABLES_DATA_SECTION_ATTRIBUTE = __VIRTUAL_TABLES_DATA_SECTION_ATTRIBUTE="__attribute__((section(\"$(VIRTUAL_TABLES_DATA_SECTION)\")))"
USE_CUSTOM_LINKER_SCRIPT = 1
endif
DATA_SECTION_ATTRIBUTES = $(MEMORY_POOL_SECTION_ATTRIBUTE) $(NON_INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE) $(INITIALIZED_GLOBAL_DATA_SECTION_ATTRIBUTE) $(STATIC_SINGLETONS_DATA_SECTION_ATTRIBUTE) $(VIRTUAL_TABLES_DATA_SECTION_ATTRIBUTE)
# Common macros for all build types
COMMON_MACROS = $(DATA_SECTION_ATTRIBUTES)
# The following blocks change some variables depending on the build type
ifeq ($(TYPE),debug)
C_PARAMS = $(ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline
C_PARAMS_FOR_ASSETS = $(ASSETS_ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline
MACROS = __DEBUG __TOOLS $(COMMON_MACROS)
endif
ifeq ($(TYPE), release)
C_PARAMS = $(ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline -save-temps=obj
C_PARAMS_FOR_ASSETS = $(ASSETS_ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline
MACROS = __RELEASE $(COMMON_MACROS)
endif
ifeq ($(TYPE), beta)
C_PARAMS = $(ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline
C_PARAMS_FOR_ASSETS = $(ASSETS_ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline
MACROS = __BETA $(COMMON_MACROS)
endif
ifeq ($(TYPE), tools)
C_PARAMS = $(ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline
C_PARAMS_FOR_ASSETS = $(ASSETS_ESSENTIAL_HEADERS) $(PROLOG_FUNCTIONS_FLAG) $(FRAME_POINTER_USAGE_FLAG) $(PEDANTIC_WARNINGS_FLAG) $(OPTIMIZATION_OPTION) -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -finline-functions -Winline
MACROS = __TOOLS $(COMMON_MACROS)
endif
ifeq ($(TYPE), preprocessor)
C_PARAMS = -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -E
C_PARAMS_FOR_ASSETS = -std=gnu99 -mv810 -nodefaultlibs -Wall -Wextra -E
MACROS = $(COMMON_MACROS)
endif
# Add directories to the includes in order of overriding priority: game, then plugins
INCLUDE_PATHS = $(shell find $(WORKING_FOLDER)/headers/$(GAME_NAME) -type d -print)
INCLUDE_PATHS := $(INCLUDE_PATHS) $(shell find $(WORKING_FOLDER)/headers -path $(WORKING_FOLDER)/headers/$(GAME_NAME) -prune -o -type d -print)
PLUGINS_CLEAN = $(shell echo $(PLUGINS) | sed -r "s@(user//|vuengine//)@/@g")
# Obligatory headers
ESSENTIAL_HEADERS = $(shell if [ ! -z $(CONFIG_FILE) ]; then echo -include $(CONFIG_FILE); fi;) \
$(shell if [ ! -z $(DEBUG_CONFIG_FILE) ]; then echo -include $(DEBUG_CONFIG_FILE); fi;) \
-include $(WORKING_FOLDER)/headers/$(ENGINE_NAME)/headers/LibVUEngine.h \
$(foreach PLUGIN, $(PLUGINS_CLEAN), $(shell if [ -f $(PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h ]; then \
echo -include $(PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h; fi; )) \
$(foreach PLUGIN, $(PLUGINS_CLEAN), $(shell if [ -f $(USER_PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h ]; then \
echo -include $(USER_PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h; fi; )) \
$(shell if [ -f $(MY_HOME)/headers/Config.h ]; then echo -include $(MY_HOME)/headers/Config.h; fi;) \
ASSETS_ESSENTIAL_HEADERS = $(shell if [ ! -z $(CONFIG_FILE) ]; then echo -include $(CONFIG_FILE); fi;) \
$(shell if [ ! -z $(DEBUG_CONFIG_FILE) ]; then echo -include $(DEBUG_CONFIG_FILE); fi;) \
-include $(WORKING_FOLDER)/headers/$(ENGINE_NAME)/headers/MinimalLib.h \
$(foreach PLUGIN, $(PLUGINS_CLEAN), $(shell if [ -f $(PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h ]; then \
echo -include $(PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h; fi; )) \
$(foreach PLUGIN, $(PLUGINS_CLEAN), $(shell if [ -f $(USER_PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h ]; then \
echo -include $(USER_PLUGINS_FOLDER)/$(PLUGIN)/headers/Config.h; fi; )) \
$(shell if [ -f $(MY_HOME)/headers/Config.h ]; then echo -include $(MY_HOME)/headers/Config.h; fi;) \
# Class setup file
SETUP_CLASSES = $(BASENAME)SetupClasses
SETUP_CLASSES_SOURCE = $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$(SETUP_CLASSES)
SETUP_CLASSES_OBJECT = $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$(SETUP_CLASSES)
FINAL_SETUP_CLASSES = setupClasses
FINAL_SETUP_CLASSES_SOURCE = $(WORKING_FOLDER)/objects/$(BUILD_MODE)/setupClasses
FINAL_SETUP_CLASSES_OBJECT = $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(FINAL_SETUP_CLASSES)
ASSETS_OBJECTS = $(file < $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/ASSETS_OBJECTS.txt)
C_OBJECTS = $(file < $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/C_OBJECTS.txt)
ASSEMBLY_OBJECTS = $(file < $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/ASSEMBLY_OBJECTS.txt)
compile: phony $(C_OBJECTS) $(ASSETS_OBJECTS) $(SETUP_CLASSES_OBJECT).o $(FINAL_SETUP_CLASSES_OBJECT).o
$(SETUP_CLASSES_OBJECT).o: $(SETUP_CLASSES_SOURCE).c
@$(CC) -c -Wp,-MD,$*.dd $(foreach INC,$(INCLUDE_PATHS),-I$(INC))\
$(foreach MACRO,$(MACROS),-D$(MACRO)) $(C_PARAMS) $< -o $@
@$(eval OBJECT_FILE=$@)
@$(eval RELATIVE_OBJECT_FILE=$(shell echo $(OBJECT_FILE) | sed -E "s@$(GAME_HOME)@@g"))
@$(eval HASH_OBJECT=$(shell echo $(RELATIVE_OBJECT_FILE) | shasum | cut -d' ' -f1))
@cp $(OBJECT_FILE) $(WORKING_FOLDER)/objects/$(BUILD_MODE)/hashes/$(NAME)/$(HASH_OBJECT).o
@sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' $*.dd > $*.d
@rm -f $*.dd
$(FINAL_SETUP_CLASSES_OBJECT).o: $(FINAL_SETUP_CLASSES_SOURCE).c
@$(CC) -c -Wp,-MD,$*.dd $(foreach INC,$(INCLUDE_PATHS),-I$(INC))\
$(foreach MACRO,$(MACROS),-D$(MACRO)) $(C_PARAMS) $< -o $@
@sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' $*.dd > $*.d
# Compile asset files
$(WORKING_FOLDER)/assets/$(NAME)/%.o: $(MY_HOME)/%.c
@$(eval SOURCE_FILE=$(shell echo $< | sed -E "s@$(MY_HOME)/assets/@@g"))
@echo "Compiling asset file: $(SOURCE_FILE)"
@$(eval OBJECT_FILE=$@)
@$(eval RELATIVE_OBJECT_FILE=$(shell echo $(OBJECT_FILE) | sed -E "s@$(GAME_HOME)@@g"))
@$(eval HASH_OBJECT=$(shell echo $(RELATIVE_OBJECT_FILE) | shasum | cut -d' ' -f1))
@rm -f $(OBJECT_FILE)
@$(CC) -c -Wp,-MD,$(WORKING_FOLDER)/assets/$(NAME)/$*.dd $(foreach INC,$(INCLUDE_PATHS),-I$(INC))\
$(foreach MACRO,$(MACROS),-D$(MACRO)) $(C_PARAMS_FOR_ASSETS) -x c $< -o $@ 2>&1 | bash $(ENGINE_HOME)/lib/compiler/preprocessor/processGCCOutput.sh -o $(OBJECT_FILE) -w $(WORKING_FOLDER) -h $(MY_HOME) -n $(NAME) -l $(PLUGINS_FOLDER)/../ -p "$(PLUGINS)"
@cp $(OBJECT_FILE) $(WORKING_FOLDER)/assets/$(NAME)/hashes/$(HASH_OBJECT).o
@sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' $(WORKING_FOLDER)/assets/$(NAME)/$*.dd > $(WORKING_FOLDER)/assets/$(NAME)/$*.d
# Compile source files
$(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/%.o: $(MY_HOME)/%.c
@$(eval RAW_SOURCE_FILE=$<)
@$(eval SOURCE_FILE=$(shell echo $< | sed -E "s@.*/(source|assets)/@$(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/\1/@g"))
@$(eval OBJECT_FILE=$@)
@$(eval RELATIVE_OBJECT_FILE=$(shell echo $(OBJECT_FILE) | sed -E "s@$(GAME_HOME)@@g"))
@$(eval HASH_OBJECT=$(shell echo $(RELATIVE_OBJECT_FILE) | shasum | cut -d' ' -f1))
@rm -f $(OBJECT_FILE)
@bash $(ENGINE_HOME)/lib/compiler/preprocessor/processSourceFile.sh -e $(ENGINE_HOME) -i $(RAW_SOURCE_FILE) -o $(SOURCE_FILE) -d -w $(WORKING_FOLDER) -c $(CLASSES_HIERARCHY_FILE) && \
$(CC) -c -Wp,-MD,$(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$*.dd $(foreach INC,$(INCLUDE_PATHS),-I$(INC)) \
$(foreach MACRO,$(MACROS),-D$(MACRO)) $(C_PARAMS) $(SOURCE_FILE) -o $(OBJECT_FILE) 2>&1 | bash $(ENGINE_HOME)/lib/compiler/preprocessor/processGCCOutput.sh -o $(OBJECT_FILE) -w $(WORKING_FOLDER) -h $(MY_HOME) -n $(NAME) -l $(PLUGINS_FOLDER)/../ -p "$(PLUGINS)"
@cp $(OBJECT_FILE) $(WORKING_FOLDER)/objects/$(BUILD_MODE)/hashes/$(NAME)/$(HASH_OBJECT).o
@sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $(OBJECT_FILE)))\1/' $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$*.dd > $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$*.dd.tmp
@sed -e 's#$(SOURCE_FILE)##' $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$*.dd.tmp > $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$*.dd
@sed -e '/^[ \\]*$$/d' $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$*.dd > $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$*.d
# Compile assembler files
$(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/%.o: $(MY_HOME)/%.s
@bash $(ENGINE_HOME)/lib/compiler/preprocessor/printCompilingInfo.sh $<
@$(eval OBJECT_FILE=$@)
@$(eval RELATIVE_OBJECT_FILE=$(shell echo $(OBJECT_FILE) | sed -E "s@$(GAME_HOME)@@g"))
@$(eval HASH_OBJECT=$(shell echo $(RELATIVE_OBJECT_FILE) | shasum | cut -d' ' -f1))
@$(AS) -o $@ $<
@cp $(OBJECT_FILE) $(WORKING_FOLDER)/objects/$(BUILD_MODE)/hashes/$(NAME)/$(HASH_OBJECT).o
$(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/%.bin: $(MY_HOME)/%.mid
@$(eval OLD_SYMBOL_NAME=_binary_$(shell echo $< | sed -e "s@[/-]@_@g" | sed -e "s@.mid@_mid_start@g"))
@$(eval NEW_SYMBOL_NAME=_$(shell echo $< | sed -e "s@.*/@@g" | sed -e "s@.mid@@g" | sed -e "s/[A-Z]/_&/g;s/^_//" | tr '[:lower:]' '[:upper:]'))
@$(OBJCOPY) -I binary -O elf32-v810 -B v810 --rename-section .data=.rodata --redefine-sym $(OLD_SYMBOL_NAME)=$(NEW_SYMBOL_NAME) $< $@
D_FILES = $(C_OBJECTS:.o=.d)
D_FILES := $(D_FILES) $(ASSETS_OBJECTS:.o=.d)
D_FILES := $(D_FILES) $(WORKING_FOLDER)/objects/$(BUILD_MODE)/$(NAME)/$(SETUP_CLASSES).d
-include $(D_FILES)
phony:
@echo > /dev/null
# @echo ASSETS_OBJECTS $(ASSETS_OBJECTS)
# @echo $(D_FILES)
# @echo $(INCLUDE_PATHS)
# @echo WORKING_FOLDER $(WORKING_FOLDER)
# @echo GAME_NAME $(GAME_NAME)
# @echo NAME $(NAME)
# @echo PLUGINS $(PLUGINS)
# @echo $(INCLUDE_PATHS)
# @$(bash sed -e 's@$(INCLUDE_PATH_CLEAN_PREFIX)/@@g' <<< $(INCLUDE_PATHS) )
# @echo Using config $(CONFIG_FILE)
# @echo Using config $(ESSENTIAL_HEADERS)