-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
executable file
·196 lines (149 loc) · 5.55 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
CCX ?= clang
CC ?= clang
ifeq ($(CCX), clang)
CC := clang
OPT_FLAGS := -fno-stack-protector -flto -funsafe-math-optimizations -fno-signed-zeros -fcf-protection=none -mtune=native -fomit-frame-pointer
WARN_FLAGS := -Wno-inconsistent-missing-override -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-function -Wno-write-strings
else
OPT_FLAGS := -fno-stack-protector -finline-small-functions -flto -faggressive-loop-optimizations -funsafe-math-optimizations -fno-signed-zeros -fsingle-precision-constant -fcf-protection=none -fvtable-verify=none -mtune=native -fomit-frame-pointer
WARN_FLAGS := -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-function -Wno-write-strings
endif
UNAME = $(shell uname)
ALL_DYNAMIC ?= true
ifeq ($(TARGET), win32)
DYNAMIC_LIBS_LIST = -luser32 -lgdi32 -lopengl32 -lgdiplus -lShlwapi -ldwmapi -lcomdlg32 -lstdc++fs -static-libgcc -static -pthread
else
STATIC_LIBS_LIST = -lc -lgcc -lstdc++ -lX11 -lstdc++fs -lxcb -lXau -lXdmcp
DYNAMIC_LIBS_LIST = -lGL -ldl -lm -lpthread
endif
ifeq ($(ALL_DYNAMIC), true)
DYNAMIC_LIBS := $(DYNAMIC_LIBS_LIST) $(STATIC_LIBS_LIST)
else
STATIC_LIBS := $(STATIC_LIBS_LIST)
DYNAMIC_LIBS := $(DYNAMIC_LIBS_LIST)
endif
PIXEL_GAME_ENGINE_ARGS := -std=c++17
CC_ARGS = $(WARN_FLAGS)
CCX_ARGS = $(WARN_FLAGS) $(PIXEL_GAME_ENGINE_ARGS)
ifeq ($(TARGET), win32)
PIXEL_GAME_ENGINE_ARGS += -static-libstdc++
DEFINES_DEF =
else
DEFINES_DEF = DATE="\"`date`\"" VER="\"$(VERSION)\"" PROG_NAME="\"$(BUILD)\"" OS_CLEAR="\"$(OS_CLEAR)\""
#FORCE_EXPERIMENTAL_FS
endif
ODIR ?= build
ROOT_DIRECTORY=.
SOURCES := ${shell find ${ROOT_DIRECTORY} -type d -print}
INCLUDE := ./include
C_FILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c) )
C_FILES := $(filter-out ./include/sound/stb_vorbis.c,$(C_FILES))
CPP_FILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp) ) #$(wildcard *.cpp)
ifeq ($(TARGET), win32)
CPP_FILES := $(filter-out ./include/filesys/os/Linux/XFileSelector/utils/Window.cpp,$(CPP_FILES))
CPP_FILES := $(filter-out ./include/filesys/os/Linux/XFileSelector/utils/MainWin.cpp,$(CPP_FILES))
CPP_FILES := $(filter-out ./include/filesys/os/Linux/XFileSelector/FileSelect.cpp,$(CPP_FILES))
endif
H_FILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.h) ) $(wildcard *.h)
ASM_FILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.asm) ) $(wildcard *.asm)
S_FILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.s) ) $(wildcard *.s)
O_FILES = $(abspath $(addprefix $(ODIR)/, $(CPP_FILES:.cpp=.o))) $(abspath $(addprefix $(ODIR)/, $(C_FILES:.c=.o)))
VERSION := 1.1
BUILD ?= sm64sfm
DEFINE_PREFIX ?= -
OS_CLEAR ?= clear
FORCE_EXPERIMENTAL_FS ?= true
DEBUG ?= false
ifeq ($(DEBUG), true)
DEFINES_DEF += DEBUG=$(DEBUG)
CC_ARGS += -g -pg
CCX_ARGS += -g -pg
CC_ARGS += -Wall -Wfatal-errors -Wall -Wextra
CCX_ARGS += -Wall -Wfatal-errors -Wall -Wextra
#CC_ARGS += -Og
#CCX_ARGS += -Og
else
CC_ARGS += -Ofast
CCX_ARGS += -Ofast
CC_ARGS += $(OPT_FLAGS)
CCX_ARGS += $(OPT_FLAGS)
endif
DEFINES = $(foreach def,$(DEFINES_DEF), $(DEFINE_PREFIX)D$(def))
$(ODIR)/./%.o : %.cpp
@echo $(notdir $(basename $*)).cpp
@mkdir -p $(dir $@)
@$(CCX) -c $*.cpp -o $@ -I $(INCLUDE) $(CCX_ARGS) $(DEFINES)
$(ODIR)/./%.o : %.c
@echo $(notdir $(basename $*)).c
@mkdir -p $(dir $@)
@$(CC) -c $*.c -o $@ -I $(INCLUDE) $(CC_ARGS) $(DEFINES)
THREAD_COUNT ?= $(grep -c processor /proc/cpuinfo)
RELEASE_FOLDER ?= release_build
DEBUG_FOLDER ?= debug_build
.PHONY: all
.PHONY: message
.PHONY: compile
.PHONY: release_compile
.PHONY: build
.PHONY: debug
.PHONY: release
$(BUILD): release
all: clean compile run
compile: $(addprefix $(ODIR)/, $(CPP_FILES:.cpp=.o)) $(addprefix $(ODIR)/, $(C_FILES:.c=.o)) | $(ODIR)
@echo "Linking ..."
#$(CCX) $(O_FILES) -o $(BUILD) -I $(INCLUDE) $(CC_ARGS) $(CCX_ARGS) $(DEFINES) $(DYNAMIC_LIBS) ${shell ./maybestatic.sh $(STATIC_LIBS) }
@$(CCX) $(O_FILES) -o $(BUILD) -I $(INCLUDE) $(CC_ARGS) $(CCX_ARGS) $(DEFINES) $(DYNAMIC_LIBS)
#@printf " $(subst ",\", ${shell ./maybestatic.sh $(STATIC_LIBS) })" >> link.sh
# @chmod +x ./link.sh
# @./link.sh
@echo "\033[32;1mDone!\033[30;0m"
release_compile: compile
@strip $(BUILD) -o $(BUILD).tmp
@mv $(BUILD).tmp $(BUILD)
message:
@echo Building ...
@echo "\tDebug Build = $(DEBUG)"
@echo "\tTarget = $(UNAME)"
@echo "\tVersion = $(VERSION)"
@echo "\tC++ Files to Compile = $(words $(CPP_FILES))"
@echo "\tC Files to Compile = $(words $(C_FILES))"
$(ODIR):
@mkdir -p $@
link:
@echo $(CCX) $(O_FILES) -o $(BUILD) -I $(INCLUDE) $(CC_ARGS) $(CCX_ARGS) $(DEFINES)
run:
@./$(BUILD)
clean:
@rm -rf $(ODIR)
@rm -rf $(RELEASE_FOLDER)
@rm -rf $(DEBUG_FOLDER)
@rm -rf x64
@rm -rf Debug
@rm -rf Release
@rm -rf .vs
@rm -rf $(BUILD)
debug:
@$(MAKE) message DEBUG=true --no-print-directory
@$(MAKE) -j $(THREAD_COUNT) compile ODIR="$(DEBUG_FOLDER)" DEBUG=true --no-print-directory
release:
@$(MAKE) message --no-print-directory
@$(MAKE) -j $(THREAD_COUNT) release_compile ODIR="$(RELEASE_FOLDER)" --no-print-directory
DESKTOP_SHORTCUT_DIR = /usr/share/applications
install:
@$(MAKE) clean --no-print-directory
@$(MAKE) compile -j $(THREAD_COUNT) --no-print-directory
#files belong to root now so allow all users to access them again
@chmod -R +rwx build
@mkdir -p /usr/local/bin
@cp ./$(BUILD) /usr/local/bin
@chmod +x /usr/local/bin/$(BUILD)
#install desktop/start menu shortcut
@cp ./linux_only_tools/$(BUILD).desktop $(DESKTOP_SHORTCUT_DIR)/sm64sfm.desktop
@chmod +x $(DESKTOP_SHORTCUT_DIR)/sm64sfm.desktop
@$(MAKE) clean --no-print-directory
@echo Installed Successfully!
uninstall:
#create install location
@rm -rf $(INSTALL_DIR)
@rm -f /usr/bin/sm64fm
@echo Deleted Successfully!