-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
179 lines (159 loc) · 9.43 KB
/
Makefile
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
# This Makefile was adapted from the one shared
# here: https://stackoverflow.com/a/27025822
#----------------------------------------------------------------------------------------------------------------------
# Default target is 'library'
#----------------------------------------------------------------------------------------------------------------------
.DEFAULT_GOAL := library
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Try to build for Switch by default, unless otherwise specified
#----------------------------------------------------------------------------------------------------------------------
ifneq "$(PLATFORM)" "__LINUX__"
$(info Note: Building for default platform '__SWITCH__')
PLATFORM := __SWITCH__
endif
#----------------------------------------------------------------------------------------------------------------------
ifeq "$(PLATFORM)" "__SWITCH__"
#----------------------------------------------------------------------------------------------------------------------
# Check if DEVKITPRO exists in current environment
#----------------------------------------------------------------------------------------------------------------------
ifndef DEVKITPRO
$(error DEVKITPRO is not present in your environment. This can be fixed by sourcing switchvars.sh from /opt/devkitpro/)
endif
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Include switch build toolchain file
#----------------------------------------------------------------------------------------------------------------------
include $(DEVKITPRO)/libnx/switch_rules
#----------------------------------------------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIC -ftls-model=local-exec
endif
#----------------------------------------------------------------------------------------------------------------------
# Definition of variables used throughout the make process
# TARGET: Library name
# BUILD: Directory to store build files
# LIB: Directory to place final binary
# OUTPUT: Path to output to
# INCLUDE: Directory containing .hpp files
# SOURCE: Directory containing .cpp files
# DOCS_CONFIG: Path to doxygen config file
#----------------------------------------------------------------------------------------------------------------------
TARGET := Aether
BUILD := build
LIB := lib
OUTPUT := $(LIB)/lib$(TARGET).a
INCLUDE := include
SOURCE := source
DOCS_CONFIG := Doxyfile
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Definition of code generation related variables
#----------------------------------------------------------------------------------------------------------------------
OBJDIR := $(BUILD)/objs
DEPDIR := $(BUILD)/deps
DEFINES := -D$(PLATFORM)
ifeq "$(PLATFORM)" "__SWITCH__"
LIBDIRS := $(PORTLIBS) $(LIBNX)
endif
INCLUDE := $(foreach dir,$(LIBDIRS),-I$(dir)/include) -I$(INCLUDE)
CFLAGS := -w -g -Wall -O3 -ffunction-sections -fdata-sections $(shell sdl2-config --cflags)\
$(ARCH) $(INCLUDE) $(DEFINES)
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++17
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Definition of variables which store file locations
#----------------------------------------------------------------------------------------------------------------------
CPPFILES := $(shell find $(SOURCE)/ -name "*.cpp")
OBJS := $(CPPFILES:$(SOURCE)/%.cpp=$(OBJDIR)/%.o)
DEPS := $(CPPFILES:$(SOURCE)/%.cpp=$(DEPDIR)/%.d)
TREE := $(sort $(patsubst %/,%,$(dir $(OBJS))))
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Include dependent files if they already exist
#----------------------------------------------------------------------------------------------------------------------
ifeq "$(MAKECMDGOALS)" ""
-include $(DEPS)
endif
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define few virtual make targets
#----------------------------------------------------------------------------------------------------------------------
.PHONY: library install uninstall docs clean cleandocs
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define target rule pre-requisites
#----------------------------------------------------------------------------------------------------------------------
library : $(OUTPUT)
.SECONDEXPANSION:
$(OBJDIR)/%.o: $(SOURCE)/%.cpp | $$(@D)
@echo -n Compiling $*.o...
@$(CXX) -MMD -MP -MF $(@:$(OBJDIR)/%.o=$(DEPDIR)/%.d) $(CXXFLAGS) -o $@ -c $<
@echo Done!
install : library
$(OUTPUT) : $(OBJS)
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define rule recipe `clean`
#----------------------------------------------------------------------------------------------------------------------
clean:
@echo -n Cleaning build files...
@rm -rf $(BUILD) $(LIB)
@echo Done!
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define rule recipe `cleandocs`
#----------------------------------------------------------------------------------------------------------------------
cleandocs:
@echo -n Cleaning generated docs...
@rm -rf docs
@echo Done!
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define rule recipe `install`
#----------------------------------------------------------------------------------------------------------------------
install:
@echo -n Installing Aether headers...
@mkdir -p $(PORTLIBS_PREFIX)/include/Aether/
@cp -r $(INCLUDES)/Aether/* $(PORTLIBS_PREFIX)/include/Aether/
@echo Done!
@echo -n Installing Aether library file...
@mkdir -p $(PORTLIBS_PREFIX)/lib/
@cp $(OUTPUT) $(PORTLIBS_PREFIX)/lib/
@echo Done!
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define rule recipe `uninstall`
#----------------------------------------------------------------------------------------------------------------------
uninstall:
@echo -n Removing Aether headers if present...
@rm -rf $(PORTLIBS_PREFIX)/include/Aether/
@echo Done!
@echo -n Removing Aether library archive if present...
@rm $(PORTLIBS_PREFIX)/lib/libAether.a
@echo Done!
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define rule recipe `$(OUTPUT)`
#----------------------------------------------------------------------------------------------------------------------
$(OUTPUT):
@[ -d $(LIB) ] || mkdir -p $(LIB)
@rm -rf $(OUTPUT)
@echo -n Creating Aether library archive at $(OUTPUT)...
@$(AR) -rc $(OUTPUT) $(OBJS)
@echo Done!
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define rule recipe `docs`
#----------------------------------------------------------------------------------------------------------------------
docs:
@[ -d $@ ] || mkdir -p $@
@echo -n Generating docs...
@doxygen $(DOCS_CONFIG)
@echo Done!
#----------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------
# Define rule recipe `$(TREE)` (creates directories for .o and .d files)
#----------------------------------------------------------------------------------------------------------------------
$(TREE): %:
@mkdir -p $@
@mkdir -p $(@:$(OBJDIR)%=$(DEPDIR)%)