@@ -5,10 +5,12 @@ CROSS ?= none
5
5
6
6
UNAME_S := $(shell uname -s)
7
7
UNAME_M := $(shell uname -m)
8
- rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1* ) ,$(call rwildcard,$d/,$2) )
8
+ rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1* ) ,$(call rwildcard,$d/,$2) )
9
9
CC_IS_CLANG := $(shell $(CC ) --version | grep -q clang && echo true || echo false)
10
10
11
- PACKAGES := capstone freetype2 glfw3 libavcodec libavformat libavutil libswresample libuv zlib libcurl
11
+ PACKAGES := capstone freetype2 glfw3 libavcodec libavformat libavutil libswresample libcurl libuv zlib
12
+ OPTIONAL_PACKAGES := md4c fmt libllhttp libluv liburiparser
13
+ OPTIONAL_LIBRARIES := multipart ucl
12
14
13
15
LOCALES := el es_ES fr ja pt_BR uk zh_CN
14
16
@@ -19,29 +21,28 @@ HAS_SUBMODULES = true
19
21
endif
20
22
21
23
CXXFLAGS += -std=c++2b
22
- CPPFLAGS += ` pkg-config --cflags $( PACKAGES) `
23
24
CPPFLAGS += -I.
24
25
CPPFLAGS += -Isrc
25
26
CPPFLAGS += -Ithird_party
26
27
CPPFLAGS += -Ithird_party/ELFIO
27
- CPPFLAGS += -Ithird_party/fmt/include/
28
+ CPPFLAGS_pkg_fmt += -Ithird_party/fmt/include/
28
29
CPPFLAGS += -Ithird_party/gl3w
29
30
CPPFLAGS += -Ithird_party/googletest/googletest/include
30
31
CPPFLAGS += -Ithird_party/imgui
31
32
CPPFLAGS += -Ithird_party/imgui/backends
32
33
CPPFLAGS += -Ithird_party/imgui/examples
33
34
CPPFLAGS += -Ithird_party/imgui/misc/cpp
34
35
CPPFLAGS += -Ithird_party/libelfin
35
- CPPFLAGS += -Ithird_party/llhttp
36
+ CPPFLAGS_pkg_libllhttp += -Ithird_party/llhttp
36
37
CPPFLAGS += -Ithird_party/luajit/src
37
- CPPFLAGS += -Ithird_party/luv/src
38
- CPPFLAGS += -Ithird_party/luv/deps/lua-compat-5.3/c-api
38
+ CPPFLAGS_pkg_libluv += -Ithird_party/luv/src
39
+ CPPFLAGS_pkg_libluv += -Ithird_party/luv/deps/lua-compat-5.3/c-api
39
40
CPPFLAGS += -Ithird_party/magic_enum/include/magic_enum
40
- CPPFLAGS += -Ithird_party/md4c/src
41
- CPPFLAGS += -Ithird_party/multipart-parser-c
41
+ CPPFLAGS_pkg_md4c += -Ithird_party/md4c/src
42
+ CPPFLAGS_lib_multipart += -Ithird_party/multipart-parser-c
42
43
CPPFLAGS += -Ithird_party/tracy/public
43
- CPPFLAGS += -Ithird_party/ucl -Ithird_party/ucl/include
44
- CPPFLAGS += -Ithird_party/uriparser/include
44
+ CPPFLAGS_lib_ucl += -Ithird_party/ucl -Ithird_party/ucl/include
45
+ CPPFLAGS_pkg_liburiparser += -Ithird_party/uriparser/include
45
46
CPPFLAGS += -Ithird_party/zep/extensions
46
47
CPPFLAGS += -Ithird_party/zep/include
47
48
CPPFLAGS += -Ithird_party/xbyak/xbyak
@@ -75,7 +76,6 @@ ifeq ($(UNAME_S),Darwin)
75
76
endif
76
77
77
78
LUAJIT_LDFLAGS := $(LDFLAGS )
78
- LDFLAGS += ` pkg-config --libs $( PACKAGES) `
79
79
80
80
ifeq ($(UNAME_S ) ,Darwin)
81
81
LDFLAGS += -lc++ -framework GLUT -framework OpenGL -framework CoreFoundation -framework Cocoa
@@ -108,8 +108,8 @@ endif
108
108
109
109
LD := $(CXX )
110
110
111
- SRCS : = $(call rwildcard,src/,* .cc)
112
- SRCS += third_party/fmt/src/os.cc third_party/fmt/src/format.cc
111
+ SRCS + = $(call rwildcard,src/,* .cc)
112
+ SRCS_pkg_fmt += third_party/fmt/src/os.cc third_party/fmt/src/format.cc
113
113
IMGUI_SRCS += $(wildcard third_party/imgui/* .cpp)
114
114
VIXL_SRCS := $(call rwildcard, third_party/vixl/src,* .cc)
115
115
SRCS += $(IMGUI_SRCS )
@@ -129,16 +129,16 @@ SRCS += third_party/imgui/misc/freetype/imgui_freetype.cpp
129
129
SRCS += third_party/imgui_lua_bindings/imgui_lua_bindings.cpp
130
130
SRCS += third_party/imgui_md/imgui_md.cpp
131
131
SRCS += third_party/imgui_memory_editor/imgui_memory_editor.cpp
132
- SRCS += $(wildcard third_party/llhttp/* .c)
132
+ SRCS_pkg_libllhttp += $(wildcard third_party/llhttp/* .c)
133
133
SRCS += $(wildcard third_party/lpeg/* .c)
134
134
SRCS += third_party/lua-protobuf/pb.c
135
135
SRCS += third_party/luafilesystem/src/lfs.c
136
- SRCS += third_party/luv/src/luv.c
137
- SRCS += third_party/md4c/src/md4c.c
138
- SRCS += third_party/multipart-parser-c/multipart_parser.c
136
+ SRCS_pkg_libluv += third_party/luv/src/luv.c
137
+ SRCS_pkg_md4c += third_party/md4c/src/md4c.c
138
+ SRCS_lib_multipart += third_party/multipart-parser-c/multipart_parser.c
139
139
SRCS += third_party/nanovg/src/nanovg.c
140
- SRCS += third_party/tracy/public/TracyClient.cpp
141
- SRCS += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c
140
+ SRCS_ReleaseWithTracy += third_party/tracy/public/TracyClient.cpp
141
+ SRCS_lib_ucl += third_party/ucl/src/n2e_99.c third_party/ucl/src/alloc.c
142
142
SRCS += $(wildcard third_party/uriparser/src/* .c)
143
143
SRCS += third_party/zep/extensions/repl/mode_repl.cpp
144
144
SRCS += $(wildcard third_party/zep/src/* .cpp)
@@ -176,6 +176,37 @@ TOOLS = exe2elf exe2iso modconv ps1-packer psyq-obj-parser
176
176
177
177
# #############################################################################
178
178
179
+ SRCS += $(SRCS_$(BUILD ) )
180
+
181
+ define CHECK_PKG
182
+ ifeq ($(shell pkg-config --exists $(1 ) && echo true || echo false) ,true)
183
+ PACKAGES += $(1 )
184
+ else
185
+ CPPFLAGS += $(CPPFLAGS_pkg_$(1 ) )
186
+ LDFLAGS += $(LDFLAGS_pkg_$(1 ) )
187
+ SRCS += $(SRCS_pkg_$(1 ) )
188
+ endif
189
+ endef
190
+
191
+ define CHECK_LIB
192
+ ifeq ($(shell echo "int main() {}" | gcc -x c - -l$(1 ) -Wl,--no-as-needed -Wl,--unresolved-symbols=ignore-all -Wl,--no-undefined -o /dev/null >& /dev/null && echo true || echo false),true)
193
+ LDFLAGS += -l$(1 )
194
+ else
195
+ CPPFLAGS += $(CPPFLAGS_lib_$(1 ) )
196
+ LDFLAGS += $(LDFLAGS_lib_$(1 ) )
197
+ SRCS += $(SRCS_lib_$(1 ) )
198
+ endif
199
+ endef
200
+
201
+ $(foreach pkg,$(OPTIONAL_PACKAGES),$(eval $(call CHECK_PKG,$(pkg))))
202
+ $(foreach lib,$(OPTIONAL_LIBRARIES),$(eval $(call CHECK_LIB,$(lib))))
203
+
204
+ CPPFLAGS_PKGCONFIG := $(shell pkg-config --cflags $(PACKAGES ) )
205
+ LDFLAGS_PKGCONFIG := $(shell pkg-config --libs $(PACKAGES ) )
206
+
207
+ CPPFLAGS += $(CPPFLAGS_PKGCONFIG )
208
+ LDFLAGS += $(LDFLAGS_PKGCONFIG )
209
+
179
210
OBJECTS += $(patsubst % .c,% .o,$(filter % .c,$(SRCS ) ) )
180
211
OBJECTS += $(patsubst % .cc,% .o,$(filter % .cc,$(SRCS ) ) )
181
212
OBJECTS += $(patsubst % .cpp,% .o,$(filter % .cpp,$(SRCS ) ) )
@@ -259,13 +290,13 @@ $(TARGET): $(OBJECTS)
259
290
% .o : % .mm
260
291
$(CC ) -c -o $@ $< $(CPPFLAGS ) $(EXTRA_CPPFLAGS ) $(CFLAGS )
261
292
262
- % .dep : % .c
293
+ % .dep : third_party/luajit/src/luajit.h % .c
263
294
$(CC ) $(CPPFLAGS ) $(EXTRA_CPPFLAGS ) $(CFLAGS ) -M -MT $(addsuffix .o, $(basename $@ ) ) -MF $@ $<
264
295
265
- % .dep : % .cc
296
+ % .dep : third_party/luajit/src/luajit.h % .cc
266
297
$(CXX ) $(CPPFLAGS ) $(EXTRA_CPPFLAGS ) $(CXXFLAGS ) -M -MT $(addsuffix .o, $(basename $@ ) ) -MF $@ $<
267
298
268
- % .dep : % .cpp
299
+ % .dep : third_party/luajit/src/luajit.h % .cpp
269
300
$(CXX ) $(CPPFLAGS ) $(EXTRA_CPPFLAGS ) $(CXXFLAGS ) -M -MT $(addsuffix .o, $(basename $@ ) ) -MF $@ $<
270
301
271
302
clean :
@@ -329,3 +360,7 @@ endif
329
360
endif
330
361
endif
331
362
endif
363
+
364
+ third_party/luajit/src/lua.hpp : third_party/luajit/src/luajit.h
365
+
366
+ third_party/luajit/src/luajit.h : third_party/luajit/src/libluajit.a
0 commit comments