-
Notifications
You must be signed in to change notification settings - Fork 5
/
tools.sh
executable file
·1855 lines (1695 loc) · 57.8 KB
/
tools.sh
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Set colors
if [ -f /.dockerenv ]; then
# Regular
black="" # Black
red="" # Red
green="" # Green
yellow="" # Yellow
blue="" # Blue
purple="" # Purple
cyan="" # Cyan
white="" # White
# Bold
BLACK="" # Black
RED="" # Red
GREEN="" # Green
YELLOW="" # Yellow
BLUE="" # Blue
PURPLE="" # Purple
CYAN="" # Cyan
WHITE="" # White
# Reset
NC="" # Text Reset
else
# Regular
black="$(tput setaf 0 2>/dev/null || echo '\e[0;30m')" # Black
red="$(tput setaf 1 2>/dev/null || echo '\e[0;31m')" # Red
green="$(tput setaf 2 2>/dev/null || echo '\e[0;32m')" # Green
yellow="$(tput setaf 3 2>/dev/null || echo '\e[0;33m')" # Yellow
blue="$(tput setaf 4 2>/dev/null || echo '\e[0;34m')" # Blue
purple="$(tput setaf 5 2>/dev/null || echo '\e[0;35m')" # Purple
cyan="$(tput setaf 6 2>/dev/null || echo '\e[0;36m')" # Cyan
white="$(tput setaf 7 2>/dev/null || echo '\e[0;37m')" # White
# Bold
BLACK="$(tput setaf 0 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;30m')" # Black
RED="$(tput setaf 1 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;31m')" # Red
GREEN="$(tput setaf 2 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;32m')" # Green
YELLOW="$(tput setaf 3 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;33m')" # Yellow
BLUE="$(tput setaf 4 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;34m')" # Blue
PURPLE="$(tput setaf 5 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;35m')" # Purple
CYAN="$(tput setaf 6 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;36m')" # Cyan
WHITE="$(tput setaf 7 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;37m')" # White
# Reset
NC="$(tput sgr 0 2>/dev/null || echo '\e[0m')" # Text Reset
fi
# Local Variables
MAKE_INSTALL=0
VERBOSE=0
CREATE_PACKAGE=0
UPDATE=0
ENABLE_STATIC=0
# Set script params
trap 'err_report $LINENO $BASH_LINENO "$BASH_COMMAND" $(printf "::%s" ${FUNCNAME[@]:-})' ERR
trap 'restore_output' EXIT
trap 'previous_command=$this_command; this_command=$BASH_COMMAND' DEBUG
redirect_output() {
if (( ! VERBOSE )); then
# Save stdout and stderr
exec 3>&1
exec 4>&2
# Set output log files
exec 1>>$LOG_FILE
exec 2>>$ERROR_FILE
fi
}
restore_output() {
if (( ! VERBOSE )); then
# Restore original stdout
exec 1>&3 3>&- # Восстановить stdout и закрыть дескр. #3
exec 2>&4 4>&- # Восстановить stderr и закрыть дескр. #4
fi
}
download() {
SRC_ARC=$(echo $1|grep -oP '[a-zA-Z0-9\.\-\_]+\.tar\.[a-z0-9]+'|head -n1)
print_info "Start download ${SRC_ARC}"
if [ ! -f ${SRC_ARC} ]; then
wget -q "$1" --no-check-certificate
fi
if [[ ! -f ${SRC_ARC} ]]; then
print_error "File ${SRC_ARC} not found! There may be installation problems"
else
restore_output
echo -n "${GREEN}[+] Extracting: $SRC_ARC"; tar -xf ${SRC_ARC}; echo " => done${NC}"
redirect_output
fi
}
strip_debug() {
${TARGET}-strip --strip-unneeded --strip-debug -x -R .comment -R .note.ABI-tag -R .note.gnu.build-id $1
}
print_info() {
restore_output
echo "${YELLOW}[*] INFO: $1${NC}"
redirect_output
}
print_error() {
restore_output
echo "${RED}[!] ERROR: $1${NC}"
redirect_output
}
print_success() {
restore_output
echo "${GREEN}[+] SUCCESS: $1${NC}"
redirect_output
}
# Set error handler
err_report() {
local line=$1 # LINENO
local linecallfunc=$2
local command="$3"
local funcstack="$4"
print_error "line $1 => '$previous_command'"
if [ "$funcstack" != "::" ]; then
echo -n "$(date) $(hostname) $0: DEBUG Error in ${funcstack} "
if [ "$linecallfunc" != "" ]; then
echo "called at line $linecallfunc"
else
echo
fi
fi
print_info "See $ERROR_FILE for more info"
exit 1
}
realpath_d() {
local dname="$1"
mkdir -p ${dname}
echo "$(realpath ${dname})"
}
getos() {
if [[ -e /etc/os-release ]]; then
. /etc/os-release;
echo $ID;
else
if [[ -e /etc/gentoo-release ]]; then
echo "gentoo"
elif [[ -e /etc/arch-release ]]; then
echo "arch"
elif [[ -e /etc/debian_version ]]; then
echo "ubuntu"
fi
fi
}
init_logs() {
export LOGS_DIR=$(mktemp -d)
if (( ! VERBOSE )); then
ERROR_FILE=${LOGS_DIR}/error.log
LOG_FILE=${LOGS_DIR}/output.log
# Clear logs
rm -f $LOG_FILE $ERROR_FILE 2>/dev/null
else
ERROR_FILE=""
LOG_FILE=""
fi
RESULT_FILE=${LOGS_DIR}/result.log
redirect_output
}
ubuntu_upgrade_system() {
print_info "Update with apt-get"
apt-get update && apt-get -y upgrade
apt-get install -y make gawk wget pkg-config ccache git
apt-get install -y libfile-dircompare-perl gcc-multilib p11-kit xz-utils texinfo g++
apt-get install -y lzma autoconf automake autopoint libtool gcc lzip m4 gettext gtk-doc-tools
apt-get install -y cmake
apt-get -y autoremove
}
gentoo_upgrade_system() {
print_info "Update with emerge"
emerge --sync && emerge --oneshot sys-apps/portage
emerge sys-devel/make dev-util/cmake net-misc/wget dev-util/ccache dev-vcs/git dev-util/pkgconf
emerge app-crypt/p11-kit app-arch/lzma app-arch/lzip app-arch/xz-utils sys-apps/texinfo
emerge sys-devel/gcc sys-devel/autoconf sys-devel/automake sys-devel/m4 sys-devel/gettext sys-devel/libtool
emerge --depclean
}
upgrade_system() {
(( ! UPDATE )) && return
local arch=$(getos)
if [[ ${arch} == "ubuntu" ]]; then
ubuntu_upgrade_system
elif [[ ${arch} == "gentoo" ]]; then
gentoo_upgrade_system
fi
}
init() {
init_logs
upgrade_system
local TOOLCHAIN_DIR=/usr
export TARGET_CC="ccache ${TARGET}-gcc ${CFLAGS_FOR_TARGET}"
export TARGET_CXX="ccache ${TARGET}-g++ ${CFLAGS_FOR_TARGET}"
export AR=${TARGET}-ar
export AS=${TARGET}-as
export RANLIB=${TARGET}-ranlib
export CFLAGS="${CFLAGS} -s -O2 "
export LDFLAGS="${LDFLAGS} -s "
export USR=${TOOLCHAIN_DIR}
export PREFIX=${PREFIX:=${USR}/$TARGET}
export PKG_CONFIG_LIBDIR=${PREFIX}/lib/pkgconfig
export PKG_CONFIG_PATH=${PKG_CONFIG_LIBDIR}
export PATH=${PATH}:${PREFIX}/bin:${USR}/bin
export PARALLEL_MAKE="-j$((`nproc` * 2))"
# if [[ $(uname -m) == x86_64 ]]; then
# export DEB_ARCH=amd64
# else
# export DEB_ARCH=i386
# fi
export WORK_DIRECTORY=$(mktemp -d)
export DEB_ARCH=all
export DEBv=1.0
export DEB_TARGET=$1 #$(echo $TARGET|tr '-' ' '|awk '{print $1}')
if [[ -z ${DEB_PACK} ]]; then
export DEB_PACK=$(pwd)/${DEB_TARGET}_tools_v${DEBv}_${DEB_ARCH}
fi
export TMP_BUILD_DIR=${WORK_DIRECTORY}/${TARGET_ARCH}-cross
export TOOLS_BIN_DIR=${TOOLS_BIN_DIR:=$(mktemp -d)/BIN}
if [[ $1 == i686 ]]; then
export CONFIGURE_ARGS=${CONFIGURE_ARGS:="--build=$TARGET"}
else
export CONFIGURE_ARGS=${CONFIGURE_ARGS:=""}
fi
# Enable static build if needed
((ENABLE_STATIC)) && CONFIGURE_ARGS+=('--enable-static')
export DEB_DESC="Description: Tools for ${DEB_TARGET} toolchain"
export TOOLS_NAME="${DEB_TARGET}"
if [[ ! -d ${TMP_BUILD_DIR} ]]; then
mkdir -p ${TMP_BUILD_DIR}
cd ${TMP_BUILD_DIR}
else
cd ${TMP_BUILD_DIR}
print_info "Remove previous sources"
ls|grep -v "\.tar\."| xargs rm -rf
fi
# Check BIN dir
if [[ ! -d ${TOOLS_BIN_DIR} ]]; then
mkdir -p ${TOOLS_BIN_DIR}
fi
# if [[ -d ${DEB_PACK} ]]; then
# rm -rf ${DEB_PACK}
# fi
# if ((CREATE_PACKAGE)); then
# mkdir -p ${DEB_PACK}
# fi
}
usage() {
init_logs
restore_output
cat << EOF
usage: tools.sh [-h] [-i] [-o DIR] [-d] [-v] -a ARCH [-p PACKETS] [-l] [-u]
optional arguments:
-h, --help Show this help message and exit
-a ARCH Target Architecture: ($(echo ${ARCHS[*]}|sed 's/ /, /g'))
-p PACKAGE Package[s] for install
-l List of available packages
-i Run "make install" for selected tools
-o DIR Binary output directory
-d Create DEB package
-v Verbose
-u Update system repository
EOF
redirect_output
exit 1
}
# Versions
export LIBPCAPv=1.8.1
export FLEXv=2.6.4
export E2FSv=1.43.4
export LMAGICv=5.31
export BEECRYPTv=4.1.2
export LDBv=6.2.23.NC
export TORv=0.3.4.9
export SSHv=7.4p1
export DROPBEARv=2017.75
export PYTHON2v=2.7.13
export RPMv=4.12.0
export E2TOOLSv=0.0.16
export EMPTYv=0.6.20b
# Links
export PCAP_LINK=http://www.tcpdump.org/release/libpcap-$LIBPCAPv.tar.gz
export FLEX_LINK=https://github.com/westes/flex/files/981163/flex-$FLEXv.tar.gz
export E2FSPROGS_LINK=https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/v$E2FSv/e2fsprogs-$E2FSv.tar.xz
export LMAGIC_LINK=ftp://ftp.astron.com/pub/file/file-$LMAGICv.tar.gz
export BEECRYPT_LINK=http://prdownloads.sourceforge.net/beecrypt/beecrypt-$BEECRYPTv.tar.gz
export LDB_LINK=http://download.oracle.com/berkeley-db/db-$LDBv.tar.gz
export TOR_LINK=https://www.torproject.org/dist/tor-$TORv.tar.gz
export SSH_LINK=http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-$SSHv.tar.gz
export DROPBEAR_LINK=https://matt.ucc.asn.au/dropbear/releases/dropbear-$DROPBEARv.tar.bz2
export PYTHON2_LINK=https://www.python.org/ftp/python/$PYTHON2v/Python-$PYTHON2v.tar.xz
export RPM_LINK=http://ftp.rpm.org/releases/rpm-4.12.x/rpm-$RPMv.tar.bz2
export E2TOOLS_LINK=http://home.earthlink.net/~k_sheff/sw/e2tools/e2tools-$E2TOOLSv.tar.gz
export EMPTY_LINK=https://downloads.sourceforge.net/project/empty/empty/empty-$EMPTYv/empty-$EMPTYv.tgz
ARCHS=(armel armbe mipsel mips i686 powerpc)
# redirect_output
#####################################################################################################
# LIBS
#####################################################################################################
is_lib_installed() {
echo "void main(){}" > test.c
$TARGET_CC test.c $1 -static -L"${PREFIX}"/lib 2>/dev/null
if [[ $? == 0 ]]; then
return 1
else
return 0
fi
}
check_lib() {
is_lib_installed "$2"
if [[ $? == 1 ]]
then
print_success "$1 Installed"
rm a.out test.c >/dev/null
else
print_error "compile $1"
exit 1
fi
}
resolve_deps() {
local depends="$@"
print_info "(${depends[@]})"
for dep in ${depends[@]}; do
case "$dep" in
bzip2 ) lib_name="-lbz2" ;;
libgpg-error|curl ) lib_name="-l$(echo ${dep}|sed 's|lib||')" ;;
gnupg ) if [[ -e ${PREFIX}/bin/gpg ]]; then continue; fi ;;
ca-certificates ) ;;
* ) lib_name="$(pkg-config --libs --static ${dep} 2>/dev/null)"; if [[ $? == 1 ]]; then lib_name="-l$(echo ${dep}|sed 's|lib||')"; fi ;;
esac
is_lib_installed "${lib_name}"
if [[ $? == 0 ]]; then
${dep}_build
fi
done
}
zlib_build() {
local pkgname=zlib
local pkgver=1.2.11
local pkgdesc="Compression library implementing the deflate compression method found in gzip and PKZIP"
local source=https://zlib.net/${pkgname}-${pkgver}.tar.gz
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Compile ${pkgname} - ${pkgdesc}"
cd ${pkgname}-${pkgver}
((ENABLE_STATIC)) && EXTRA_FLAGS=('--static')
CC="${TARGET_CC}" ./configure \
--prefix=${PREFIX} \
${EXTRA_FLAGS[@]}
make ${PARALLEL_MAKE}
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install
fi
if ((MAKE_INSTALL)); then
make install
fi
cd ..
# Test zlib
check_lib "zLib" "$(pkg-config --libs --static zlib 2>/dev/null)"
}
openssl_build() {
local pkgname=openssl
local pkgver=1.1.1
local pkgdesc="The Open Source toolkit for Secure Sockets Layer and Transport Layer Security"
local source=https://www.openssl.org/source/${pkgname}-${pkgver}.tar.gz
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Compile ${pkgname} - ${pkgdesc}"
# prepare
cd ${pkgname}-${pkgver}
# Patch ssl dir to /etc/ssl
sed -i "s|./demoCA|$(realpath_d ${PREFIX}/../etc/ssl)|g" ./apps/*.{cnf,in}
# build
if [[ ${TARGET_ARCH} == i686 ]]; then
local EXTRA_FLAGS=("-m32")
elif [[ ${TARGET_ARCH} == powerpc ]]; then
local EXTRA_FLAGS=("")
else
local EXTRA_FLAGS=("-march=${SSL_MARCH}" "-lpthread")
fi
((ENABLE_STATIC)) && EXTRA_FLAGS+=("no-shared")
CC="${TARGET_CC}" CXX="${TARGET_CXX}" ./Configure \
$SSL_ARCH \
--prefix=${PREFIX} \
--openssldir="$(realpath_d ${PREFIX}/../etc/ssl)" \
no-fuzz-afl \
no-fuzz-libfuzzer \
-fPIC -I${PREFIX}/include -L${PREFIX}/lib \
${LDFLAGS} ${CFLAGS} \
${EXTRA_FLAGS[@]}
make ${PARALLEL_MAKE}
strip_debug apps/openssl
# package
if ((MAKE_INSTALL)); then
make install
fi
if ((CREATE_PACKAGE)); then
# Create DEB
CC="$TARGET_CC" CXX="$TARGET_CXX" ./Configure \
$SSL_ARCH \
--prefix=${pkgdir}/${PREFIX} \
--openssldir="$(realpath_d ${pkgdir}/${PREFIX}/../etc/ssl)" \
no-fuzz-afl \
no-fuzz-libfuzzer \
-fPIC -I${PREFIX}/include -L${PREFIX}/lib \
${LDFLAGS} ${CFLAGS} \
${EXTRA_FLAGS[@]}
make ${PARALLEL_MAKE}
make install
fi
cd ..
# Test openssl
check_lib "OpenSSL" "-lssl -lcrypto"
}
libevent_build() {
local pkgname=libevent
local pkgver=2.1.8-stable
local pkgdesc="An event notification library"
local source=https://github.com/${pkgname}/${pkgname}/releases/download/release-${pkgver}/${pkgname}-${pkgver}.tar.gz
local depends=('openssl')
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Resolve dependies for ${pkgname}"
resolve_deps ${depends[@]}
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
CFLAGS="${CFLAGS} -ldl" CC="$TARGET_CC" ../${pkgname}-${pkgver}/configure \
--host=${TARGET} \
--with-pic \
--prefix=${PREFIX} \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install
fi
if ((MAKE_INSTALL)); then
make install
fi
cd ..
check_lib "LibEvent" "-levent"
DEB_DESC+="\n .\n libevent-$LIBEVENTv"
TOOLS_NAME+="-libevent"
}
libtasn1_build() {
local pkgname=libtasn1
local pkgver=4.12
local pkgdesc="The ASN.1 library used in GNUTLS"
local source=http://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Compile ${pkgname} - ${pkgdesc}"
# build
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
CC="$TARGET_CC" ../${pkgname}-${pkgver}/configure \
--prefix=${PREFIX} \
--host=${TARGET} \
--disable-doc \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
check_lib "LibTasn1" "-ltasn1"
}
flex_build() {
download $FLEX_LINK
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir flex-$FLEXv-build && cd flex-$FLEXv-build
if [[ $(uname -m) == x86_64 ]]; then
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -static -O2 -s" CXXFLAGS=$CFLAGS CC="$TARGET_CC" ../flex-$FLEXv/configure --prefix=$PREFIX --enable-static --host=$TARGET $BUILDTARGET CFLAGS_FOR_BUILD="-s -O2 -m32"
else
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -static -O2 -s" CXXFLAGS=$CFLAGS CC="$TARGET_CC" ../flex-$FLEXv/configure --prefix=$PREFIX --enable-static --host=$TARGET $BUILDTARGET
fi
make ${PARALLEL_MAKE}
# make install-strip
make DESTDIR=${DEB_PACK} install-strip
if [[ $1 != i686 ]] || [[ $1 != i686 ]]; then
rm -rf $PREFIX/bin/flex*
if [[ $(uname -m) == x86_64 ]]; then
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -static -O2 -s" CXXFLAGS=$CFLAGS CC=gcc ../flex-$FLEXv/configure --prefix=$PREFIX --enable-static --disable-libfl CFLAGS_FOR_BUILD="-s -O2 -m32"
else
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -static -O2 -s" CXXFLAGS=$CFLAGS CC=gcc ../flex-$FLEXv/configure --prefix=$PREFIX --enable-static --disable-libfl
fi
make ${PARALLEL_MAKE}
make install-strip
fi
cd ..
# Test libfl
check_lib "flex" "-lfl"
}
libpcap_build() {
if [[ ! -x flex ]]; then
flex_build $(echo $TARGET|tr "-" " "|awk '{print $1}')
fi
download $PCAP_LINK
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir libpcap-$LIBPCAPv-build && cd libpcap-$LIBPCAPv-build
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -static -O2 -s" CC="$TARGET_CC" ../libpcap-$LIBPCAPv/configure \
--prefix=$PREFIX \
--host=$TARGET \
--with-pcap=linux \
--disable-shared \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
make install
if ((CREATE_PACKAGE)); then
make DESTDIR=${DEB_PACK} install
fi
cd ..
# Test libpcap
check_lib "LibPCAP" "-lpcap"
}
# Not tested for deb
libarchive_build() {
local pkgname=libarchive
local pkgver=3.3.2
local pkgdesc="Multi-format archive and compression library"
local source=https://www.libarchive.org/downloads/${pkgname}-${pkgver}.tar.gz
local depends=('acl' 'zlib' 'attr' 'openssl')
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Resolve dependies for ${pkgname}"
resolve_deps ${depends[@]}
print_info "Compile ${pkgname} - ${pkgdesc}"
# build
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
CC="$TARGET_CC" ../${pkgname}-${pkgver}/configure \
--prefix=${PREFIX} \
--host=${TARGET} \
--without-xml2 \
--without-lzma \
--with-zlib \
--without-nettle \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
check_lib "libArchive" "-larchive"
}
e2fsprogs_build() {
download $E2FSPROGS_LINK
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir e2fsprogs-$E2FSv-build && cd e2fsprogs-$E2FSv-build
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -s -static -O2" CC="$TARGET_CC" ../e2fsprogs-$E2FSv/configure \
--prefix=$PREFIX \
--host=$TARGET \
--disable-threads \
--disable-tls \
--disable-uuidd \
--disable-nls \
--disable-defrag \
--disable-debugfs \
--disable-testio-debug \
--disable-fsck \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
if ((CREATE_PACKAGE)); then
make DESTDIR=${DEB_PACK} install-libs
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
# Test e2fsprogs
echo "void main(){}" > test.c
$TARGET_CC test.c -static -lcom_err -lblkid -luuid -lss -lext2fs
check_lib "e2fsprogs"
DEB_DESC+="\n .\n e2fsprogs-$E2FSv"
TOOLS_NAME+="-e2fsprogs"
}
magic_build() {
download $LMAGIC_LINK
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir file-$LMAGICv-build && cd file-$LMAGICv-build
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -s -w -static -O2" CC="$TARGET_CC" ../file-$LMAGICv/configure \
--prefix=$PREFIX \
--host=$TARGET \
--includedir=$PREFIX/include \
--libdir=$PREFIX/lib \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
if ((CREATE_PACKAGE)); then
make DESTDIR=${DEB_PACK} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
# Test libmagic
check_lib "libmagic" "-lmagic -lz"
}
popt_build() {
local pkgname=popt
local pkgver=1.16
local pkgdesc="A commandline option parser"
local source="https://deb.debian.org/debian/pool/main/p/${pkgname}/${pkgname}_${pkgver}.orig.tar.gz"
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
CC="$TARGET_CC" ../${pkgname}-${pkgver}/configure \
--prefix=${PREFIX} \
--host=${TARGET} \
--disable-nls \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install
fi
if ((MAKE_INSTALL)); then
make install
fi
cd ..
# Test libpopt
check_lib "libpopt" "-lpopt"
}
beecrypt_build() {
download $BEECRYPT_LINK
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir beecrypt-$BEECRYPTv-build && cd beecrypt-$BEECRYPTv-build
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -s -static -O2" CC="$TARGET_CC" ../beecrypt-$BEECRYPTv/configure \
--prefix=$PREFIX \
--host=$TARGET \
--enable-openmp \
--disable-debug \
--without-java \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
if ((CREATE_PACKAGE)); then
make DESTDIR=${DEB_PACK} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
# Test libbeecrypt
echo "char mpfprintln (); int main (){ return mpfprintln (); return 0; }" > test.c
$TARGET_CC test.c -lbeecrypt
check_lib "beecrypt"
DEB_DESC+="\n .\n beecrypt-$BEECRYPTv"
TOOLS_NAME+="-beecrypt"
}
db_build() {
download $LDB_LINK
print_info "Compile ${pkgname} - ${pkgdesc}"
mkdir db-$LDBv-build && cd db-$LDBv-build
LDFLAGS="${LDFLAGS} -static -s" CFLAGS="${CFLAGS} -s -static -O2" CC="$TARGET_CC" ../db-$LDBv/dist/configure \
--prefix=$PREFIX \
--host=$TARGET \
--disable-java \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
if ((CREATE_PACKAGE)); then
make DESTDIR=${DEB_PACK} install_lib install_include
fi
make install_lib install_include
cd ..
# Test libdb
echo "void main(){}" > test.c
$TARGET_CC test.c -static -ldb
check_lib "libdb"
DEB_DESC+="\n .\n db-$LDBv"
TOOLS_NAME+="-db"
}
ca-certificates_build() {
local pkgbase=ca-certificates
local pkgname=ca-certificates-utils
local pkgver=20181109
local pkgdesc="Common CA certificates"
local source=https://git.archlinux.org/svntogit/packages.git/plain/trunk/update-ca-trust?h=packages/ca-certificates
print_info "Compile ${pkgname} - ${pkgdesc}"
# build
cd $(mktemp -d)
wget ${source} --no-check-certificate -O update-ca-trust
sed -ir "s|/etc|$(realpath_d ${PREFIX}/../etc)|" update-ca-trust
# package
install -D update-ca-trust "${PREFIX}/bin/update-ca-trust"
# Trust source directories
install -d ${PREFIX}/../{etc,usr/share}/${pkgbase}/trust-source/{anchors,blacklist}
# Directories used by update-ca-trust (aka "trust extract-compat")
install -d ${PREFIX}/../etc/${pkgbase}/extracted
# Compatibility link for OpenSSL using /etc/ssl as CAdir
# Used in preference to the individual links in /etc/ssl/certs
ln -sr "${PREFIX}/../etc/${pkgbase}/extracted/tls-ca-bundle.pem" "${PREFIX}/../etc/ssl/cert.pem"
# Compatiblity link for legacy bundle
ln -sr "${PREFIX}/../etc/${pkgbase}/extracted/tls-ca-bundle.pem" "${PREFIX}/../etc/ssl/certs/ca-certificates.crt"
${PREFIX}/bin/update-ca-trust
cd ..
}
curl_build() {
local pkgname=curl
local pkgver=7.53.1
local pkgdesc="An URL retrieval utility and library"
local source=https://curl.haxx.se/download/${pkgname}-${pkgver}.tar.gz
local depends=('zlib' 'openssl' 'ca-certificates')
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Resolve dependies for ${pkgname}"
resolve_deps ${depends[@]}
print_info "Compile ${pkgname} - ${pkgdesc}"
# build
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
((ENABLE_STATIC)) && CPPFLAGS="-DCURL_STATICLIB"
LIBS="-ldl -lpthread" CPPFLAGS="${CPPFLAGS}" CC=${TARGET_CC} ../${pkgname}-${pkgver}/configure \
--host=${TARGET} \
--target=${TARGET} \
--prefix=${PREFIX} \
--disable-ipv6 \
--disable-ldap \
--disable-ldaps \
--disable-rtsp \
--disable-dict \
--disable-telnet \
--disable-tftp \
--disable-pop3 \
--disable-imap \
--disable-smb \
--disable-smtp \
--disable-gopher \
--disable-crypto-auth \
--disable-sspi \
--disable-debug \
--disable-curldebug \
--disable-manual \
--enable-rt \
--enable-ftp \
--enable-http \
--enable-cookies \
--enable-optimize \
--without-axtls \
--with-proxy \
--with-zlib \
--with-ssl="$(realpath -s ${PREFIX}/../etc/ssl)" \
--with-ca-bundle="$(realpath -s ${PREFIX}/../etc/ssl/certs/ca-certificates.crt)" \
--with-random=/dev/urandom \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
strip_debug src/curl
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
check_lib "libCURL" "-lcurl -L${PREFIX}/lib"
}
libunistring_build() {
local pkgname=libunistring
local pkgver=0.9.10
local pkgdesc="Library for manipulating Unicode strings and C strings"
local source=https://ftp.gnu.org/gnu/$pkgname/${pkgname}-${pkgver}.tar.xz
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Compile ${pkgname} - ${pkgdesc}"
# prepare
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
# https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=cca32830b5
sed -i '/pragma weak pthread_create/d' tests/glthread/thread.h
# build
CC="${TARGET_CC}" ../${pkgname}-${pkgver}/configure \
--prefix=${PREFIX} \
--host=${TARGET} \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install
fi
if ((MAKE_INSTALL)); then
make install
fi
cd ..
check_lib "libunistring" "-lunistring -L${PREFIX}/lib"
}
libgpg-error_build() {
local pkgname=libgpg-error
local pkgver=1.37
local pkgdesc="Support library for libgcrypt"
local source=ftp://ftp.gnupg.org/gcrypt/libgpg-error/${pkgname}-${pkgver}.tar.bz2
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Compile ${pkgname} - ${pkgdesc}"
# prepare
cd ${pkgname}-${pkgver}
autoreconf -vfi
# build
CC="$TARGET_CC" ./configure \
--prefix=${PREFIX} \
--host=${TARGET} \
--disable-doc \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
check_lib "libgpg-error" "$(${PREFIX}/bin/gpg-error-config --libs)"
}
libassuan_build() {
local pkgname=libassuan
local pkgver=2.5.3
local pkgdesc="IPC library used by some GnuPG related software"
local source="https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2"
local depends=('libgpg-error')
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Resolve dependies for ${pkgname}"
resolve_deps ${depends[@]}
print_info "Compile ${pkgname} - ${pkgdesc}"
# build
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
CC="$TARGET_CC" ../${pkgname}-${pkgver}/configure \
--prefix=${PREFIX} \
--host=${TARGET} \
--disable-doc \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
check_lib "libassuan" "$(${PREFIX}/bin/libassuan-config --libs)"
}
gmp_build() {
local pkgname=gmp
local pkgver=6.1.2
local pkgdesc="A free library for arbitrary precision arithmetic"
local source=https://gmplib.org/download/${pkgname}/${pkgname}-${pkgver}.tar.lz
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Compile ${pkgname} - ${pkgdesc}"
# build
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
CC="$TARGET_CC" ../${pkgname}-${pkgver}/configure \
--prefix=${PREFIX} \
--host=${TARGET} \
--enable-cxx \
--enable-fat \
--build=${MACHTYPE} \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install-strip
fi
if ((MAKE_INSTALL)); then
make install-strip
fi
cd ..
check_lib "GMP" "-lgmp"
}
nettle_build() {
local pkgname=nettle
local pkgver=3.5.1
local pkgdesc="A low-level cryptographic library"
local source=https://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.gz
local depends=('gmp')
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Resolve dependies for ${pkgname}"
resolve_deps ${depends[@]}
print_info "Compile ${pkgname} - ${pkgdesc}"
# build
mkdir ${pkgname}-${pkgver}-build && cd ${pkgname}-${pkgver}-build
CC="$TARGET_CC" ../${pkgname}-${pkgver}/configure \
--prefix=${PREFIX} \
--host=${TARGET} \
--enable-mini-gmp \
${CONFIGURE_ARGS[@]}
make ${PARALLEL_MAKE}
# package
if ((CREATE_PACKAGE)); then
make DESTDIR=${pkgdir} install
fi
if ((MAKE_INSTALL)); then
make install
fi
cd ..
check_lib "libnettle" "$(pkg-config --libs --static hogweed 2>/dev/null)"
}
gnutls_build() {
local pkgname=gnutls
local pkgver=3.6.13
local pkgdesc="A library which provides a secure layer over a reliable transport layer"
local source=https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/${pkgname}-${pkgver}.tar.xz
local depends=('libtasn1' 'zlib' 'nettle' 'libunistring' 'libassuan')
local pkgdir="/tmp/${pkgname}-${pkgver}"
download ${source}
print_info "Resolve dependies for ${pkgname}"
resolve_deps ${depends[@]}
print_info "Compile ${pkgname} - ${pkgdesc}"