Skip to content

Instantly share code, notes, and snippets.

@Subv
Created February 21, 2015 19:12
Show Gist options
  • Save Subv/c469b32cb3fbc686be72 to your computer and use it in GitHub Desktop.
Save Subv/c469b32cb3fbc686be72 to your computer and use it in GitHub Desktop.
diff --git a/Makefile b/Makefile
index 61f45d3..7d2293e 100644
--- a/Makefile
+++ b/Makefile
@@ -15,22 +15,30 @@ include $(DEVKITARM)/3ds_rules
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
-# SPECS is the directory containing the important build and link files
-#---------------------------------------------------------------------------------
-export TARGET := $(shell basename $(CURDIR))
+#
+# NO_SMDH: if set to anything, no SMDH file is generated.
+# APP_TITLE is the name of the app stored in the SMDH file (Optional)
+# APP_DESCRIPTION is the description of the app stored in the SMDH file (Optional)
+# APP_AUTHOR is the author of the app stored in the SMDH file (Optional)
+# ICON is the filename of the icon (.png), relative to the project folder.
+# If not set, it attempts to use one of the following (in this order):
+# - <Project name>.png
+# - icon.png
+# - <libctru folder>/default_icon.png
+#---------------------------------------------------------------------------------
+TARGET := $(notdir $(CURDIR))
BUILD := build
-SOURCES := source source/common source/tests source/tests/fs source/tests/cpu source/tests/kernel
+SOURCES := source source/common source/tests source/tests/fs source/tests/cpu source/tests/kernel source/tests/gpu
DATA := data
-INCLUDES := source #include
-
+INCLUDES := source
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
-ARCH := -march=armv6k -mtune=mpcore
+ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard
-CFLAGS := -g -Wall -O2 -mword-relocations -save-temps \
- -fomit-frame-pointer -ffast-math -mfloat-abi=softfp \
+CFLAGS := -g -Wall -O2 -mword-relocations \
+ -fomit-frame-pointer -ffast-math \
$(ARCH)
CFLAGS += $(INCLUDE) -DARM11 -D_3DS
@@ -38,8 +46,7 @@ CFLAGS += $(INCLUDE) -DARM11 -D_3DS
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11
ASFLAGS := -g $(ARCH)
-LDFLAGS = -specs=3dsx.specs -g $(ARCH) \
- -Wl,-Map,$(TARGET).map
+LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
LIBS := -lctru -lm
@@ -48,15 +55,15 @@ LIBS := -lctru -lm
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS := $(CTRULIB)
-
-
+
+
#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
-
+
export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
@@ -93,54 +100,76 @@ export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
+ifeq ($(strip $(ICON)),)
+ icons := $(wildcard *.png)
+ ifneq (,$(findstring $(TARGET).png,$(icons)))
+ export APP_ICON := $(TOPDIR)/$(TARGET).png
+ else
+ ifneq (,$(findstring icon.png,$(icons)))
+ export APP_ICON := $(TOPDIR)/icon.png
+ endif
+ endif
+else
+ export APP_ICON := $(TOPDIR)/$(ICON)
+endif
+
+ifeq ($(strip $(NO_SMDH)),)
+ export _3DSXFLAGS += --smdh=$(CURDIR)/$(TARGET).smdh
+endif
+
.PHONY: $(BUILD) clean all
-
+
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@[ -d $@ ] || mkdir -p $@
- @make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
-
+ @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
+
#---------------------------------------------------------------------------------
clean:
@echo clean ...
- @rm -fr $(BUILD) $(TARGET).3dsx $(TARGET).elf
-
-
+ @rm -fr $(BUILD) $(TARGET).3dsx $(OUTPUT).smdh $(TARGET).elf
+
+
#---------------------------------------------------------------------------------
else
-
+
DEPENDS := $(OFILES:.o=.d)
-
+
#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
+ifeq ($(strip $(NO_SMDH)),)
+$(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh
+else
$(OUTPUT).3dsx : $(OUTPUT).elf
+endif
+
$(OUTPUT).elf : $(OFILES)
#---------------------------------------------------------------------------------
-# you need a rule like this for each extension you use as binary data
+# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)
-# not the right way to do this
+# WARNING: This is not the right way to do this! TODO: Do it right!
#---------------------------------------------------------------------------------
%.vsh.o : %.vsh
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@python $(AEMSTRO)/aemstro_as.py $< ../$(notdir $<).shbin
- @bin2s ../$(notdir $<).shbin | arm-none-eabi-as -o $@
+ @bin2s ../$(notdir $<).shbin | $(PREFIX)as -o $@
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u8" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(notdir $<).shbin | tr . _)`.h
@echo "extern const u32" `(echo $(notdir $<).shbin | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(notdir $<).shbin | tr . _)`.h
@rm ../$(notdir $<).shbin
-include $(DEPENDS)
-
+
#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment