-
Notifications
You must be signed in to change notification settings - Fork 2
/
installmpc
executable file
·1873 lines (1551 loc) · 47.3 KB
/
installmpc
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/sh
############################# MPC License ##############################
# Wed Nov 19 15:19:19 CET 2008 #
# Copyright or (C) or Copr. Commissariat a l'Energie Atomique #
# #
# IDDN.FR.001.230040.000.S.P.2007.000.10000 #
# This file is part of the MPC Runtime. #
# #
# This software is governed by the CeCILL-C license under French law #
# and abiding by the rules of distribution of free software. You can #
# use, modify and/ or redistribute the software under the terms of #
# the CeCILL-C license as circulated by CEA, CNRS and INRIA at the #
# following URL http://www.cecill.info. #
# #
# The fact that you are presently reading this means that you have #
# had knowledge of the CeCILL-C license and that you accept its #
# terms. #
# #
# Authors: #
# - CARRIBAULT Patrick [email protected] #
# - PERACHE Marc [email protected] #
# - JAEGER Julien [email protected] #
# #
########################################################################
# Path to the configure script
SCRIPT=$(readlink -f "$0")
# Directory containing configure
SCRIPTPATH=$(dirname "$SCRIPT")
# Where MPC is currently being BUILT
PROJECT_BUILD_DIR=$(readlink -f "$PWD")
USE_COLOR="no"
####################
# BUILD PARAMETERS #
####################
LSP="no"
MAKE_J=""
# NOTE: these are only meaningful when not using spack
ALL_PACKAGE_ARGS=""
MPC_COMP_ADD_BUILD_PARAMETERS=""
OPENPA_BUILD_PARAMETERS=""
MPCALLOC_BUILD_PARAMETERS=""
OFI_BUILD_PARAMETERS=""
HWLOC_BUILD_PARAMETERS="--disable-werror --enable-static"
HYDRA_BUILD_PARAMETERS=""
MPC_DMTCP_BUILD_PARAMETERS="--enable-pthread-mutex-wrappers"
MPC_GDB_BUILD_PARAMETERS="--without-zlib --disable-werror"
# Stop on error
set -e
#
# Utilities
#
#
# Output MGT
#
# Print an error message and exit
# Args:
# -$1 : Message to print
die(){
echo "================ ERROR ================"
echo "$1"
echo "======================================="
exit 1
}
#
# Check call return code
# Args:
# - $1: retcode to check
# - $2: error if NOK (no error if not given)
check_retcode()
{
if test "x$1" = "x0"; then
ok
else
nok
if test -n "$2"; then
die "$2"
fi
fi
}
#
# Ensures the prefix has not been emptied
# and remove marker file if so
# Args:
# - $1: prefix to check
#
check_prefix_is_clean()
{
if test -d "$PREFIX/lib/" -a -d "$PREFIX/bin/"; then
return
else
# Apparently prefix was cleared somehow
# Make sure deps are reinstalled
rm -fr "$PREFIX"/.mpc-installed-*
info "Prefix seems to be incomplete, forcing reinstall."
fi
}
#
# Output helpers
#
set_color_model()
{
if test "x$USE_COLOR" = "xyes"; then
colRESET="\e[0m"
colGRAY="\e[90m"
colRED="\e[31m"
colGREEN="\e[32m"
colMAGENTA="\e[35m"
colYELLOW="\e[33m"
colbgGRAY="\e[100m"
colbgMAGENTA="\e[45m"
colBLINK="\e[5m"
UNDERLINE="\e[4m"
fi
}
PENDING_LB=""
STEP_WRAPPER_VERBOSE=0
show_run_cmd()
{
if test $STEP_WRAPPER_VERBOSE -gt 0; then
test -n "${PENDING_LB}" && echo ""
PENDING_LB=""
echo "$ $*"
fi
}
info()
{
printf "${colbgGRAY}==>${colRESET}${colGRAY} $1${colRESET}\n"
}
LAST_RESULT=""
checking()
{
LAST_RESULT=""
PENDING_LB="yes"
printf "${colbgMAGENTA}==>${colRESET}${colMAGENTA} $1... ${colRESET}"
}
ok()
{
PENDING_LB=""
LAST_RESULT="ok"
if test $STEP_WRAPPER_VERBOSE -eq 0; then
printf "${colGREEN}SUCCESS${colRESET}\n"
fi
}
nok()
{
PENDING_LB=""
LAST_RESULT="nok"
printf "${UNDERLINE}${colBLINK}${colRED}FAIL${colRESET}\n"
}
skip()
{
PENDING_LB=""
LAST_RESULT="skip"
printf "${UNDERLINE}${colBLINK}${colYELLOW}SKIPPED${colRESET}\n"
}
notapplicable()
{
PENDING_LB=""
LAST_RESULT="na"
printf "${colbgGRAY}NA${colRESET}\n"
}
#
# Check for common commands
#
LIST_OF_FOUND_CMD=""
COMMON_CMD="bear cmake spack patch cut ls pwd grep rm rev basename dirname make bzip2 gcc g++ ldd pkg-config mktemp getconf nproc lscpu wget curl"
check_for_commands()
{
# Check already done
test -n "$LIST_OF_FOUND_CMD" && return
set +e
for c in $COMMON_CMD; do
command -v "$c" > /dev/null 2>&1
if test "x$?" = "x0"; then
LIST_OF_FOUND_CMD="$LIST_OF_FOUND_CMD $c"
else
checking "locate '$c' command in PATH"
nok
fi
done
set -e
}
have_cmd()
{
set +e
echo "$LIST_OF_FOUND_CMD" | grep "$1" > /dev/null 2>&1
if test "x$?" = "x0"; then
HAVE_CMD="yes"
else
HAVE_CMD="no"
fi
set -e
}
assert_cmd()
{
check_for_commands
have_cmd "$1"
if test "x${HAVE_CMD}" = "xno"; then
checking "$1 is in path"
nok
die "$1 could not be found in path"
fi
}
guess_cpu_count()
{
checking "Looking for number of CPUs"
if test -f "/proc/cpuinfo"; then
show_run_cmd "grep -c processor < /proc/cpuinfo"
TMP=$(grep -c "processor" < "/proc/cpuinfo" 2>/dev/null)
if test "x${TMP}" != "x0"; then
ok
NCPU="$TMP"
return
fi
fi
have_cmd "nproc"
if test "x${HAVE_CMD}" = "xyes"; then
show_run_cmd "nproc"
TMP=$(nproc 2> /dev/null || true)
if test "x${?}" = "x0"; then
ok
NCPU="$TMP"
return
fi
fi
# Could not guess stay serial
nok
NCPU="1"
info "Failed at guessing number of cores use -jX for parallel build"
}
#Extract parameter value and put in given variable
#Args :
# -$1 : Output variable name
# -$2 : parameter name (without --, eg. --with-XXX => 'with-XXX')
# -$3 : User value (--with-XXX=blablable)
extractParamValue()
{
#extract in local vars
outputvar="$1"
name="$2"
arg="$3"
value=$(echo "$arg" | sed -e "s/^--${name}=//g")
eval "${outputvar}=\"${value}\""
}
######################################################
#Extract parameter value and put in given variable
#Args :
# -$1 : Output variable name
# -$2 : parameter name (without -, eg. -XXX)
# -$3 : User value (-XXX=value)
extractParamValueAlt()
{
#extract in local vars
outputvar="$1"
name="$2"
arg="$3"
value=$(echo "$arg" | sed -e "s/^-${name}//g")
eval "${outputvar}=\"${value}\""
}
# Set a var to a value if not already set
#args :
# -$1 : output variable name
# -$2 : value triggering a set
# -$3 : value to set
enableParamIfNot()
{
#extract in local vars
outputvar="$1"
output="$2"
trigger="$3"
value="$4"
if [ "${output}" = "${trigger}" ]
then
eval "${outputvar}=\"${value}\""
fi
}
#Extract parameter value and put in given variable
#Args :
# -$1 : Output variable name
# -$2 : parameter prefix (eg --libxml2-XXXX to add --XXX to libxml2 params)
# -$3 : User value (--libxml2-XXXX)
extractAndAddPackageOption()
{
#extract in local vars
outputvar="$1"
name="$2"
arg="$3"
value=$(echo "$arg" | sed -e "s/^--${name}//g")
eval "${outputvar}=\"\$${outputvar} ${value}\""
}
wrap_output()
{
assert_cmd "mktemp"
outfile=$(mktemp)
set +e
show_run_cmd "$@"
if test $STEP_WRAPPER_VERBOSE -eq 3; then
"$@"
else
"$@" > "$outfile" 2>&1
fi
if test "x$?" = "x0"; then
rm "$outfile"
else
nok
if test $STEP_WRAPPER_VERBOSE -gt 0; then
cat "$outfile"
fi
die "See $outfile an error occurred when running $*"
fi
set -e
}
#
# Helper to export build environment
#
propagate_build_env()
{
export PATH
export PKG_CONFIG_PATH
export CPATH
export CMAKE_PREFIX_PATH
export SPACK_LOADED_HASHES
export ACLOCAL_PATH
export MANPATH
export LD_LIBRARY_PATH
}
# Build spack package name
# Args:
# -$1 : package
# -$2 : version
# -$3 : variant
#
SPECIFY_SPACK_ARCH="yes"
ENABLE_GENERIC_SPACK_BUILD="no"
FORCE_SPACK_ARCH=""
build_package_name()
{
SPACK_ARCH=""
if test -n "$FORCE_SPACK_ARCH"; then
SPACK_ARCH=" arch=$FORCE_SPACK_ARCH"
else
GENERIC_FLAG=""
if test "x${ENABLE_GENERIC_SPACK_BUILD}" = "xyes"; then
GENERIC_FLAG=" -g "
fi
if test "x${SPECIFY_SPACK_ARCH}" = "xyes"; then
set +e
spack arch $GENERIC_FLAG > /dev/null 2>&1
if test "x$?" = "x0"; then
SPACK_ARCH=" arch=$(spack arch $GENERIC_FLAG)"
fi
set -e
fi
fi
VARIANT=""
if test -n "$3"; then
VARIANT=" $3"
fi
if test -n "$2"; then
echo "${1}@${2}${VARIANT}${SPACK_ARCH}"
else
echo "$1${VARIANT}${SPACK_ARCH}"
fi
}
# The --force-spack-package=* option allows to force the use
# of a given spack package for installing a given dependency
# usually for testing or development purposes of when there are version conflicts
#
# Syntax is :
# DEP:SPACK_DESC,DEP:SPACK_DESC...
# For example:
# libxml2:/dzadzad,openpa:[email protected]
#
# Args:
# -$1 package name
# -$2 package version
# -$3 variant
#
# Fils in concretized_package with either $1@$2 or overrid if exists
#
OVERRIDEN_SPACK_PKGS=""
#
check_if_spack_package_is_overriden()
{
concretized_package="$(build_package_name "$1" "$2" "$3")"
if test -z "$OVERRIDEN_SPACK_PKGS"; then
return
fi
for override in $(echo "$OVERRIDEN_SPACK_PKGS" | sed "s/,/\n/g")
do
DEP=$(echo "$override" | cut -d ':' -f 1)
SPACK_DESC=$(echo "$override" | cut -d ':' -f 2)
if test "x${DEP}" = "x${SPACK_DESC}" -o -z "${SPACK_DESC}"; then
nok
die "No forced spack descriptor provided to dependency ${DEP}\n--force-spack-package=$OVERRIDEN_SPACK_PKGS"
fi
if test "x${DEP}" = "x${1}"; then
checking "overriden with ${SPACK_DESC}"
concretized_package="${SPACK_DESC}"
if echo "$concretized_package" | grep "^/" > /dev/null; then
#This is a hash so package must exist at load time
set +e
spack find "$TO_LOAD_NAME" > /dev/null 2>&1
if test "x$?" != "x0"; then
nok
die "Failed loading forced spack dependency ${SPACK_DESC} for ${DEP}"
fi
set -e
fi
fi
done
}
# Try to find a dep using spack
# Args:
# -$1 : package
# -$2 : version
# -$3 : variant (optional)
#
DEP_FOUND="no"
find_dep_with_spack()
{
DEP_FOUND="no"
have_cmd "spack"
if test "x${HAVE_CMD}" = "xno"; then
return
fi
PKG_NAME="$(build_package_name "$1" "$2" "$3")"
checking "load $PKG_NAME using spack"
show_run_cmd "spack info $1"
spack info "$1" > /dev/null 2>&1 || notapplicable
if test "x${LAST_RESULT}" = "xna"; then
return
fi
# Now check if dependency has been forced
check_if_spack_package_is_overriden "$1" "$2" "$3"
TO_LOAD_NAME="$concretized_package"
show_run_cmd "spack load --sh $TO_LOAD_NAME"
set +e
LOAD_CMD=$(spack load --sh $TO_LOAD_NAME 2> /dev/null)
check_retcode "$?"
set -e
if test "x${LAST_RESULT}" = "xok"; then
eval "$LOAD_CMD"
DEP_FOUND="yes"
fi
propagate_build_env
}
# Try to install a package using spack
#
#
install_dep_with_spack()
{
assert_cmd "spack"
PKG_NAME="$(build_package_name "$1" "$2" "$3")"
checking "install $PKG_NAME using spack"
check_if_spack_package_is_overriden "$1" "$2" "$3"
PKG_NAME="$concretized_package"
show_run_cmd "spack info $PKG_NAME"
spack info "$PKG_NAME" > /dev/null 2>&1 || notapplicable
if test "x${LAST_RESULT}" = "xna"; then
return
fi
show_run_cmd "spack install -j ${MAKE_J} $PKG_NAME"
# We need to allow expansion here as PKG_NAME can contain multiple params
wrap_output spack install -j "${MAKE_J}" $PKG_NAME
check_retcode "$?"
if test "x${LAST_RESULT}" = "xok"; then
find_dep_with_spack "$1" "$2" "$3"
fi
}
#
# Remove duplicates from an env type var (outputs on stdout)
# Args:
# - $1: variable to clean
#
clean_env_path_var()
{
var_data=$1
new_data_list=$(echo "$var_data" | sed "s/\\:/\\n/g" | sort | uniq | xargs echo)
ret=""
for entry in $new_data_list
do
ret="${ret}:${entry}"
done
echo "$ret"
}
#
# Load a prefix by appending a given directory
# Args:
# - $1: prefix to insert
#
load_prefix()
{
if test ! -d "$1"; then
nok
die "Could not locate prefix directory $1"
fi
test -d "$1/bin" && PATH=$(clean_env_path_var "$1/bin:$PATH")
test -d "$1/lib" && LD_LIBRARY_PATH=$(clean_env_path_var "$1/lib:$LD_LIBRARY_PATH")
test -d "$1/lib64" && LD_LIBRARY_PATH=$(clean_env_path_var "$1/lib64:$LD_LIBRARY_PATH")
test -d "$1/include" && CPATH=$(clean_env_path_var "$1/include:$CPATH")
test -d "$1/lib/pkgconfig/" && PKG_CONFIG_PATH=$(clean_env_path_var "$1/lib/pkgconfig/:$PKG_CONFIG_PATH")
test -d "$1/lib64/pkgconfig/" && PKG_CONFIG_PATH=$(clean_env_path_var "$1/lib64/pkgconfig/:$PKG_CONFIG_PATH")
test -d "$1/share/man/" && MANPATH=$(clean_env_path_var "$1/share/man/:$MANPATH")
propagate_build_env
}
# Check if an entry is in a list
#
# Args:
# - 1: needle
# - 2: haystack
in_list()
{
echo "$2" | grep "$1" > /dev/null
}
# Cat a file filtering lines starting with #
# Args:
# - Path to file
#
_config_file_clean()
{
grep -v "^\#" < "$1" | sed -E "s/\s+/ /g"
}
# Get package list from source.txt
package_list()
{
_config_file_clean "${SCRIPTPATH}/config/source.txt" | cut -d " " -f 1
}
# Assert package is known
# Args:
# - 1: package name
assert_package()
{
if in_list "$1" "$(package_list)"; then
true
else
die "No such package $1."
fi
}
# Get package list from version.txt
vesion_list()
{
_config_file_clean "${SCRIPTPATH}/config/version.txt" | cut -d " " -f 1
}
# Assert package version is known
# Args:
# - 1: package name
assert_version()
{
if in_list "$1" "$(vesion_list)"; then
true
else
die "No such package $1 in version.txt."
fi
}
# Get package version
# Args:
# - 1: package name
# - 2: version
#
package_version()
{
assert_version "$1"
_config_file_clean "${SCRIPTPATH}/config/version.txt" | grep "$1" | cut -d " " -f 2
}
# Get package URL
# Args:
# - 1: package name
# - 2: version
#
package_download_address()
{
_config_file_clean "${SCRIPTPATH}/config/source.txt" | grep "$1" | cut -d " " -f 2 | sed "s/VERSION/${2}/g"
}
# Package Filename
# - 1: package name
# - 2: version
#
package_filename()
{
package_download_address "$1" "$2" | rev | cut -d "/" -f 1 | rev
}
# Download a dependency
# Args:
# - 1 : package name
# - 2 : package version
# Returns in ENV:
# TARBALL_PATH where the tarball is
download_package()
{
PKG=$1
VERS=$2
cd "$PROJECT_BUILD_DIR" || die "Could not go back to builddir"
assert_package "$PKG"
FNAME=$(package_filename "$PKG" "${VERS}")
checking "Downloading $PKG-$VERS"
have_cmd "wget"
if test "x${HAVE_CMD}" = "xyes"; then
wrap_output wget "$(package_download_address "$PKG" "${VERS}")"
else
have_cmd "curl"
if test "x${HAVE_CMD}" = "xyes"; then
wrap_output curl -L "$(package_download_address "$PKG" "${VERS}")" -o "./${FNAME}"
else
nok
die "Curl or wget is required for dep download or use --download."
fi
fi
ok
#(TARBALL_PATH is the return value)
TARBALL_PATH="${PWD}/${FNAME}"
}
# Locate tarball for a dependency (or download it)
# Args:
# - 1 : package name
# - 2 : package version
# Returns in ENV:
# TARBALL_PATH where the tarball is
locate_tarball()
{
PKG=$1
VERS=$2
# Now attempt to locate archive
tarball="$PKG-$VERS"
TARBALL_PATH=$( (find "$HOME/.mpcdep/" -iname "${tarball}*tar*" 2> /dev/null | head -n 1) || true)
if test -f "$TARBALL_PATH"; then
# Found in .mpcdep in $HOME
return
fi
TARBALL_PATH=$(find "$SCRIPTPATH/deps/$package/" -iname "${tarball}*tar*" 2> /dev/null || true)
if test -f "$TARBALL_PATH"; then
# Found in dependency patch dir
return
fi
TARBALL_PATH=$(find "${PROJECT_BUILD_DIR}/" -iname "${tarball}*tar*" 2> /dev/null || true)
if test -f "$TARBALL_PATH"; then
# Found in build dir
return
fi
TARBALL_PATH=$(find "$SCRIPTPATH/deps/" -iname "${tarball}*tar*" 2> /dev/null || true)
if test -f "$TARBALL_PATH"; then
# Found in flat deps dir
return
fi
TARBALL_PATH=$(find "${SCRIPTPATH}/" -iname "${tarball}*tar*" 2> /dev/null || true)
if test -f "$TARBALL_PATH"; then
# Found in root source dir
return
fi
# All failed now download
download_package "$PKG" "$VERS"
}
# Download all deps for MPC
download_all_missing_deps()
{
DEP_LIST=""
for p in $(package_list)
do
VERSION="$(package_version "$p")"
FNAME=$(package_filename "$p" "${VERSION}")
locate_tarball "$p" "$VERSION"
# Copy from other place to here if not present
if test ! -f "./${FNAME}"; then
checking "Copying tarball from ${TARBALL_PATH}"
wrap_output cp ${TARBALL_PATH} ./${FNAME}
ok
fi
DEP_LIST="./${FNAME} ${DEP_LIST}"
done
echo "DEP_LIST=${DEP_LIST}"
}
#
# Find a package prefix from env
# $1 Package name
# $2 Package version
# $3 Package manual prefix
#
# Return PACK_PREFIX (set to "" if not resolved)
#
find_package_prefix()
{
PACK_PREFIX=""
if test -d "$3"; then
PACK_PREFIX="$3"
return
fi
# Do not forget to trim as spack has 2 spaces in its separator
SPACKFIND=$(spack find -p ${1}@${2} | grep "${1}@${2}" | cut -d " " -f 2- | awk '{$1=$1};1' 2> /dev/null || true)
if test "x$?" != "x0"; then
return
fi
if test -d "$SPACKFIND"; then
PACK_PREFIX="$SPACKFIND"
fi
}
#
# Build a configure based package
#
# Args:
# - $1: package name
# - $2: package version
# - $3: extra arguments for configure
#
BUILD_IS_DISABLED="no"
build_configure_based_package()
{
package="$1"
version="$2"
extra_config_args=$3
if test "x${BUILD_IS_DISABLED}" = "xyes"; then
die "--disable-build was passed and a package was not provided through spack"
fi
#
# INSTALL FLAG MANAGEMENT
#
assert_cmd "cut"
assert_cmd "rev"
assert_cmd "grep"
# Check if another version of the dependency is not already installed
installed_vers=$(ls "${PREFIX}/.mpc-installed-${package}-*" 2> /dev/null || true)
if test -n "$installed_vers"; then
# There is already a version
installed_version=$(echo "$installed_vers" | rev | cut -d "-" -f 1 | rev)
if test "x${installed_version}" != "x${version}"; then
info "there is $package $installed_version in $PREFIX and MPC provides $version"
die "MPC does not support installing mismatching $package versions in the same prefix"
fi
fi
# The flag to determine if a dependency is already in prefix
DEP_FLAG=${PREFIX}/.mpc-installed-$package-$version
# If already deployed no need to redo
if test -f "$DEP_FLAG"; then
checking "Installing $package-$version"
skip
load_prefix "$PREFIX"
return
fi
#
# Tarball Extraction
#
# Where the tarball is extracted (depends on inner tarball dir name)
ORIG_PKG_SOURCE_DIR=${PROJECT_BUILD_DIR}/${package}-${version}/
# Where we move it in MPC to simplify deletion thanks to dep-* prefix
PKG_SOURCE_DIR=${PROJECT_BUILD_DIR}/dep-${package}-${version}/
if test ! -d "$PKG_SOURCE_DIR"; then
pkg_dir="$SCRIPTPATH/config/deps/$package"
locate_tarball "$package" "$version"
checking "Extracting $package-$version"
if test ! -f "$TARBALL_PATH"; then
nok
die "Could not locate a tarball for $package-$version in $pkg_dir"
fi
wrap_output tar xf "$TARBALL_PATH"
if test ! -d "$ORIG_PKG_SOURCE_DIR"; then
nok
die "Could not locate sources in $PKG_SOURCE_DIR after extracting $TARBALL_PATH"
else
show_run_cmd "mv $ORIG_PKG_SOURCE_DIR $PKG_SOURCE_DIR"
# Rename to $PKG_SOURCE_DIR
mv "$ORIG_PKG_SOURCE_DIR" "$PKG_SOURCE_DIR"
ok
fi
#
# Patching (when needed)
#
PACKAGE_PATCH=$pkg_dir/${package}-${version}.patch
if test -f "$PACKAGE_PATCH"; then
checking "Patching $package $version"
show_run_cmd "cd $PKG_SOURCE_DIR"
cd "$PKG_SOURCE_DIR"
show_run_cmd "patch -p 1 < $PACKAGE_PATCH"
patch -p 1 < "$PACKAGE_PATCH" > /dev/null
check_retcode "$?" "Failed to patch $package $version"
info "PATCH: ${PACKAGE_PATCH}"
show_run_cmd "cd $PROJECT_BUILD_DIR"
cd "${PROJECT_BUILD_DIR}"
fi
else
checking "Tarball for ${package}-${version} already extracted"
skip
fi
#
# Actual BUILD
#
if test ! -d "${PKG_SOURCE_DIR}/BUILD"; then
show_run_cmd "mkdir ${PKG_SOURCE_DIR}/BUILD"
mkdir "${PKG_SOURCE_DIR}/BUILD"
fi
show_run_cmd "cd ${PKG_SOURCE_DIR}/BUILD"
cd "${PKG_SOURCE_DIR}/BUILD"
if test -f "${PKG_SOURCE_DIR}/configure"; then
# Regular configure / make / make install
checking "Configuring $package-$version"
# we want parameter expansion
# shellcheck disable=SC2086
wrap_output "${PKG_SOURCE_DIR}/configure" "--prefix=${PREFIX}" $extra_config_args $ALL_PACKAGE_ARGS
ok
checking "Building $package-$version"
wrap_output make "-j${MAKE_J}"
ok
checking "Installing $package-$version"
wrap_output make install
ok
else
die "Could not locate ./configure in ${PKG_SOURCE_DIR}"
fi
show_run_cmd "cd ${PROJECT_BUILD_DIR}"
cd "${PROJECT_BUILD_DIR}"