forked from JohnnyonFlame/gmloader-next
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile.gmloader
89 lines (70 loc) · 3.01 KB
/
Makefile.gmloader
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
ARCH ?= aarch64-linux-gnu
CROSS ?= ${ARCH}-
CC := ${CROSS}gcc
CXX := ${CROSS}g++
LD := ${CROSS}ld
PKG_CONFIG := ${CROSS}pkg-config
BUILD_DATE = $(shell date +"%Y%m%d_%H%M%S")
GIT_BRANCH = ${GITHUB_REF_NAME}
GIT_BRANCH_FRIENDLY = $(subst -,_,$(GIT_BRANCH))
DEVICE_ARCH = aarch64
ifeq ($(ARCH), arm-linux-gnueabihf)
DEVICE_ARCH = armhf
endif
LIBS=\
-pthread \
-lm \
-lrt \
$(shell ${PKG_CONFIG} sdl2 --libs) \
$(shell ${PKG_CONFIG} zlib --libs) \
$(shell ${PKG_CONFIG} libzip --libs)
# General compilation flags
OPTM?=-Os
COMMONFLAGS=-Wno-strict-aliasing -Werror=return-type -I. -I./thunks/ -I./loader/ -I./gmloader/ -I./build/${ARCH}/thunks/libc -I./jni/ -I./3rdparty/json/include ${OPTM} -MMD
CFLAGS=$(shell ${PKG_CONFIG} sdl2 --cflags) ${COMMONFLAGS}
CXXFLAGS=-std=gnu++2a -fuse-cxa-atexit $(shell ${PKG_CONFIG} sdl2 --cflags) ${COMMONFLAGS}
LDFLAGS=-L3rdparty/libbsd/src/.libs ${OPTM} -Wl,--defsym,BUILD_DATE_$(BUILD_DATE)=0 -Wl,--defsym,GIT_HASH_$(GITHUB_SHA)=0 -Wl,--defsym,GIT_BRANCH_$(GIT_BRANCH_FRIENDLY)=0
# General pre-processing flags
LLVM_FILE?=
LLVM_INC?=/usr/${ARCH}/include
GENERATE?=--llvm-includes ${LLVM_INC}
ifneq (${LLVM_FILE},)
GENERATE+=--llvm-library-file "${LLVM_FILE}"
endif
# Used by generate_libc.py to generate the function tables that are exported to the
# application.
LIBC_SRCS=$(filter-out $(if ${exclude_file1},,thunks/libc/libc_table.cpp),$(wildcard thunks/libc/*.cpp))
LIBC_TABS=build/${ARCH}/thunks/libc/impl_header.h build/${ARCH}/thunks/libc/impl_tab.h
# Files that are compiled into your loader
LOADER_OBJS=$(patsubst %.cpp,build/%.cpp.o,$(wildcard loader/*.cpp))
THUNK_OBJS=$(patsubst %.cpp,build/%.cpp.o,$(wildcard thunks/*/*.cpp))
JNI_OBJS:=$(patsubst %.cpp,build/%.cpp.o,$(wildcard jni/classes/*.cpp))
JNI_OBJS+=$(patsubst %.cpp,build/%.cpp.o,$(wildcard jni/*.cpp))
GMLOADER_OBJS:=$(patsubst %.cpp,build/%.cpp.o,$(wildcard gmloader/*.cpp))
GMLOADER_OBJS+=$(patsubst %.cpp,build/%.cpp.o,$(wildcard gmloader/classes/*.cpp))
GENERIC_OBJ:=\
${LOADER_OBJS} \
${THUNK_OBJS} \
${JNI_OBJS} \
${GMLOADER_OBJS}
OBJ=$(patsubst build/%,build/${ARCH}/%,${GENERIC_OBJ})
all: build/${ARCH}/gmloader/gmloadernext.${DEVICE_ARCH}
clean:
rm -rf build/${ARCH}
# Include libbsd/libmd and their relevant flags
-include 3rdparty/libbsd.mk
# By repeating the generated headers on this rule, we force them to start building
# as soon as possible, so libc_table.cpp isn't waiting forever.
build/${ARCH}/gmloader/gmloadernext.${DEVICE_ARCH}: ${LIBC_TABS} $(BSD_OBJ) $(OBJ)
$(CXX) $(LDFLAGS) -o $@ $(OBJ) $(BSD_OBJ) $(LIBS)
build/${ARCH}/%.cpp.o: %.cpp
@mkdir -p $(@D)
$(CXX) $(CXXFLAGS) $(BSD_FLAGS) $(MD_FLAGS) -c $< -o $@
# The libc_table.cpp symbol table depends on the generated headers
%/libc_table.cpp: ${LIBC_TABS};
# The generated headers depend on the libc sources
${LIBC_TABS} &: ${LIBC_SRCS} thunks/libc/symtab thunks/libc/symtab_exclude thunks/libc/c_prototypes.h thunks/libc/common.hpp
@mkdir -p $(@D)
python3 scripts/generate_libc.py ${ARCH} ${GENERATE}
# Include all build dependencies too
-include $(OBJ:%.o=%.d)