|
| 1 | +#--------------------------------------------------------------------------------- |
| 2 | +.SUFFIXES: |
| 3 | +#--------------------------------------------------------------------------------- |
| 4 | + |
| 5 | +ifeq ($(strip $(DEVKITARM)),) |
| 6 | +$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM") |
| 7 | +endif |
| 8 | + |
| 9 | +TOPDIR ?= $(CURDIR) |
| 10 | +include $(DEVKITARM)/3ds_rules |
| 11 | + |
| 12 | +#--------------------------------------------------------------------------------- |
| 13 | +# TARGET is the name of the output |
| 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 | +# GRAPHICS is a list of directories containing graphics files |
| 19 | +# GFXBUILD is the directory where converted graphics files will be placed |
| 20 | +# If set to $(BUILD), it will statically link in the converted |
| 21 | +# files as if they were data files. |
| 22 | +# |
| 23 | +# NO_SMDH: if set to anything, no SMDH file is generated. |
| 24 | +# ROMFS is the directory which contains the RomFS, relative to the Makefile (Optional) |
| 25 | +# APP_TITLE is the name of the app stored in the SMDH file (Optional) |
| 26 | +# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional) |
| 27 | +# APP_AUTHOR is the author of the app stored in the SMDH file (Optional) |
| 28 | +# ICON is the filename of the icon (.png), relative to the project folder. |
| 29 | +# If not set, it attempts to use one of the following (in this order): |
| 30 | +# - <Project name>.png |
| 31 | +# - icon.png |
| 32 | +# - <libctru folder>/default_icon.png |
| 33 | +#--------------------------------------------------------------------------------- |
| 34 | +TARGET := $(notdir $(CURDIR)) |
| 35 | +BUILD := build |
| 36 | +SOURCES := source |
| 37 | +DATA := data |
| 38 | +INCLUDES := include |
| 39 | +GRAPHICS := gfx |
| 40 | +#GFXBUILD := $(BUILD) |
| 41 | +ROMFS := romfs |
| 42 | +GFXBUILD := $(ROMFS)/gfx |
| 43 | + |
| 44 | +APP_TITLE := FlappyBird $(VERSTRING) |
| 45 | +APP_DESCRIPTION := A FlappyBird clone made as a first project |
| 46 | +APP_AUTHOR := LiamTrader |
| 47 | + |
| 48 | +#--------------------------------------------------------------------------------- |
| 49 | +# options for code generation |
| 50 | +#--------------------------------------------------------------------------------- |
| 51 | +ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft |
| 52 | + |
| 53 | +CFLAGS := -g -Wall -O2 -mword-relocations \ |
| 54 | + -ffunction-sections \ |
| 55 | + $(ARCH) |
| 56 | + |
| 57 | +CFLAGS += $(INCLUDE) -D__3DS__ |
| 58 | + |
| 59 | +CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 |
| 60 | + |
| 61 | +ASFLAGS := -g $(ARCH) |
| 62 | +LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) |
| 63 | + |
| 64 | +LIBS := -lcitro2d -lcitro3d -lctru -lm |
| 65 | + |
| 66 | +#--------------------------------------------------------------------------------- |
| 67 | +# list of directories containing libraries, this must be the top level containing |
| 68 | +# include and lib |
| 69 | +#--------------------------------------------------------------------------------- |
| 70 | +LIBDIRS := $(CTRULIB) |
| 71 | + |
| 72 | + |
| 73 | +#--------------------------------------------------------------------------------- |
| 74 | +# no real need to edit anything past this point unless you need to add additional |
| 75 | +# rules for different file extensions |
| 76 | +#--------------------------------------------------------------------------------- |
| 77 | +ifneq ($(BUILD),$(notdir $(CURDIR))) |
| 78 | +#--------------------------------------------------------------------------------- |
| 79 | + |
| 80 | +export OUTPUT := $(CURDIR)/$(TARGET) |
| 81 | +export TOPDIR := $(CURDIR) |
| 82 | + |
| 83 | +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ |
| 84 | + $(foreach dir,$(GRAPHICS),$(CURDIR)/$(dir)) \ |
| 85 | + $(foreach dir,$(DATA),$(CURDIR)/$(dir)) |
| 86 | + |
| 87 | +export DEPSDIR := $(CURDIR)/$(BUILD) |
| 88 | + |
| 89 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 90 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 91 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 92 | +PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) |
| 93 | +SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) |
| 94 | +GFXFILES := $(foreach dir,$(GRAPHICS),$(notdir $(wildcard $(dir)/*.t3s))) |
| 95 | +BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) |
| 96 | + |
| 97 | +#--------------------------------------------------------------------------------- |
| 98 | +# use CXX for linking C++ projects, CC for standard C |
| 99 | +#--------------------------------------------------------------------------------- |
| 100 | +ifeq ($(strip $(CPPFILES)),) |
| 101 | +#--------------------------------------------------------------------------------- |
| 102 | + export LD := $(CC) |
| 103 | +#--------------------------------------------------------------------------------- |
| 104 | +else |
| 105 | +#--------------------------------------------------------------------------------- |
| 106 | + export LD := $(CXX) |
| 107 | +#--------------------------------------------------------------------------------- |
| 108 | +endif |
| 109 | +#--------------------------------------------------------------------------------- |
| 110 | + |
| 111 | +#--------------------------------------------------------------------------------- |
| 112 | +ifeq ($(GFXBUILD),$(BUILD)) |
| 113 | +#--------------------------------------------------------------------------------- |
| 114 | +export T3XFILES := $(GFXFILES:.t3s=.t3x) |
| 115 | +#--------------------------------------------------------------------------------- |
| 116 | +else |
| 117 | +#--------------------------------------------------------------------------------- |
| 118 | +export ROMFS_T3XFILES := $(patsubst %.t3s, $(GFXBUILD)/%.t3x, $(GFXFILES)) |
| 119 | +export T3XHFILES := $(patsubst %.t3s, $(BUILD)/%.h, $(GFXFILES)) |
| 120 | +#--------------------------------------------------------------------------------- |
| 121 | +endif |
| 122 | +#--------------------------------------------------------------------------------- |
| 123 | + |
| 124 | +export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 125 | + |
| 126 | +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \ |
| 127 | + $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ |
| 128 | + $(addsuffix .o,$(T3XFILES)) |
| 129 | + |
| 130 | +export OFILES := $(OFILES_BIN) $(OFILES_SOURCES) |
| 131 | + |
| 132 | +export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(SHLISTFILES:.shlist=_shbin.h) \ |
| 133 | + $(addsuffix .h,$(subst .,_,$(BINFILES))) \ |
| 134 | + $(GFXFILES:.t3s=.h) |
| 135 | + |
| 136 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 137 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 138 | + -I$(CURDIR)/$(BUILD) |
| 139 | + |
| 140 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) |
| 141 | + |
| 142 | +export _3DSXDEPS := $(if $(NO_SMDH),,$(OUTPUT).smdh) |
| 143 | + |
| 144 | +ifeq ($(strip $(ICON)),) |
| 145 | + icons := $(wildcard *.png) |
| 146 | + ifneq (,$(findstring $(TARGET).png,$(icons))) |
| 147 | + export APP_ICON := $(TOPDIR)/$(TARGET).png |
| 148 | + else |
| 149 | + ifneq (,$(findstring icon.png,$(icons))) |
| 150 | + export APP_ICON := $(TOPDIR)/icon.png |
| 151 | + endif |
| 152 | + endif |
| 153 | +else |
| 154 | + export APP_ICON := $(TOPDIR)/$(ICON) |
| 155 | +endif |
| 156 | + |
| 157 | +ifeq ($(strip $(NO_SMDH)),) |
| 158 | + export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh |
| 159 | +endif |
| 160 | + |
| 161 | +ifneq ($(ROMFS),) |
| 162 | + export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) |
| 163 | +endif |
| 164 | + |
| 165 | +.PHONY: all clean |
| 166 | + |
| 167 | +#--------------------------------------------------------------------------------- |
| 168 | +all: $(BUILD) $(GFXBUILD) $(DEPSDIR) $(ROMFS_T3XFILES) $(T3XHFILES) |
| 169 | + @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile |
| 170 | + |
| 171 | +$(BUILD): |
| 172 | + @mkdir -p $@ |
| 173 | + |
| 174 | +ifneq ($(GFXBUILD),$(BUILD)) |
| 175 | +$(GFXBUILD): |
| 176 | + @mkdir -p $@ |
| 177 | +endif |
| 178 | + |
| 179 | +ifneq ($(DEPSDIR),$(BUILD)) |
| 180 | +$(DEPSDIR): |
| 181 | + @mkdir -p $@ |
| 182 | +endif |
| 183 | + |
| 184 | +#--------------------------------------------------------------------------------- |
| 185 | +clean: |
| 186 | + @echo clean ... |
| 187 | + @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf $(GFXBUILD) |
| 188 | + |
| 189 | +#--------------------------------------------------------------------------------- |
| 190 | +$(GFXBUILD)/%.t3x $(BUILD)/%.h : %.t3s |
| 191 | +#--------------------------------------------------------------------------------- |
| 192 | + @echo $(notdir $<) |
| 193 | + @tex3ds -i $< -H $(BUILD)/$*.h -d $(DEPSDIR)/$*.d -o $(GFXBUILD)/$*.t3x |
| 194 | + |
| 195 | +#--------------------------------------------------------------------------------- |
| 196 | +else |
| 197 | + |
| 198 | +#--------------------------------------------------------------------------------- |
| 199 | +# main targets |
| 200 | +#--------------------------------------------------------------------------------- |
| 201 | +$(OUTPUT).3dsx : $(OUTPUT).elf $(_3DSXDEPS) |
| 202 | + |
| 203 | +$(OFILES_SOURCES) : $(HFILES) |
| 204 | + |
| 205 | +$(OUTPUT).elf : $(OFILES) |
| 206 | + |
| 207 | +#--------------------------------------------------------------------------------- |
| 208 | +# you need a rule like this for each extension you use as binary data |
| 209 | +#--------------------------------------------------------------------------------- |
| 210 | +%.bin.o %_bin.h : %.bin |
| 211 | +#--------------------------------------------------------------------------------- |
| 212 | + @echo $(notdir $<) |
| 213 | + @$(bin2o) |
| 214 | + |
| 215 | +#--------------------------------------------------------------------------------- |
| 216 | +.PRECIOUS : %.t3x %.shbin |
| 217 | +#--------------------------------------------------------------------------------- |
| 218 | +%.t3x.o %_t3x.h : %.t3x |
| 219 | +#--------------------------------------------------------------------------------- |
| 220 | + $(SILENTMSG) $(notdir $<) |
| 221 | + $(bin2o) |
| 222 | + |
| 223 | +#--------------------------------------------------------------------------------- |
| 224 | +%.shbin.o %_shbin.h : %.shbin |
| 225 | +#--------------------------------------------------------------------------------- |
| 226 | + $(SILENTMSG) $(notdir $<) |
| 227 | + $(bin2o) |
| 228 | + |
| 229 | +-include $(DEPSDIR)/*.d |
| 230 | + |
| 231 | +#--------------------------------------------------------------------------------------- |
| 232 | +endif |
| 233 | +#--------------------------------------------------------------------------------------- |
0 commit comments