forked from grumpycoders/pcsx-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
326 lines (271 loc) · 11.9 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
TARGET := pcsx-redux
BUILD ?= Release
DESTDIR ?= /usr/local
CROSS ?= none
UNAME_S := $(shell uname -s)
UNAME_M := $(shell uname -m)
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
CC_IS_CLANG := $(shell $(CC) --version | grep -q clang && echo true || echo false)
PACKAGES := capstone freetype2 glfw3 libavcodec libavformat libavutil libswresample libuv zlib libcurl
LOCALES := el es_ES fr ja pt_BR uk zh_CN
ifeq ($(wildcard third_party/imgui/imgui.h),)
HAS_SUBMODULES = false
else
HAS_SUBMODULES = true
endif
CXXFLAGS += -std=c++2b
CPPFLAGS += `pkg-config --cflags $(PACKAGES)`
CPPFLAGS += -I.
CPPFLAGS += -Isrc
CPPFLAGS += -Ithird_party
CPPFLAGS += -Ithird_party/ELFIO
CPPFLAGS += -Ithird_party/fmt/include/
CPPFLAGS += -Ithird_party/gl3w
CPPFLAGS += -Ithird_party/googletest/googletest/include
CPPFLAGS += -Ithird_party/imgui
CPPFLAGS += -Ithird_party/imgui/backends
CPPFLAGS += -Ithird_party/imgui/examples
CPPFLAGS += -Ithird_party/imgui/misc/cpp
CPPFLAGS += -Ithird_party/http-parser
CPPFLAGS += -Ithird_party/libelfin
CPPFLAGS += -Ithird_party/luajit/src
CPPFLAGS += -Ithird_party/luv/src
CPPFLAGS += -Ithird_party/luv/deps/lua-compat-5.3/c-api
CPPFLAGS += -Ithird_party/md4c/src
CPPFLAGS += -Ithird_party/ucl -Ithird_party/ucl/include
CPPFLAGS += -Ithird_party/zep/extensions
CPPFLAGS += -Ithird_party/zep/include
CPPFLAGS += -Ithird_party/xbyak/xbyak
CPPFLAGS += -g
CPPFLAGS += -DIMGUI_IMPL_OPENGL_LOADER_GL3W -DIMGUI_ENABLE_FREETYPE
CPPFLAGS += -DZEP_FEATURE_CPP_FILE_SYSTEM
CPPFLAGS += -DNVG_NO_STB
CPPFLAGS += -DPB_STATIC_API
IMGUI_CPPFLAGS += -include src/forced-includes/imgui.h
CPPFLAGS_Release += -O3
CPPFLAGS_Debug += -O0
CPPFLAGS_Coverage += -O0
ifeq ($(CC_IS_CLANG),true)
CPPFLAGS_Coverage += -fprofile-instr-generate -fcoverage-mapping
else
CPPFLAGS_Coverage += -fprofile-arcs -ftest-coverage
endif
CPPFLAGS_asan += -O1 -fsanitize=address -fno-omit-frame-pointer
CPPFLAGS_ubsan += -O1 -fsanitize=undefined -fno-omit-frame-pointer
CPPFLAGS_lto += -O3 -flto=auto -fno-fat-lto-objects -flto-partition=one
CPPFLAGS_ReleaseWithTracy += -O3 -DTRACY_ENABLE
ifeq ($(CC_IS_CLANG),true)
LUAJIT_CFLAGS = -fno-stack-check
endif
ifeq ($(UNAME_S),Darwin)
CPPFLAGS += -mmacosx-version-min=10.15
CPPFLAGS += -stdlib=libc++
endif
LUAJIT_LDFLAGS := $(LDFLAGS)
LDFLAGS += `pkg-config --libs $(PACKAGES)`
ifeq ($(UNAME_S),Darwin)
LDFLAGS += -lc++ -framework GLUT -framework OpenGL -framework CoreFoundation -framework Cocoa
LDFLAGS += -mmacosx-version-min=10.15
else
LDFLAGS += -lstdc++fs
LDFLAGS += -lGL -lX11 -lxcb
endif
LDFLAGS += third_party/luajit/src/libluajit.a
LDFLAGS += -ldl
LDFLAGS += -g
ifeq ($(CC_IS_CLANG),true)
LDFLAGS_Coverage += -fprofile-instr-generate -fcoverage-mapping
else
LDFLAGS_Coverage += -fprofile-arcs -ftest-coverage
endif
LDFLAGS_asan += -fsanitize=address
LDFLAGS_ubsan += -fsanitize=undefined
LDFLAGS_lto += -O3 -flto=auto -flto-partition=one
CPPFLAGS += $(CPPFLAGS_$(BUILD)) -pthread
LDFLAGS += $(LDFLAGS_$(BUILD)) -pthread
ifeq ($(CROSS),arm64)
CPPFLAGS += -fPIC -Wl,-rpath-link,/opt/cross/sysroot/usr/lib/aarch64-linux-gnu -L/opt/cross/sysroot/usr/lib/aarch64-linux-gnu
LDFLAGS += -fPIC -Wl,-rpath-link,/opt/cross/sysroot/usr/lib/aarch64-linux-gnu -L/opt/cross/sysroot/usr/lib/aarch64-linux-gnu
endif
LD := $(CXX)
SRCS := $(call rwildcard,src/,*.cc)
SRCS += third_party/fmt/src/os.cc third_party/fmt/src/format.cc
IMGUI_SRCS += $(wildcard third_party/imgui/*.cpp)
VIXL_SRCS := $(call rwildcard, third_party/vixl/src,*.cc)
SRCS += $(IMGUI_SRCS)
SRCS += $(wildcard third_party/libelfin/*.cc)
SRCS += third_party/cq/reclaimer.cc
SRCS += third_party/clip/clip.cpp
SRCS += third_party/clip/image.cpp
SRCS += $(wildcard third_party/cueparser/*.c)
SRCS += third_party/gl3w/GL/gl3w.c
SRCS += third_party/gl3w/GL/gl3w-throwers.cc
SRCS += third_party/http-parser/http_parser.c
SRCS += $(wildcard third_party/iec-60908b/*.c)
SRCS += third_party/ImFileDialog/ImFileDialog.cpp
SRCS += third_party/imgui/backends/imgui_impl_opengl3.cpp
SRCS += third_party/imgui/backends/imgui_impl_glfw.cpp
SRCS += third_party/imgui/misc/cpp/imgui_stdlib.cpp
SRCS += third_party/imgui/misc/freetype/imgui_freetype.cpp
SRCS += third_party/imgui_lua_bindings/imgui_lua_bindings.cpp
SRCS += third_party/imgui_md/imgui_md.cpp
SRCS += third_party/imgui_memory_editor/imgui_memory_editor.cpp
SRCS += $(wildcard third_party/lpeg/*.c)
SRCS += third_party/lua-protobuf/pb.c
SRCS += third_party/luafilesystem/src/lfs.c
SRCS += third_party/luv/src/luv.c
SRCS += third_party/md4c/src/md4c.c
SRCS += third_party/multipart-parser-c/multipart_parser.c
SRCS += third_party/nanovg/src/nanovg.c
SRCS += third_party/tracy/public/TracyClient.cpp
SRCS += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c
SRCS += third_party/zep/extensions/repl/mode_repl.cpp
SRCS += $(wildcard third_party/zep/src/*.cpp)
SRCS += third_party/zep/src/mcommon/animation/timer.cpp
SRCS += third_party/zep/src/mcommon/file/path.cpp
SRCS += third_party/zep/src/mcommon/string/stringutils.cpp
ifeq ($(UNAME_S),Darwin)
SRCS += src/main/complain.mm third_party/clip/clip_osx.mm
else
SRCS += third_party/clip/clip_x11.cpp
endif
ifeq ($(UNAME_M),aarch64)
SRCS += $(VIXL_SRCS)
CPPFLAGS += -DVIXL_INCLUDE_TARGET_AARCH64 -DVIXL_CODE_BUFFER_MMAP
CPPFLAGS += -Ithird_party/vixl/src -Ithird_party/vixl/src/aarch64
endif
ifeq ($(UNAME_M),arm64)
SRCS += $(VIXL_SRCS)
CPPFLAGS += -DVIXL_INCLUDE_TARGET_AARCH64 -DVIXL_CODE_BUFFER_MMAP
CPPFLAGS += -Ithird_party/vixl/src -Ithird_party/vixl/src/aarch64
endif
ifeq ($(CROSS),arm64)
SRCS += $(VIXL_SRCS)
CPPFLAGS += -DVIXL_INCLUDE_TARGET_AARCH64 -DVIXL_CODE_BUFFER_MMAP
CPPFLAGS += -Ithird_party/vixl/src -Ithird_party/vixl/src/aarch64
endif
SUPPORT_SRCS := src/support/file.cc src/support/mem4g.cc src/support/zfile.cc
SUPPORT_SRCS += src/supportpsx/adpcm.cc src/supportpsx/binloader.cc src/supportpsx/ps1-packer.cc
SUPPORT_SRCS += third_party/fmt/src/os.cc third_party/fmt/src/format.cc
SUPPORT_SRCS += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c
SUPPORT_SRCS += $(wildcard third_party/iec-60908b/*.c)
OBJECTS := third_party/luajit/src/libluajit.a
TOOLS = exe2elf exe2iso modconv ps1-packer psyq-obj-parser
##############################################################################
OBJECTS += $(patsubst %.c,%.o,$(filter %.c,$(SRCS)))
OBJECTS += $(patsubst %.cc,%.o,$(filter %.cc,$(SRCS)))
OBJECTS += $(patsubst %.cpp,%.o,$(filter %.cpp,$(SRCS)))
OBJECTS += $(patsubst %.mm,%.o,$(filter %.mm,$(SRCS)))
SUPPORT_OBJECTS := $(patsubst %.c,%.o,$(filter %.c,$(SUPPORT_SRCS)))
SUPPORT_OBJECTS += $(patsubst %.cc,%.o,$(filter %.cc,$(SUPPORT_SRCS)))
NONMAIN_OBJECTS := $(filter-out src/main/mainthunk.o,$(OBJECTS))
IMGUI_OBJECTS := $(patsubst %.cpp,%.o,$(filter %.cpp,$(IMGUI_SRCS)))
VIXL_OBJECTS := $(patsubst %.cc,%.o,$(filter %.cc,$(VIXL_SRCS)))
$(IMGUI_OBJECTS): EXTRA_CPPFLAGS := $(IMGUI_CPPFLAGS)
TESTS_SRC := $(call rwildcard,tests/,*.cc)
TESTS := $(patsubst %.cc,%,$(TESTS_SRC))
CP ?= cp
MKDIRP ?= mkdir -p
all: check_submodules dep $(TARGET)
ifeq ($(HAS_SUBMODULES),true)
check_submodules:
else
check_submodules:
@echo "You need to clone this repository recursively, in order to get its submodules."
@false
endif
strip: all
strip $(TARGET)
openbios:
$(MAKE) $(MAKEOPTS) -C src/mips/openbios
install: all strip
$(MKDIRP) $(DESTDIR)/bin
$(MKDIRP) $(DESTDIR)/share/applications
$(MKDIRP) $(DESTDIR)/share/icons/hicolor/256x256/apps
$(MKDIRP) $(DESTDIR)/share/pcsx-redux/fonts
$(MKDIRP) $(DESTDIR)/share/pcsx-redux/i18n
$(MKDIRP) $(DESTDIR)/share/pcsx-redux/resources
$(CP) $(TARGET) $(DESTDIR)/bin
$(CP) resources/pcsx-redux.desktop $(DESTDIR)/share/applications
convert resources/pcsx-redux.ico[0] -alpha on -background none $(DESTDIR)/share/icons/hicolor/256x256/apps/pcsx-redux.png
$(CP) third_party/noto/* $(DESTDIR)/share/pcsx-redux/fonts
$(CP) i18n/*.po $(DESTDIR)/share/pcsx-redux/i18n
$(CP) resources/*.ico $(DESTDIR)/share/pcsx-redux/resources
$(CP) third_party/SDL_GameControllerDB/LICENSE $(DESTDIR)/share/pcsx-redux/resources
$(CP) third_party/SDL_GameControllerDB/gamecontrollerdb.txt $(DESTDIR)/share/pcsx-redux/resources
install-openbios: openbios
$(MKDIRP) $(DESTDIR)/share/pcsx-redux/resources
$(CP) src/mips/openbios/openbios.bin $(DESTDIR)/share/pcsx-redux/resources
zip -j src/mips/openbios/openbios.zip src/mips/openbios/openbios.elf
appimage:
rm -rf AppDir
DESTDIR=AppDir/usr $(MAKE) $(MAKEOPTS) install
appimage-builder --skip-tests
ifeq ($(CROSS),arm64)
third_party/luajit/src/libluajit.a:
$(MAKE) $(MAKEOPTS) -C third_party/luajit/src amalg HOST_CC=cc CROSS=aarch64-linux-gnu- TARGET_CFLAGS=--sysroot=/opt/cross/sysroot BUILDMODE=static CFLAGS=$(LUAJIT_CFLAGS) LDFLAGS=$(LUAJIT_LDFLAGS) XCFLAGS="-DLUAJIT_ENABLE_GC64 -DLUAJIT_ENABLE_LUA52COMPAT" MACOSX_DEPLOYMENT_TARGET=10.15
else
third_party/luajit/src/libluajit.a:
$(MAKE) $(MAKEOPTS) -C third_party/luajit/src amalg CC=$(CC) BUILDMODE=static CFLAGS=$(LUAJIT_CFLAGS) LDFLAGS=$(LUAJIT_LDFLAGS) XCFLAGS="-DLUAJIT_ENABLE_GC64 -DLUAJIT_ENABLE_LUA52COMPAT" MACOSX_DEPLOYMENT_TARGET=10.15
endif
$(TARGET): $(OBJECTS)
$(LD) -o $@ $(OBJECTS) $(LDFLAGS)
%.o: %.c
$(CC) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CFLAGS)
%.o: %.cc
$(CXX) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS)
%.o: %.cpp
$(CXX) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS)
%.o: %.mm
$(CC) -c -o $@ $< $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CFLAGS)
%.dep: %.c
$(CC) $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $<
%.dep: %.cc
$(CXX) $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $<
%.dep: %.cpp
$(CXX) $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CXXFLAGS) -M -MT $(addsuffix .o, $(basename $@)) -MF $@ $<
clean:
rm -f $(OBJECTS) $(TARGET) $(DEPS) gtest-all.o gtest_main.o
$(MAKE) -C third_party/luajit clean MACOSX_DEPLOYMENT_TARGET=10.15
gtest-all.o: $(wildcard third_party/googletest/googletest/src/*.cc)
$(CXX) -O3 -g $(CXXFLAGS) -Ithird_party/googletest/googletest -Ithird_party/googletest/googletest/include -c third_party/googletest/googletest/src/gtest-all.cc
gtest_main.o: third_party/googletest/googletest/src/gtest_main.cc
$(CXX) -O3 -g $(CXXFLAGS) -Ithird_party/googletest/googletest -Ithird_party/googletest/googletest/include -c third_party/googletest/googletest/src/gtest_main.cc
gitclean:
git clean -f -d -x
git submodule foreach --recursive git clean -f -d -x
define msgmerge
-msgmerge --update i18n/$(1).po i18n/pcsx-redux.pot
endef
regen-i18n:
find src -name *.cc -or -name *.c -or -name *.h | sort -u > pcsx-src-list.txt
xgettext --from-code=utf-8 --keyword=_ --keyword=f_ --keyword=l_ --language=C++ --add-comments --sort-by-file -o i18n/pcsx-redux.pot -f pcsx-src-list.txt
find src -name *.lua | sort -u > pcsx-src-list.txt
xgettext --from-code=utf-8 --keyword=t_ --language=Lua --join-existing --sort-by-file -o i18n/pcsx-redux.pot -f pcsx-src-list.txt
sed '/POT-Creation-Date/d' -i i18n/pcsx-redux.pot
rm pcsx-src-list.txt
$(foreach l,$(LOCALES),$(call msgmerge,$(l)))
pcsx-redux-tests: $(foreach t,$(TESTS),$(t).o) $(NONMAIN_OBJECTS) gtest-all.o gtest_main.o
$(LD) -o pcsx-redux-tests $(NONMAIN_OBJECTS) gtest-all.o gtest_main.o $(foreach t,$(TESTS),$(t).o) -Ithird_party/googletest/googletest/include $(LDFLAGS)
runtests: pcsx-redux-tests
./pcsx-redux-tests
define TOOLDEF
$(1): $(SUPPORT_OBJECTS) tools/$(1)/$(1).o
$(LD) -o $(1) $(CPPFLAGS) $(CXXFLAGS) $(SUPPORT_OBJECTS) tools/$(1)/$(1).o -static -lz
endef
$(foreach tool,$(TOOLS),$(eval $(call TOOLDEF,$(tool))))
tools: $(TOOLS)
.PHONY: all dep clean gitclean regen-i18n runtests openbios install strip appimage tools
DEPS += $(patsubst %.c,%.dep,$(filter %.c,$(SRCS)))
DEPS += $(patsubst %.cc,%.dep,$(filter %.cc,$(SRCS)))
DEPS += $(patsubst %.cpp,%.dep,$(filter %.cpp,$(SRCS)))
dep: $(DEPS)
ifneq ($(MAKECMDGOALS), regen-i18n)
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), gitclean)
ifeq ($(HAS_SUBMODULES), true)
-include $(DEPS)
endif
endif
endif
endif