-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (103 loc) · 5.02 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
# ========== 極性 -Kyokusei- ============================= Makefile ============================== #
# template from devkitARM examples, modified to suit library use #
# __________ current version: 0.1.0-20191106 _____________________________________________________ #
# ----------------------- suffix setting --------------------------------------------------------- #
.SUFFIXES:
# ----------------------- color escape codes ----------------------------------------------------- #
BLD_BLU := $(shell printf "\033[1;34m")
BLD_GRN := $(shell printf "\033[1;32m")
BLD_PRP := $(shell printf "\033[1;35m")
# ----------------------- find devkitARM var ----------------------------------------------------- #
ifeq ($(strip $(DEVKITARM)),)
$(error "DEVKITARM environment variable not found. Use export DEVKITARM=<path to>devkitARM")
endif
# ---------------------- include gba_rules & garphics_lib.mk ------------------------------------- #
include $(DEVKITARM)/gba_rules
# include ./gfx_make.mk
# ----------------------- set source directories ------------------------------------------------- #
TARGET := $(notdir $(CURDIR))
TARGETS := $(TARGET).elf $(TARGET).gba $(TARGET).sav
BUILD := build
C_SOURCES := C_source
SOURCES := ${C_SOURCES} src/c_files
INCLUDES := include
BIN_DATA :=
AUDIO := audio
GRAPHICS := src/gfx
BOOK := book
# ----------------------- code gen options ------------------------------------------------------- #
ARCH := -mthumb -mthumb-interwork
CFLAGS := -g -Wall -O3 -mcpu=arm7tdmi -mtune=arm7tdmi $(ARCH)
CFLAGS += $(INCLUDE)
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := -g $(ARCH)
LDFLAGS := -g $(ARCH) -Wl,-Map,$(notdir $*.map)
# ----------------------- libraries and lib_dirs ------------------------------------------------- #
LIBS := -ltonc -lmm
LIBTONC := $(DEVKITPRO)/libtonc
LIBDIRS := $(LIBTONC) $(LIBGBA)
# LIBGFX := libgfx.a
# +++++++++++++++++++++++ build procedures +++++++++++++++++++++++++++++++++++++++++++++++++++++++ #
ifneq ($(BUILD),$(notdir $(CURDIR)))
# ----------------------- file collecting -------------------------------------------------------- #
export OUTPUT := $(CURDIR)/$(TARGET)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(BIN_DATA),$(CURDIR)/$(dir)) \
$(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(BIN_DATA),$(notdir $(wildcard $(dir)/*.*)))
ifneq ($(strip $(AUDIO)),)
export AUDIOFILES := $(foreach dir,$(notdir $(wildcard $(AUDIO)/*.*)),$(CURDIR)/$(AUDIO)/$(dir))
BINFILES += soundbank.bin
endif
ifneq ($(strip $(BOOK)),)
BOOKSRC := $(BOOK)/src
export MDFILES := $(foreach dir,$(notdir $(wildcard $(BOOKSRC)/*.md)),$(CURDIR)/$(BOOKSRC)/$(dir))
endif
# ----------------------- linking file preferences ----------------------------------------------- #
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
# ----------------------- variable exports ------------------------------------------------------- #
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)
export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-iquote $(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
# ----------------------- build targets ---------------------------------------------------------- #
.PHONY: $(BUILD) clean
all : $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@printf "\n$(BLD_PRP)::\033[0m \033[1;4mCompiling generated C files...\033[0m\n"
# @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile -s
@$(MAKE) -C $(BUILD) -f $(CURDIR)/Makefile -s
@printf "\n$(BLD_GRN)::\033[0m \033[1mkyokusei.gba created.\033[0m\n\n"
clean:
@printf "\n$(BLD_BLU)::\033[0m \033[1mcleaning files...\033[0m\n\n"
@rm -rfv $(BUILD) $(TARGETS) guidebook.pdf $(C_SOURCES) $(GRAPHICS)/*.bin
@printf "\n$(BLD_GRN)::\033[0m \033[1mproject cleaned.\033[0m\n\n"
else
DEPENDS := $(OFILES:.o=.d)
# ----------------------- main targets ----------------------------------------------------------- #
$(OUTPUT).gba : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)
$(OFILES_SOURCES) : $(HFILES)
# ----------------------- soundbank generation --------------------------------------------------- #
soundbank.bin soundbank.h : $(AUDIOFILES)
@mmutil $^ -osoundbank.bin -hsoundbank.h
# ----------------------- binary data linking ---------------------------------------------------- #
%.bin.o %_bin.h : %.bin
@printf "$(notdir $<)\n"
@$(bin2o)
-include $(DEPSDIR)/*.d
endif
# ======================= EOF ==================================================================== #