-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
152 lines (118 loc) · 4.16 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
ifeq ($(OS),Windows_NT)
detected_OS := Windows
else
detected_OS := $(shell sh -c 'uname -s 2>/dev/null || echo not')
endif
ifeq ($(detected_OS),Windows)
obj_type = i386pe
mkdir = mkdir $(subst /,\,$(1)) > nop 2>&1 || (exit 0)
rm = $(wordlist 2,65535,$(foreach FILE,$(subst /,\,$(1)),& del $(FILE) > nop 2>&1)) || (exit 0)
rmdir = rmdir $(subst /,\,$(1)) > nop 2>&1 || (exit 0)
echo = echo $(1)
else
obj_type = elf_i386
mkdir = mkdir -p $(1)
rm = rm $(1) > /dev/null 2>&1 || true
rmdir = rmdir $(1) > /dev/null 2>&1 || true
echo = echo "$(1)"
endif
OBJS = ./*cpp
HEADS = ./patcher/binPatcher.hpp
PREP = -include $(HEADS)
CC = g++
ASTYLE = astyle
#LIBRARY_PATHS specifies the additional library paths we'll need
LIBRARY_PATHS = -L ./lib
INCLUDE_PATHS = -I ./boost_lib -I .
align_size = 0x100
align_data = 0x1000
align_rdata = 0x1000
align_bss = 0x1000
align_idata = 0x1000
#OBJ_NAME specifies the name of our exectuable
OBJ_NAME = FaP.exe
#COMPILER_FLAGS specifies the additional compilation options we're using
# -w suppresses all warnings
# -Wl,-subsystem,windows gets rid of the console window
COMPILER_FLAGS = -w -DOBJ_NAME='"$(OBJ_NAME)"' -O3
ifeq ($(detected_OS),Windows)
WINAPI = -lmingw32 -lkernel32 -lm -ldxguid -ldxerr8 -luser32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lgdi32 -lcomdlg32 -lwinspool
WINAPI+= -lcomctl32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -lshlwapi -lversion -lwinpthread -ldbghelp -lpthread
COMPILER_FLAGS += -static
endif
SHARED_FLAGS = -I ..
export SHARED_FLAGS
#LINKER_FLAGS specifies the libraries we're linking against
LINKER_FLAGS = -static-libgcc -static-libstdc++
LOCAL_LIBS = -lpatcher -lfilesystem -lsystem -lpebliss -lasmjit -ltcc
ifeq ($(detected_OS),Linux)
LOCAL_LIBS += -ldl
endif
#-oformat -Ttext=0x006B8FB9
#echo align_size = $(align_size)';' > Env.ld
align:
echo align_size = $(align_size)';' > Env.ld
peLib:
$(MAKE) all -C ./pe_lib
boostLib:
$(MAKE) all -C ./boost_lib/filesystem
$(MAKE) all -C ./boost_lib/system
patcherLib:
$(MAKE) all OBJ_NAME=$(OBJ_NAME) -C ./patcher
asmjitLib:
$(MAKE) all -C ./asmjit_lib
./tinycc/wrap.o: ./tinycc/wrap.cpp
$(CC) ./tinycc/wrap.cpp -c -w -o ./tinycc/wrap.o -I . -I ./boost_lib
tcc: ./tinycc/wrap.o
$(MAKE) libtcc.a -C ./tinycc
cleanall:
$(MAKE) clean -C ./boost_lib/filesystem
$(MAKE) clean -C ./boost_lib/system
$(MAKE) clean -C ./pe_lib
$(MAKE) clean -C ./asmjit_lib
$(MAKE) clean -C ./patcher
$(MAKE) clean -C ./tinycc
rm -Rf ./build
cleanbuild:
rm -Rf ./build
directories:
$(call mkdir, /build)
$(call mkdir, /preprocessor)
ext_sector:
$(MAKE) all_individual -C ./sections
$(MAKE) link -C ./sections
_hooks:
$(MAKE) all OBJ_NAME=$(OBJ_NAME_) OBJS=$(OBJS) -C ./hooks
_fast_hooks:
$(MAKE) fast_compile -C ./hooks
ext_gpp_link:
$(call echo, align_data = $(align_data)';' > Env.ld)
$(call echo, align_rdata = $(align_rdata)';' >> Env.ld)
$(call echo, align_bss = $(align_bss)';' >> Env.ld)
$(call echo, align_idata = $(align_idata)';' >> Env.ld)
echo align_data = $(align_data)';' > Env.ld
echo align_rdata = $(align_rdata)';' >> Env.ld
echo align_bss = $(align_bss)';' >> Env.ld
echo align_idata = $(align_idata)';' >> Env.ld
ld -T ./linker/sectionLinker.ld -static -m $(obj_type) $(PRIME_NAME) -o $(TMP_NAME)
hook_gpp_link:
$(call echo, align_size = $(align_size)';' > Env.ld)
echo align_size = $(align_size)';' > Env.ld
ld -T ./linker/hookLinker.ld -static -m $(obj_type) $(PRIME_NAME) -o $(TMP_NAME)
rip_out_binary:
objcopy --strip-all -O binary -R .eh_fram $(TMP_NAME) $(PRIME_NAME)
pre_comp_h:
$(CC) -w $(INCLUDE_PATHS) $(HEADS)
#This is the target that compiles our executable
all : peLib boostLib asmjitLib patcherLib tcc
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(LOCAL_LIBS) -o $(OBJ_NAME)
@echo ./FaPatcher built successfully.
allwin : peLib boostLib asmjitLib patcherLib
$(CC) $(OBJS) $(INCLUDE_PATHS) $(LIBRARY_PATHS) $(COMPILER_FLAGS) $(LINKER_FLAGS) $(LOCAL_LIBS) $(WINAPI) -o $(OBJ_NAME)
@echo ./FaPatcher built successfully.
format:
$(ASTYLE) --style=allman --indent=tab --recursive *.c, *.cpp, *.h, *.hpp
clean_f:
find . -type f -name '*.orig' -delete
clean_g:
find . -type f -name '*.gch' -delete