diff options
Diffstat (limited to 'gba/Makefile')
-rw-r--r-- | gba/Makefile | 168 |
1 files changed, 168 insertions, 0 deletions
diff --git a/gba/Makefile b/gba/Makefile new file mode 100644 index 0000000..99dfbb6 --- /dev/null +++ b/gba/Makefile | |||
@@ -0,0 +1,168 @@ | |||
1 | #--------------------------------------------------------------------------------- | ||
2 | # Clear the implicit built in rules | ||
3 | #--------------------------------------------------------------------------------- | ||
4 | .SUFFIXES: | ||
5 | #--------------------------------------------------------------------------------- | ||
6 | ifeq ($(strip $(DEVKITARM)),) | ||
7 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM) | ||
8 | endif | ||
9 | |||
10 | include $(DEVKITARM)/gba_rules | ||
11 | |||
12 | #--------------------------------------------------------------------------------- | ||
13 | # TARGET is the name of the output, if this ends with _mb a multiboot image is generated | ||
14 | # BUILD is the directory where object files & intermediate files will be placed | ||
15 | # SOURCES is a list of directories containing source code | ||
16 | # DATA is a list of directories containing data files | ||
17 | # INCLUDES is a list of directories containing header files | ||
18 | #--------------------------------------------------------------------------------- | ||
19 | TARGET := $(shell basename $(CURDIR))_mb | ||
20 | BUILD := build | ||
21 | SOURCES := source | ||
22 | DATA := | ||
23 | GRAPHICS := gfx | ||
24 | INCLUDES := | ||
25 | |||
26 | #--------------------------------------------------------------------------------- | ||
27 | # options for code generation | ||
28 | #--------------------------------------------------------------------------------- | ||
29 | ARCH := -mthumb -mthumb-interwork | ||
30 | |||
31 | CFLAGS := -g -Wall -O3\ | ||
32 | -mcpu=arm7tdmi -mtune=arm7tdmi\ | ||
33 | -fomit-frame-pointer\ | ||
34 | -ffast-math \ | ||
35 | $(ARCH) | ||
36 | |||
37 | CFLAGS += $(INCLUDE) | ||
38 | |||
39 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions | ||
40 | |||
41 | ASFLAGS := $(ARCH) | ||
42 | LDFLAGS = -g $(ARCH) -Wl,-Map,$(notdir $@).map | ||
43 | |||
44 | #--------------------------------------------------------------------------------- | ||
45 | # any extra libraries we wish to link with the project | ||
46 | #--------------------------------------------------------------------------------- | ||
47 | LIBS := -lgba | ||
48 | |||
49 | #--------------------------------------------------------------------------------- | ||
50 | # list of directories containing libraries, this must be the top level containing | ||
51 | # include and lib | ||
52 | #--------------------------------------------------------------------------------- | ||
53 | LIBDIRS := $(LIBGBA) | ||
54 | |||
55 | #--------------------------------------------------------------------------------- | ||
56 | # no real need to edit anything past this point unless you need to add additional | ||
57 | # rules for different file extensions | ||
58 | #--------------------------------------------------------------------------------- | ||
59 | ifneq ($(BUILD),$(notdir $(CURDIR))) | ||
60 | #--------------------------------------------------------------------------------- | ||
61 | |||
62 | export OUTPUT := $(CURDIR)/$(TARGET) | ||
63 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ | ||
64 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) | ||
65 | |||
66 | export DEPSDIR := $(CURDIR)/$(BUILD) | ||
67 | |||
68 | #--------------------------------------------------------------------------------- | ||
69 | # automatically build a list of object files for our project | ||
70 | #--------------------------------------------------------------------------------- | ||
71 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) | ||
72 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) | ||
73 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) | ||
74 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) | ||
75 | BMPFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.bmp))) | ||
76 | |||
77 | #--------------------------------------------------------------------------------- | ||
78 | # use CXX for linking C++ projects, CC for standard C | ||
79 | #--------------------------------------------------------------------------------- | ||
80 | ifeq ($(strip $(CPPFILES)),) | ||
81 | #--------------------------------------------------------------------------------- | ||
82 | export LD := $(CC) | ||
83 | #--------------------------------------------------------------------------------- | ||
84 | else | ||
85 | #--------------------------------------------------------------------------------- | ||
86 | export LD := $(CXX) | ||
87 | #--------------------------------------------------------------------------------- | ||
88 | endif | ||
89 | #--------------------------------------------------------------------------------- | ||
90 | |||
91 | export OFILES := $(addsuffix .o,$(BINFILES)) \ | ||
92 | $(BMPFILES:.bmp=.o) \ | ||
93 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) | ||
94 | |||
95 | #--------------------------------------------------------------------------------- | ||
96 | # build a list of include paths | ||
97 | #--------------------------------------------------------------------------------- | ||
98 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ | ||
99 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ | ||
100 | -I$(CURDIR)/$(BUILD) | ||
101 | |||
102 | #--------------------------------------------------------------------------------- | ||
103 | # build a list of library paths | ||
104 | #--------------------------------------------------------------------------------- | ||
105 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) | ||
106 | |||
107 | .PHONY: $(BUILD) clean | ||
108 | |||
109 | #--------------------------------------------------------------------------------- | ||
110 | $(BUILD): | ||
111 | @[ -d $@ ] || mkdir -p $@ | ||
112 | @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile | ||
113 | |||
114 | all : $(BUILD) | ||
115 | #--------------------------------------------------------------------------------- | ||
116 | clean: | ||
117 | @echo clean ... | ||
118 | @rm -fr $(BUILD) $(TARGET).elf $(TARGET).gba | ||
119 | |||
120 | #--------------------------------------------------------------------------------- | ||
121 | else | ||
122 | |||
123 | DEPENDS := $(OFILES:.o=.d) | ||
124 | |||
125 | #--------------------------------------------------------------------------------- | ||
126 | # main targets | ||
127 | #--------------------------------------------------------------------------------- | ||
128 | $(OUTPUT).gba : $(OUTPUT).elf | ||
129 | |||
130 | $(OUTPUT).elf : $(OFILES) | ||
131 | |||
132 | |||
133 | #--------------------------------------------------------------------------------- | ||
134 | # The bin2o rule should be copied and modified | ||
135 | # for each extension used in the data directories | ||
136 | #--------------------------------------------------------------------------------- | ||
137 | |||
138 | #--------------------------------------------------------------------------------- | ||
139 | # This rule links in binary data with the .bin extension | ||
140 | #--------------------------------------------------------------------------------- | ||
141 | %.bin.o : %.bin | ||
142 | #--------------------------------------------------------------------------------- | ||
143 | @echo $(notdir $<) | ||
144 | @$(bin2o) | ||
145 | |||
146 | #--------------------------------------------------------------------------------- | ||
147 | # This rule links in binary data with the .raw extension | ||
148 | #--------------------------------------------------------------------------------- | ||
149 | %.raw.o : %.raw | ||
150 | #--------------------------------------------------------------------------------- | ||
151 | @echo $(notdir $<) | ||
152 | @$(bin2o) | ||
153 | |||
154 | #--------------------------------------------------------------------------------- | ||
155 | # This rule creates assembly source files using grit | ||
156 | # grit takes an image file and a .grit describing how the file is to be processed | ||
157 | # add additional rules like this for each image extension | ||
158 | # you use in the graphics folders | ||
159 | #--------------------------------------------------------------------------------- | ||
160 | %.s %.h : %.bmp %.grit | ||
161 | #--------------------------------------------------------------------------------- | ||
162 | grit $< -fts -o$* | ||
163 | |||
164 | -include $(DEPENDS) | ||
165 | |||
166 | #--------------------------------------------------------------------------------- | ||
167 | endif | ||
168 | #--------------------------------------------------------------------------------- | ||