-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinstall_tools
More file actions
executable file
·975 lines (822 loc) · 32.3 KB
/
install_tools
File metadata and controls
executable file
·975 lines (822 loc) · 32.3 KB
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
#!/bin/bash
###########################################################
#
# Author: Maxime Arthaud <maxime.arthaud@nasa.gov>,
# Hamza Bourbouh <hamza.bourbouh@nasa.gov>
# Notices:
#
# Copyright @ 2020 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.
#
# Notice: The accuracy and quality of the results of running CoCoSim
# directly corresponds to the quality and accuracy of the model and the
# requirements given as inputs to CoCoSim. If the models and requirements
# are incorrectly captured or incorrectly input into CoCoSim, the results
# cannot be relied upon to generate or error check software being developed.
# Simply stated, the results of CoCoSim are only as good as
# the inputs given to CoCoSim.
###########################################################
################################################################################
# This script assumes the operating system provides:
# bash, basename, dirname, mkdir, touch, sed, date
#
################################################################################
####### Utils ###############
source bash_utils
progname=$(basename "$0")
####### Machine #############
unameOut="$(uname -s)"
case "${unameOut}" in
Darwin*) machine="osx";;
*) machine="linux"
esac
# Version settings
cmake_required_version="2.8.11"
cmake_install_version="3.7.2"
m4_install_version="1.4.18"
python_required_version="3.8.10"
python_install_version="3.8.10"
ocaml_required_version="4.10.0"
# ocaml_install_version="4.03.0"
autoconf_install_version="2.69"
automake_install_version="1.15"
# ocamlfind_install_version="1.7.1"
# ocamlbuild_install_version="0.9.3"
# ocamlgraph_install_version="1.8.7"
menhir_install_version="20170101"
# Default parameters
install_dir=""
build_dir="/tmp/cocosim-build"
verbose=0
force=0
use_colors=1
# akatis: LustreC build fails in some machines when njobs > 1
# if command -v nproc >/dev/null 2>&1; then
# njobs=$(nproc)
# else
# njobs=1
# fi
njobs=1
# Zustre is disabled at the moment
# zustre_url="https://github.com/coco-team/zustre.git"
# zustre_branch="master"
kind2_url="https://github.com/kind2-mc/kind2.git"
kind2_branch="develop"
################
# Main program #
################
# Parse options
explode_args "$@"
set -- "${ARGS[@]}"
unset ARGS
while [[ $1 ]]; do
case "$1" in
-h|--help) usage; exit 0;;
-v|--verbose) (( verbose ++ ));;
-f|--force) (( force ++ ));;
--no-colors) use_colors=0;;
--prefix) shift; install_dir=$1;;
--builddir) shift; build_dir=$1;;
--jobs) shift; njobs=$1;;
--lustrec-url) shift; lustrec_url=$1;;
--lustrec-branch) shift; lustrec_branch=$1;;
#--zustre-url) shift; zustre_url=$1;;
#--zustre-branch) shift; zustre_branch=$1;;
--kind2-url) shift; kind2_url=$1;;
--kind2-branch) shift; kind2_branch=$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 "$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
elif [[ -z "$lustrec_url" ]]; then
error "missing argument --lustrec-url"; short_help; exit 2
elif [[ -z "$lustrec_branch" ]]; then
error "missing argument --lustrec-branch"; short_help; exit 2
# elif [[ -z "$zustre_url" ]]; then
# error "missing argument --zustre-url"; short_help; exit 2
# elif [[ -z "$zustre_branch" ]]; then
# error "missing argument --zustre-branch"; short_help; exit 2
elif [[ -z "$kind2_url" ]]; then
error "missing argument --kind2-url"; short_help; exit 2
elif [[ -z "$kind2_branch" ]]; then
error "missing argument --kind2-branch"; short_help; exit 2
fi
install_dir_orig=$install_dir
install_dir=$(abs_path "$install_dir")
build_dir_orig=$build_dir
build_dir=$(abs_path "$build_dir")
download_dir_orig="$build_dir_orig/downloads"
download_dir="$build_dir/downloads"
log_file_orig="$build_dir_orig/bootstrap.log"
log_file="$build_dir/bootstrap.log"
# Initialize colors
init_colors
# Create directories
mkdir -p "$install_dir" 2>/dev/null || { error "cannot create directory '$install_dir_orig'"; exit 2; }
mkdir -p "$install_dir/bin" 2>/dev/null || { error "cannot create directory '$install_dir_orig/bin'"; 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; }
touch "$log_file" 2>/dev/null || { error "cannot create '$log_file_orig'"; exit 2; }
#initialize the log file
echo "" > "$log_file"
######################
# Activation scripts #
######################
unset act_prepend_path
unset act_prepend_manpath
unset act_prepend_infopath
unset act_prepend_python_path
################################
# Check required dependencies #
################################
progress "Checking required dependencies"
if command_exists "$CC"; then
debug "Found CC=$CC"
export CC
elif command_exists cc; then
debug "Found cc at $(command -v cc)"
export CC="cc"
elif command_exists gcc; then
debug "Found gcc at $(command -v gcc)"
export CC="gcc"
elif command_exists clang; then
debug "Found clang at $(command -v clang)"
export CC="clang"
else
error "Unable to find a C compiler"
exit 4
fi
if command_exists "$CXX"; then
debug "Found CXX=$CXX"
export CXX
elif command_exists c++; then
debug "Found c++ at $(command -v c++)"
export CXX="c++"
elif command_exists g++; then
debug "Found g++ at $(command -v g++)"
export CXX="g++"
elif command_exists clang++; then
debug "Found clang++ at $(command -v clang++)"
export CXX="clang++"
else
error "Unable to find a C++ compiler"
exit 4
fi
utils_deps=('cat' 'rm' 'mv' 'cp' 'ln' 'find' 'tee' \
'patch' 'tar' 'gzip' 'gunzip' 'xz' \
'make' 'install' 'git' 'opam'\
'autoconf' 'automake' 'aclocal' 'pkg-config')
unset missing_deps
## autoconf and automake should be installed by the user.
###################
# install autoconf#
###################
# if ! command_exists autoconf; then
# if [[ -x "$install_dir/autoconf-$autoconf_install_version/bin/autoconf" ]]; then
# progress "Using already built ${cgreen}autoconf $autoconf_install_version"
# else
# progress "Installing ${cgreen}autoconf $autoconf_install_version"
# cd "$build_dir"
# curl -O -L "http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz"
# tar -xzf autoconf-2.69.tar.gz
# cd "$build_dir/autoconf-$autoconf_install_version"
# progress_run ./configure \
# -prefix "$install_dir/autoconf-$autoconf_install_version" \
# -with-debug-runtime || error_configure autoconf
# progress_run make || error_make autoconf
# progress_run make install || error_install autoconf
# success "${cgreen}autoconf $autoconf_install_version${coff}${cbold} successfully installed"
# fi
# prepend_path "$install_dir/autoconf-$autoconf_install_version/bin"
# fi
###################
# install automake#
###################
# if ! command_exists automake; then
# if [[ -x "$install_dir/automake-$automake_install_version/bin/automake" ]]; then
# progress "Using already built ${cgreen}automake $autoconf_install_version"
# else
# progress "Installing ${cgreen}automake $automake_install_version"
# cd "$build_dir"
# curl -O -L "http://ftpmirror.gnu.org/automake/automake-1.15.tar.gz"
# tar -xzf automake-1.15.tar.gz
# cd "$build_dir/automake-$automake_install_version"
# progress_run ./configure \
# -prefix "$install_dir/automake-$automake_install_version" \
# -with-debug-runtime || error_configure automake
# progress_run make || error_make automake
# progress_run make install || error_install automake
# success "${cgreen}automake $automake_install_version${coff}${cbold} successfully installed"
# fi
# prepend_path "$install_dir/automake-$automake_install_version/bin"
# fi
###########
for cmd in "${utils_deps[@]}"; do
if command_exists "$cmd"; then
debug "Found $cmd at $(command -v "$cmd")"
else
missing_deps+=("$cmd")
fi
done
if ! command_exists libtool && ! command_exists libtoolize &&
! command_exists glibtool && ! command_exists glibtoolize; then
missing_deps+=("libtool")
fi
if command_exists curl; then
debug "Found curl at $(command -v curl)"
download_agent='curl -OLfC - --progress-bar --ftp-pasv --retry 3 --retry-delay 3'
elif command_exists wget; then
debug "Found wget at $(command -v wget)"
download_agent='wget -c -q --show-progress --tries=3 --waitretry=3'
else
missing_deps+=("curl")
fi
if (( ${#missing_deps[@]} > 0 )); then
error "Missing required utilities: $(join ", " "${missing_deps[@]}")"
error "Please install the previous required utilities before running this script."
# TODO: uncomment the following line to force exit.
#exit 4
fi
unset utils_deps missing_deps
success "Found all required utilities"
#########
# Flags #
#########
export MAKEFLAGS="-j$njobs $MAKEFLAGS"
###############
# Check cmake #
###############
# progress "Checking for CMake"
# found_cmake=0
# if command_exists cmake; then
# version=$(cmake_parse_version cmake) || error_parse_version cmake
#version_ge deprecated: Check python_satisfies_requirements in bash_utils to see a way to do version checking if it is needed for cmake.
# if version_ge "$version" "$cmake_required_version"; then
# found_cmake=1
# success "Found CMake $version"
# else
# progress "Found CMake $version, version too old, skipped"
# fi
# fi
##############################
# Install cmake if necessary #
##############################
# if (( ! found_cmake )); then
# progress "Could NOT find CMake >= $cmake_required_version"
# if [[ -x "$install_dir/cmake-$cmake_install_version/bin/cmake" ]]; then
# progress "Using already built ${cgreen}cmake $cmake_install_version"
# else
# progress "Installing ${cgreen}cmake $cmake_install_version"
# download_extract "https://cmake.org/files/v${cmake_install_version%.*}/cmake-$cmake_install_version.tar.gz" \
# "$build_dir/cmake-$cmake_install_version"
# cd "$build_dir/cmake-$cmake_install_version"
# progress_run ./configure \
# --prefix="$install_dir/cmake-$cmake_install_version" \
# --no-system-libs || error_configure cmake
# progress_run make || error_make cmake
# progress_run make install || error_install cmake
# fi
# prepend_path "$install_dir/cmake-$cmake_install_version/bin"
# (command_exists cmake && version=$(cmake_parse_version cmake) &&
# [[ "$version" = "$cmake_install_version" ]]) ||
# assert_failed "cmake is not properly installed"
# success "${cgreen}cmake $cmake_install_version${coff}${cbold} successfully installed"
# fi
############
# Check m4 #
############
# progress "Checking for m4"
# found_m4=0
# if command_exists m4; then
# version=$(m4_parse_version m4) || error_parse_version m4
# success "Found m4 $version"
# found_m4=1
# fi
###########################
# Install m4 if necessary #
###########################
# if (( ! found_m4 )); then
# progress "Could NOT find m4"
# if [[ -x "$install_dir/m4-$m4_install_version/bin/m4" ]]; then
# progress "Using already built ${cgreen}m4 $m4_install_version"
# else
# progress "Installing ${cgreen}m4 $m4_install_version"
# download_extract "https://ftp.gnu.org/gnu/m4/m4-$m4_install_version.tar.xz" \
# "$build_dir/m4-$m4_install_version"
# cd "$build_dir/m4-$m4_install_version"
# progress_run ./configure \
# --prefix="$install_dir/m4-$m4_install_version" \
# --disable-dependency-tracking || error_configure m4
# progress_run make || error_make m4
# progress_run make install || error_install m4
# fi
# prepend_path "$install_dir/m4-$m4_install_version/bin"
# prepend_manpath "$install_dir/m4-$m4_install_version/share/man"
# prepend_infopath "$install_dir/m4-$m4_install_version/share/info"
# (command_exists m4 && version=$(m4_parse_version m4) &&
# [[ "$version" = "$m4_install_version" ]]) ||
# assert_failed "m4 is not properly installed"
# success "${cgreen}m4 $m4_install_version${coff}${cbold} successfully installed"
# fi
################
# Check python #
################
progress "Checking for Python"
found_python=0
# Check the default python
if command_exists python; then
version=$(python_parse_version python) || error_parse_version python
if python_satisfies_requirements "$version"; then
found_python=1
success "Found Python $version"
else
progress "Found Python $version, version too old, skipped"
fi
fi
# Check all available versions of python
if (( ! found_python )); then
for cmd in $(glob_binaries "python[0-9\.\-][0-9\.\-]*"); do
if command_exists "$cmd"; then
version=$(python_parse_version "$cmd") || error_parse_version python
if python_satisfies_requirements "$version"; then
found_python=1
success "Found Python $version"
# Create symbolic links
progress "Using symbolic links to make it the default python"
if [[ ! -d "$install_dir/python-$version" ]]; then
mkdir -p "$install_dir/python-$version/bin"
cd "$install_dir/python-$version/bin"
ln -s "$(command -v "$cmd")" python
ln -s "$(command -v "$cmd")-config" python-config
fi
prepend_path "$install_dir/python-$version/bin"
break
else
progress "Found Python $version, version too old, skipped"
fi
fi
done
fi
# Check for python distutils (required by spacer)
if ! python -c "import distutils" 2>/dev/null; then
error "Missing required python module: distutils"
exit 4
fi
###############################
# Install python if necessary #
###############################
if (( ! found_python )); then
progress "Could NOT find Python >= $python_required_version"
if [[ -x "$install_dir/python-$python_install_version/bin/python" ]]; then
progress "Using already built ${cgreen}python $python_install_version"
else
progress "Installing ${cgreen}python $python_install_version"
download_extract "https://www.python.org/ftp/python/$python_install_version/Python-$python_install_version.tar.xz" \
"$build_dir/python-$python_install_version"
cd "$build_dir/python-$python_install_version"
progress_run ./configure \
--prefix="$install_dir/python-$python_install_version" || error_configure python
progress_run make || error_make python
progress_run make install || error_install python
fi
prepend_path "$install_dir/python-$python_install_version/bin"
prepend_manpath "$install_dir/python-$python_install_version/share/man"
success "${cgreen}python $python_install_version${coff}${cbold} successfully installed"
fi
(command_exists python && version=$(python_parse_version python) &&
python_satisfies_requirements "$version") ||
assert_failed "python is not properly installed"
####################
# Installing OCaml #
####################
progress "Installing OCaml $ocaml_required_version, ocamlfind, ocamlbuild, ocamlgraph, fmt, logs, topkg, cmdliner, num, yojson, zarith."
progress_run opam init -y --comp=$ocaml_required_version || error_install opam
progress_run opam switch -y $ocaml_required_version || {
progress_run opam switch create -y $ocaml_required_version
}
progress_run eval `opam config env` || error_install opam
progress_run opam update
progress_run opam install -y ocamlfind ocamlbuild ocamlgraph fmt logs topkg cmdliner num yojson zarith|| error_install ocaml
# install z3 for lustreC
# progress_run opam pin add -y z3 4.8.14
if ! command -v z3; then
progress "Installing Z3. This may take several minutes."
progress_run opam install -y z3
fi
# install menhir
progress "Installing menhir."
progress_run opam install -y menhir
################
# Check menhir #
################
# progress "Checking for Menhir"
# found_menhir=0
# if command_exists menhir; then
# version=$(menhir_parse_version menhir) || error_parse_version menhir
# found_menhir=1
# success "Found Menhir $version"
# fi
###############################
# Install menhir if necessary #
###############################
# menhir_failed=0
# if (( ! found_menhir )); then
# progress "Could NOT find Menhir"
# if [[ -x "$install_dir/menhir-$menhir_install_version/bin/menhir" ]]; then
# progress "Using already built ${cgreen}menhir $menhir_install_version"
# else
# progress "Installing ${cgreen}menhir $menhir_install_version"
# download_extract "http://cristal.inria.fr/~fpottier/menhir/menhir-$menhir_install_version.tar.gz" \
# "$build_dir/menhir-$menhir_install_version"
# cd "$build_dir/menhir-$menhir_install_version"
# progress_run make \
# PREFIX="$install_dir/menhir-$menhir_install_version" \
# all -j1 || {
# error_make menhir;
# menhir_failed=1;
# }
# if (( ! menhir_failed )); then
# progress_run make \
# PREFIX="$install_dir/menhir-$menhir_install_version" \
# install || {
# error_install menhir;
# menhir_failed=1;
# }
# fi
# fi
# if (( ! menhir_failed )); then
# prepend_path "$install_dir/menhir-$menhir_install_version/bin"
# (command_exists menhir && version=$(menhir_parse_version menhir) &&
# [[ "$version" = "$menhir_install_version" ]]) ||
# error_msg "menhir is not properly installed"
# success "${cgreen}menhir $menhir_install_version${coff}${cbold} successfully installed"
# else
# error_msg "Skipping menhir: menhir installation, failed"
# fi
# fi
##################
# Install spacer for Zustre #
##################
# spacer_failed=0
# if [[ -x "$install_dir/spacer/bin/z3" ]]; then
# progress "Using already built ${cgreen}spacer"
# else
# progress "Installing ${cgreen}spacer${coff}${cbold} from upstream repository"
# git_clone "https://bitbucket.org/spacer/code.git" "spacer"\
# "$build_dir/spacer"
# cd "$build_dir/spacer"
# progress_run python scripts/mk_make.py \
# --prefix="$install_dir/spacer" || {
# error_configure spacer;
# spacer_failed=1;
# }
# if (( ! spacer_failed )); then
# cd "$build_dir/spacer/build"
# progress_run make || {
# error_make spacer;
# spacer_failed=1;
# }
# fi
# if (( ! spacer_failed )); then
# progress_run make install || {
# error_install spacer;
# spacer_failed=1;
# }
# fi
# fi
# if (( ! spacer_failed )); then
# #prepend_path "$install_dir/spacer/bin" # do not prepend_path for z3 binary of spacer. We'll use the one of z3 as default one.
# prepend_python_path "$install_dir/spacer/lib/python"*"/dist-packages"
# if [[ ! -x "$install_dir/spacer/bin/z3" ]]; then
# error_msg "spacer is not properly installed"
# spacer_failed=1
# fi
# if (( ! spacer_failed )); then
# version=$(spacer_parse_version "$install_dir/spacer/bin/z3") || {
# error_parse_version spacer;
# spacer_failed=1;
# }
# fi
# if (( ! spacer_failed )); then
# success "${cgreen}spacer $version${coff}${cbold} successfully installed"
# fi
# else
# error_msg "Skipping spacer: spacer installation, failed"
# fi
##################
# Install Z3 #
##################
z3_failed=0
chmod +x "$install_dir/z3/bin/z3" 2>/dev/null || {}
if [[ -x "$install_dir/z3/bin/z3" ]]; then
progress "${cgreen}Z3 is already accessible from CoCoSim. Skipping installation."
elif command -v z3; then
progress "Z3 is already installed in this environment. Copying binary to CoCoSim installation."
cp "$(command which z3)" "$install_dir/bin/z3"
else
progress "Installing ${cgreen}z3${coff}${cbold} from github. This may take several minutes."
git_clone "https://github.com/Z3Prover/z3.git" "master" \
"$build_dir/z3"
cd "$build_dir/z3"
progress_run python scripts/mk_make.py \
--prefix="$install_dir/z3" || {
error_configure z3;
z3_failed=1;
}
if (( ! z3_failed )); then
cd "$build_dir/z3/build"
progress_run make || {
error_make z3;
z3_failed=1;
}
fi
if (( ! z3_failed )); then
progress_run make install || {
error_install z3;
z3_failed=1;
}
fi
fi
if (( ! z3_failed )); then
prepend_path "$install_dir/z3/bin"
prepend_python_path "$install_dir/z3/lib/python"*"/dist-packages"
if [[ -x "$install_dir/z3/bin/z3" ]]; then
# update z3 binary by original z3 and not spacer.
cp "$install_dir/z3/bin/z3" "$install_dir/bin/z3"
chmod +x "$install_dir/bin/z3" 2>/dev/null || {}
fi
command_exists z3 || {
error_msg "z3 is not properly installed";
z3_failed=1;
}
if (( ! z3_failed )); then
version=$(spacer_parse_version "$install_dir/z3/bin/z3") || {
error_parse_version z3;
z3_failed=1;
}
fi
if (( ! z3_failed )); then
success "${cgreen}z3 $version${coff}${cbold} successfully installed"
fi
else
error_msg "Skipping z3: z3 installation, failed"
fi
###################
# Install lustrec #
###################
lustrec_failed=0
chmod +x "$install_dir/bin/lustrec" 2>/dev/null
if [[ -x "$install_dir/bin/lustrec" ]]; then
progress "Using already built ${cgreen}lustrec"
else
progress "Installing ${cgreen}lustrec${coff}${cbold} from upstream repository"
git_clone "$lustrec_url" "$lustrec_branch" "$build_dir/lustrec"
cd "$build_dir/lustrec"
#akatis: For some reason I had to switch to `ocaml_required_version` again here.
#akatis: Otherwise, the script uses the system default.
progress_run opam switch -y $ocaml_required_version || {
progress_run opam switch create -y $ocaml_required_version
}
progress_run eval `opam config env` || error_install opam
progress_run autoconf || {
error_configure lustrec; lustrec_failed=1;
}
if (( ! lustrec_failed )); then
progress_run ./configure \
--disable-salsa --disable-lustresf --prefix="$install_dir" || {
error_configure lustrec; lustrec_failed=1;
}
fi
# There is an error with mkdir of src/_build.
# The following is to git rid of that error
#rm -rf src/_build/ || {}
if (( ! lustrec_failed )); then
progress_run make || {
error_make lustrec; lustrec_failed=1;
}
fi
# this hack because lustrec was broken
#mkdir "$install_dir/include/"
#mkdir "$install_dir/include/lustrec/"
#cp -r "$build_dir/lustrec/include/"* "$install_dir/include/lustrec/"
if (( ! lustrec_failed )); then
progress_run make install || {
error_install lustrec; lustrec_failed=1;
}
fi
fi
if (( ! lustrec_failed )); then
prepend_path "$install_dir/bin"
command_exists lustrec || {
error_msg "lustrec is not properly installed";
lustrec_failed=1;
}
#akatis: Added missing LustreC version parsing.
if (( ! lustrec_failed )); then
version=$(lustrec_parse_version "$install_dir/bin/lustrec") || {
error_parse_version lustrec;
lustrec_failed=1;
}
fi
if (( ! lustrec_failed )); then
success "${cgreen}lustrec $version${coff}${cbold} successfully installed"
else
error_msg "Please remove $install_dir/bin/lustrec and run the script again"
fi
else
error_msg "Skipping Lustrec: lustrec installation, failed"
fi
##################
# Install zustre #
##################
# zustre_failed=0
# if [ $lustrec_failed -eq 1 -o $spacer_failed -eq 1 ]; then
# error_msg "Skipping Zustre: dependancies Lustrec or spacer installation has failed"
# else
# if [[ -x "$install_dir/bin/zustre" ]]; then
# progress "Using already built ${cgreen}zustre"
# else
# progress "Installing ${cgreen}zustre${coff}${cbold} from upstream repository"
# git_clone "$zustre_url" "$zustre_branch" "$build_dir/zustre"
# cd "$build_dir/zustre"
# mkdir build
# cd build
# progress_run cmake \
# -DCMAKE_BUILD_TYPE=Release \
# -DCMAKE_INSTALL_PREFIX="$install_dir" \
# -DLUSTREC_ROOT="$install_dir" \
# -DLUSTREC_INCLUDE_DIR="$install_dir/include/lustrec" \
# -DZ3_ROOT="$install_dir/spacer" \
# .. || {
# error_configure zustre;
# zustre_failed=1;
# }
# if (( ! zustre_failed )); then
# progress_run cmake --build . || {
# error_make zustre;
# zustre_failed=1;
# }
# fi
# if (( ! zustre_failed )); then
# progress_run cmake --build . --target install || {
# error_install zustre;
# zustre_failed=1;
# }
# fi
# command_exists zustre || {
# error_msg "zustre is not properly installed";
# zustre_failed=1;
# }
# fi
# if (( ! zustre_failed )); then
# success "${cgreen}zustre${coff}${cbold} successfully installed"
# if (( ! z3_failed )); then
# # update z3 binary by original z3 and not spacer.
# cp "$install_dir/z3/bin/z3" "$install_dir/bin/z3"
# fi
# if [[ -f "$build_dir/zustre/tests/two_counters.lus" ]]; then
# progress "Testing zustre on a simple example"
# zustre_output=$(run_log_debug zustre --xml "$build_dir/zustre/tests/two_counters.lus" 2>&1) || {
# error_test zustre;
# zustre_failed=1;
# }
# (( verbose >= 1 )) && echo "$zustre_output"
# if (( ! zustre_failed )); then
# [[ "$zustre_output" == *"<Answer>SAFE</Answer>"* ]] || {
# error_test zustre;
# zustre_failed=1;
# }
# fi
# fi
# else
# error_msg "Skipping Zustre: zustre installation, failed"
# fi
# fi
#################
# Install kind2 using opam
#################
kind2_download_failed=0
kind2_failed=0
#akatis: Added check for an existing Kind2 binary, similarly to Z3 and LustreC
chmod +x "$install_dir/bin/kind2" 2>/dev/null
if [[ -x "$install_dir/bin/kind2" ]]; then
progress "${cgreen}kind2 is already accessible from CoCoSim. Skipping installation."
elif command -v kind2; then
progress "kind2 is already installed in this environment. Copying to CoCoSim installation."
cp "$(command which kind2)" "$install_dir/bin/kind2"
else
# Try first the downloaded version
#akatis: Reverted to v1.1.0 because of parsing issues with Kind2 on Lustre translation of Stateflow models.
#akatis: Previous OS check didn't work for Linux systems (Ubuntu 20.04)
if [[ "$OSTYPE" == "darwin"* ]]; then
arch=$(uname -m)
if [[ "$arch" == 'x86_64' ]]; then
wget https://github.com/kind2-mc/kind2/releases/download/v1.9.0/kind2-v1.9.0-macos-11-x86_64.tar.gz -O - | tar -xz || {
kind2_download_failed=1; }
else
wget https://github.com/kind2-mc/kind2/releases/download/v1.9.0/kind2-v1.9.0-macos-12-arm64.tar.gz -O - | tar -xz || {
kind2_download_failed=1; }
fi
if (( ! kind2_download_failed )); then
cp "kind2" "$install_dir/bin/kind2"
chmod +x "$install_dir/bin/kind2"
fi
else
wget https://github.com/kind2-mc/kind2/releases/download/v1.9.0/kind2-v1.9.0-linux-x86_64.tar.gz -O - | tar -xz || {
kind2_download_failed=1;
}
if (( ! kind2_download_failed )); then
cp "kind2" "$install_dir/bin/kind2"
chmod +x "$install_dir/bin/kind2"
fi
fi
kind2_output=$(run_log_debug "$install_dir/bin/kind2" --help 2>&1) || {
kind2_download_failed=1;
}
if (( kind2_download_failed )); then
#akatis: Commented the two lines below, shouldn't be necessary.
# progress_run opam pin add -y -n kind2 ${kind2_url}#${kind2_branch}
# progress_run opam depext -y kind2
#akatis: Added error handling if Kind2 opam installation fails.
progress_run opam install -y kind2 || {
error_install kind2; kind2_failed=1;
}
if (( ! kind2_failed )); then
cp "$(which kind2)" "$install_dir/bin/kind2"
fi
fi
if (( !kind2_download_failed && !kind2_failed )); then
version=$(kind2_parse_version "$install_dir/bin/kind2") || {
error_parse_version kind2;
kind2_failed=1;
}
if (( !kind2_failed )); then
success "${cgreen}kind2 $version${coff}${cbold} successfully installed"
fi
fi
fi
##################################
# Generate the activation script #
##################################
echo '#!/bin/bash' > "$install_dir/activate"
generate_env_path_line PATH "${act_prepend_path[@]}" >> "$install_dir/activate"
generate_env_path_line MANPATH "${act_prepend_manpath[@]}" >> "$install_dir/activate"
generate_env_path_line INFOPATH "${act_prepend_infopath[@]}" >> "$install_dir/activate"
generate_env_path_line PYTHONPATH "${act_prepend_python_path[@]}" >> "$install_dir/activate"
###########
# Success #
###########
if command_exists source; then
source_cmd="source"
else
source_cmd="."
fi
if [ $lustrec_failed -eq 1 -o $kind2_failed -eq 1 ]; then
error_msg "Part of the dependencies installation has failed, check error messages above."
else
success "Main CoCoSim dependencies have been successfully installed."
fi
info "(Optional) If you wish to add CoCoSim dependencies lustrec, kind2 to your environment, run:"
info "$ $source_cmd $install_dir/activate"
info "You should consider adding this in your .bashrc file."