forked from hercules-390/decNumber-icu-368
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build
executable file
·1518 lines (1201 loc) · 41.4 KB
/
build
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
#!/usr/bin/env bash
# If this bash script works then it was written by Fish.
# If it doesn't then I don't know who the heck wrote it.
_versnum="2.5"
_versdate="January 3, 2021"
#------------------------------------------------------------------------------
# BUILD
#------------------------------------------------------------------------------
help()
{
errmsg ""
errmsg " NAME"
errmsg ""
errmsg " $nx0 -- Builds and installs a Hercules external package"
errmsg ""
errmsg " SYNOPSIS"
errmsg ""
errmsg " $nx0 [ { -d | --pkgdir } [ pkgdir ] ]"
errmsg " [ { -n | --pkgname } [ pkgname ] ]"
errmsg " [ { -m | --cpu } { arch } ]"
errmsg " [ { -a | --arch } { 64 | 32 | BOTH } ]"
errmsg " [ { -c | --config } { Release | Debug | BOTH } ]"
errmsg " [ { -all | --all } ]"
errmsg " [ { -r | --rebuild } ]"
errmsg " [ { -i | --install } [ instdir ] ]"
errmsg " [ { -u | --uninstall } [ uinstdir ] ]"
errmsg " [ { -f | --force } ]"
errmsg " [ { -su | --sudo } ]"
errmsg ""
errmsg " ARGUMENTS"
errmsg ""
errmsg " pkgdir The package directory where the CMakeLists.txt"
errmsg " file exists. This is usually the name of the"
errmsg " package's primary source directory (i.e. its"
errmsg " repository directory). The default when not"
errmsg " specified is the same directory as where $nx0"
errmsg " is running from."
errmsg ""
errmsg " pkgname The single word alphanumeric package name. The"
errmsg " default if not specified is derived from the last"
errmsg " directory component of pkgdir. The value \".\" may"
errmsg " be specified to derive from the last component of"
errmsg " the current directory instead."
errmsg ""
errmsg " cpu The machine (CPU) architecture of the target system"
errmsg " if other than x86. Recognized machine architectures"
errmsg " are: aarch64, arm, i686, mips, ppc, s390x, sparc,"
errmsg " x86, xscale, and unknown."
errmsg " The default if not specified is x86."
errmsg ""
errmsg " arch The build architecture. Use '32' to build an x86"
errmsg " 32-bit version of the package. Use '64' to build"
errmsg " an x64 64-bit version of the package. Use 'BOTH'"
errmsg " to build both architectures. The default is 64."
errmsg ""
errmsg " config The build configuration. Specify 'Debug' to build"
errmsg " an unoptimized debug version of the product. Use"
errmsg " Release to build an optimized version (which also"
errmsg " has debugging symbols). The default is Release."
errmsg ""
errmsg " install Install the package into the specified directory."
errmsg " If not specified the package won't be installed."
errmsg ""
errmsg " instdir The package installation directory. If specified"
errmsg " the given directory MUST exist. If not specified"
errmsg " the directory specified in a previous run is used"
errmsg " if such is possible. Otherwise the CMake default"
errmsg " installation directory is used instead, which for"
errmsg " Linux is /usr/local."
errmsg ""
errmsg " uninstall Uninstalls the previously installed package."
errmsg ""
errmsg " uinstdir The directory where the package was installed. If"
errmsg " specified without the force option, the value MUST"
errmsg " match the install directory used in a previous run."
errmsg " If not specified, then the install directory from"
errmsg " the previous run is retrieved from the CMake cache"
errmsg " and used instead. If the directory isn't found in"
errmsg " CMake's cache the package default install directory"
errmsg " is used instead. The directory MUST exist."
errmsg ""
errmsg " OPTIONS"
errmsg ""
errmsg " all Shorthand for \"--arch BOTH --config BOTH\"."
errmsg ""
errmsg " rebuild Forces a complete reconfigure and rebuild."
errmsg ""
errmsg " force Overrides CMake's cached install directory used in"
errmsg " a previous run and forces the uninstall to use the"
errmsg " specified directory instead. It effectively forces"
errmsg " a complete CMake reconfigure just like the rebuild"
errmsg " option does but is used exclusively for uninstalls."
errmsg ""
errmsg " sudo Prefix install or uninstall command with \"sudo\"."
errmsg " Use this option if installing to or uninstalling"
errmsg " from /usr/local or anywhere else requiring root."
errmsg ""
errmsg " NOTES"
errmsg ""
errmsg " $nx0 first creates a build directory in the current directory,"
errmsg " changes to the build directory, invokes the cmake command (to"
errmsg " create the makefile) and then issues the make and make install"
errmsg " commands to actually build and install the specified package"
errmsg " for the given cpu, architecture and configuration combination."
errmsg " The name of the build directory is derived from the package's"
errmsg " name and the specified architetcure/configuration combination."
errmsg ""
errmsg " EXIT STATUS"
errmsg ""
errmsg " 0 All requested actions successfully completed."
errmsg " n One or more builds/installs failed w/error(s) where 'n'"
errmsg " is the highest return code detected."
errmsg ""
errmsg " AUTHOR"
errmsg ""
errmsg " \"Fish\" (David B. Trout)"
errmsg ""
errmsg " VERSION"
errmsg ""
errmsg " $_versnum ($_versdate)"
errmsg ""
quit
}
#------------------------------------------------------------------------------
# INIT
#------------------------------------------------------------------------------
init()
{
pushd "." >/dev/null 2>&1
# Define some constants...
dp0="$(dirname "$0")"
nx0="$(basename "$0")"
x0="${nx0##*.}"
n0="${nx0%.*}"
nx0_cmdline="$nx0 $*"
rc=0
maxrc=0
tool1="cmake"
# Options as listed in help...
pkgdir=""
pkgname=""
install=""
instdir=""
uninstall=""
uinstdir=""
arch=""
config=""
rebuild=""
force=""
bldall=""
cpu=""
sudo=""
# Default values...
def_pkgdir="$dp0"
def_arch="64"
def_config="Release"
parse_args $@
}
#------------------------------------------------------------------------------
# push_shopt
#------------------------------------------------------------------------------
push_shopt()
{
if [[ -z $shopt_idx ]]; then shopt_idx="-1"; fi
shopt_idx=$(( $shopt_idx + 1 ))
shopt_opt[ $shopt_idx ]=$2
shopt -q $2
shopt_val[ $shopt_idx ]=$?
eval shopt $1 $2
}
#------------------------------------------------------------------------------
# pop_shopt
#------------------------------------------------------------------------------
pop_shopt()
{
if [[ -n $shopt_idx ]] && (( $shopt_idx >= 0 )); then
if (( ${shopt_val[ $shopt_idx ]} == 0 )); then
eval shopt -s ${shopt_opt[ $shopt_idx ]}
else
eval shopt -u ${shopt_opt[ $shopt_idx ]}
fi
shopt_idx=$(( $shopt_idx - 1 ))
fi
}
#------------------------------------------------------------------------------
# trace
#------------------------------------------------------------------------------
trace()
{
if [[ -n $debug ]] || \
[[ -n $DEBUG ]]; then
logmsg "++ $1"
fi
}
#------------------------------------------------------------------------------
# logmsg
#------------------------------------------------------------------------------
logmsg()
{
stdmsg "stdout" "$1"
}
#------------------------------------------------------------------------------
# errmsg
#------------------------------------------------------------------------------
errmsg()
{
stdmsg "stderr" "$1"
setrc1
}
#------------------------------------------------------------------------------
# stdmsg
#------------------------------------------------------------------------------
stdmsg()
{
local _stdxxx="$1"
local _msg="$2"
push_shopt -s nocasematch
if [[ $_stdxxx != "stdout" ]] && \
[[ $_stdxxx != "stderr" ]]; then
_stdxxx=stdout
fi
if [[ $_stdxxx == "stdout" ]]; then
echo "$_msg"
else
echo "$_msg" 1>&2
fi
pop_shopt
}
#------------------------------------------------------------------------------
# load_tools
#------------------------------------------------------------------------------
load_tools()
{
local _tool="$( which "$tool1" 2>/dev/null )"
if [[ -z $_tool ]] || \
[[ ! -x $_tool ]]; then errmsg "'$tool1' not found."
fi
}
#------------------------------------------------------------------------------
# fullpath
#------------------------------------------------------------------------------
fullpath()
{
# Upon return $fullpath will contain full path or empty string if not found.
# If optional argument 2 is passed then that variable also set to $fullpath.
fullpath="$(readlink -e "$1" 2>/dev/null)"
# PROGRAMMING NOTE: "fullpath" can fail on MacOS because it doesn't support
# the '-e' option. The following 'if' statement is the temporary workaround.
if [[ -z $fullpath ]] && [[ -a $1 ]]; then
# MacOS: "\"readlink -e $1\" resulted in a null string but the file exists.
fullpath="$1"
fi
# Assign the results to the requested return variable, if asked to.
if [[ -n $fullpath ]] && [[ -n $2 ]]; then
eval $2="\$fullpath"
fi
}
#------------------------------------------------------------------------------
# isfile
#------------------------------------------------------------------------------
isfile()
{
# isfile $foo; if [[ -n $isfile ]]; then isfile; else notfile; fi
if [[ -f $1 ]]; then isfile=1; else isfile=""; fi
}
#------------------------------------------------------------------------------
# isdir
#------------------------------------------------------------------------------
isdir()
{
# isdir $foo; if [[ -n $isdir ]]; then isdir; else notdir; fi
if [[ -d $1 ]]; then isdir=1; else isdir=""; fi
}
#------------------------------------------------------------------------------
# tempfn
#------------------------------------------------------------------------------
tempfn()
{
# Usage: tempfn tmpfn ext
# Upon return, $tmpfn will contain filename.ext
local _tmpf="$(mktemp)"
_tmpf="${_tmpf}.$2"
eval $1="\$_tmpf"
}
#------------------------------------------------------------------------------
# normalize_dir
#------------------------------------------------------------------------------
normalize_dir()
{
# Note: while Windows paths can contain mixed path separators ('/' or '\')
# Linux paths can only have one and ONLY one path separator character '/'
# so all we need to do here is to check for the trailing separator.
local var_name="$1"
local var_value="$2"
if [[ -n $var_value ]]; then
# Remove trailing separator if there is one
if [[ $var_value != "/" ]] && \
[[ ${var_value: -1} == "/" ]]; then
var_value=${var_value:0:${#var_value}-1}
fi
fi
eval $var_name="\$var_value"
}
#------------------------------------------------------------------------------
# is_valid_dir
#------------------------------------------------------------------------------
is_valid_dir()
{
# Return value 'is_valid_dir' defined if valid, otherwise undefined.
# Passed variable will ALWAYS be updated (normalized) REGARDLESS of
# whether it is determined to be valid or not.
# Use quiet option to preserve rc/maxrc value if only interested in
# the 'is_valid_dir' return value. Otherwise an error message will
# be issued and 'rc' & 'maxrc' will be updated if directory invalid.
is_valid_dir=1
local var_name=$1
local var_value=$2
local quiet=$3
local norm_val=""
normalize_dir norm_val "$var_value"
fullpath "$norm_val"
if [[ -z $fullpath ]]; then
is_valid_dir=""
if [[ -z $quiet ]]; then
errmsg "ERROR: $var_name \"$var_value\" not found."
fi
else
norm_val=$fullpath
isdir "$norm_val"
if [[ -z $isdir ]]; then
is_valid_dir=""
if [[ -z $quiet ]]; then
errmsg "ERROR: $var_name \"$var_value\" is not a directory."
fi
fi
fi
eval $var_name="\$norm_val"
}
#------------------------------------------------------------------------------
# isalphanum
#------------------------------------------------------------------------------
isalphanum()
{
# isalphanum $foo; if [[ -n $isalphanum ]]; then isalphanum; else notalphanum; fi
isalphanum=""
if [[ "$1" =~ [a-zA-Z0-9]+ ]]; then
# (ensure first char is letter not number)
if [[ "${1:0:1}" =~ [a-zA-Z0-9] ]]; then
isalphanum="1"
fi
fi
}
#------------------------------------------------------------------------------
# get_num_cpus
#------------------------------------------------------------------------------
get_num_cpus()
{
CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null` # Linux
[ -z "$CPUS" ] && CPUS=`getconf NPROCESSORS_ONLN` # FreeBSD
[ -z "$CPUS" ] && CPUS=`ksh93 -c 'getconf NPROCESSORS_ONLN'` # Solaris
[ -z "$CPUS" ] && CPUS=1 # Default
}
#------------------------------------------------------------------------------
# get_cache_value
#------------------------------------------------------------------------------
get_cache_value()
{
local _cachefile="$1"
local _varname="$2"
cache_value=""
if [ -f $_cachefile ]; then
local _cache_re="(^.*):(.*)=(.*)$"
local _orig_IFS="$IFS"
IFS=""
while read -r _stmt || [[ -n "$_stmt" ]]; do
if [[ $_stmt =~ $_cache_re ]] && \
[[ ${BASH_REMATCH[1]} == $_varname ]]; then
cache_value=${BASH_REMATCH[3]}
break
fi
done < "$_cachefile"
IFS="$_orig_IFS"
fi
}
#------------------------------------------------------------------------------
# (parse_args helper)
#------------------------------------------------------------------------------
isopt()
{
# isopt $foo; if [[ -n $isopt ]]; then isopt; else notopt; fi
# Examines first character of passed value to determine
# whether it's the next option or not. If it starts with
# a '-' then it's the next option. Else it's not.
isopt="$1"
if [[ -n $isopt ]] && \
[[ ${isopt:0:1} != "-" ]]; then
isopt=""
fi
}
#------------------------------------------------------------------------------
# (parse_args helper)
#------------------------------------------------------------------------------
parseopt()
{
# This function expects the next two command line arguments
# $1 and $2 to be passed to it. $1 is expected to be a true
# option (its first character should start with a '-' dash).
#
# Both arguments are then examined and the results are placed
# into the following variables:
#
# $opt The current option as-is (e.g. "-d")
#
# $optname Just the characters following the '-' (e.g. "d")
#
# $optval The next token following the option (i.e. $2),
# but only if it's not an option itself (not isopt).
# Otherwise optval is set to empty/undefined since
# it is not actually an option value but is instead
# the next option.
opt="$1"
optval="$2"
optname="${opt:1}"
local _saved_isopt="$isopt"
isopt "$optval"
local _optval_isopt="$isopt"
isopt="$_saved_isopt"
if [[ -n $_optval_isopt ]]; then
optval=""
fi
}
#------------------------------------------------------------------------------
# parse_args
#------------------------------------------------------------------------------
parse_args()
{
rc=0
push_shopt -s nocasematch
if [[ $1 == "?" ]]; then help; fi
if [[ $1 == "-?" ]]; then help; fi
if [[ $1 == "-h" ]]; then help; fi
if [[ $1 == "--help" ]]; then help; fi
load_tools
# Abort if required tool(s) not found
if (( $rc != 0 )); then quit; fi
# Parse command line options...
while [[ -n $1 ]]
do
cmdline_arg="$1"
isopt "$1"
parseopt "$1" "$2"
shift 1
if [[ -n $isopt ]]; then
case "$optname" in
# ------------------------------------
# Options that require an argument
# ------------------------------------
d)
if [[ -z $optval ]]; then parse_missing_optarg; else
pkgdir="$optval"
shift 1 # (consume this option's value)
fi
;;
n)
if [[ -z $optval ]]; then parse_missing_optarg; else
pkgname="$optval"
shift 1 # (consume this option's value)
fi
;;
a)
if [[ -z $optval ]]; then parse_missing_optarg; else
arch="$optval"
shift 1 # (consume this option's value)
fi
;;
c)
if [[ -z $optval ]]; then parse_missing_optarg; else
config="$optval"
shift 1 # (consume this option's value)
fi
;;
m)
if [[ -z $optval ]]; then parse_missing_optarg; else
cpu="$optval"
shift 1 # (consume this option's value)
fi
;;
# ------------------------------------
# Options whose argument is optional
# ------------------------------------
i)
install=1
if [[ -n $optval ]]; then
instdir="$optval"
shift 1 # (consume this option's value)
fi
;;
# ------------------------------------
# Options that are just switches
# ------------------------------------
h)
help
;;
u)
uninstall=1
;;
r)
rebuild=1
;;
f)
force=1
;;
all)
bldall=1
;;
su)
sudo="sudo"
;;
# ------------------------------------
# (none of the above)
# ------------------------------------
*) # (check if "--xxxx" long option)
isopt "$optname"
if [[ -z $isopt ]]; then
parse_unknown_opt
else
# ------------------------------------
# Long "--xxxxx" option parsing...
# We use $1 here (instead of $2)
# since shift 1 was already done.
# ------------------------------------
parseopt "$optname" "$1"
case "$optname" in
# ------------------------------------
# Options that require an argument
# ------------------------------------
pkgdir)
if [[ -z $optval ]]; then parse_missing_optarg; else
pkgdir="$optval"
shift 1 # (consume this option's value)
fi
;;
pkgname)
if [[ -z $optval ]]; then parse_missing_optarg; else
pkgname="$optval"
shift 1 # (consume this option's value)
fi
;;
arch)
if [[ -z $optval ]]; then parse_missing_optarg; else
arch="$optval"
shift 1 # (consume this option's value)
fi
;;
config)
if [[ -z $optval ]]; then parse_missing_optarg; else
config="$optval"
shift 1 # (consume this option's value)
fi
;;
cpu)
if [[ -z $optval ]]; then parse_missing_optarg; else
cpu="$optval"
shift 1 # (consume this option's value)
fi
;;
# ------------------------------------
# Options whose argument is optional
# ------------------------------------
install)
install=1
if [[ -n $optval ]]; then
instdir="$optval"
shift 1 # (consume this option's value)
fi
;;
uninstall)
uninstall=1
if [[ -n $optval ]]; then
uinstdir="$optval"
shift 1 # (consume this option's value)
fi
;;
# ------------------------------------
# Options that are just switches
# ------------------------------------
help)
help
;;
rebuild)
rebuild=1
;;
force)
force=1
;;
all)
bldall=1
;;
sudo)
sudo="sudo"
;;
version)
errmsg "$nx0 version $_versnum ($_versdate)"
;;
# ------------------------------------
# (none of the above)
# ------------------------------------
*)
parse_unknown_opt
;;
esac
fi
;;
esac
else
# ------------------------------------
# Must be a positional option.
# Set optname identical to opt
# and empty meaningless optval.
# ------------------------------------
optname="$opt"
optval=""
# We do not have any positional arguments...
parse_unknown_arg
# ...but if we did, this is how we'd do it.
if [ ]; then # (beg disabled code block)
if [[ -z $positional_argument_1 ]]; then
positional_argument_1="$opt"
else
if [[ -z $positional_argument_2 ]]; then
positional_argument_2="$opt"
else
if [[ -z $positional_argument_3 ]]; then
positional_argument_3="$opt"
else
parse_unknown_arg
fi
fi
fi
fi # (end disabled code block)
fi
done
pop_shopt
trace "Debug: values after parsing:"
trace ""
trace "pkgdir = \"$pkgdir\""
trace "pkgname = \"$pkgname\""
trace "install = \"$install\""
trace "instdir = \"$instdir\""
trace "uninstall = \"$uninstall\""
trace "uinstdir = \"$uinstdir\""
trace "cpu = \"$cpu\""
trace "arch = \"$arch\""
trace "config = \"$config\""
trace "rebuild = \"$rebuild\""
trace "force = \"$force\""
trace "bldall = \"$bldall\""
trace ""
if (( $rc != 0 )); then quit; fi
validate_args
}
#------------------------------------------------------------------------------
# (parse_args helper)
#------------------------------------------------------------------------------
parse_unknown_arg()
{
errmsg "ERROR: Unrecognized/extraneous argument '$cmdline_arg'."
}
parse_unknown_opt()
{
errmsg "ERROR: Unknown/unsupported option '$cmdline_arg'."
}
parse_missing_optarg()
{
errmsg "ERROR: Option '$cmdline_arg' is missing its required argument."
}
#------------------------------------------------------------------------------
# validate_args
#------------------------------------------------------------------------------
validate_args()
{
push_shopt -s nocasematch
#----------------------------------------------------------------------------
# Validate pkgdir
# Use default pkgdir if pkgdir is not defined yet
if [[ -z $pkgdir ]]; then
pkgdir="$def_pkgdir"
fi
is_valid_dir pkgdir "$pkgdir"
if (( $rc == 0 )); then
pushd "$pkgdir" >/dev/null 2>&1
fullpath "CMakeLists.txt"
popd >/dev/null 2>&1
if [[ -z $fullpath ]]; then
errmsg "ERROR: File \"CMakeLists.txt\" not found in pkgdir."
pkgdir=""
fi
fi
#----------------------------------------------------------------------------
# Validate pkgname
while true; do
if [[ $pkgname == "." ]]; then
# derive pkgname from current directory
pkgname="$(basename "$(pwd)")"
pkgname="${pkgname//[^a-zA-Z0-9]}"
else
if [[ -z $pkgname ]]; then
# derive pkgname from pkgdir
pkgname="$(basename "$pkgdir")"
pkgname="${pkgname//[^a-zA-Z0-9]}"
fi
fi
# validate specific pkgname
isalphanum "$pkgname"
if [[ -z $isalphanum ]]; then
errmsg "ERROR: Invalid pkgname \"$pkgname\"."
break
fi
break
done
#----------------------------------------------------------------------------
# Validate instdir
if [[ -n $instdir ]]; then
is_valid_dir instdir "$instdir"
# (if invalid, errmsg already issued and rc/maxrc updated)
fi
#----------------------------------------------------------------------------
# Validate uinstdir
if [[ -n $uinstdir ]]; then
is_valid_dir uinstdir "$uinstdir"
# (if invalid, errmsg already issued and rc/maxrc updated)
fi
#----------------------------------------------------------------------------
# Validate build...
# Ignore specified arch and config values if bldall was specified
if [[ -n $bldall ]]; then
if [[ -n $arch ]] && [[ $arch != "BOTH" ]]; then
logmsg "WARNING: arch ignored due to 'all' option."
arch=""
fi
if [[ -n $config ]] && [[ $config != "BOTH" ]]; then
logmsg "WARNING: config ignored due to 'all' option."
config=""
fi
else # (use default values if not specified)
if [[ -z $arch ]]; then
arch="$def_arch"
fi
if [[ -z $config ]]; then
config="$def_config"
fi
fi
# Validate arch and config if not bldall
if [[ -z $bldall ]]; then
if [[ $arch != "32" ]] && \
[[ $arch != "64" ]] && \
[[ $arch != "BOTH" ]]; then
errmsg "ERROR: Invalid architecture \"$arch\""
fi
if [[ "$config" != "Debug" ]] && \
[[ "$config" != "Release" ]] && \
[[ "$config" != "BOTH" ]]; then
errmsg "ERROR: Invalid configuration \"$config\""
fi
fi
# Both 'arch' and 'config' == "BOTH" implies 'bldall'
if [[ $arch == "BOTH" ]] && \
[[ $config == "BOTH" ]]; then
arch=""
config=""
bldall=1
fi
# Validate 'cpu' option
if [[ -z $cpu ]]; then
cpu="x86"
fi
if [[ "$cpu" != "aarch64" ]] && \
[[ "$cpu" != "arm" ]] && \
[[ "$cpu" != "e2k" ]] && \
[[ "$cpu" != "i686" ]] && \
[[ "$cpu" != "mips" ]] && \
[[ "$cpu" != "ppc" ]] && \
[[ "$cpu" != "s390x" ]] && \
[[ "$cpu" != "sparc" ]] && \
[[ "$cpu" != "x86" ]] && \
[[ "$cpu" != "xscale" ]] && \
[[ "$cpu" != "unknown" ]]; then
errmsg "ERROR: Invalid machine cpu \"$cpu\""