|
| 1 | +#--------------------------------------------------------------------------------- |
| 2 | +# Starlight-specific |
| 3 | +# CROSSVER is the target version of SSBU, but without the decimal points |
| 4 | +# This can be changed by compiling for a different version (e.g. make 600) |
| 5 | +# (used for C defines, filenames, etc) |
| 6 | +# LINKERSCRIPTS is the directory where the function addresses for Splatoon 2 are |
| 7 | +# stored |
| 8 | +# Each script is stored as syms$(CROSSVER).ld |
| 9 | +# (used for mapping SSBU functions to the proper address) |
| 10 | +#--------------------------------------------------------------------------------- |
| 11 | + |
| 12 | +LINKERSCRIPTS := linkerscripts |
| 13 | + |
| 14 | +#--------------------------------------------------------------------------------- |
| 15 | +#.SUFFIXES: |
| 16 | +#--------------------------------------------------------------------------------- |
| 17 | + |
| 18 | +ifeq ($(strip $(DEVKITPRO)),) |
| 19 | +$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro") |
| 20 | +endif |
| 21 | + |
| 22 | +TOPDIR ?= $(CURDIR) |
| 23 | +include $(DEVKITPRO)/libnx/switch_rules |
| 24 | + |
| 25 | +#--------------------------------------------------------------------------------- |
| 26 | +# TARGET is the name of the output |
| 27 | +# BUILD is the directory where object files & intermediate files will be placed |
| 28 | +# SOURCES is a list of directories containing source code |
| 29 | +# DATA is a list of directories containing data files |
| 30 | +# INCLUDES is a list of directories containing header files |
| 31 | +#--------------------------------------------------------------------------------- |
| 32 | +TARGET ?= $(notdir $(CURDIR))$(CROSSVER) |
| 33 | +BUILD ?= build$(CROSSVER) |
| 34 | +SOURCES := source \ |
| 35 | + source/skyline \ |
| 36 | + source/skyline/nx \ |
| 37 | + source/skyline/nx/arm \ |
| 38 | + source/skyline/nx/kernel \ |
| 39 | + source/skyline/nx/runtime \ |
| 40 | + source/skyline/nx/sf \ |
| 41 | + source/skyline/inlinehook \ |
| 42 | + source/skyline/logger \ |
| 43 | + source/skyline/utils \ |
| 44 | + source/skyline/arc \ |
| 45 | + source/skyline/plugin |
| 46 | +DATA := data |
| 47 | +INCLUDES := include |
| 48 | + |
| 49 | +#--------------------------------------------------------------------------------- |
| 50 | +# options for code generation |
| 51 | +#--------------------------------------------------------------------------------- |
| 52 | +ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec |
| 53 | + |
| 54 | +CFLAGS := -g -Wall -ffunction-sections \ |
| 55 | + $(ARCH) $(DEFINES) |
| 56 | + |
| 57 | +CFLAGS += $(INCLUDE) -D__SWITCH__ -DCROSSVER=$(CROSSVER) |
| 58 | + |
| 59 | +CXXFLAGS := $(CFLAGS) -fno-rtti -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -enable-libstdcxx-allocator=new -fpermissive |
| 60 | + |
| 61 | +ASFLAGS := -g $(ARCH) |
| 62 | +LDFLAGS = -specs=../switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) -Wl,--version-script=$(TOPDIR)/exported.txt -Wl,-init=__custom_init -Wl,-fini=__custom_fini -nostdlib |
| 63 | + |
| 64 | + |
| 65 | +LIBS := -lgcc -lstdc++ -u malloc |
| 66 | + |
| 67 | +#--------------------------------------------------------------------------------- |
| 68 | +# list of directories containing libraries, this must be the top level containing |
| 69 | +# include and lib |
| 70 | +#--------------------------------------------------------------------------------- |
| 71 | +LIBDIRS := $(PORTLIBS) $(LIBNX) |
| 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,$(DATA),$(CURDIR)/$(dir)) |
| 85 | + |
| 86 | +export DEPSDIR ?= $(CURDIR)/$(BUILD) |
| 87 | + |
| 88 | +CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) |
| 89 | +CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) |
| 90 | +SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) |
| 91 | + |
| 92 | +#--------------------------------------------------------------------------------- |
| 93 | +# use CXX for linking C++ projects, CC for standard C |
| 94 | +#--------------------------------------------------------------------------------- |
| 95 | +ifeq ($(strip $(CPPFILES)),) |
| 96 | +#--------------------------------------------------------------------------------- |
| 97 | + export LD := $(CC) |
| 98 | +#--------------------------------------------------------------------------------- |
| 99 | +else |
| 100 | +#--------------------------------------------------------------------------------- |
| 101 | + export LD := $(CXX) |
| 102 | +#--------------------------------------------------------------------------------- |
| 103 | +endif |
| 104 | +#--------------------------------------------------------------------------------- |
| 105 | +export OFILES_BIN := $(addsuffix .o,$(BINFILES)) |
| 106 | +export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) |
| 107 | +export OFILES := $(OFILES_BIN) $(OFILES_SRC) |
| 108 | +export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) |
| 109 | + |
| 110 | +export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ |
| 111 | + $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ |
| 112 | + -I$(CURDIR)/$(BUILD) |
| 113 | + |
| 114 | +export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) |
| 115 | + |
| 116 | +ifeq ($(strip $(ICON)),) |
| 117 | + icons := $(wildcard *.jpg) |
| 118 | + ifneq (,$(findstring $(TARGET).jpg,$(icons))) |
| 119 | + export APP_ICON := $(TOPDIR)/$(TARGET).jpg |
| 120 | + else |
| 121 | + ifneq (,$(findstring icon.jpg,$(icons))) |
| 122 | + export APP_ICON := $(TOPDIR)/icon.jpg |
| 123 | + endif |
| 124 | + endif |
| 125 | +else |
| 126 | + export APP_ICON := $(TOPDIR)/$(ICON) |
| 127 | +endif |
| 128 | + |
| 129 | +ifeq ($(strip $(NO_ICON)),) |
| 130 | + export NROFLAGS += --icon=$(APP_ICON) |
| 131 | +endif |
| 132 | + |
| 133 | +ifeq ($(strip $(NO_NACP)),) |
| 134 | + export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp |
| 135 | +endif |
| 136 | + |
| 137 | +.PHONY: $(BUILD) clean all |
| 138 | + |
| 139 | +#--------------------------------------------------------------------------------- |
| 140 | + |
| 141 | +all: $(BUILD) |
| 142 | + |
| 143 | +$(BUILD): |
| 144 | + @echo "${SOURCES}" |
| 145 | + @echo "${CPPFILES}" |
| 146 | + @[ -d $@ ] || mkdir -p $@ |
| 147 | + @cp $(LINKERSCRIPTS)/syms$(CROSSVER).ld $(LINKERSCRIPTS)/symstemp.ld # This is required because you can't pass a variable to the .specs |
| 148 | + $(MAKE) -C $(BUILD) -f $(CURDIR)/MakefileNSO |
| 149 | + @rm -f $(LINKERSCRIPTS)/symstemp.ld |
| 150 | + |
| 151 | +#--------------------------------------------------------------------------------- |
| 152 | +clean: |
| 153 | + @echo clean ... |
| 154 | + @rm -fr build* *.nso *.elf |
| 155 | + |
| 156 | + |
| 157 | +#--------------------------------------------------------------------------------- |
| 158 | +else |
| 159 | +.PHONY: all |
| 160 | + |
| 161 | +DEPENDS := $(OFILES:.o=.d) |
| 162 | + |
| 163 | +#--------------------------------------------------------------------------------- |
| 164 | +# main targets |
| 165 | +#--------------------------------------------------------------------------------- |
| 166 | +%.nso: %.elf |
| 167 | + @elf2nso $< $@ |
| 168 | + @echo built ... $(notdir $@) |
| 169 | + |
| 170 | +%.nro: %.elf |
| 171 | + @elf2nro $< $@ $(NROFLAGS) |
| 172 | + @echo built ... $(notdir $@) |
| 173 | + |
| 174 | +#--------------------------------------------------------------------------------- |
| 175 | +all : $(OUTPUT).nso |
| 176 | + |
| 177 | +$(OUTPUT).elf : $(OFILES) |
| 178 | + |
| 179 | + |
| 180 | +$(OFILES_SRC) : $(HFILES_BIN) |
| 181 | + |
| 182 | +#--------------------------------------------------------------------------------- |
| 183 | +# you need a rule like this for each extension you use as binary data |
| 184 | +#--------------------------------------------------------------------------------- |
| 185 | +%.bin.o %_bin.h : %.bin |
| 186 | +#--------------------------------------------------------------------------------- |
| 187 | + @echo $(notdir $<) |
| 188 | + @$(bin2o) |
| 189 | + |
| 190 | +-include $(DEPENDS) |
| 191 | + |
| 192 | +#--------------------------------------------------------------------------------------- |
| 193 | +endif |
| 194 | +#--------------------------------------------------------------------------------------- |
0 commit comments