-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
163 lines (119 loc) · 5.49 KB
/
Makefile
File metadata and controls
163 lines (119 loc) · 5.49 KB
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
.SUFFIXES:
LIB_NAME := m3ds
C_VERSION := 23
CXX_VERSION := 26
#---------------------------------------------------------------------------------
# Environment Setup
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>devkitPro")
endif
ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
BUILD_DIR := build
SOURCES_DIR := source
INCLUDE_DIR := include
EMBED_DIR := $(BUILD_DIR)
GFX_DIR := gfx
ifndef (OUTPUT_DIR)
OUTPUT_DIR := lib
endif
#---------------------------------------------------------------------------------
# Flags
#---------------------------------------------------------------------------------
ARCH_FLAGS := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mword-relocations
WARNINGS := -Wall -Werror -Wextra -Wconversion -Wpedantic -Wno-psabi
MAKEFLAGS := -j14 --silent
COMMON_FLAGS := $(WARNINGS) -ffast-math $(ARCH_FLAGS) -D__3DS__
C_FLAGS := $(COMMON_FLAGS) -std=c$(C_VERSION)
CXX_FLAGS := $(COMMON_FLAGS) -std=c++$(CXX_VERSION) -fno-rtti -fno-exceptions
DEBUG_FLAGS := -O0 -g -DDEBUG
RELEASE_FLAGS := -O2 -DNDEBUG -s -fomit-frame-pointer
ASM_FLAGS := $(ARCH_FLAGS)
LD_FLAGS := -specs=3dsx.specs $(ARCH_FLAGS) -z noexecstack
ifeq ($(OS),Windows_NT)
DEVKITPRO := $(shell echo "$(DEVKITPRO)" | sed -e 's|^/opt|C:|')
DEVKITARM := $(shell echo "$(DEVKITARM)" | sed -e 's|^/opt|C:|')
endif
PORTLIBS := $(DEVKITPRO)/portlibs/3ds
LIBCTRU := $(DEVKITPRO)/libctru
LIB_DIRS := $(PORTLIBS) $(LIBCTRU)
#---------------------------------------------------------------------------------
# Build Variable Setup
#---------------------------------------------------------------------------------
recurse = $(shell find $2 -type $1 -name '$3' 2> /dev/null)
C_FILES := $(foreach dir,$(SOURCES_DIR),$(call recurse,f,$(dir),*.c))
CXX_FILES := $(foreach dir,$(SOURCES_DIR),$(call recurse,f,$(dir),*.cpp))
PICA_FILES := $(foreach dir,$(SOURCES_DIR),$(call recurse,f,$(dir),*.pica))
GFX_FILES := $(foreach dir,$(GFX_DIR),$(call recurse,f,$(dir),*.*))
GFX_EXTENSIONS := $(addprefix %.,PNG png JPG jpg JPEG jpeg BMP bmp)
T3X_FILES := $(addsuffix .t3x, $(addprefix $(BUILD_DIR)/, $(filter $(GFX_EXTENSIONS),$(GFX_FILES))))
O_FILES := $(patsubst $(SOURCES_DIR)/%,$(BUILD_DIR)/%,$(addsuffix .o, $(basename $(C_FILES) $(CXX_FILES))))
OD_FILES := $(patsubst $(SOURCES_DIR)/%,$(BUILD_DIR)/%,$(addsuffix _DEBUG.o, $(basename $(C_FILES) $(CXX_FILES))))
BIN_FILES := $(patsubst $(SOURCES_DIR)/%,$(BUILD_DIR)/%,$(addsuffix .bin, $(basename $(basename $(PICA_FILES)))))
INCLUDE := $(foreach dir,$(INCLUDE_DIR),-I./$(dir)) $(foreach dir,$(LIB_DIRS),-isystem $(dir)/include)
EMBED := $(foreach dir,$(EMBED_DIR),--embed-dir=./$(dir))
CC := $(DEVKITARM)/bin/arm-none-eabi-gcc
CXX := $(DEVKITARM)/bin/arm-none-eabi-g++
AR := $(DEVKITARM)/bin/arm-none-eabi-gcc-ar
LD := $(CXX)
# msys2 make and mingw32-make don't agree on PATH format on Windows
PATH := $(DEVKITPRO)/tools/bin/:$(DEVKITARM)/bin/:$(PATH)
PATH := $(subst C:/,/c/,$(DEVKITPRO)/tools/bin/:$(DEVKITARM)/bin/):$(PATH)
.PHONY: lib clean all debug release
all: debug release
# Shaders
$(BUILD_DIR)/%.bin: $(SOURCES_DIR)/%.v.pica
$(info Compiling $^)
@mkdir -p $(dir $@)
@picasso -o $@ $^
$(BUILD_DIR)/%.bin: $(SOURCES_DIR)/%.v.pica $(SOURCES_DIR)/%.g.pica
$(info Compiling $^)
@mkdir -p $(dir $@)
@picasso -o $@ $^
# Textures
$(BUILD_DIR)/%.t3x: %
$(info Processing texture $<)
@mkdir -p $(dir $@)
@tex3ds --atlas -f rgba8888 -z -i $< -o $@ > /dev/null 2>&1
# Release
$(OUTPUT_DIR)/%.a: $(O_FILES)
$(info Archiving $(notdir $@))
@mkdir -p $(dir $@)
@$(AR) rcs $@ $(O_FILES)
$(info Compiled $(LIB_NAME) in release mode!)
$(BUILD_DIR)/%.o: $(SOURCES_DIR)/%.c $(BIN_FILES) $(T3X_FILES)
$(info Compiling $< for release)
@mkdir -p $(dir $@)
@$(CC) -MMD -MP -MF $(BUILD_DIR)/$*.d $(C_FLAGS) $(RELEASE_FLAGS) $(INCLUDE) $(EMBED) -c $< -o $@
$(BUILD_DIR)/%.o: $(SOURCES_DIR)/%.cpp $(BIN_FILES) $(T3X_FILES)
$(info Compiling $< for release)
@mkdir -p $(dir $@)
@$(CXX) -MMD -MP -MF $(BUILD_DIR)/$*.d $(CXX_FLAGS) $(RELEASE_FLAGS) $(INCLUDE) $(EMBED) -c $< -o $@
# Debug
$(OUTPUT_DIR)/%d.a: $(OD_FILES)
$(info Archiving $(notdir $@))
@mkdir -p $(dir $@)
@$(AR) rcs $@ $(OD_FILES)
$(info Compiled $(LIB_NAME) in debug mode!)
$(BUILD_DIR)/%_DEBUG.o: $(SOURCES_DIR)/%.c $(BIN_FILES) $(T3X_FILES)
$(info Compiling $< for debug)
@mkdir -p $(dir $@)
@$(CC) -MMD -MP -MF $(BUILD_DIR)/$*_DEBUG.d $(C_FLAGS) $(DEBUG_FLAGS) $(INCLUDE) $(EMBED) -c $< -o $@
$(BUILD_DIR)/%_DEBUG.o: $(SOURCES_DIR)/%.cpp $(BIN_FILES) $(T3X_FILES)
$(info Compiling $< for debug)
@mkdir -p $(dir $@)
@$(CXX) -MMD -MP -MF $(BUILD_DIR)/$*_DEBUG.d $(CXX_FLAGS) $(DEBUG_FLAGS) $(INCLUDE) $(EMBED) -c $< -o $@
debug: $(OUTPUT_DIR)/lib$(LIB_NAME)d.a
release: $(OUTPUT_DIR)/lib$(LIB_NAME).a
lib: debug release
install: debug release
$(info Installing $(LIB_NAME) to $(DEVKITPRO)/portlibs/3ds...)
@rm -rf $(DEVKITPRO)/portlibs/3ds/include/$(LIB_NAME)
@cp -rv include lib $(DEVKITPRO)/portlibs/3ds > /dev/null
$(info Installed $(LIB_NAME)!)
clean:
@echo Cleaning $(LIB_NAME)...
@rm -rf $(BUILD_DIR) $(OUTPUT_DIR)
-include $(O_FILES:.o=.d) $(OD_FILES:.o=.d)