forked from good-tools/wiregasm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
379 lines (319 loc) · 11.8 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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# Makefile from VLC contrib was used as a reference
# https://code.videolan.org/videolan/vlc/-/blob/master/contrib/src/main.mak
all: .wiregasm
TARBALLS := tarballs
PATCHES := ../patches
PREFIX := ../built
PREFIX := $(abspath $(PREFIX))
VPATH := $(TARBALLS)
BUILD ?= x86_64-linux
HOST := wasm32-unknown-emscripten
ACLOCAL_AMFLAGS += -I$(PREFIX)/share/aclocal
export ACLOCAL_AMFLAGS
download = curl -sSL -- "$(1)" > "$@"
checksum = echo "$(1) $(2)" | sha512sum --check --status
EXTRACT_DIR = $(patsubst %.tar,%,$(basename $(notdir $<)))
APPLY = (cd $(EXTRACT_DIR) && patch -fp1) <
MOVE = mv $(EXTRACT_DIR) $@ && touch $@
CLEANUP = rm -rf $@
BUILD_DIR = $</wg_build
AUTORECONF = GTKDOCIZE=true autoreconf
RECONF = mkdir -p -- $(PREFIX)/share/aclocal && cd $< && $(AUTORECONF) -fiv $(ACLOCAL_AMFLAGS)
CMAKECLEAN = rm -f $(BUILD_DIR)/CMakeCache.txt
PKG_CONFIG_PATH := $(PREFIX)/lib/pkgconfig
EM_PKG_CONFIG_PATH := $(PKG_CONFIG_PATH)
export PKG_CONFIG_PATH
export EM_PKG_CONFIG_PATH
.PHONY: GUARD
guard-%: GUARD
@ if [ -z '${${*}}' ]; then echo 'Environment variable $* not set.' && exit 1; fi
# common
HOSTCONF := --prefix="$(PREFIX)"
HOSTCONF += --datarootdir="$(PREFIX)/share"
HOSTCONF += --includedir="$(PREFIX)/include"
HOSTCONF += --libdir="$(PREFIX)/lib"
HOSTCONF += --program-prefix=""
HOSTCONF += --build="$(BUILD)" --host="$(HOST)" --target="$(HOST)"
HOSTCONF += --enable-static --disable-shared --disable-dependency-tracking
HOSTCONF += PKG_CONFIG_PATH="$(PKG_CONFIG_PATH)"
EXTRA_LDFLAGS := -s TOTAL_MEMORY=128MB
EXTRA_CFLAGS := -O3
CFLAGS := $(CFLAGS) $(EXTRA_CFLAGS)
LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS)
HOSTTOOLS := \
EM_PKG_CONFIG_PATH="$(EM_PKG_CONFIG_PATH)" \
CFLAGS="$(CFLAGS)" \
LDFLAGS="$(LDFLAGS)"
# meson
MESON_CLEAN = rm -rf $(BUILD_DIR)/meson-private
MESON_SETUP = meson setup $(BUILD_DIR) $< --default-library static --prefix $(PREFIX) --buildtype release --backend ninja -Dlibdir=lib --cross-file $(abspath crossfile.meson)
MESON_BUILD = meson compile -C $(BUILD_DIR) && meson install -C $(BUILD_DIR)
mostlyclean:
rm -rf c-ares ffi gcrypt glib gpg-error lua pcre nghttp2 wireshark
rm -rf .c-ares .ffi .gcrypt .glib .gpg-error .lua .pcre .nghttp2 .wireshark
rm -rf .sum-*
clean: mostlyclean
rm -rf $(TARBALLS)/*.*
#
# CARES
#
CARES_VERSION := 1.15.0
CARES_URL := https://c-ares.org/download/c-ares-$(CARES_VERSION).tar.gz
CARES_CHECKSUM := a1de6c5e7e1a6a13c926aae690e83d5caa51e7313d63da1cf2af6bc757c41d585aad5466bc3ba7b7f7793cb1748fa589f40972b196728851c8b059cfc8c3be50
$(TARBALLS)/c-ares-$(CARES_VERSION).tar.gz:
$(call download,$(CARES_URL))
.sum-c-ares: c-ares-$(CARES_VERSION).tar.gz
$(call checksum,$(CARES_CHECKSUM),$<)
touch $@
c-ares: c-ares-$(CARES_VERSION).tar.gz .sum-c-ares
$(CLEANUP)
tar xzfo $<
$(MOVE)
.c-ares: c-ares
echo "[+] Building c-ares"
$(RECONF)
mkdir -p $(BUILD_DIR) && rm -f $(BUILD_DIR)/config.status && test ! -f $</config.status || $(MAKE) -C $< distclean
cd $(BUILD_DIR) && $(HOSTTOOLS) emconfigure ../configure $(HOSTCONF)
emmake make -C $(BUILD_DIR)
emmake make -C $(BUILD_DIR) install
touch $@
#
# FFI
#
FFI_VERSION := 3.4.4
FFI_URL := https://github.com/libffi/libffi/releases/download/v$(FFI_VERSION)/libffi-$(FFI_VERSION).tar.gz
FFI_CHECKSUM := 88680aeb0fa0dc0319e5cd2ba45b4b5a340bc9b4bcf20b1e0613b39cd898f177a3863aa94034d8e23a7f6f44d858a53dcd36d1bb8dee13b751ef814224061889
$(TARBALLS)/libffi-$(FFI_VERSION).tar.gz:
$(call download,$(FFI_URL))
.sum-ffi: libffi-$(FFI_VERSION).tar.gz
$(call checksum,$(FFI_CHECKSUM),$<)
touch $@
ffi: libffi-$(FFI_VERSION).tar.gz .sum-ffi
$(CLEANUP)
tar xzfo $<
$(APPLY) $(PATCHES)/ffi/emscripten.3.4.4.patch
$(MOVE)
.ffi: ffi
echo "[+] Building ffi"
$(RECONF)
mkdir -p $(BUILD_DIR) && rm -f $(BUILD_DIR)/config.status && test ! -f $</config.status || $(MAKE) -C $< distclean
cd $(BUILD_DIR) && $(HOSTTOOLS) emconfigure ../configure $(HOSTCONF)
emmake make -C $(BUILD_DIR)
emmake make -C $(BUILD_DIR) install
touch $@
#
# PCRE
#
# XXX: the glib project can also built pcre
#
PCRE_VERSION := 10.42
PCRE_URL := https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$(PCRE_VERSION)/pcre2-$(PCRE_VERSION).tar.bz2
PCRE_CHECKSUM := 72fbde87fecec3aa4b47225dd919ea1d55e97f2cbcf02aba26e5a0d3b1ffb58c25a80a9ef069eb99f9cf4e41ba9604ad06a7ec159870e1e875d86820e12256d3
$(TARBALLS)/pcre2-$(PCRE_VERSION).tar.bz2:
$(call download,$(PCRE_URL))
.sum-pcre: pcre2-$(PCRE_VERSION).tar.bz2
$(call checksum,$(PCRE_CHECKSUM),$<)
touch $@
pcre: pcre2-$(PCRE_VERSION).tar.bz2 .sum-pcre
$(CLEANUP)
tar xjfo $<
$(MOVE)
.pcre: pcre
echo "[+] Building pcre"
$(RECONF)
mkdir -p $(BUILD_DIR) && rm -f $(BUILD_DIR)/config.status && test ! -f $</config.status || $(MAKE) -C $< distclean
cd $(BUILD_DIR) && $(HOSTTOOLS) emconfigure ../configure $(HOSTCONF)
emmake make -C $(BUILD_DIR)
emmake make -C $(BUILD_DIR) install
touch $@
#
# GPG-ERROR
#
GPGERROR_VERSION := 1.46
GPGERROR_URL := https://www.gnupg.org/ftp/gcrypt/libgpg-error/libgpg-error-$(GPGERROR_VERSION).tar.bz2
GPGERROR_CHECKSUM := b06223bb2b0f67d3db5d0d9ab116361a0eda175d4667352b5c0941408d37f2b0ba8e507297e480ccebb88cbba9d0a133820b896914b07d264fb3edaac7b8c99d
GPGERROR_CONF := \
--disable-nls \
--disable-languages \
--disable-tests \
--disable-doc
$(TARBALLS)/libgpg-error-$(GPGERROR_VERSION).tar.bz2:
$(call download,$(GPGERROR_URL))
.sum-gpg-error: libgpg-error-$(GPGERROR_VERSION).tar.bz2
$(call checksum,$(GPGERROR_CHECKSUM),$<)
touch $@
gpg-error: libgpg-error-$(GPGERROR_VERSION).tar.bz2 .sum-gpg-error
$(CLEANUP)
tar xjfo $<
cp -f -- "$(PATCHES)/gpg-error/lock-obj-pub.emscripten.h" \
"$(EXTRACT_DIR)/src/syscfg/lock-obj-pub.emscripten.h"
$(MOVE)
.gpg-error: gpg-error
echo "[+] Building gpg-error"
$(RECONF)
mkdir -p $(BUILD_DIR) && rm -f $(BUILD_DIR)/config.status && test ! -f $</config.status || $(MAKE) -C $< distclean
cd $(BUILD_DIR) && $(HOSTTOOLS) emconfigure ../configure $(HOSTCONF) $(GPGERROR_CONF)
emmake make -C $(BUILD_DIR) pre_mkheader_cmds=true bin_PROGRAMS=
emmake make -C $(BUILD_DIR) pre_mkheader_cmds=true bin_PROGRAMS= install
touch $@
#
# GCRYPT
#
GCRYPT_VERSION := 1.10.1
GCRYPT_URL := http://www.gnupg.org/ftp/gcrypt/libgcrypt/libgcrypt-$(GCRYPT_VERSION).tar.bz2
GCRYPT_CHECKSUM := e5ca7966624fff16c3013795836a2c4377f0193dbb4ac5ad2b79654b1fa8992e17d83816569a402212dc8367a7980d4141f5d6ac282bae6b9f02186365b61f13
GCRYPT_CONF = \
--enable-ciphers=aes,des,rfc2268,arcfour,chacha20 \
--enable-digests=sha1,md5,rmd160,sha256,sha512,blake2 \
--enable-pubkey-ciphers=dsa,rsa,ecc \
--disable-doc
$(TARBALLS)/libgcrypt-$(GCRYPT_VERSION).tar.bz2:
$(call download,$(GCRYPT_URL))
.sum-gcrypt: libgcrypt-$(GCRYPT_VERSION).tar.bz2
$(call checksum,$(GCRYPT_CHECKSUM),$<)
touch $@
gcrypt: libgcrypt-$(GCRYPT_VERSION).tar.bz2 .sum-gcrypt
$(CLEANUP)
tar xjfo $<
$(MOVE)
.gcrypt: gcrypt .gpg-error
echo "[+] Building Gcrypt"
$(RECONF)
mkdir -p $(BUILD_DIR) && rm -f $(BUILD_DIR)/config.status && test ! -f $</config.status || $(MAKE) -C $< distclean
cd $(BUILD_DIR) && $(HOSTTOOLS) emconfigure ../configure $(HOSTCONF) $(GCRYPT_CONF)
emmake make -C $(BUILD_DIR)
emmake make -C $(BUILD_DIR) install
touch $@
#
# GLIB
#
GLIB_VERSION := 2.75
GLIB_MINOR_VERSION := $(GLIB_VERSION).0
GLIB_URL := https://ftp.gnome.org/pub/gnome/sources/glib/$(GLIB_VERSION)/glib-$(GLIB_MINOR_VERSION).tar.xz
GLIB_CHECKSUM := 0402c063975680ff2385876f521b37aa4cc599d2570eb79976ad2a1b530e47a086d514fe122fd870b4a8f7358f48c926285694d153cc2c32cf6963ed2d5da9d9
$(TARBALLS)/glib-$(GLIB_MINOR_VERSION).tar.xz:
$(call download,$(GLIB_URL))
.sum-glib: glib-$(GLIB_MINOR_VERSION).tar.xz
$(call checksum,$(GLIB_CHECKSUM),$<)
touch $@
glib: glib-$(GLIB_MINOR_VERSION).tar.xz .sum-glib
$(CLEANUP)
tar xJfo $<
$(APPLY) $(PATCHES)/glib/emscripten.2.75.0.patch
$(MOVE)
.glib: glib .pcre .ffi crossfile.meson
echo "[+] Building Glib"
$(MESON_CLEAN)
$(MESON_SETUP) --force-fallback-for=gvdb,zlib -Dselinux=disabled -Dxattr=false -Dlibmount=disabled \
-Dnls=disabled -Dtests=false -Dglib_assert=false -Dglib_checks=false
+$(MESON_BUILD)
touch $@
#
# LUA
#
LUA_VERSION := 5.2.4
LUA_URL := https://www.lua.org/ftp/lua-$(LUA_VERSION).tar.gz
LUA_CHECKSUM := cd77148aba4b707b6c159758b5e8444e04f968092eb98f6b4c405b2fb647e709370d5a8dcf604176101d3407e196a7433b5dcdce4fe9605c76191d3649d61a8c
# Borrowed from https://github.com/ysugimoto/webassembly-lua/blob/master/Dockerfile
LUA_CONF := CC='emcc -s WASM=1'
$(TARBALLS)/lua-$(LUA_VERSION).tar.gz:
$(call download,$(LUA_URL))
.sum-lua: lua-$(LUA_VERSION).tar.gz
$(call checksum,$(LUA_CHECKSUM),$<)
touch $@
lua: lua-$(LUA_VERSION).tar.gz .sum-lua
$(CLEANUP)
tar xzfo $<
$(MOVE)
.lua: lua
echo "[+] Building Lua"
$(MAKE) -C $< clean
emmake make -C $< generic INSTALL_TOP=$(PREFIX) install $(LUA_CONF)
touch $@
NGHTTP2_VERSION := 1.61.0
NGHTTP2_URL := https://github.com/nghttp2/nghttp2/releases/download/v$(NGHTTP2_VERSION)/nghttp2-$(NGHTTP2_VERSION).tar.xz
NGHTTP2_CHECKSUM := 01e930d7caf464699505f92b76e2bc8192d168612dc564d2546812c42afea2fb81d552d70e8a5fed35e2bf5deadbec8eda095af94a2484bca41542988afce52a
NGHTTP2_CONF := \
--enable-lib-only
$(TARBALLS)/nghttp2-$(NGHTTP2_VERSION).tar.xz:
$(call download,$(NGHTTP2_URL))
.sum-nghttp2: nghttp2-$(NGHTTP2_VERSION).tar.xz
$(call checksum,$(NGHTTP2_CHECKSUM),$<)
touch $@
nghttp2: nghttp2-$(NGHTTP2_VERSION).tar.xz .sum-nghttp2
$(CLEANUP)
tar xJfo $<
$(MOVE)
.nghttp2: nghttp2
echo "[+] Building nghttp2"
$(RECONF)
mkdir -p $(BUILD_DIR) && rm -f $(BUILD_DIR)/config.status && test ! -f $</config.status || $(MAKE) -C $< distclean
cd $(BUILD_DIR) && $(HOSTTOOLS) emconfigure ../configure $(HOSTCONF) $(NGHTTP2_CONF)
emmake make -C $(BUILD_DIR)
emmake make -C $(BUILD_DIR) install
touch $@
#
# Wireshark (epan)
#
WIRESHARK_VERSION := 4.0.3
WIRESHARK_URL := https://gitlab.com/wireshark/wireshark/-/archive/v$(WIRESHARK_VERSION)/wireshark-v$(WIRESHARK_VERSION).tar.bz2
WIRESHARK_CHECKSUM := 2f0f166dae43706945d681dd9f07aa4aa8d303967baae7d4065e1437fc0ae14c65648578ad3734e71729f3449ccc1590baadd6b140d246115cf7be8c5af55a83
# do not build any tools, we're only interested in libwireshark (epan)
WIRESHARK_CONF = \
-DBUILD_wireshark=OFF \
-DBUILD_tshark=OFF \
-DBUILD_rawshark=OFF \
-DBUILD_dumpcap=OFF \
-DBUILD_text2pcap=OFF \
-DBUILD_mergecap=OFF \
-DBUILD_reordercap=OFF \
-DBUILD_editcap=OFF \
-DBUILD_capinfos=OFF \
-DBUILD_captype=OFF \
-DBUILD_randpkt=OFF \
-DBUILD_dftest=OFF \
-DBUILD_dcerpcidl2wrs=OFF \
-DBUILD_androiddump=OFF \
-DBUILD_sshdump=OFF \
-DBUILD_ciscodump=OFF \
-DBUILD_dpauxmon=OFF \
-DBUILD_randpktdump=OFF \
-DBUILD_wifidump=OFF \
-DBUILD_etwdump=OFF \
-DBUILD_sdjournal=OFF \
-DBUILD_udpdump=OFF \
-DBUILD_sharkd=OFF \
-DBUILD_mmdbresolve=OFF \
-DENABLE_CAP=OFF
$(TARBALLS)/wireshark-v$(WIRESHARK_VERSION).tar.bz2:
$(call download,$(WIRESHARK_URL))
.sum-wireshark: wireshark-v$(WIRESHARK_VERSION).tar.bz2
$(call checksum,$(WIRESHARK_CHECKSUM),$<)
touch $@
wireshark: wireshark-v$(WIRESHARK_VERSION).tar.bz2 .sum-wireshark
$(CLEANUP)
tar xjfo $<
$(APPLY) $(PATCHES)/wireshark/0001-dont-build-radiotap-lemon.patch
$(APPLY) $(PATCHES)/wireshark/0002-fix-cpu-name-unknown.patch
$(APPLY) $(PATCHES)/wireshark/0003-disable-snort-emscripten.patch
$(APPLY) $(PATCHES)/wireshark/0004-export-wireshark-common.patch
$(APPLY) $(PATCHES)/wireshark/0005-force-data-dir.patch
$(APPLY) $(PATCHES)/wireshark/0006-threadless-registration.patch
$(APPLY) $(PATCHES)/wireshark/0007-export-lrexlib.patch
$(APPLY) $(PATCHES)/wireshark/0008-export-wslua-headers.patch
$(MOVE)
.wireshark: wireshark .c-ares .gcrypt .glib .lua .nghttp2
echo "[+] Building Wireshark"
$(CMAKECLEAN)
emcmake cmake -G Ninja -S $< -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:STRING=$(PREFIX) -DCMAKE_FIND_ROOT_PATH:STRING=$(PREFIX) $(WIRESHARK_CONF)
env cmake --build $(BUILD_DIR)
env cmake --install $(BUILD_DIR) --prefix $(PREFIX)
touch $@
#
# Wiregasm Lib
#
.wiregasm: wiregasm .wireshark crossfile.meson
echo "[+] Building Wiregasm"
$(MESON_CLEAN)
$(MESON_SETUP)
+$(MESON_BUILD)