forked from frida/frida
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.sdk.mk
287 lines (245 loc) · 8.2 KB
/
Makefile.sdk.mk
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
MAKE_J ?= -j 8
REPO_BASE_URL = "git://github.com/frida"
REPO_SUFFIX = ".git"
build_platform := $(shell uname -s | tr '[A-Z]' '[a-z]' | sed 's,^darwin$$,mac,')
build_arch := $(shell uname -m)
build_platform_arch := $(build_platform)-$(build_arch)
ifeq ($(build_platform), linux)
download := wget -O - -q
else
download := curl -sS
endif
ifdef FRIDA_HOST
host_platform := $(shell echo $(FRIDA_HOST) | cut -f1 -d"-")
else
host_platform := $(build_platform)
endif
ifdef FRIDA_HOST
host_arch := $(shell echo $(FRIDA_HOST) | cut -f2 -d"-")
else
host_arch := $(shell uname -m)
endif
host_platform_arch := $(host_platform)-$(host_arch)
ifeq ($(host_platform), linux)
bfd := build/fs-%/lib/libbfd.a
endif
ifeq ($(host_platform), android)
iconv := build/fs-%/lib/libiconv.a
bfd := build/fs-%/lib/libbfd.a
endif
all: build/sdk-$(host_platform)-$(host_arch).tar.bz2
@echo ""
@echo "\033[0;32mSuccess!\033[0;39m Here's your SDK: \033[1m$<\033[0m"
@echo ""
@echo "It will be picked up automatically if you now proceed to build Frida."
@echo ""
build/sdk-$(host_platform)-$(host_arch).tar.bz2: build/fs-tmp-$(host_platform_arch)/.package-stamp
tar \
-C build/fs-tmp-$(host_platform_arch)/package \
-cjf $(abspath [email protected]) \
.
mv [email protected] $@
build/fs-tmp-%/.package-stamp: \
$(iconv) \
$(bfd) \
build/fs-%/lib/pkgconfig/libffi.pc \
build/fs-%/lib/pkgconfig/glib-2.0.pc \
build/fs-%/lib/pkgconfig/gee-0.8.pc \
build/fs-%/lib/pkgconfig/json-glib-1.0.pc \
build/fs-%/lib/pkgconfig/v8.pc
$(RM) -r $(@D)/package
mkdir -p $(@D)/package
cd build/fs-$* \
&& tar -c \
include \
lib/*.a \
lib/*.la \
lib/glib-2.0 \
lib/libffi* \
lib/pkgconfig \
share/aclocal \
share/glib-2.0/schemas \
share/vala \
| tar -C $(abspath $(@D)/package) -xf -
releng/relocatify.sh $(@D)/package $(abspath build/fs-$*) $(abspath build/fs-sdk-$*)
ifeq ($(host_platform), ios)
cp /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/mach/mach_vm.h $(@D)/package/include/frida_mach_vm.h
endif
@touch $@
build/.libiconv-stamp:
$(RM) -r libiconv
mkdir libiconv
cd libiconv \
&& $(download) http://gnuftp.uib.no/libiconv/libiconv-1.14.tar.gz | tar -xz --strip-components 1 \
&& patch -p1 < ../releng/patches/libiconv-android.patch
@mkdir -p $(@D)
@touch $@
build/fs-tmp-%/libiconv/Makefile: build/fs-env-%.rc build/.libiconv-stamp
$(RM) -r $(@D)
mkdir -p $(@D)
. $< \
&& cd $(@D) \
&& FRIDA_LEGACY_AUTOTOOLS=1 ../../../libiconv/configure \
--enable-static \
--enable-relocatable \
--disable-rpath
build/fs-%/lib/libiconv.a: build/fs-env-%.rc build/fs-tmp-%/libiconv/Makefile
. $< && make -C build/fs-tmp-$*/libiconv $(MAKE_J) install
@touch $@
build/.binutils-stamp:
$(RM) -r binutils
mkdir binutils
cd binutils \
&& $(download) http://gnuftp.uib.no/binutils/binutils-2.24.tar.bz2 | tar -xj --strip-components 1 \
&& patch -p1 < ../releng/patches/binutils-android.patch
@mkdir -p $(@D)
@touch $@
build/fs-tmp-%/binutils/libiberty/Makefile: build/fs-env-%.rc build/.binutils-stamp
$(RM) -r $(@D)
mkdir -p $(@D)
. $< && cd $(@D) && ../../../../binutils/libiberty/configure
build/fs-tmp-%/binutils/bfd/Makefile: build/fs-env-%.rc build/.binutils-stamp
$(RM) -r $(@D)
mkdir -p $(@D)
. $< && cd $(@D) && ../../../../binutils/bfd/configure
build/fs-%/lib/libbfd.a: \
build/fs-env-%.rc \
build/fs-%/include/bfd.h \
build/fs-tmp-%/binutils/libiberty/libiberty.a \
build/fs-tmp-%/binutils/bfd/libbfd.a
mkdir -p $(@D)
$(RM) -r build/fs-tmp-$*/binutils/tmp
mkdir build/fs-tmp-$*/binutils/tmp
. $< \
&& cd build/fs-tmp-$*/binutils/tmp \
&& $$AR x ../libiberty/libiberty.a \
&& $$AR x ../bfd/libbfd.a \
&& $$AR r libbfd-full.a *.o \
&& $$RANLIB libbfd-full.a \
&& install -m 644 libbfd-full.a ../../../../$@
build/fs-%/include/bfd.h: build/fs-env-%.rc build/fs-tmp-%/binutils/bfd/Makefile
. $< && make -C build/fs-tmp-$*/binutils/bfd $(MAKE_J) install-bfdincludeHEADERS
build/fs-tmp-%/binutils/libiberty/libiberty.a: build/fs-env-%.rc build/fs-tmp-%/binutils/libiberty/Makefile
. $< && make -C $(@D) $(MAKE_J)
build/fs-tmp-%/binutils/bfd/libbfd.a: build/fs-env-%.rc build/fs-tmp-%/binutils/bfd/Makefile
. $< && make -C $(@D) $(MAKE_J)
define make-plain-module-rules
build/.$1-stamp:
$(RM) -r $1
git clone $(REPO_BASE_URL)/$1$(REPO_SUFFIX)
@mkdir -p $$(@D)
@touch $$@
$1/configure: build/fs-env-$(build_platform_arch).rc build/.$1-stamp
. $$< && cd $$(@D) && NOCONFIGURE=1 ./autogen.sh
build/fs-tmp-%/$1/Makefile: build/fs-env-%.rc $1/configure
$(RM) -r $$(@D)
mkdir -p $$(@D)
. $$< && cd $$(@D) && ../../../$1/configure
build/fs-%/lib/pkgconfig/$2.pc: build/fs-env-%.rc build/fs-tmp-%/$1/Makefile $3
. $$< && make -C build/fs-tmp-$$*/$1 $(MAKE_J) install GLIB_GENMARSHAL=glib-genmarshal GLIB_MKENUMS=glib-mkenums
@touch $$@
endef
$(eval $(call make-plain-module-rules,libffi,libffi,))
$(eval $(call make-plain-module-rules,glib,glib-2.0,$(iconv)))
$(eval $(call make-plain-module-rules,libgee,gee-0.8,build/fs-%/lib/pkgconfig/glib-2.0.pc))
$(eval $(call make-plain-module-rules,json-glib,json-glib-1.0,build/fs-%/lib/pkgconfig/glib-2.0.pc))
ifeq ($(host_arch), i386)
v8_arch := ia32
endif
ifeq ($(host_arch), x86_64)
v8_arch := x64
endif
ifeq ($(host_arch), arm)
v8_arch := arm
endif
ifeq ($(host_arch), arm64)
v8_arch := arm64
endif
ifeq ($(host_platform), linux)
v8_host_flags := -f make-linux
v8_libs_private := " -lm"
endif
ifeq ($(host_platform), android)
v8_flavor_prefix := android_
v8_host_flags := -f make-android -D clang=1
v8_libs_private := " -lm"
endif
ifeq ($(host_platform), mac)
v8_host_flags := -f make-mac -D mac_deployment_target=10.7 -D clang=1
endif
ifeq ($(host_platform), ios)
v8_host_flags := -f make-mac -D mac_deployment_target=10.7 -D ios_deployment_target=7.0 -D clang=1
endif
v8_flags := -D host_os=$(build_platform) -D werror='' -Dv8_enable_gdbjit=0 -Dv8_enable_i18n_support=0 $(v8_host_flags)
v8_target := $(v8_flavor_prefix)$(v8_arch).release
ifeq ($(build_platform), mac)
ifeq ($(host_platform), android)
v8_env_vars := \
MACOSX_DEPLOYMENT_TARGET="" \
CXX="$$CXX" \
CXX_host="$$(xcrun --sdk macosx10.9 -f clang++) -stdlib=libc++" \
CXX_target="$$CXX" \
LINK="$$CXX" \
LINK_host="$$(xcrun --sdk macosx10.9 -f clang++) -stdlib=libc++" \
CFLAGS="" \
CXXFLAGS="" \
CPPFLAGS="" \
LDFLAGS=""
else
v8_env_vars := \
MACOSX_DEPLOYMENT_TARGET="" \
CXX="$$CXX -stdlib=libc++" \
CXX_host="$$CXX -stdlib=libc++" \
CXX_target="$$CXX -stdlib=libc++" \
LINK="$$CXX -stdlib=libc++"
endif
else
v8_env_vars := \
CXX_host="$$CXX" \
CXX_target="$$CXX" \
LINK="$$CXX"
endif
build/.v8-stamp:
$(RM) -r v8
git clone $(REPO_BASE_URL)/v8$(REPO_SUFFIX)
@mkdir -p $(@D)
@touch $@
build/fs-tmp-%/.v8-stamp: build/.v8-stamp
# Poor-man's substitute for out-of-tree builds
@mkdir -p $(@D)
git clone --depth 1 v8 $(@D)/v8
@touch $@
build/fs-tmp-%/v8/out/$(v8_target)/libv8_base.$(v8_arch).a: build/fs-env-%.rc build/fs-tmp-%/.v8-stamp
. $< \
&& cd build/fs-tmp-$*/v8 \
&& PATH="/usr/bin:/bin:/usr/sbin:/sbin" \
$(v8_env_vars) \
make $(MAKE_J) $(v8_target) GYPFLAGS="$(v8_flags)"
@touch $@
build/fs-%/lib/pkgconfig/v8.pc: build/fs-tmp-%/v8/out/$(v8_target)/libv8_base.$(v8_arch).a
install -d build/fs-$*/include
install -m 644 v8/include/* build/fs-$*/include
install -d build/fs-$*/lib
install -m 644 build/fs-tmp-$*/v8/out/$(v8_target)/libv8_base.$(v8_arch).a build/fs-$*/lib
install -m 644 build/fs-tmp-$*/v8/out/$(v8_target)/libv8_snapshot.a build/fs-$*/lib
install -d $(@D)
echo "prefix=\$${frida_sdk_prefix}" > [email protected]
echo "exec_prefix=\$${prefix}" >> [email protected]
echo "libdir=\$${exec_prefix}/lib" >> [email protected]
echo "includedir=\$${prefix}/include" >> [email protected]
echo "" >> [email protected]
echo "Name: V8" >> [email protected]
echo "Description: V8 JavaScript Engine" >> [email protected]
echo "Version: 3.26.6.1" >> [email protected]
echo "Libs: -L\$${libdir} -lv8_base.$(v8_arch) -lv8_snapshot$(v8_libs_private)" >> [email protected]
echo "Cflags: -I\$${includedir}" >> [email protected]
mv [email protected] $@
build/.fs-sdk-$(host_platform_arch)-stamp:
$(RM) -r build/fs-sdk-$(host_platform_arch)
mkdir -p build/fs-sdk-$(host_platform_arch)/share/aclocal
touch build/fs-sdk-$(host_platform_arch)/.stamp
touch $@
build/fs-env-%.rc: build/.fs-sdk-$(host_platform_arch)-stamp
FRIDA_ENV_NAME=fs FRIDA_HOST=$* ./releng/setup-env.sh
.PHONY: all
.SECONDARY: