-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxbuild
executable file
·928 lines (768 loc) · 26.2 KB
/
xbuild
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
#!/bin/bash
# ................................................
# X-Build util 0.4.0 2024-diasgc
# ................................................
function init {
: "${debug:=false}"
: "${config_timeout:=86400}"
: "${timeout_days:=3}"
: "${banner:=true}"
source .common
source ./utils/.utils
set -o pipefail
trap err ERR
case "${1}" in
--debug|-d) shift; set -x; debug=true;;
--help|-h) show_banner; usage; exit 0;;
--new|-n) shift; generate_script $@; exit 0;;
esac
# array of args first passed to scripts
export root_args=( $@ )
export dir_patches="${dir_root}/patches"
test -d "${dir_patches}" || exit_err "patches dir is missing. Reinstall please."
export dir_pkgdist="${dir_root}/dist"
test -d "${dir_pkgdist}" || mkdir -p "${dir_pkgdist}"
export dir_sources="${dir_root}/sources"
test -d "${dir_sources}" || mkdir -p "${dir_sources}"
test -f ".config" || ./xsetup
test -f ".config" || exit_err 'Unable to initialize config file: .config not found'
source .config
if [ $(($(date +%s) - ${config_lastupdate})) -gt $((config_timeout * timeout_days)) ]; then
test -f .config_old && rm -f .config_old
mv -f .config .config_old
./xsetup
source .config
fi
}
# first load .common functions and error trap
test -z ${vsh+x} && init $@
script_name=${1}
script_path="${dir_root}/scripts/${script_name}"
if [ ! -f "${script_path}" ]; then
usage && exit 0
fi
source "${script_path}"
shift
case "${1}" in
--opts|-o) show_build_opts; exit 0;;
esac
export script_name script_path
export host_trip CPPFLAGS
export json_heredoc="$(heredoc_extract ${script_path} JSONDATA)"
export dir_src="${dir_sources}/${lib}"
: "${MAKE_EXECUTABLE:=make}"
: "${CMAKE_EXECUTABLE:=cmake}"
: "${API:=${ANDROID_NDK_API}}"
: "${NDK_API:=${ANDROID_NDK_API}}"
# am_no_host (autotools): dont add --host=arch flag on cross-compiling
: "${am_nohost:=false}"
# am_nosysroot (autotools): dont add --sysroot=<sysroot> or --with-sysroot=<sysroot> flag
: "${am_nosysroot:=false}"
# am_nopic (autotools): dont add --with-pic flag
: "${am_nopic:=false}"
# default is running autoreconf -fiv before configure
: "${ac_reconf:=true}"
# shared link to dependencies (default static link)
: "${build_shared_deps:=false}"
# strip libraries before install
: "${build_strip:=false}"
# build dist package
: "${build_dist:=true}"
: "${build_cpack:=false}"
# dont build dependencies, download prebuilt
: "${build_download:=false}"
: "${def_build_sys:=meson}"
: "${cmake_build_type:=Release}"
: "${src_rel:=true}"
: "${tar_stripcomponents:=false}"
: "${req_update_deps:=false}"
: "${update:=${req_update_deps}}"
: "${git_checkout:=false}"
: "${host_native:=false}"
: "${pkg:=${lib}}"
: "${pkg_deb:=lib${lib//lib/}-dev}"
: "${inline:=false}"
: "${indent:=0}"
: "${ind:=}"
: "${vnd:=}"
: "${is_running:=false}"
: "${pkg_fmt:=tgz}"
: "${break_on_git:=false}"
: "${break_on_patch:=false}"
: "${break_on_config:=false}"
: "${break_on_build:=false}"
: "${break_on_make:=false}"
: "${skip_pc:=false}"
: "${skip_make:=false}"
: "${skip_install:=false}"
: "${skip_dl:=false}"
# make_install: rule for install 'make $make_install' (default: install)
: "${make_install:=install}"
# make_clean: rule for clean 'make $make_clean' (default: clean)
: "${make_clean:=clean}"
# make_args: additional rule for make
: "${use_clang:=true}"
: "${ndkcmake:=false}"
cmake_toolchain_file=
pc_filelist=
update=false
retry=false
logtime_start=0
logtime_end=0
# Variables
start(){
# Should we download the package instead of building it?
if ${build_download}; then
local lnk="$(get_link_pkg "${arch}" "${lib}")"
if [ -n "${lnk}" ]; then
wget_pkg_tgz "${lnk}" "${dir_install}"
${skip_pc} || logver "${dir_install_pc}/${pkg}.pc"
end_script
fi
fi
# Apply custom configurations
fn_defined 'on_config' && fn_log '' on_config
case ${host_trip[3]} in
android) fn_defined 'on_config_ndk' && fn_log '' on_config_ndk;;
gnu) fn_defined 'on_config_gnu' && fn_log '' on_config_gnu;;
mingw32) fn_defined 'on_config_mingw' && fn_log '' on_config_mingw;;
esac
if ${host_arm}; then
fn_defined 'on_config_arm' && fn_log '' on_config_arm
else
fn_defined 'on_config_x86x' && fn_log '' on_config_x86x
fi
fn_defined 'on_build_bin' && unset cfg_bin && fn_log '' on_build_bin
fn_defined 'on_build_static' && unset lib_link && fn_log '' on_build_static
fn_defined 'on_build_shared' && unset lib_link && fn_log '' on_build_shared
# check whether to update source of main lib and dependencies
if ${update}; then
safe_rm "${dir_src}"
! ${req_update_deps} && update=false
else
! ${git_checkout} && ! ${retry} && [ -f "${dir_install_pc}/${pkg}.pc" ] && exit
fi
# check build tools
check_tools ${tls}
# build dependencies
build_dependencies ${dep}
# start log
log_start "${arch}" "$((${eta}/$(nproc)))s"
check_pkg
echo -ne "$(bool2str ${build_static} ${SSB} ${CD})[static]"
echo -ne "$(bool2str ${build_shared} ${SSB} ${CD})[shared]"
echo -ne "$(bool2str ${build_bin} ${SSB} ${CD})[bin] ${C0}"
safe_cd "${dir_sources}"
# remove the build dir only if different from source or config dir
if [ ! ${retry} ]; then
if [ "${dir_build}" != "${dir_src}" ] && [[ "${dir_build}" != "${dir_config}" ]]; then
rm -rf ${dir_build}
fi
fi
local request_config=false
local request_patch=false
# get source
if [ ! -d "${dir_src}" ];then
get_source
${break_on_git} && end_script
request_config=true
fi
safe_cd "${dir_src}"
if [ -d "${dir_src}/.git" ]; then
if [ -n "${bra}" ]; then
do_log "checkout ${bra}" git checkout ${bra}
elif ${git_checkout}; then
do_log 'checkout' git checkout
unset git_checkout
fi
fi
safe_cd "${dir_config}"
# if there is no config selected, try guess
test -z "${cfg}" && config_guess
if ${request_config}; then
# check whether to custom config source
if fn_defined 'source_config'; then
fn_log 'config' source_config
elif [ -n "${cfg_cmd}" ];then
do_log 'config' ${cfg_cmd}
unset cfg_cmd
else case "${cfg}" in
ab) test -f "${dir_config}/boostrap" && do_log 'bootstrap' ${dir_config}/boostrap
test -f "${dir_config}/boostrap.sh" && do_log 'bootstrap' ${dir_config}/boostrap.sh
;;
ag) do_am_autogen ${dir_config} --noconfigure;;
ar) do_am_autoreconf ${dir_config};;
am) am_config_guess;;
esac
fi
request_patch=true
fi
if ${request_patch}; then
# check if there is a source_patch function
if fn_defined 'source_patch'; then
fn_log 'patch' source_patch
unset source_patch
fi
# check if there is a cmake file
if [ -n "${cmake_file}" ] && [ -f "${dir_root}/patches/${cmake_file}.cmake" ]; then
cp -f "${dir_root}/patches/${cmake_file}.cmake" "${dir_src}/CMakeLists.txt" || exit_err "Unable to copy ${cmake_file}"
unset cmake_file
fi
# check for patch file and apply
test -n "${patch[@]}" && fn_log '' patch_fromfilelist
fi
${break_on_patch} && end_script
if [ -z "${build_dir}" ]; then
if ${build_out}; then
dir_build="${dir_config}/build_${arch}"
safe_rm ${dir_build}
safe_mkdir "${dir_build}"
else
dir_build=${dir_config}
fi
fi
safe_cd "${dir_build}"
log_vars dir_src dep PKG_CONFIG_LIBDIR SYSROOT TOOLCHAIN
log_vars CC CXX LD AS AR NM ADDR2LINE OBJCOPY OBJDUMP RANLIB READELF SIZE STRINGS STRIP WINDRES API
if fn_defined 'build_all'; then
fn_log 'build' build_all
end_script
fi
if fn_defined 'build_prepare'; then
fn_log 'prepare' build_prepare
unset build_prepare
fi
if fn_defined 'build_clean'; then
fn_log 'clean' build_clean
unset build_clean
elif [ -f "Makefile" ]; then
test -z "${make_clean}" && make_clean="$(make_findtarget "distclean" "clean")"
test -n "${make_clean}" && do_quietly 'clean' "${MAKE_EXECUTABLE}" "${make_clean}"
fi
if fn_defined 'build_config'; then
fn_log 'config' build_config
unset -f build_config
else case "${build_system}" in
cmake) setup_cmake_config;;
automake) setup_am_config;;
meson) setup_meson_config;;
cargo) setup_cargo_config;;
make) setup_make_config ;;
bazel) setup_bazel_config;;
*) if [ -n "${cfg_cmd}" ]; then
log_buildvars
do_log 'config' "${cfg_cmd}" "${cfg_args[@]}"
else
exit_err "cfg ${cfg} unknown or cfg_cmd not defined. Use build_config to custom configure makefile"
fi
;;
esac
log_buildvars
test -n "${cfg_cmd}" && do_log "${build_system}" "${cfg_cmd}" "${cfg_args[@]}"
case ${cfg} in ccm|ccmake) tput sc; ccmake ..; tput rc;; esac
fi
${break_on_config} && end_script
if fn_defined 'before_make'; then
fn_log 'preparing' before_make
fi
[ -n "${WFLAGS}" ] && CPPFLAGS+=" ${WFLAGS}"
${host_clang} && ${build_static} && LDFLAGS="-static ${LDFLAGS}"
log_vars CFLAGS CXXFLAGS WFLAGS CPPFLAGS LDFLAGS LIBS
: "${install_args:=install}"
: "${skip_make:=false}"
if fn_defined 'on_make'; then
fn_log 'make' on_make
else
do_progress "${build_tag}" "${build_cmd}" "${build_args[@]}" || err
fi
${break_on_make} && end_script
### install ###
# before install custom ops
fn_defined 'before_install' && fn_log 'preparing' before_install
# strip libs before install
if ! ${host_mingw}; then
if fn_defined 'on_strip'; then
fn_log 'strip' on_strip
unset on_strip
elif ${build_strip}; then
do_log 'strip' do_strip
fi
fi
# install
if fn_defined 'on_install'; then
fn_log 'install' on_install
unset on_install
elif [ -n "${install_cmd}" ]; then
safe_cd "${dir_build}"
do_log 'install' "${install_cmd}" "${install_args}"
fi
# check whether to create pkg-config .pc file
if ! ${skip_pc}; then
fn_defined 'set_version' && set_version && unset set_version
fn_defined 'on_create_pc' && fn_log 'pkgconfig' on_create_pc && unset 'on_create_pc'
fi
local pcfile="${dir_install_pc}/${pkg}.pc"
if [ ! -f "${pcfile}" ] && [ -f "${dir_install}/share/pkgconfig/${lib}.pc" ]; then
ln -sf "${dir_install}/share/pkgconfig/${lib}.pc" "${pcfile}"
fi
if ${build_cpack}; then
if [ -z "${CPACK}" ]; then
if fn_defined 'on_pack'; then
fn_log 'pack' on_pack
elif ${build_package}; then
if [ -f "${dir_build}/install_manifest.txt" ]; then
do_log 'cpack' cmake_build_package
else
do_log 'pack' build_packages_bin
fi
fi
else
safe_cd "${dir_build}"
vrs="$(pkg-config ${pcfile} --modversion)"
do_log 'cpack' cpack -G DEB -P "${lib}_${vrs}_${arch}"
fi
fi
safe_cd "${dir_src}"
${skip_pc} || logver "${pcfile}"
fn_defined 'on_end' && fn_log '' on_end
vrs=$(pkg-config --modversion ${pcfile})
test -n "${vrs}" && sed -i "s/dev_vrs='.*'/dev_vrs='"${vrs}"'/g" ${script_path}
end_script
}
function do_strip {
local libdir
for dd in $(find "${dir_build}" \( -name "*.a" -o -name "*.so" \));do
${STRIP} --strip-unneeded "${dd}" >>${log_file}
done
}
function end_script {
log_end
sed -i "s/eta='.*'/eta='"${eta}"'/g" ${script_path}
# check if parent process is shell script
local parent=$(ps -o comm= ${PPID})
[ "${parent: -3}" == ".sh" ] || echo -e "\n${CT1}::Done ${C0}${lib} ${vrs}\n"
${debug} && set +x
unset dir_config dir_build dir_src \
lib_link cfg_bin exec_config vrs vnd \
am_nohost am_nopic am_nosysroot ac_opts ac_reconf \
req_pcforlibs make_clean make_install mingw_posix \
cfg_args LIBS CFLAGS CXXFLAGS LDFLAGS WFLAGS
dec_tab
echo -e "${CD}${ind}"
exit 0
}
check_install(){
local ext=''
case "${1}" in
# check includes
inc*)
for h in $lst_inc; do
test -z "$(ls ${dir_install}/include/$h 2>/dev/null)" && echo && return 0
done
echo 1
return 0
;;
# check libs
static*) ext='\.a';;
shared*) $host_mingw && ext='\.dll*' || ext='\.so*';;
lib*) ext='.*';;
# check bin
bin)
for h in $lst_bin; do
test -z "$(ls "${dir_install}/bin/${h}" 2>/dev/null)" && echo && return 0
done
echo 1
return 0
;;
# check pkgconfig
pc|pkgconfig)
[ -z "${lst_pc}" ] && echo && return 0
for h in ${lst_pc}; do
test -z "$(ls "${dir_install}/lib/pkgconfig/${h}" 2>/dev/null)" && echo && return 0
done
echo 1
return 0
;;
esac
if [ -n "${ext}" ];then
for h in ${lst_lib}; do
echo "listing ${dir_install}/lib/${h}${ext}"
test -z "$(ls ${dir_install}/lib/${h}.* | grep ''${ext}'' 2>/dev/null)" && echo && return 0
done
echo 1
return 0
fi
echo
return 0
}
function build_dependencies {
local dep_args
local pkgfile libname
while [ -n "${1}" ]; do
test -f "${dir_root}/scripts/${1}" || exit_err "Fail to build dependency ${1}. Script file not found."
pkgfile=$(./xbuild ${1} ${arch} --get pc)
if [ ! -f "${pkgfile}" ]; then
dep_args="${arch} $(bool2str ${build_shared_deps} --shared --static)"
${build_download} && dep_args+=" --dl"
./xbuild "${1}" ${dep_args}
else
log_info "${1}: ${C0} version $(pkg-config --modversion ${pkgfile})"
fi
shift
done
}
toolchain_android(){
PLATFORM='Android'
[ -d "${ANDROID_NDK_HOME}" ] || exit_err "No ANDROID NDK Toolchain found. Aborting."
TOOLCHAIN="/usr/${arch}"
SYSROOT="${TOOLCHAIN}/sysroot"
CROSS_PREFIX="${TOOLCHAIN}/bin/"
CC="${CROSS_PREFIX}clang"
CXX="${CROSS_PREFIX}clang++"
AS="${CC}"
LD="${CROSS_PREFIX}ld"
YASM=${CROSS_PREFIX}yasm
ASM_NASM=${YASM}
LT_SYS_LIBRARY_PATH="${TOOLCHAIN}/lib:${SYSROOT}/usr/lib/${arch}:${SYSROOT}/usr/lib/${arch}/${NDK_API}"
CPPFLAGS+=" -I${SYSROOT}/usr/include -I/usr/${arch}/include -I${SYSROOT}/usr/include"
LDFLAGS="-Wl,-rpath,${LT_SYS_LIBRARY_PATH} ${LDFLAGS}"
cmake_system_processor="${host_trip[0]}${host_trip[1]}"
$host_arm32 && cmake_system_processor="armv7-a"
cmake_findrootpath="/usr/${arch} /usr/${arch}/lib /usr/${arch}/lib/${ANDROID_NDK_API} /usr/${arch}/sysroot/usr ${dir_install}"
export NDK_API=${ANDROID_NDK_API}
}
toolchain_llvm_mingw(){
local ltsdir
local cargs=
PLATFORM='Windows'
SYSROOT="/usr/${arch}"
TOOLCHAIN="${SYSROOT}/bin/"
CROSS_PREFIX="${LLVM_MINGW_HOME}/bin/${arch}-"
if $use_clang; then
CC="${CROSS_PREFIX}clang"
CXX="${CROSS_PREFIX}clang++"
AS="${CC}"
LD="${CROSS_PREFIX}ld"
else
CC="${CROSS_PREFIX}gcc"
CXX="${CROSS_PREFIX}g++"
AS="${CROSS_PREFIX}as"
LD="${CROSS_PREFIX}ld"
fi
export RC=${CROSS_PREFIX}windres
LT_SYS_LIBRARY_PATH="${LLVM_MINGW_HOME}/lib/clang/${xv_llvm_mingw}"
CPPFLAGS+=" -I${SYSROOT}/include"
LDFLAGS="-L${LT_SYS_LIBRARY_PATH}/lib -L${SYSROOT}/lib ${LDFLAGS}"
YASM=yasm
NASM=nasm
ASM_NASM=${NASM}
cmake_findrootpath="${SYSROOT} ${LT_SYS_LIBRARY_PATH} ${dir_install}"
}
toolchain_linux(){
${host_cross} && cross="-cross"
ltsdir=$(gcc -dumpversion)
if ${use_clang}; then
SYSROOT="/usr/${arch}"
TOOLCHAIN="${SYSROOT}/bin"
CROSS_PREFIX="llvm-"
CC="${TOOLCHAIN}/clang"
#CC="clang -target ${arch}" # -fuse-ld=lld"
CXX="${TOOLCHAIN}/clang++"
#CXX="clang++ -target ${arch}" # -fuse-ld=lld"++
AS="${CC}"
LD="${TOOLCHAIN}/ld.lld" # --sysroot=${SYSROOT}"+
#$build_static && LDFLAGS+=" -static"
GNU_CLANG_VERSION_FULL="$(clang -dumpversion)"
GNU_CLANG_VERSION_MAJOR=${GNU_CLANG_VERSION_FULL%%\.*}
CPPFLAGS="-I$/usr/lib/clang/${GNU_CLANG_VERSION_MAJOR}/include ${CPPFLAGS}"
LT_SYS_LIBRARY_PATH="/usr/lib/llvm-${GNU_CLANG_VERSION_MAJOR}/lib"
else
SYSROOT="/usr/${arch}"
TOOLCHAIN="/usr/bin"
CROSS_PREFIX="${TOOLCHAIN}/${arch}-"
CC="${CROSS_PREFIX}gcc"
CXX="${CROSS_PREFIX}g++"
AS="${CROSS_PREFIX}as"
LD="${CROSS_PREFIX}ld"
LT_SYS_LIBRARY_PATH="/usr/lib/gcc${cross}/${arch}/${ltsdir}"
fi
ASM_NASM=nasm
LDFLAGS="-L${SYSROOT}/lib -L${LT_SYS_LIBRARY_PATH} ${LDFLAGS}"
CPPFLAGS=" -I${SYSROOT}/include -I${SYSROOT}/local/include ${CPPFLAGS}"
cmake_findrootpath="${SYSROOT} ${LT_SYS_LIBRARY_PATH} ${dir_install}"
}
loadToolchain(){
CMAKE_EXECUTABLE=cmake
YASM=yasm
PKG_CONFIG=pkg-config
#reset flags
CPPFLAGS+=" -I${dir_install_include}"
LDFLAGS="-L${dir_install_lib}"
cmake_system_processor="${host_trip[0]}${host_trip[1]}"
if ${host_cross}; then
case "${PLATFORM}" in
Android) toolchain_android;;
Windows) toolchain_llvm_mingw;;
Linux) toolchain_linux;;
esac
else
TOOLCHAIN=/usr/bin
SYSROOT=/usr
if ${use_clang}; then
CROSS_PREFIX=llvm-
CC=clang CXX=clang++ AS=${CC} LD=ld.lld
${host_native} && CPPFLAGS="-mtune=native ${CPPFLAGS}"
else
CROSS_PREFIX=
CC=gcc CXX=g++ AS=as LD=ld
${host_native} && CPPFLAGS="-march=native ${CPPFLAGS}"
fi
ASM_NASM=nasm
fi
AR=${CROSS_PREFIX}ar
NM=${CROSS_PREFIX}nm
ADDR2LINE=${CROSS_PREFIX}addr2line
OBJCOPY=${CROSS_PREFIX}objcopy
OBJDUMP=${CROSS_PREFIX}objdump
RANLIB=${CROSS_PREFIX}ranlib
READELF=${CROSS_PREFIX}readelf
SIZE=${CROSS_PREFIX}size
STRINGS=${CROSS_PREFIX}strings
STRIP=${CROSS_PREFIX}strip
WINDRES=${CROSS_PREFIX}windres
test -z ${GCOV+x} && GCOV=${CROSS_PREFIX}gcov
# export
export CMAKE_EXECUTABLE YASM PKG_CONFIG API \
PLATFORM TOOLCHAIN SYSROOT CC CXX LD AS \
ADDR2LINE AR NM OBJCOPY OBJDUMP RANLIB \
READELF SIZE STRINGS STRIP WINDRES \
CROSS_PREFIX LT_SYS_LIBRARY_PATH CPPFLAGS LDFLAGS
}
set_host(){
cpu_id="${1}"
host_trip=("${2}" "${3}" "${4}" "${5}" "${6}" "${7}" "${8}")
arch="${2}-${4}-${5}${6}"
CT0="${9}"
CT1="${10}"
CPU=${2}
ABI=${7}
EABI=${6}
set_env
}
set_host_build(){
host_trip[5]=$(uname -m)
arch="${host_trip[5]}-${OSTYPE}"
host_trip[0]=${host_trip[5]}
if [ "${host_triple[0]::3}" == "arm" ]; then
host_trip[1]="${host_triple[0]:3}"
host_trip[0]="${host_triple[0]::3}"
fi
arr=( ${OSTYPE//-/ } )
host_trip[2]=${arr[0]}
host_trip[3]=${arr[1]}
if [ -z "${host_trip[3]##*eabi*}" ] ;then
local a2=${host_trip[3]%eabi*}
host_trip[4]=${host_trip[3]#${a2}*}
host_trip[3]=${a2}
fi
set_env
}
set_env(){
case ${host_trip[0]} in
aarch64) host_arm=true; host_arm32=false; host_arm64=true; host_x86=false; host_x64=false; host_bits=64;;
arm) host_arm=true; host_arm32=true; host_arm64=true; host_x86=false; host_x64=false; host_bits=32;;
i686) host_arm=false; host_arm32=false; host_arm64=false; host_x86=true; host_x64=false; host_bits=32;;
x86_64) host_arm=false; host_arm32=false; host_arm64=false; host_x86=false; host_x64=true; host_bits=64;;
esac
case ${host_trip[3]} in
android) host_sys=linux; host_mingw=false; host_os=android; host_ndk=true; host_gnu=false; host_clang=true; PLATFORM="Android"
dir_install="/usr/${arch}/local"
;;
gnu) host_sys=linux; host_mingw=false; host_os=gnu; host_ndk=false; host_gnu=true; host_clang=false; PLATFORM="Linux"
dir_install="${dir_root}/builds/${PLATFORM,,}/${host_trip[5]}"
;;
mingw32) host_sys=windows; host_mingw=true; host_os=mingw32; host_ndk=false; host_gnu=false; host_clang=true; PLATFORM="Windows"
dir_install="${dir_root}/builds/${PLATFORM,,}/${host_trip[5]}"
;;
esac
#LIBSDIR="$(pwd)/builds/${PLATFORM,,}/${host_trip[5]}"
dir_install_bin="${dir_install}/bin"
dir_install_include="${dir_install}/include"
dir_install_lib="${dir_install}/lib"
dir_install_pc="${dir_install_lib}/pkgconfig"
PKG_CONFIG_LIBDIR="${dir_install_pc}:${dir_install}/share/pkgconfig"
unset PKG_CONFIG_PATH
safe_mkdir "${dir_install}" "${dir_install_bin}" "${dir_install_include}" "${dir_install_lib}" "${dir_install_pc}"
export dir_install dir_install_bin dir_install_include dir_install_lib dir_install_pc PKG_CONFIG_PATH PKG_CONFIG_LIBDIR
}
function parse_arg {
fn_defined 'extra_options' && extra_options "${1}" || cfg_args+=( "${1}" )
}
# main
test $# -eq 0 && usage && exit 0
aa64='@(aa64|aa8|a*64-*android|android*-a*64|arm*8*android|android*arm*8)'
aa32='@(aa32|aa7|arm-*android*|arm*7*-android*|android*arm*7*)'
ax86='@(a86|ax86|*86-*android|android*86)'
ax64='@(a64|ax64|*64-*android|android*64)'
la64='@(la8|la64|a*64-linux|arm*8*-linux|a*64-linux|a*64-*gnu|arm*8*-*gnu)'
la32='@(la7|lahf|arm*hf|arm-linux*)'
lx86='@(l86|lx86|*86-linux*|linux*32)'
lx64='@(l64|lx64|*64-linux*|linux*64|linux)'
wa64='@(wa8|a*64-w64*|a*64-*mingw*)'
wa32='@(wa7|arm*-w64*|arm*-*mingw*)'
wx86='@(w86|wx86|*86-win*|*86-*mingw*|w*32)'
wx64='@(w64|wx64|*64-win*|*64-*mingw*|windows|win|w*64)'
optVrs='@(--version|--vrs|--ver|-v)'
optDnl='@(--download|--dl|-d)'
# set host: must be first arg
case "${1}" in
# native host=build
native) set_host_build; host_native=true;;
# android host: aarch64, arm, i686, x86_64. todo: add riscv
$aa64 ) set_host '0' 'aarch64' '' 'linux' 'android' '' 'arm64-v8a' '64' $CG3 $CG6;;
$aa32 ) set_host '1' 'arm' 'v7a' 'linux' 'android' 'eabi' 'armeabi-v7a' '32' $CG2 $CG5;;
$ax86 ) set_host '2' 'i686' '' 'linux' 'android' '' 'x86' '32' $CG0 $CG1;;
$ax64 ) set_host '3' 'x86_64' '' 'linux' 'android' '' 'x86_64' '64' $CG0 $CG1;;
# linux gnu host: aarch64, arm, i686, x86_64
$la64 ) set_host '4' 'aarch64' '' 'linux' 'gnu' '' 'aarch64' '64' $CM4 $CM6;;
$la32 ) set_host '5' 'arm' '' 'linux' 'gnu' 'eabihf' 'armv7' '32' $CM4 $CM6;;
$lx86 ) set_host '6' 'i686' '' 'linux' 'gnu' '' 'x86' '32' $CM0 $CM1;;
$lx64 ) set_host '7' 'x86_64' '' 'linux' 'gnu' '' 'x86_64' '64' $CM0 $CM1;;
# mingw windows host: aarch64, arm, i686, x86_64
$wa64 ) set_host '8' 'aarch64' '' 'w64' 'mingw32' '' 'arm64' '64' $CC0 $CC1;;
$wa32 ) set_host '9' 'arm' 'v7' 'w64' 'mingw32' '' 'armv7' '32' $CC0 $CC1;;
$wx86 ) set_host '10' 'i686' '' 'w64' 'mingw32' '' 'x86' '32' $CB0 $CB1;;
$wx64 ) set_host '11' 'x86_64' '' 'w64' 'mingw32' '' 'x86_64' '64' $CB0 $CB1;;
# error: unknown host
*) exit_err "Unknown ${1} architecture";;
esac
# default build static, no shared, no executables
: "${build_shared:=false}"
: "${build_static:=false}"
: "${build_bin:=false}"
: "${build_man:=false}"
: "${build_package:=true}"
# Other options
while [ -n "${1}" ];do
case "${1}" in
# build
--static) build_static=true;;
--shared) build_shared=true;;
--sharedd) build_shared_deps=true;;
--bin) build_bin=true;;
--man) build_man=true;;
--full) build_shared=true
build_static=true
build_bin=true
build_dist=true
;;
# compiler
--clang) use_clang=true;;
--gcc) use_clang=false;;
--strip) build_strip=true;;
--api) shift; export API=$1;;
--tune) shift; menu_tune $1;;
--cpus) loadToolchain; ${CC} --print-supported-cpus; exit 0;;
--mcpu) shift; export CPPFLAGS+=" -mcpu=${1}";;
--mtune) shift; export CPPFLAGS+=" -mtune=${1}";;
# install
--prefix) shift; dir_install="${1}";;
--dist) build_dist=true;;
--cpack) build_cpack=true;;
# source
--devel) src_rel=false;;
--release) src_rel=true;;
--git) shift; menu_git $@; exit 0;;
--bra*) shift; export bra="${1}";;
--checkout) git_checkout=true; rebuild=true;;
--update) update=true; rebuild=true;;
--retry) retry=true; rebuild=true;;
--upd-all) update=true; req_update_deps=true; rebuild=true;;
--force) safe_rm "${dir_install_pc}/${pkg}.pc"; rebuild=true;;
$optDnl) build_download=true;;
# script
--check) ckeck_pkg; exit 0;;
--break) shift; set_break ${1};;
--skip) shift; menu_skip_options $@;;
$optVrs) shift; vrs="${1}";;
--diff) shift; create_diff $@; exit 0;;
--libName) echo "${lib}"; exit 0;;
--var) shift; echo "$($1)"; exit 0;;
--clear) shift; menu_clear $@; exit 0;;
--desc ) echo $dsc && exit 0;;
--get) shift; menu_get $@; exit 0;;
--check2) shift; check_install $@; exit 0;;
--list) shift; menu_list $@; exit 0;;
--patch) shift; menu_patch $@;;
--goto) shift; menu_goto $@; exit 0;;
--dir-build) shift; dir_build=$1;;
--inline) inline=true;;
--cmake) cfg='cmake';;
--ndk-cmake) ndkcmake=true;;
--ccmake) cfg='ccm';;
--nobanner) banner=false;;
--latest-release) utils_get_latest_release; exit 0;;
*) parse_arg "${1}";;
esac
shift
done
${build_shared_deps} && build_shared=true
! ${build_shared} && ! ${build_static} && build_static=true
fn_undef 'extra_options'
if fn_defined 'compiler_config'; then
compiler_config
fn_undef 'compiler_config'
fi
test -z "${mingw_posix}" && mingw_posix=false
# Set default Host
test -z "${host_trip}" && set_host_build
# is cross-compile?
host_cross=$([ "${build_arch}" == "${arch}" ] && false || true)
loadToolchain
# exit if missing vars lib arch or src
test -z "${lib}" && exit_info " ${arch} toolchain is loadad.\n Now exiting...\n\n"
if ${banner} && ! ${is_running}; then
show_banner
is_running=true
fi
if [ -n "${sudo}" ] && ! ${sudo} -n true 2>/dev/null; then
echo -ne "${CY1}Requesting sudo for tool install " && sudo echo -e "\e[1A\e[2K"
fi
# check build system
# if no cfg provided, try to guess
test -z "${cfg}" && config_guess
test -z "${cfg}" && exit_err 'No build system found. Exiting.'
# check if defined custom dir_config location (config_dir)
test -n "${config_dir+x}" && dir_config="${dir_src}/${config_dir}"
# default dir_config is dir_src
: "${dir_config:=${dir_src}}"
# is build dir outside source dir
build_out=false
case "${cfg}" in
cmake) build_system='cmake'; build_out=true;;
meson) build_system='meson'; build_out=true;;
bazel) build_system='bazel';;
cargo) build_system='cargo';;
mk|make) build_system='make';;
other) build_system='other';;
ab|am|ac|ar|ag|auto*)
build_system='automake'; build_out=true;;
*) unset build_system;;
esac
export arch update retry \
build_shared build_static build_bin build_system \
dir_install \
lib_link cfg_bin LIBSDIR PLATFORM CPU ABI EABI \
host_arch host_64 host_eabi host_vnd host_arm host_os \
mingw_posix MAKE_EXECUTABLE cmake_includes
# if pkg-config file exists and not rebuilding, exit
test ! ${rebuild} && [ -f "$(menu_get pc)" ] && end_script
#test ! ${rebuild} && check_pkg && end_script
inc_tab
# reset logfile
export log_file="${dir_install}/${lib}.log"
safe_rm "${log_file}"
#check_pkg && end_script
# show package info
package_showinfo
start