-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mk
114 lines (98 loc) · 3.66 KB
/
build.mk
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
# Makefile
# This is for building .nso and .npdm
# The content in build directory are managed by this make file
# The other wrapper scripts are contained in Justfile
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
include $(DEVKITPRO)/libnx/switch_rules
#---------------------------------------------------------------------------------
# Variables
# Target name
TARGET := botwigd
# DIRECTORIES
# Build Output (This mk file operates inside the build folder)
BUILD_DIR := .
# Root Directory
ROOT_DIR := ..
# Dependencies
LIB_DIR := $(ROOT_DIR)/libs
# Our Sources
SOURCE_DIR := $(ROOT_DIR)/src/botwigd
# Skyline (the injection framework) source
SKYLINE_SRC := $(LIB_DIR)/locked/skyline/src
# Scan for nested source directories
ALL_SOURCES_DIRS := $(shell find $(SOURCE_DIR) -type d) $(shell find $(SKYLINE_SRC) -type d)
# Library paths
LIBDIRS := $(PORTLIBS) $(LIBNX)
# Include paths
ALL_INCLUDE_DIRS := \
$(SOURCE_DIR) \
$(LIB_DIR)/locked/skyline/include \
$(LIB_DIR)/locked/libeiffel/include \
$(LIB_DIR)/sync/agl/include \
$(LIB_DIR)/sync/sead/include \
${LIB_DIR}/sync/nnheaders/include \
${LIB_DIR}/sync/xlink2/include \
${LIB_DIR}/sync/botw/src
# VPATH for make to search for files
VPATH := $(foreach dir,$(ALL_SOURCES_DIRS),$(CURDIR)/$(dir))
# INPUT FILES
# Linker script for uking symbols
LDSCRIPT := $(BUILD_DIR)/syms.ld
# Linker version script
LINKER_VERSION_SCRIPT := $(SKYLINE_SRC)/../exported.txt
# Source files
CFILES := $(foreach dir,$(ALL_SOURCES_DIRS),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(ALL_SOURCES_DIRS),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(ALL_SOURCES_DIRS),$(notdir $(wildcard $(dir)/*.s)))
# OUTPUT FILES
# .specs file for linking
SWITCH_SPECS := $(SOURCE_DIR)/../switch.specs
# .o files
OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
# .d files
DFILES := $(OFILES:.o=.d)
# Application json for generating npdm
APP_JSON := $(SOURCE_DIR)/../app.json
# CODE GEN OPTIONS
# Use CXX for linking
LD := $(CXX)
# Include path
INCLUDE := \
$(foreach dir,$(ALL_INCLUDE_DIRS),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include)
# Defines
DEFINES := -D__SWITCH__ -DSWITCH -DNNSDK
# Architecture
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
# C flags
CFLAGS := -g -Wall -ffunction-sections -O3 $(ARCH) $(DEFINES) $(INCLUDE)
ifneq ($(strip $(NOLOG)),)
CFLAGS += "-DNOLOG"
endif
# CXX flags
CXXFLAGS := $(CFLAGS) -fno-rtti -fomit-frame-pointer -fno-exceptions -fno-asynchronous-unwind-tables -fno-unwind-tables -enable-libstdcxx-allocator=new -fpermissive -std=c++17
# AS flags
ASFLAGS := -g $(ARCH)
# LD flags
LDFLAGS := -specs=$(SWITCH_SPECS) -g $(ARCH) -Wl,-Map,$(TARGET).map -Wl,--version-script=$(LINKER_VERSION_SCRIPT) -Wl,-init=__custom_init -Wl,-fini=__custom_fini -Wl,--export-dynamic -nodefaultlibs
# LD libs
LIBS := -lgcc -lstdc++ -u malloc
# LD lib paths
LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
# DEPSDIR used by DEVKITPRO for exporting .d files
DEPSDIR ?= .
#---------------------------------------------------------------------------------
# Make Targets
.PHONY: all
all: $(TARGET).nso app.npdm
# Make target ELF depend on all .o files
$(TARGET).elf : $(OFILES) $(SWITCH_SPECS)
# Not sure why the default npdm rule fails. Redefining the rule here.
# The tool prints error message for missing fields in json. They are not important so we ignore the errors
app.npdm: $(APP_JSON)
npdmtool $(APP_JSON) $@ 2> /dev/null
# The rest of the build rules are specified by the devkitpro makefile
# Include the .d files generated
-include $(DFILES)