-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
153 lines (117 loc) · 4.58 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
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
#Makefile taken from Wikipedia.org
#
# Specify the main target
TARGET = output
# Default build type
#TYPE = debug
TYPE = release
#TYPE = preprocessor
# Which directories contain source files
DIRS := $(shell find * -type d -print)
# Which libraries are linked
LIBS =
ROMHEADER=lib/vb.hdr
# Dynamic libraries
DLIBS =
# Obligatory headers
VBJAENGINE = $(VBDE)/libs/vbjaengine
VBJANEGINE_CONFIG_FILE = $(shell pwd)/config.h
GAME_ESSENTIALS = -include $(VBJANEGINE_CONFIG_FILE) \
-include $(VBJAENGINE)/libvbjae.h
# The next blocks change some variables depending on the build type
ifeq ($(TYPE),debug)
LDPARAM = -fno-builtin -ffreestanding -T$(VBJAENGINE)/lib/compiler/extra/vb.ld -L/opt/gccvb/v810/lib/ -L/opt/gccvb/v810/include/ -lm -lvbjae
CCPARAM = -fno-builtin -ffreestanding -nodefaultlibs -mv810 -O0 -Wall $(GAME_ESSENTIALS)
MACROS = __DEBUG
endif
ifeq ($(TYPE), release)
LDPARAM = -T$(VBJAENGINE)/lib/compiler/extra/vb.ld -L/opt/gccvb/v810/lib/ -L/opt/gccvb/v810/include/ -lm -lvbjae
CCPARAM = -nodefaultlibs -mv810 -finline-functions -Wall -O3 -Winline $(GAME_ESSENTIALS)
MACROS =
endif
ifeq ($(TYPE), release-tools)
LDPARAM = -T$(VBJAENGINE)/lib/compiler/extra/vb.ld -L/opt/gccvb/v810/lib/ -L/opt/gccvb/v810/include/ -lm -lvbjae
CCPARAM = -nodefaultlibs -mv810 -finline-functions -Wall -O3 -Winline $(GAME_ESSENTIALS)
MACROS = __DEBUG_TOOLS __STAGE_EDITOR __ANIMATION_EDITOR
endif
ifeq ($(TYPE),preprocessor)
LDPARAM = -T$(VBJAENGINE)/lib/compiler/extra/vb.ld -L/opt/gccvb/v810/lib/ -L/opt/gccvb/v810/include/ -lm -lvbjae
CCPARAM = -nodefaultlibs -mv810 -Wall -Winline $(GAME_ESSENTIALS) -E
MACROS = __DEBUG __DEBUG_TOOLS __STAGE_EDITOR __ANIMATION_EDITOR
endif
# Add directories to the include and library paths
INCPATH_ENGINE := $(shell find $(VBJAENGINE) -type d -print)
INCPATH_GAME := $(shell find * -type d -print)
LIBPATH =
# Which files to add to backups, apart from the source code
EXTRA_FILES = makefile
# The compiler
GCC = v810-gcc
OBJCOPY = v810-objcopy
OBJDUMP = v810-objdump
# Where to store object and dependancy files.
STORE = .make-$(TYPE)
# Makes a list of the source (.cpp) files.
SOURCE := $(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.c))
# List of header files.
HEADERS := $(foreach DIR,$(DIRS),$(wildcard $(DIR)/*.h))
# Makes a list of the object files that will have to be created.
OBJECTS := $(addprefix $(STORE)/, $(SOURCE:.c=.o))
# Same for the .d (dependancy) files.
DFILES := $(addprefix $(STORE)/,$(SOURCE:.c=.d))
# Specify phony rules. These are rules that are not real files.
.PHONY: clean backup dirs
# Main target. The @ in front of a command prevents make from displaying
# it to the standard output.
# first build the engine
ENGINE = libvbjae.a
pad: $(TARGET).vb
@echo "Padding " $(TARGET).vb
@$(VBJAENGINE)/lib/utilities/padder $(TARGET).vb
all: $(TARGET).vb
deleteEngine:
@rm -f $(ENGINE)
$(ENGINE): deleteEngine
$(MAKE) -f $(VBJAENGINE)/makefile $@ -e TYPE=$(TYPE) -e CONFIG_FILE=$(VBJANEGINE_CONFIG_FILE)
$(TARGET).vb: main.elf
@echo Creating $@
@$(OBJCOPY) -O binary main.elf $@
@echo $(TARGET).vb done
asm: main.elf
@echo Generating assembler code...
@$(OBJDUMP) -t main.elf > sections.txt
@$(OBJDUMP) -S main.elf > machine.asm
@echo machine.asm done
main.elf: $(ENGINE) dirs $(OBJECTS)
@echo Linking $(TARGET).
@$(GCC) -o $@ $(OBJECTS) $(LDPARAM) \
$(foreach LIBRARY, $(LIBS),-l$(LIBRARY)) $(foreach LIB,$(LIBPATH),-L$(LIB))
# Rule for creating object file and .d file, the sed magic is to add
# the object path at the start of the file because the files gcc
# outputs assume it will be in the same dir as the source file.
$(STORE)/%.o: %.c
@echo Creating object file for $*...
@$(GCC) -Wp,-MD,$(STORE)/$*.dd $(CCPARAM) $(foreach INC,$(INCPATH_ENGINE) $(INCPATH_GAME),-I$(INC))\
$(foreach MACRO,$(MACROS),-D$(MACRO)) -c $< -o $@
@sed -e '1s/^\(.*\)$$/$(subst /,\/,$(dir $@))\1/' $(STORE)/$*.dd > $(STORE)/$*.d
@rm -f $(STORE)/$*.dd
# Empty rule to prevent problems when a header is deleted.
%.h: ;
# Cleans up the objects, .d files and executables.
clean:
@echo Making clean.
@-rm -f $(foreach DIR,$(DIRS),$(STORE)/$(DIR)/*.d $(STORE)/$(DIR)/*.o)
@-rm -Rf $(STORE)
@-rm -f $(ENGINE)
# Backup the source files.
backup:
@-if [ ! -e .backup ]; then mkdir .backup; fi;
@zip .backup/backup_`date +%d-%m-%y_%H.%M`.zip $(SOURCE) $(HEADERS) $(EXTRA_FILES)
# Create necessary directories
dirs:
@-if [ ! -e $(STORE) ]; then mkdir $(STORE); fi;
@-$(foreach DIR,$(DIRS), if [ ! -e $(STORE)/$(DIR) ]; \
then mkdir -p $(STORE)/$(DIR); fi; )
# Includes the .d files so it knows the exact dependencies for every
# source.
-include $(DFILES)