forked from aknetk/HatchGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.nx
191 lines (141 loc) · 5.18 KB
/
Makefile.nx
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif
TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules
rwc = $(foreach d, $(wildcard $1*), $(call rwc,$d/,$2) $(filter $(subst *,%,$2),$d))
SRC_C = $(call rwc, source/, *.c)
SRC_CPP = $(call rwc, source/, *.cpp)
SRC_DIRS := $(sort \
$(addprefix source/, $(dir $(SRC_C:source/%.c=%.o))) \
$(addprefix source/, $(dir $(SRC_CPP:source/%.cpp=%.o))) )
TARGETNAME = HatchGameEngine
TARGET := builds/nx/$(TARGETNAME)
BUILD := out/nx
SOURCES := $(SRC_DIRS)
DATA := data
INCLUDES := source include
ROMFS := romfs
EXEFS_SRC := exefs
APP_TITLE := HatchGameEngine
APP_AUTHOR := aknetk
APP_VERSION := 1.0
ICON := meta/nx/icon.jpg
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE -ftls-model=local-exec
CFLAGS := -g -Wall -O3 -ffunction-sections \
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__ \
`freetype-config --cflags` \
-DSWITCH -DOGG_MUSIC -DDEBUG -DTARGET_NAME=\"$(TARGETNAME)\"
CFLAGS += -DSWITCH_ROMFS
CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++14 -Wno-unused-variable
ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Bdynamic,-Map,$(notdir $*.map)
# SDL2 Libraries
LIBS := -lSDL2_image -lSDL2
# Format Libraries
LIBS += -lpng -ljpeg -lwebp -lvorbisidec -logg `freetype-config --libs`
# OpenGL Libraries
LIBS += -lglad -lGLESv2 -lEGL -lglapi -ldrm_nouveau
# FFmpeg Libraries
# LIBS += -lm -lstdc++ -lc -lnosys -lavformat -lavcodec -lopus -lopusfile -lswresample -lswscale -lavutil
# LIBS += -lvpx
# Networking Libraries
# LIBS += -lcurl -lmbedtls -lmbedx509 -lmbedcrypto
# Standard Libraries
LIBS += -lz -lbz2 -lnx
# CFLAGS += -DUSING_LIBAV
# CFLAGS += -DUSING_CURL
CFLAGS += -DUSING_OPENGL
CFLAGS += -DUSING_VM_DISPATCH_TABLE
# CFLAGS += -DUSING_LIBPNG -DUSING_LIBPNG_HEADER=<libpng16/png.h>
LIBDIRS := $(PORTLIBS) $(LIBNX)
#---------------------------------------------------------------------------------
ifneq ($(notdir $(BUILD)),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------
export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
export DEPSDIR := $(CURDIR)/$(BUILD)
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
ifeq ($(strip $(CPPFILES)),)
export LD := $(CC)
else
export LD := $(CXX)
endif
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)
ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
else
ifneq (,$(findstring icon.jpg,$(icons)))
export APP_ICON := $(TOPDIR)/icon.jpg
endif
endif
else
export APP_ICON := $(TOPDIR)/$(ICON)
endif
ifeq ($(strip $(NO_ICON)),)
export NROFLAGS += --icon=$(APP_ICON)
endif
ifeq ($(strip $(NO_NACP)),)
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
endif
ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif
ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif
.PHONY: $(BUILD) clean all
#---------------------------------------------------------------------------------
all: $(BUILD)
$(BUILD):
@mkdir -p "builds"
@mkdir -p "builds/nx"
@mkdir -p "out"
@mkdir -p "out/nx"
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile.nx
clean:
@rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf
else
.PHONY: all
DEPENDS := $(OFILES:.o=.d)
all : $(OUTPUT).pfs0 $(OUTPUT).nro
$(OUTPUT).pfs0 : $(OUTPUT).nso
$(OUTPUT).nso : $(OUTPUT).elf
ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
else
$(OUTPUT).nro : $(OUTPUT).elf
endif
$(OUTPUT).elf : $(OFILES)
$(OFILES_SRC) : $(HFILES_BIN)
%.bin.o : %.bin
@echo $(notdir $<)
@$(bin2o)
%.obj.o : %.obj
@echo $(notdir $<)
-include $(DEPENDS)
endif
# $(notdir $(CURDIR))