-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmakefile-game
134 lines (110 loc) · 4.91 KB
/
makefile-game
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
# Engine name
override ENGINE_NAME = core
# Engine's home
override ENGINE_HOME = $(ENGINE_FOLDER)
# My home
override MY_HOME = $(shell pwd)
# Where the game lives
override GAME_HOME = $(MY_HOME)
# Project name
override GAME_NAME = $(shell basename $(MY_HOME))
# Game name
override NAME = $(GAME_NAME)
# Common
include $(ENGINE_HOME)/makefile-common
ifneq ($(BUILD_MODE),)
TYPE = $(BUILD_MODE)
endif
DUMP_TARGET =
ifeq ($(DUMP_ELF), 1)
DUMP_TARGET = dump
endif
PAD =
ifeq ($(PAD_ROM), 1)
PAD = pad
endif
# linker script
LINKER_SCRIPT = $(shell pwd)/lib/compiler/linker/vb_$(TYPE).ld
# the target file
TARGET_FILE = output
TARGET = $(WORKING_FOLDER)/$(TARGET_FILE)-$(TYPE)
# define the engine
VUENGINE = $(BUILD_DIR)/lib$(ENGINE_NAME).a
all: printPreBuildingInfo dirs deleteLibraries postDirCleanUp preprocessClasses engine plugins printBuildingInfo $(TARGET).vb $(PAD) $(DUMP_TARGET) printPostBuildingInfo
printPreBuildingInfo:
@echo
@echo "STARTING BUILD"
@$(eval START_TIME=$(shell date +%s))
@echo "Starting at: "$(shell date)
@$(eval HUMAN_START_DATE=$(shell date +%H:%M:%S))
@echo "Build type: $(TYPE)"
@echo "Compiler: $(COMPILER_NAME) $(COMPILER_VERSION)"
@echo "Make Jobs: $(MAKE_JOBS)"
@echo
@echo "Checking dirs..."
@echo
deleteLibraries:
ifeq ($(BUILD_ALL), 1)
@rm -f $(WORKING_FOLDER)/libraries/$(BUILD_MODE)/*.a
@rm -f $(BUILD_DIR)/*.a
endif
@rm -f $(TARGET).elf
postDirCleanUp:
# @echo "Finding total number of components"
@$(shell rm -f $(WORKING_FOLDER)/traces/$(BUILD_MODE)/*omponents.txt*)
@$(shell echo "core" > $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt)
@rm -f $(WORKING_FOLDER)/traces/$(BUILD_MODE)/preprocessing.txt
@rm -f $(WORKING_FOLDER)/*.a
printComponentsToBuildInformation:
@$(shell sort -u $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt > $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt.tmp)
@$(shell sort -u $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt >> $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt.tmp)
@$(shell sort -u $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt > $(WORKING_FOLDER)/traces/$(BUILD_MODE)/builtComponents.txt)
@$(eval COMPONENTS=$(shell wc -l < $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt.tmp))
@echo "Components: $$(($(COMPONENTS) / 2))"
@echo "Build steps: $(COMPONENTS)"
@echo "COMPONENTS=$(COMPONENTS)" > $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt
@cat $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt.tmp >> $(WORKING_FOLDER)/components.txt
@rm -f $(WORKING_FOLDER)/traces/$(BUILD_MODE)/components.txt.tmp
printBuildingInfo:
@echo ""
@$(shell echo $(NAME) >> $(WORKING_FOLDER)/traces/$(BUILD_MODE)/builtComponents.txt)
# @$(eval BUILT_COMPONENTS=$(shell wc -l < $(WORKING_FOLDER)/traces/$(BUILD_MODE)/builtComponents.txt))
@echo "Building $(BASENAME)"
# @echo "($(BUILT_COMPONENTS)/$(COMPONENTS)) Building $(BASENAME)"
printPostBuildingInfo:
@echo "BUILD FINISHED"
@$(eval END_TIME=$(shell date +%s))
@echo Done compiling in $(TYPE) mode with GCC $(COMPILER_VERSION)
@echo "Started at: "$(HUMAN_START_DATE)
@echo "Ended at: "$(shell date +%H:%M:%S)
@echo "Total time:" $$(( ($(END_TIME) - $(START_TIME)) / 60 ))" min. "$$(( ($(END_TIME) - $(START_TIME)) % 60 ))" sec."
portToNewSyntax: dirs
@bash $(ENGINE_HOME)/lib/compiler/preprocessor/cleanSyntax.sh $(ENGINE_HOME) $(MY_HOME)/source $(WORKING_FOLDER)
dump: $(TARGET).elf
@$(OBJDUMP) -t $(TARGET).elf > $(WORKING_FOLDER)/sections-$(TYPE).txt
@$(OBJDUMP) -S $(TARGET).elf > $(WORKING_FOLDER)/machine-$(TYPE).asm
@echo "Memory map $(TARGET).map"
@echo "Sections $(WORKING_FOLDER)/sections-$(TYPE).txt"
@echo "Assembly $(WORKING_FOLDER)/machine-$(TYPE).asm"
@echo
pad: $(TARGET).vb
@echo Padding $(BUILD_DIR)/$(TARGET_FILE).vb
@$(ENGINE_HOME)/lib/utilities/padder $(BUILD_DIR)/$(TARGET_FILE).vb 3
@echo " "
$(TARGET).vb: compile $(TARGET).elf
@$(OBJCOPY) -O binary $(TARGET).elf $@
@cp $(TARGET).vb $(BUILD_DIR)/$(TARGET_FILE).vb
@du -h $(BUILD_DIR)/*.vb
@echo
$(TARGET).elf: $(VUENGINE) $(foreach PLUGIN, $(PLUGINS), $(shell echo $(PLUGIN) | sed -e "s@.*/@@" | sed -e "s@^@$(BUILD_DIR)/lib@").a) $(SETUP_CLASSES_OBJECT).o $(FINAL_SETUP_CLASSES_OBJECT).o
@echo
@echo Linking game library
@$(AR) rcs $(BUILD_DIR)/lib$(GAME_NAME).a $(WORKING_FOLDER)/objects/$(BUILD_MODE)/hashes/$(NAME)/*.o $(WORKING_FOLDER)/assets/$(NAME)/hashes/*.o
@echo Linking $(TARGET).elf...
@echo
@$(CC) -o $@ -nostartfiles -T$(LINKER_SCRIPT) -lm $(WORKING_FOLDER)/objects/$(BUILD_MODE)/hashes/$(NAME)/*.o $(WORKING_FOLDER)/assets/$(NAME)/hashes/*.o $(FINAL_SETUP_CLASSES_OBJECT).o $(BINARY_ASSETS) $(VUENGINE) \
$(foreach PLUGIN, $(PLUGINS),-l$(shell echo $(PLUGIN) | sed -e "s@.*/@@")) $(foreach LIB,$(PLUGINS_PATH),-L$(LIB)) $(VUENGINE) -Wl,-Map=$(TARGET).map
@cp $(TARGET).map $(BUILD_DIR)/output.map
@echo
@du -h build/*.a
@echo