-
Notifications
You must be signed in to change notification settings - Fork 152
/
bootstrap
executable file
·2481 lines (2026 loc) · 76.1 KB
/
bootstrap
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
################################################################################
#
# Installation script that does not require root access.
#
# Author: Maxime Arthaud
#
# Contact: [email protected]
#
# Notices:
#
# Copyright (c) 2011-2023 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Disclaimers:
#
# No Warranty: THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF
# ANY KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT LIMITED
# TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO SPECIFICATIONS,
# ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
# OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL BE
# ERROR FREE, OR ANY WARRANTY THAT DOCUMENTATION, IF PROVIDED, WILL CONFORM TO
# THE SUBJECT SOFTWARE. THIS AGREEMENT DOES NOT, IN ANY MANNER, CONSTITUTE AN
# ENDORSEMENT BY GOVERNMENT AGENCY OR ANY PRIOR RECIPIENT OF ANY RESULTS,
# RESULTING DESIGNS, HARDWARE, SOFTWARE PRODUCTS OR ANY OTHER APPLICATIONS
# RESULTING FROM USE OF THE SUBJECT SOFTWARE. FURTHER, GOVERNMENT AGENCY
# DISCLAIMS ALL WARRANTIES AND LIABILITIES REGARDING THIRD-PARTY SOFTWARE,
# IF PRESENT IN THE ORIGINAL SOFTWARE, AND DISTRIBUTES IT "AS IS."
#
# Waiver and Indemnity: RECIPIENT AGREES TO WAIVE ANY AND ALL CLAIMS AGAINST
# THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS, AS WELL
# AS ANY PRIOR RECIPIENT. IF RECIPIENT'S USE OF THE SUBJECT SOFTWARE RESULTS
# IN ANY LIABILITIES, DEMANDS, DAMAGES, EXPENSES OR LOSSES ARISING FROM SUCH
# USE, INCLUDING ANY DAMAGES FROM PRODUCTS BASED ON, OR RESULTING FROM,
# RECIPIENT'S USE OF THE SUBJECT SOFTWARE, RECIPIENT SHALL INDEMNIFY AND HOLD
# HARMLESS THE UNITED STATES GOVERNMENT, ITS CONTRACTORS AND SUBCONTRACTORS,
# AS WELL AS ANY PRIOR RECIPIENT, TO THE EXTENT PERMITTED BY LAW.
# RECIPIENT'S SOLE REMEDY FOR ANY SUCH MATTER SHALL BE THE IMMEDIATE,
# UNILATERAL TERMINATION OF THIS AGREEMENT.
#
################################################################################
#
# This script assumes the operating system provides:
# bash, basename, dirname, mkdir, touch, sed, date
#
# Bash should provide the following builtins:
# cd, pwd, exit, command, [[, ((, echo, set, unset, local, read, printf,
# pushd, popd, return, shift
#
# Exit codes:
# 0: success
# 1: running as root
# 2: bad argument
# 3: assertion failed
# 4: missing dependencies
# 5: unable to detect version
# 6: error while fetching a source code
# 7: error while extracting an archive
# 8: error while patching
# 9: error while configuring
# 10: error while building
# 11: error while testing
# 12: error while installing
#
################################################################################
progname=$(basename "$0")
# Version settings
ikos_version="3.1"
gcc_required_version="4.9.2"
clang_required_version="3.4"
apple_clang_required_version="3.4"
gcc_install_version="9.2.0"
gcc_gmp_install_version="6.1.0"
gcc_mpfr_install_version="3.1.4"
gcc_mpc_install_version="1.0.3"
gcc_isl_install_version="0.18"
cmake_required_version="3.4.3"
cmake_install_version="3.15.2"
zlib_install_version="1.2.11"
ncurses_install_version="6.1"
libedit_install_version="2.11"
m4_install_version="1.4.18"
gmp_required_version="5.0.0"
gmp_install_version="6.1.2"
mpfr_install_version="4.0.2"
ppl_install_version="1.2"
apron_install_version="0.9.10"
sqlite_required_version="3.6.20"
sqlite_install_version="3.29.0"
boost_required_version="1.55.0"
boost_install_version="1.70.0"
tbb_required_version="2"
tbb_install_version="11009"
python3_required_version="3.3"
python_install_version="3.3"
llvm_required_version="9"
llvm_install_version="9.0.0"
# Default parameters
install_dir=""
src_dir="$(dirname "$0")/.."
build_dir="/tmp/ikos-build"
verbose=0
force=0
use_colors=1
check=1
if command -v nproc >/dev/null 2>&1; then
njobs=$(nproc)
else
njobs=1
fi
build_type="Release"
#####################
# General functions #
#####################
function init_colors() {
if (( use_colors )); then
coff="\033[0m"
cbold="\033[1m"
cred="\033[31m"
cgreen="\033[32m"
cyellow="\033[33m"
cblue="\033[34m"
cpurple="\033[35m"
ccyan="\033[36m"
cwhite="\033[37m"
else
coff=""
cbold=""
cred=""
cgreen=""
cyellow=""
cblue=""
cpurple=""
ccyan=""
cwhite=""
fi
}
function usage() {
echo "usage: $progname [options]"
echo ""
echo "Build and install IKOS on any UNIX environment without root access."
echo ""
echo "Defaults for the options are specified in brackets."
echo ""
echo "Configuration:"
echo " --prefix=PREFIX Path to the installation directory"
echo " --srcdir=SRC_DIR Path to the source directory [$src_dir]"
echo " --builddir=BUILD_DIR Path to the build directory [$build_dir]"
echo ""
echo "Optional arguments:"
echo " -h, --help Display this help and exit"
echo " -V, --version Display version information and exit"
echo " -v, --verbose Make this script more verbose"
echo " -f, --force Force"
echo " --no-colors Disable colors"
echo " --no-check Do not run ikos tests"
echo " --jobs=N Allow N jobs at once [$njobs]"
echo " --build-type=TYPE Specify the build type {Release,Debug} [$build_type]"
}
function short_help() {
echo "Try '$progname -h' for more information." >&2
}
function version() {
echo "ikos $ikos_version"
echo "Copyright (c) 2011-2019 United States Government as represented by the"
echo "Administrator of the National Aeronautics and Space Administration."
echo "All Rights Reserved."
}
function error() {
echo "$progname: error: $1" >&2
}
# Split command line arguments, i.e:
# -ab -> -a -b
# --foo=bar -> --foo bar
#
# Split arguments are stored in the ARGS array
#
# Parameters:
# $1,$2,$3,...,$n: arguments to split
function explode_args() {
unset ARGS
local arg=$1 key value
while [[ $arg ]]; do
[[ $arg = "--" ]] && ARGS+=("$@") && break
# Short options
if [[ ${arg:0:1} = "-" && ${arg:1:1} != "-" ]]; then
ARGS+=("-${arg:1:1}")
(( ${#arg} > 2 )) && arg="-${arg:2}" || { shift; arg=$1; }
# Long options
elif [[ ${arg:0:2} = "--" ]]; then
# Split argument at '=':
# e.g --foo=bar -> key=--foo, value=bar
key=${arg%%=*}; value=${arg#*=}
ARGS+=("$key")
[[ "$key" != "$value" ]] && ARGS+=("$value")
shift; arg=$1
else
ARGS+=("$arg"); shift; arg=$1
fi
done
}
# Return a concatenation of strings separated by a given separator, i.e:
# , a b c -> a,b,c
#
# Parameters:
# $1: separator
# $2,$2,$4,...,$n: arguments to join
function join() {
local sep=$1; shift
echo -n "$1"; shift
printf "%s" "${@/#/$sep}"
}
# Check if a command exists
function command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Return the absolute path of the given filename
function abs_path() {
local arg=${1/#\~/$HOME}
local dirname=$(dirname "$arg") basename=$(basename "$arg")
while [[ ! -d "$dirname" ]]; do
basename="$(basename "$dirname")/$basename"
dirname=$(dirname "$dirname")
done
pushd . >/dev/null
cd "$dirname"
dirname=$(pwd)
popd >/dev/null
if [[ "$dirname" = "/" ]]; then
echo -n "/$basename"
else
echo -n "$dirname/$basename"
fi
}
# Find a pattern within the standard input
#
# If found, return 0 and print the given captured group
# Otherwise, return 1
#
# Parameters:
# $1: regular expression
# $2: parenthesis group number to capture
function match() {
while read -r line; do
if [[ "$line" =~ $1 ]]; then
echo -n "${BASH_REMATCH[$2]}"
return 0
fi
done
return 1
}
# Return the name of all binaries in the PATH matching a regular expression
function glob_binaries() {
local IFS=:
find $PATH \
-maxdepth 1 \
-regex ".*/$1" \
-exec basename {} \; 2>/dev/null | sort -u
}
########################
# Download and extract #
########################
# Download a file from an URL.
#
# The file is stored under $download_dir and is named after the remote file
function download() {
local url=$1 filename=$(basename "$1")
cd "$download_dir"
if [[ -f "$filename" ]]; then
progress "Using already downloaded $filename from $url"
else
progress "Downloading $url"
# Note: do not try to capture curl/wget output because it contains
# the progress bar
$download_agent "$url" || {
rm -f "$filename"; error "Error while fetching $filename"; exit 6;
}
fi
}
# Extract an archive and move the root directory
#
# Parameters:
# $1: path to the archive
# $2: destination path
function extract() {
local archive_path=$1 destination_path=$2
local archive_filename=$(basename "$archive_path")
local archive_directory=$(dirname "$archive_path")
progress "Extracting $archive_filename"
cd "$archive_directory"
run_log_debug tar xf "$archive_filename" || {
error "Error while extracting $archive_filename"; exit 7;
}
root_directory=$archive_filename
for ext in .gz .xz .bz2 .tar .tgz; do
root_directory=${root_directory%$ext}
done
[[ -d "$root_directory" ]] || assert_failed "$root_directory does not exist"
rm -rf "$destination_path"
mv "$root_directory" "$destination_path"
}
# Download an archive from an URL and extract it at the given location
#
# Parameters:
# $1: URL
# $2: destination path
function download_extract() {
local url=$1 destination_path=$2
download "$url"
extract "$download_dir/$(basename "$url")" "$destination_path"
}
######################
# Version comparison #
######################
# Compare two version numbers
#
# Return 0 if $1 is equal to $2,
# 1 if $1 is greater than $2 and
# 2 if $1 is lower than $2
function version_compare() {
[[ $1 == $2 ]] && return 0
local IFS=.
local i ver1=($1) ver2=($2)
# fill empty fields in ver1 with zeros
for ((i = ${#ver1[@]}; i < ${#ver2[@]}; i++)); do
ver1[i]=0
done
for ((i = 0; i < ${#ver1[@]}; i++)); do
if [[ -z ${ver2[i]} ]]; then
# fill empty fields in ver2 with zeros
ver2[i]=0
fi
if (( 10#${ver1[i]} > 10#${ver2[i]} )); then
return 1
fi
if (( 10#${ver1[i]} < 10#${ver2[i]} )); then
return 2
fi
done
return 0
}
# Compare two version numbers
#
# Return 0 iff $1 is greater or equal to $2
function version_ge() {
version_compare "$1" "$2"; (( $? <= 1 ))
}
# Return 0 iif $1 major version number is $2
function major_version_eq() {
[[ "$1" = "$2."* ]]
}
#####################
# Version detection #
#####################
version_regex='[0-9]+(\.[0-9]+)*'
# Parse and detect the version and compiler id of a C/C++ compiler, given the
# command name
#
# Set the variable `result` to (cc_family cxx_family version)
#
# For example:
# compiler_parse_version "gcc" -> result=("gcc" "g++" "6.1.0")
# compiler_parse_version "clang++-3.7" -> result=("clang" clang++" "3.7.1")
function compiler_parse_version() {
unset result
local ver
local cmd_regex=$(basename "$1" | sed -E 's/(^|[^\])([\(\)\.\+\-])/\1\\\2/g')
local version_output=$("$1" --version 2>&1)
debug "'$1 --version':\n$version_output"
ver=$(echo "$version_output" | match "^((gcc)|($cmd_regex)) \([^\)]+\) ($version_regex)( [0-9]+)?( \([^\)]+\))*$" 4)
(( $? == 0 )) && result=("gcc" "g++" "$ver") && return 0
ver=$(echo "$version_output" | match "^clang version ($version_regex) \([^\)]+\)( \([^\)]+\))*$" 1)
(( $? == 0 )) && result=("clang" "clang++" "$ver") && return 0
ver=$(echo "$version_output" | match "^((Apple LLVM)|(Apple clang)) version ($version_regex) \([^\)]+\)( \([^\)]+\))*$" 4)
(( $? == 0 )) && result=("apple-clang" "apple-clang++" "$ver") && return 0
return 1
}
# Check if a C/C++ compiler satisfies IKOS requirements
#
# Parameters:
# $1: family (gcc, clang, apple-clang)
# $2: version
function compiler_satisfies_requirements() {
local family=$1 version=$2
([[ "$family" = "gcc" || "$family" = "g++" ]] && version_ge "$version" "$gcc_required_version") ||
([[ "$family" = "clang" || "$family" = "clang++" ]] && version_ge "$version" "$clang_required_version") ||
([[ "$family" = "apple-clang" || "$family" = "apple-clang++" ]] && version_ge "$version" "$apple_clang_required_version")
}
# Parse and detect the version of cmake, given the command name
function cmake_parse_version() {
local version_output=$("$1" --version 2>&1)
debug "'$1 --version':\n$version_output"
echo "$version_output" | match "^cmake version ($version_regex)$" 1
}
# Parse the output of gcc -v to get the installation prefix
function gcc_install_prefix() {
local output=$("$1" -v 2>&1 | egrep -o -- '--prefix=([^-]|(-[^-]))+ --')
echo -n "${output:9:${#output}-12}"
}
function cc_compile() {
if (( verbose >= 1 )); then
run_log_debug "$CC" $CPPFLAGS $CFLAGS $LDFLAGS -xc - "$@"
else
run_log_quiet "$CC" $CPPFLAGS $CFLAGS $LDFLAGS -xc - "$@"
fi
}
function cxx_compile() {
if (( verbose >= 1 )); then
run_log_debug "$CXX" $CPPFLAGS $CXXFLAGS $LDFLAGS -xc++ - "$@"
else
run_log_quiet "$CXX" $CPPFLAGS $CXXFLAGS $LDFLAGS -xc++ - "$@"
fi
}
# Compile a simple program using zlib
function zlib_version_compile() {
cc_compile -o "$tests_dir/zlib_version" -lz <<'EOF'
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <zlib.h>
int main() {
assert(strcmp(ZLIB_VERSION, zlibVersion()) == 0);
printf("%s", zlibVersion());
return 0;
}
EOF
}
# Detect the version of zlib
function zlib_version() {
zlib_version_compile && "$tests_dir/zlib_version"
}
# Compile a simple program using ncurses
function ncurses_version_compile() {
cc_compile -o "$tests_dir/ncurses_version" -lncurses <<'EOF'
#include <stdio.h>
#include <ncurses.h>
int main() {
printf("%s", NCURSES_VERSION);
return 0;
}
EOF
}
# Detect the version of ncurses
function ncurses_version() {
ncurses_version_compile && "$tests_dir/ncurses_version"
}
# Compile a simple program using libedit
function libedit_version_compile() {
cc_compile -o "$tests_dir/libedit_version" -ledit <<'EOF'
#include <assert.h>
#include <stdio.h>
#include <histedit.h>
int main(int argc, char** argv) {
EditLine* el = el_init(argv[0], stdin, stdout, stderr);
assert(el != NULL);
printf("%d.%d", LIBEDIT_MAJOR, LIBEDIT_MINOR);
return 0;
}
EOF
}
# Detect the version of libedit
function libedit_version() {
libedit_version_compile && "$tests_dir/libedit_version"
}
# Parse and detect the version of m4, given the command name
function m4_parse_version() {
local version_output=$("$1" --version 2>&1)
debug "'$1 --version':\n$version_output"
echo "$version_output" | match "^((GNU M4)|(m4 \(GNU M4\))) ($version_regex)$" 4
}
# Compile a simple program using gmp
function gmp_version_compile() {
cc_compile -o "$tests_dir/gmp_version" -lgmp <<'EOF'
#include <assert.h>
#include <stdio.h>
#include <gmp.h>
int main() {
mpz_t i, j, k;
mpz_init_set_str(i, "1a", 16);
mpz_init(j);
mpz_init(k);
mpz_sqrtrem(j, k, i);
assert(mpz_get_si(j) == 5 && mpz_get_si(k) == 1);
printf("%s", gmp_version);
return 0;
}
EOF
}
# Detect the version of gmp
function gmp_version() {
gmp_version_compile && "$tests_dir/gmp_version"
}
# Compile a simple program using mpfr
function mpfr_version_compile() {
cc_compile -o "$tests_dir/mpfr_version" -lmpfr <<'EOF'
#include <stdio.h>
#include <mpfr.h>
int main() {
mpfr_t x;
mpfr_init_set_ui(x, 2, MPFR_RNDN);
printf("%s", mpfr_get_version());
return 0;
}
EOF
}
# Detect the version of mpfr
function mpfr_version() {
mpfr_version_compile && "$tests_dir/mpfr_version"
}
# Compile a simple program using ppl
function ppl_version_compile() {
cc_compile -o "$tests_dir/ppl_version" -lppl_c <<'EOF'
#include <stdio.h>
#include <ppl_c.h>
int main() {
const char* version;
ppl_initialize();
ppl_version(&version);
printf("%s", version);
return ppl_finalize();
}
EOF
}
# Detect the version of ppl
function ppl_version() {
ppl_version_compile && "$tests_dir/ppl_version"
}
# Compile a simple program using apron
function apron_compile() {
cc_compile -o "$tests_dir/apron" -lapron -lboxMPQ <<'EOF'
#include <ap_global0.h>
#include <box.h>
int main() {
ap_manager_t* manbox = box_manager_alloc();
ap_abstract0_t* top = ap_abstract0_top(manbox, 0, 0);
ap_abstract0_free(manbox, top);
ap_manager_free(manbox);
return 0;
}
EOF
}
# Check if apron is available
function has_apron() {
apron_compile && "$tests_dir/apron"
}
# Compile a simple program using sqlite
function sqlite_version_compile() {
cc_compile -o "$tests_dir/sqlite_version" -lsqlite3 <<'EOF'
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <sqlite3.h>
int main() {
assert(strcmp(SQLITE_VERSION, sqlite3_libversion()) == 0);
printf("%s", sqlite3_libversion());
return 0;
}
EOF
}
# Detect the version of sqlite
function sqlite_version() {
sqlite_version_compile && "$tests_dir/sqlite_version"
}
# Compile a simple program using boost
function boost_version_compile() {
cxx_compile -o "$tests_dir/boost_version" <<'EOF'
#include <iostream>
#include <boost/version.hpp>
int main() {
std::cout << (BOOST_VERSION / 100000)
<< "." << (BOOST_VERSION / 100 % 1000)
<< "." << (BOOST_VERSION % 100);
return 0;
}
EOF
}
# Detect the version of boost
function boost_version() {
boost_version_compile && "$tests_dir/boost_version"
}
# Compile a simple program using boost::system
function boost_system_compile() {
cxx_compile -o "$tests_dir/boost_system" -lboost_system <<'EOF'
#include <boost/system/error_code.hpp>
int main() {
boost::system::error_code e;
return 0;
}
EOF
}
# Check if boost::system is available
function has_boost_system() {
boost_system_compile && "$tests_dir/boost_system"
}
# Compile a simple program using boost::filesystem
function boost_filesystem_compile() {
cxx_compile -o "$tests_dir/boost_filesystem" -lboost_system -lboost_filesystem <<'EOF'
#include <boost/filesystem.hpp>
int main() {
boost::filesystem::path p;
return 0;
}
EOF
}
# Check if boost::filesystem is available
function has_boost_filesystem() {
boost_filesystem_compile && "$tests_dir/boost_filesystem"
}
# Compile a simple program using boost::thread
function boost_thread_compile() {
for libname in "boost_thread" "boost_thread-mt"; do
cxx_compile -o "$tests_dir/boost_thread" -l$libname <<'EOF'
#include <boost/thread/mutex.hpp>
int main() {
boost::mutex m;
return 0;
}
EOF
(( $? == 0 )) && return 0
done
return 1
}
# Check if boost::thread is available
function has_boost_thread() {
boost_thread_compile && "$tests_dir/boost_thread"
}
# Compile a simple program using boost::unit_test_framework
function boost_unit_test_framework_compile() {
cxx_compile -o "$tests_dir/boost_unit_test_framework" -lboost_unit_test_framework <<'EOF'
#define BOOST_TEST_MODULE test
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(test) {
BOOST_CHECK(true);
}
EOF
}
# Check if boost::unit_test_framework is available
function has_boost_unit_test_framework() {
boost_unit_test_framework_compile && "$tests_dir/boost_unit_test_framework" >/dev/null 2>&1
}
# Compile a simple program using tbb
function tbb_version_compile() {
cxx_compile -o "$tests_dir/tbb_version" -ltbb <<'EOF'
#include <iostream>
#include <tbb/tbb_stddef.h>
#include <tbb/mutex.h>
int main() {
tbb::mutex m;
std::cout << tbb::TBB_runtime_interface_version();
return 0;
}
EOF
}
# Detect the version of tbb
function tbb_version() {
tbb_version_compile && "$tests_dir/tbb_version"
}
# Parse and detect the version of python, given the command name
function python_parse_version() {
local version_output=$("$1" --version 2>&1)
debug "'$1 --version':\n$version_output"
echo "$version_output" | match "^Python ($version_regex)(\+)?$" 1
}
# Check if a python version satisfies IKOS requirements
function python_satisfies_requirements() {
local version=$1
([[ ${version:0:1} = 3 ]] && version_ge "$version" "$python3_required_version")
}
# Parse and detect the version of llvm-config, given the command name
function llvm_parse_version() {
local version_output=$("$1" --version 2>&1)
debug "'$1 --version':\n$version_output"
echo "$version_output" | match "^($version_regex)$" 1
}
# Parse and detect the version of ikos, given the command name
function ikos_parse_version() {
local version_output=$("$1" --version 2>&1)
debug "'$1 --version':\n$version_output"
echo "$version_output" | match "^ikos ($version_regex)(\.r[0-9a-zA-Z\.]+)?$" 1
}
################
# Main program #
################
# Parse options
explode_args "$@"
set -- "${ARGS[@]}"
unset ARGS
while [[ $1 ]]; do
case "$1" in
-h|--help) usage; exit 0;;
-V|--version) version; exit 0;;
-v|--verbose) (( verbose ++ ));;
-f|--force) (( force ++ ));;
--no-colors) use_colors=0;;
--no-check) check=0;;
--prefix) shift; install_dir=$1;;
--srcdir) shift; src_dir=$1;;
--builddir) shift; build_dir=$1;;
--jobs) shift; njobs=$1;;
--build-type) shift; build_type=$1;;
*) error "unrecognized option: $1"; short_help; exit 2;;
esac
shift
done
# Check if running as root
if (( ! force && UID == 0 )); then
error "this script should NOT run as root"
echo "Use --force to ignore this message." >&2
exit 1
fi
# Check options
if [[ -z "$install_dir" ]]; then
error "missing argument --prefix"; short_help; exit 2
elif [[ -z "$src_dir" ]]; then
error "missing argument --srcdir"; short_help; exit 2
elif [[ -z "$build_dir" ]]; then
error "missing argument --builddir"; short_help; exit 2
elif [[ ! "$njobs" =~ ^[1-9][0-9]*$ ]]; then
error "'$njobs' is not a positive number"; short_help; exit 2
fi
install_dir_orig=$install_dir
install_dir=$(abs_path "$install_dir")
src_dir_orig=$src_dir
src_dir=$(abs_path "$src_dir")
build_dir_orig=$build_dir
build_dir=$(abs_path "$build_dir")
download_dir_orig="$build_dir_orig/downloads"
download_dir="$build_dir/downloads"
tests_dir_orig="$build_dir_orig/tests"
tests_dir="$build_dir/tests"
log_file_orig="$build_dir_orig/bootstrap.log"
log_file="$build_dir/bootstrap.log"
# Check that src_dir contains IKOS source code
if [[ ! -e "$src_dir" ]]; then
error "cannot access '$src_dir_orig': No such file or directory"; exit 2
elif [[ ! -d "$src_dir" ]]; then
error "'$src_dir_orig' is not a directory"; exit 2
elif [[ ! -f "$src_dir/CMakeLists.txt" ]]; then
error "'$src_dir_orig' does not contain ikos source code"; exit 2
fi
# Initialize colors
init_colors
# Create directories
mkdir -p "$install_dir" 2>/dev/null || { error "cannot create directory '$install_dir_orig'"; exit 2; }
mkdir -p "$build_dir" 2>/dev/null || { error "cannot create directory '$build_dir_orig'"; exit 2; }
mkdir -p "$download_dir" 2>/dev/null || { error "cannot create directory '$download_dir_orig'"; exit 2; }
mkdir -p "$tests_dir" 2>/dev/null || { error "cannot create directory '$tests_dir_orig'"; exit 2; }
touch "$log_file" 2>/dev/null || { error "cannot create '$log_file_orig'"; exit 2; }
######################
# Output and logging #
######################
function strip_colors() {
echo -en "$1" | sed -E 's#'$(echo -en '\x1B')'\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]##g'
}
function log() {
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $(strip_colors "$2")" >> "$log_file"
}
function error() {
echo -e "${cbold}${cred}$1${coff}" >&2
log error "$1"
}
function warning() {
echo -e "${cbold}${cyellow}==> Warning: $1${coff}"
log warning "$1"
}
function success() {
echo -e "${cbold}${cgreen}==> ${coff}${cbold}$1${coff}"
log success "$1"
}
function progress() {
echo -e "${cbold}${cblue}==> ${coff}${cbold}$1${coff}"
log progress "$1"
}
function info() {
echo -e "$1${coff}"
log info "$1"
}
function debug() {
if (( verbose >= 1 )); then
echo -e "$1${coff}" >&2
fi
log debug "$1"
}
function assert_failed() {
error "Assertion failed: $1"; exit 3;
}
function error_parse_version() {
error "Unable to detect the version of '$1'"; exit 5;
}
function error_patch() {
error "Error while patching $1. see $log_file_orig for more details."
exit 8
}
function error_configure() {
if (( verbose == 0 )); then
error "Error while configuring $1. see $log_file_orig for more details."
else
error "Error while configuring $1."
fi
exit 9
}
function error_make() {
if (( verbose == 0 )); then
error "Error while building $1. see $log_file_orig for more details."
else
error "Error while building $1."
fi
exit 10
}
function error_check() {
if (( verbose == 0 )); then
error "Error while testing $1. see $log_file_orig for more details."
else
error "Error while testing $1."
fi
exit 11
}
function error_install() {
if (( verbose == 0 )); then
error "Error while installing $1. see $log_file_orig for more details."
else
error "Error while installing $1."
fi
exit 12
}
# log everything, display everything
function run_log_debug() {
"$@" 2>&1 | tee -a "$log_file" >&2
return ${PIPESTATUS[0]}
}
# log everything, only display stderr
function run_log_verbose() {
{ "$@" >> "$log_file" 2>&3; } 3>&1 | tee -a "$log_file" >&2
return ${PIPESTATUS[0]}
}
# log everything, do not display anything
function run_log_quiet() {
"$@" >> "$log_file" 2>&1
}
function progress_run() {
progress "$*"
if (( verbose >= 2 )); then
run_log_debug "$@"
elif (( verbose == 1 )); then
run_log_verbose "$@"
else
run_log_quiet "$@"
fi
}
# Warning if the installation path contains a whitespace
if [[ "$install_dir" = *\ * ]]; then
warning "The installation path contains a whitespace. The script might fail."
fi