-
-
Notifications
You must be signed in to change notification settings - Fork 360
/
Copy pathci_build.sh
executable file
·2505 lines (2264 loc) · 111 KB
/
ci_build.sh
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
################################################################################
# This file is based on a template used by zproject, but isn't auto-generated. #
# Its primary use is to automate a number of BUILD_TYPE scenarios for the NUT #
# CI farm, but for the same reason it can also be useful to reduce typing for #
# reproducible build attempts with NUT development and refactoring workflows. #
# Note that it is driven by enviroment variables rather than CLI arguments -- #
# this approach better suits the practicalities of CI build farm technologies. #
################################################################################
set -e
SCRIPTDIR="`dirname "$0"`"
SCRIPTDIR="`cd "$SCRIPTDIR" && pwd`"
SCRIPT_PATH="${SCRIPTDIR}/`basename $0`"
SCRIPT_ARGS=("$@")
# Quick hijack for interactive development like this:
# BUILD_TYPE=fightwarn-clang ./ci_build.sh
# or to quickly hit the first-found errors in a larger matrix
# (and then easily `make` to iterate fixes), like this:
# CI_REQUIRE_GOOD_GITIGNORE="false" CI_FAILFAST=true DO_CLEAN_CHECK=no BUILD_TYPE=fightwarn ./ci_build.sh
#
# For out-of-tree builds you can specify a CI_BUILDDIR (absolute or relative
# to SCRIPTDIR - not current path), or just call .../ci_build.sh while being
# in a different directory and then it would be used with a warning. This may
# require that you `make distclean` the original source checkout first:
# CI_BUILDDIR=obj BUILD_TYPE=default-all-errors ./ci_build.sh
case "$BUILD_TYPE" in
fightwarn) ;; # for default compiler
fightwarn-all)
# This recipe allows to test with different (default-named)
# compiler suites if available. Primary goal is to see whether
# everything is building ok on a given platform, with one shot.
TRIED_BUILD=false
if (command -v gcc) >/dev/null ; then
TRIED_BUILD=true
BUILD_TYPE=fightwarn-gcc "$0" || exit
else
echo "SKIPPING BUILD_TYPE=fightwarn-gcc: compiler not found" >&2
fi
if (command -v clang) >/dev/null ; then
TRIED_BUILD=true
BUILD_TYPE=fightwarn-clang "$0" || exit
else
echo "SKIPPING BUILD_TYPE=fightwarn-clang: compiler not found" >&2
fi
if ! $TRIED_BUILD ; then
echo "FAILED to run: no default-named compilers were found" >&2
exit 1
fi
exit 0
;;
fightwarn-gcc)
CC="gcc"
CXX="g++"
# Avoid "cpp" directly as it may be too "traditional"
#CPP="cpp"
CPP="gcc -E"
BUILD_TYPE=fightwarn
;;
fightwarn-clang)
CC="clang"
CXX="clang++"
if (command -v clang-cpp) >/dev/null 2>/dev/null ; then
CPP="clang-cpp"
else
CPP="clang -E"
fi
BUILD_TYPE=fightwarn
;;
esac
if [ "$BUILD_TYPE" = fightwarn ]; then
# For CFLAGS/CXXFLAGS keep caller or compiler defaults
# (including C/C++ revision)
BUILD_TYPE=default-all-errors
#BUILD_WARNFATAL=yes
# configure => "yes" except for antique compilers
BUILD_WARNFATAL=auto
# Current fightwarn goal is to have no warnings at preset level below,
# or at the level defaulted with configure.ac (perhaps considering the
# compiler version, etc.):
#[ -n "$BUILD_WARNOPT" ] || BUILD_WARNOPT=hard
#[ -n "$BUILD_WARNOPT" ] || BUILD_WARNOPT=medium
# configure => default to medium, detect by compiler type
[ -n "$BUILD_WARNOPT" ] || BUILD_WARNOPT=auto
# Eventually this constraint would be removed to check all present
# SSL implementations since their ifdef-driven codebases differ and
# emit varied warnings. But so far would be nice to get the majority
# of shared codebase clean first:
#[ -n "$NUT_SSL_VARIANTS" ] || NUT_SSL_VARIANTS=auto
# Similarly for libusb implementations with varying support
#[ -n "$NUT_USB_VARIANTS" ] || NUT_USB_VARIANTS=auto
fi
# configure default is "no"; an "auto" value is "yes unless CFLAGS say something"
[ -n "${BUILD_DEBUGINFO-}" ] || BUILD_DEBUGINFO=""
# Set this to enable verbose profiling
[ -n "${CI_TIME-}" ] || CI_TIME=""
case "$CI_TIME" in
[Yy][Ee][Ss]|[Oo][Nn]|[Tt][Rr][Uu][Ee])
CI_TIME="time -p " ;;
[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee])
CI_TIME="" ;;
esac
# Set this to enable verbose tracing
[ -n "${CI_TRACE-}" ] || CI_TRACE="no"
case "$CI_TRACE" in
[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee])
set +x ;;
[Yy][Ee][Ss]|[Oo][Nn]|[Tt][Rr][Uu][Ee])
set -x ;;
esac
[ -n "${CI_REQUIRE_GOOD_GITIGNORE-}" ] || CI_REQUIRE_GOOD_GITIGNORE="true"
case "$CI_REQUIRE_GOOD_GITIGNORE" in
[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee])
CI_REQUIRE_GOOD_GITIGNORE="false" ;;
[Yy][Ee][Ss]|[Oo][Nn]|[Tt][Rr][Uu][Ee])
CI_REQUIRE_GOOD_GITIGNORE="true" ;;
esac
# Abort loops like BUILD_TYPE=default-all-errors as soon as we have a problem
# (allowing to rebuild interactively and investigate that set-up)?
[ -n "${CI_FAILFAST-}" ] || CI_FAILFAST=false
# We allow some CI setups to CI_SKIP_CHECK (avoiding it during single-process
# scripted build), so tests can be done as a visibly separate stage.
# This does not really apply to some build scenarios whose purpose is to
# loop and check many build scenarios (e.g. BUILD_TYPE="default-all-errors"
# and "fightwarn*" family), but it is up to caller when and why to set it.
# It is also a concern of the caller (for now) if actually passing the check
# relies on something this script does (set envvars, change paths...)
[ -n "${CI_SKIP_CHECK-}" ] || CI_SKIP_CHECK=false
# By default we configure and build in the same directory as source;
# and a `make distcheck` handles how we build from a tarball.
# However there are also cases where source is prepared (autogen) once,
# but is built in various directories with different configurations.
# This is something to test via CI, that recipes are not broken for
# such use-case. Note the path should be in .gitignore, e.g. equal to
# or under ./tmp/ or ./obj/ for the CI_REQUIRE_GOOD_GITIGNORE sanity
# checks to pass.
case "${CI_BUILDDIR-}" in
"") # Not set, likeliest case
CI_BUILDDIR="`pwd`"
if [ x"${SCRIPTDIR}" = x"${CI_BUILDDIR}" ] ; then
CI_BUILDDIR="."
else
echo "=== WARNING: This build will use '${CI_BUILDDIR}'"
echo "=== for an out-of-tree build of NUT with sources located"
echo "=== in '${SCRIPTDIR}'"
echo "=== PRESS CTRL+C NOW if you did not mean this! (Sleeping 5 sec)"
sleep 5
fi
;;
".") ;; # Is SCRIPTDIR, in-tree build
/*) ;; # Absolute path located somewhere else
*) # Non-trivial, relative to SCRIPTDIR, may not exist yet
CI_BUILDDIR="${SCRIPTDIR}/${CI_BUILDDIR}"
;;
esac
# Just in case we get blanks from CI - consider them as not-set:
if [ -z "`echo "${MAKE-}" | tr -d ' '`" ] ; then
if [ "$1" = spellcheck -o "$1" = spellcheck-interactive ] \
&& (command -v gmake) >/dev/null 2>/dev/null \
; then
# GNU make processes quiet mode better, which helps with spellcheck use-case
MAKE=gmake
else
# Use system default, there should be one (or fail eventually if not)
MAKE=make
fi
export MAKE
fi
[ -n "$GGREP" ] || GGREP=grep
[ -n "$MAKE_FLAGS_QUIET" ] || MAKE_FLAGS_QUIET="VERBOSE=0 V=0 -s"
[ -n "$MAKE_FLAGS_VERBOSE" ] || MAKE_FLAGS_VERBOSE="VERBOSE=1 V=1 -s"
[ -n "$MAKE_FLAGS_CLEAN" ] || MAKE_FLAGS_CLEAN="${MAKE_FLAGS_QUIET}"
normalize_path() {
# STDIN->STDOUT: strip duplicate "/" and extra ":" if present,
# leave first copy of duplicates in (preferred) place
sed -e 's,:::*,:,g' -e 's,^:*,,' -e 's,:*$,,' -e 's,///*,/,g' \
| tr ':' '\n' \
| ( P=""
while IFS='' read D ; do
case "${D}" in
"") continue ;;
/) ;;
*/) D="`echo "${D}" | sed 's,/*$,,'`" ;;
esac
case "${P}" in
"${D}"|*":${D}"|"${D}:"*|*":${D}:"*) ;;
"") P="${D}" ;;
*) P="${P}:${D}" ;;
esac
done
echo "${P}"
)
}
propose_CI_CCACHE_SYMLINKDIR() {
# This is where many symlinks like "gcc -> ../bin/ccache" reside:
echo \
"/usr/lib/ccache" \
"/mingw64/lib/ccache/bin" \
"/mingw32/lib/ccache/bin" \
"/usr/lib64/ccache" \
"/usr/libexec/ccache" \
"/usr/lib/ccache/bin" \
"/usr/local/lib/ccache"
if [ -n "${HOMEBREW_PREFIX-}" ]; then
echo "${HOMEBREW_PREFIX}/opt/ccache/libexec"
fi
}
ensure_CI_CCACHE_SYMLINKDIR_envvar() {
# Populate CI_CCACHE_SYMLINKDIR envvar (if not yet populated e.g. by caller)
# with location of symlinks like "gcc -> ../bin/ccache" to use
# NOTE: a caller-provided value of "-" requests the script to NOT use
# a CI_CCACHE_SYMLINKDIR; however ccache may still be used via prefixing
# to compiler command, if the tool is found in the PATH, e.g. by calling
# optional_ensure_ccache(), unless you export CI_CCACHE_USE=no also.
if [ -z "${CI_CCACHE_SYMLINKDIR-}" ] ; then
for D in `propose_CI_CCACHE_SYMLINKDIR` ; do
if [ -d "$D" ] ; then
if ( ls -la "$D" | grep -e ' -> .*ccache' >/dev/null) \
|| ( test -n "`find "$D" -maxdepth 1 -type f -exec grep -li ccache '{}' \;`" ) \
; then
CI_CCACHE_SYMLINKDIR="$D" && break
else
echo "WARNING: Found potential CI_CCACHE_SYMLINKDIR='$D' but it did not host expected symlink patterns, skipped" >&2
fi
fi
done
if [ -n "${CI_CCACHE_SYMLINKDIR-}" ] ; then
echo "INFO: Detected CI_CCACHE_SYMLINKDIR='$CI_CCACHE_SYMLINKDIR'; specify another explicitly if desired" >&2
else
echo "WARNING: Did not find any CI_CCACHE_SYMLINKDIR; specify one explicitly if desired" >&2
fi
else
if [ x"${CI_CCACHE_SYMLINKDIR-}" = x- ] ; then
echo "INFO: Empty CI_CCACHE_SYMLINKDIR was explicitly requested" >&2
CI_CCACHE_SYMLINKDIR=""
fi
fi
}
optional_prepare_ccache() {
# Prepare CCACHE_* variables and directories, determine if we HAVE_CCACHE
# See also optional_ensure_ccache(), optional_prepare_compiler_family(),
# ensure_CI_CCACHE_SYMLINKDIR_envvar()
echo "PATH='$PATH' before possibly applying CCACHE into the mix"
( echo "$PATH" | grep ccache ) >/dev/null && echo "WARNING: ccache is already in PATH"
if [ -n "$CC" ]; then
echo "CC='$CC' before possibly applying CCACHE into the mix"
$CC --version $CFLAGS || \
$CC --version || true
fi
if [ -n "$CXX" ]; then
echo "CXX='$CXX' before possibly applying CCACHE into the mix"
$CXX --version $CXXFLAGS || \
$CXX --version || true
fi
if [ x"${CI_CCACHE_USE-}" = xno ]; then
HAVE_CCACHE=no
CI_CCACHE_SYMLINKDIR=""
echo "WARNING: Caller required to not use ccache even if available" >&2
else
if [ -n "${CI_CCACHE_SYMLINKDIR}" ]; then
# Tell ccache the PATH without itself in it, to avoid loops processing
PATH="`echo "$PATH" | sed -e 's,^'"${CI_CCACHE_SYMLINKDIR}"'/?:,,' -e 's,:'"${CI_CCACHE_SYMLINKDIR}"'/?:,,' -e 's,:'"${CI_CCACHE_SYMLINKDIR}"'/?$,,' -e 's,^'"${CI_CCACHE_SYMLINKDIR}"'/?$,,'`"
fi
CCACHE_PATH="$PATH"
CCACHE_DIR="${HOME}/.ccache"
export CCACHE_PATH CCACHE_DIR PATH
HAVE_CCACHE=no
if (command -v ccache || which ccache) \
&& ( [ -z "${CI_CCACHE_SYMLINKDIR}" ] || ls -la "${CI_CCACHE_SYMLINKDIR}" ) \
; then
HAVE_CCACHE=yes
fi
mkdir -p "${CCACHE_DIR}"/ || HAVE_CCACHE=no
fi
}
is_gnucc() {
if [ -n "$1" ] && LANG=C "$1" --version 2>&1 | grep 'Free Software Foundation' > /dev/null ; then true ; else false ; fi
}
is_clang() {
if [ -n "$1" ] && LANG=C "$1" --version 2>&1 | grep 'clang version' > /dev/null ; then true ; else false ; fi
}
filter_version() {
# Starting with number like "6.0.0" or "7.5.0-il-0" is fair game,
# but a "gcc-4.4.4-il-4" (starting with "gcc") is not
sed -e 's,^.* \([0-9][0-9]*\.[0-9][^ ),]*\).*$,\1,' -e 's, .*$,,' | grep -E '^[0-9]' | head -1
}
ver_gnucc() {
[ -n "$1" ] && LANG=C "$1" --version 2>&1 | grep -i gcc | filter_version
}
ver_clang() {
[ -n "$1" ] && LANG=C "$1" --version 2>&1 | grep -i 'clang' | filter_version
}
optional_prepare_compiler_family() {
# Populate CC, CXX, CPP envvars according to actual tools used/requested
# Remember them as COMPILER_FAMILY
# See also: optional_prepare_ccache(), ensure_CI_CCACHE_SYMLINKDIR_envvar(),
# optional_prepare_compiler_family()
COMPILER_FAMILY=""
if [ -n "$CC" -a -n "$CXX" ]; then
if is_gnucc "$CC" && is_gnucc "$CXX" ; then
COMPILER_FAMILY="GCC"
export CC CXX
elif is_clang "$CC" && is_clang "$CXX" ; then
COMPILER_FAMILY="CLANG"
export CC CXX
fi
else
# Generally we prefer GCC unless it is very old so we can't impact
# its warnings and complaints.
if is_gnucc "gcc" && is_gnucc "g++" ; then
# Autoconf would pick this by default
COMPILER_FAMILY="GCC"
[ -n "$CC" ] || CC=gcc
[ -n "$CXX" ] || CXX=g++
export CC CXX
elif is_gnucc "cc" && is_gnucc "c++" ; then
COMPILER_FAMILY="GCC"
[ -n "$CC" ] || CC=cc
[ -n "$CXX" ] || CXX=c++
export CC CXX
fi
if ( [ "$COMPILER_FAMILY" = "GCC" ] && \
case "`ver_gnucc "$CC"`" in
[123].*) true ;;
4.[0123][.,-]*) true ;;
4.[0123]) true ;;
*) false ;;
esac && \
case "`ver_gnucc "$CXX"`" in
[123].*) true ;;
4.[0123][.,-]*) true ;;
4.[0123]) true ;;
*) false ;;
esac
) ; then
echo "NOTE: default GCC here is very old, do we have a CLANG instead?.." >&2
COMPILER_FAMILY="GCC_OLD"
fi
if [ -z "$COMPILER_FAMILY" ] || [ "$COMPILER_FAMILY" = "GCC_OLD" ]; then
if is_clang "clang" && is_clang "clang++" ; then
# Autoconf would pick this by default
[ "$COMPILER_FAMILY" = "GCC_OLD" ] && CC="" && CXX=""
COMPILER_FAMILY="CLANG"
[ -n "$CC" ] || CC=clang
[ -n "$CXX" ] || CXX=clang++
export CC CXX
elif is_clang "cc" && is_clang "c++" ; then
[ "$COMPILER_FAMILY" = "GCC_OLD" ] && CC="" && CXX=""
COMPILER_FAMILY="CLANG"
[ -n "$CC" ] || CC=cc
[ -n "$CXX" ] || CXX=c++
export CC CXX
fi
fi
if [ "$COMPILER_FAMILY" = "GCC_OLD" ]; then
COMPILER_FAMILY="GCC"
fi
fi
if [ -n "$CPP" ] ; then
# Note: can be a multi-token name like "clang -E" or just not a full pathname
( [ -x "$CPP" ] || $CPP --help >/dev/null 2>/dev/null ) && export CPP
else
# Avoid "cpp" directly as it may be too "traditional"
case "$COMPILER_FAMILY" in
CLANG*|GCC*) CPP="$CC -E" && export CPP ;;
*) if is_gnucc "cpp" ; then
CPP=cpp && export CPP
fi ;;
esac
fi
}
optional_ensure_ccache() {
# Prepare PATH, CC, CXX envvars to use ccache (if enabled, applicable and available)
# See also optional_prepare_ccache()
if [ "$HAVE_CCACHE" = yes ] && [ "${COMPILER_FAMILY}" = GCC -o "${COMPILER_FAMILY}" = CLANG ]; then
if [ -n "${CI_CCACHE_SYMLINKDIR}" ]; then
echo "INFO: Using ccache via PATH preferring tool names in ${CI_CCACHE_SYMLINKDIR}" >&2
PATH="${CI_CCACHE_SYMLINKDIR}:$PATH"
export PATH
else
case "$CC" in
"") ;; # skip
*ccache*) ;; # already requested to use ccache
*) CC="ccache $CC" ;;
esac
case "$CXX" in
"") ;; # skip
*ccache*) ;; # already requested to use ccache
*) CXX="ccache $CXX" ;;
esac
# No-op for CPP currently
fi
if [ -n "$CC" ] && [ -n "${CI_CCACHE_SYMLINKDIR}" ]; then
if [ -x "${CI_CCACHE_SYMLINKDIR}/`basename "$CC"`" ]; then
case "$CC" in
*ccache*) ;;
*/*) DIR_CC="`dirname "$CC"`" && [ -n "$DIR_CC" ] && DIR_CC="`cd "$DIR_CC" && pwd `" && [ -n "$DIR_CC" ] && [ -d "$DIR_CC" ] || DIR_CC=""
[ -z "$CCACHE_PATH" ] && CCACHE_PATH="$DIR_CC" || \
if echo "$CCACHE_PATH" | grep -E '(^'"$DIR_CC"':.*|^'"$DIR_CC"'$|:'"$DIR_CC"':|:'"$DIR_CC"'$)' ; then
CCACHE_PATH="$DIR_CC:$CCACHE_PATH"
fi
;;
esac
CC="${CI_CCACHE_SYMLINKDIR}/`basename "$CC"`"
else
CC="ccache $CC"
fi
fi
if [ -n "$CXX" ] && [ -n "${CI_CCACHE_SYMLINKDIR}" ]; then
if [ -x "${CI_CCACHE_SYMLINKDIR}/`basename "$CXX"`" ]; then
case "$CXX" in
*ccache*) ;;
*/*) DIR_CXX="`dirname "$CXX"`" && [ -n "$DIR_CXX" ] && DIR_CXX="`cd "$DIR_CXX" && pwd `" && [ -n "$DIR_CXX" ] && [ -d "$DIR_CXX" ] || DIR_CXX=""
[ -z "$CCACHE_PATH" ] && CCACHE_PATH="$DIR_CXX" || \
if echo "$CCACHE_PATH" | grep -E '(^'"$DIR_CXX"':.*|^'"$DIR_CXX"'$|:'"$DIR_CXX"':|:'"$DIR_CXX"'$)' ; then
CCACHE_PATH="$DIR_CXX:$CCACHE_PATH"
fi
;;
esac
CXX="${CI_CCACHE_SYMLINKDIR}/`basename "$CXX"`"
else
CXX="ccache $CXX"
fi
fi
if [ -n "$CPP" ] && [ -n "${CI_CCACHE_SYMLINKDIR}" ] \
&& [ -x "${CI_CCACHE_SYMLINKDIR}/`basename "$CPP"`" ]; then
case "$CPP" in
*ccache*) ;;
*/*) DIR_CPP="`dirname "$CPP"`" && [ -n "$DIR_CPP" ] && DIR_CPP="`cd "$DIR_CPP" && pwd `" && [ -n "$DIR_CPP" ] && [ -d "$DIR_CPP" ] || DIR_CPP=""
[ -z "$CCACHE_PATH" ] && CCACHE_PATH="$DIR_CPP" || \
if echo "$CCACHE_PATH" | grep -E '(^'"$DIR_CPP"':.*|^'"$DIR_CPP"'$|:'"$DIR_CPP"':|:'"$DIR_CPP"'$)' ; then
CCACHE_PATH="$DIR_CPP:$CCACHE_PATH"
fi
;;
esac
CPP="${CI_CCACHE_SYMLINKDIR}/`basename "$CPP"`"
else
: # CPP="ccache $CPP"
fi
CCACHE_BASEDIR="${PWD}"
export CCACHE_BASEDIR
return 0
fi
# Not enabled or incompatible compiler
# Still, if ccache somehow gets used, let it
# know the correct BASEDIR of the built project
CCACHE_BASEDIR="${PWD}"
export CCACHE_BASEDIR
return 1
}
if [ -z "$TMPDIR" ]; then
echo "WARNING: TMPDIR not set, trying to guess"
if [ -d /tmp -a -w /tmp ] ; then
TMPDIR=/tmp
export TMPDIR
fi
fi
if [ -z "$TMPDIR" ]; then
echo "WARNING: TMPDIR still not set, some tools (notably clang) can fail"
fi
# For two-phase builds (quick parallel make first, sequential retry if failed)
# how verbose should that first phase be? Nothing, automake list of ops, CLIs?
# See build_to_only_catch_errors_target() for a consumer of this setting.
case "${CI_PARMAKE_VERBOSITY-}" in
silent|quiet|verbose|default) ;;
*) CI_PARMAKE_VERBOSITY=silent ;;
esac
# Set up the parallel make with reasonable limits, using several ways to
# gather and calculate this information. Note that "psrinfo" count is not
# an honest approach (there may be limits of current CPU set etc.) but is
# a better upper bound than nothing...
[ -n "$NCPUS" ] || { \
NCPUS="`/usr/bin/getconf _NPROCESSORS_ONLN`" || \
NCPUS="`/usr/bin/getconf NPROCESSORS_ONLN`" || \
NCPUS="`cat /proc/cpuinfo | grep -wc processor`" || \
{ [ -x /usr/sbin/psrinfo ] && NCPUS="`/usr/sbin/psrinfo | wc -l`"; } \
|| NCPUS=1; } 2>/dev/null
[ x"$NCPUS" != x -a "$NCPUS" -ge 1 ] || NCPUS=1
[ x"$NPARMAKES" = x ] && { NPARMAKES="`expr "$NCPUS" '*' 2`" || NPARMAKES=2; }
[ x"$NPARMAKES" != x -a "$NPARMAKES" -ge 1 ] || NPARMAKES=2
[ x"$MAXPARMAKES" != x ] && [ "$MAXPARMAKES" -ge 1 ] && \
[ "$NPARMAKES" -gt "$MAXPARMAKES" ] && \
echo "INFO: Detected or requested NPARMAKES=$NPARMAKES," \
"however a limit of MAXPARMAKES=$MAXPARMAKES was configured" && \
NPARMAKES="$MAXPARMAKES"
# GNU make allows to limit spawning of jobs by load average of the host,
# where LA is (roughly) the average amount over the last {timeframe} of
# queued processes that are ready to compute but must wait for CPU.
# The rough estimate for VM builders however seems that they always have
# some non-trivial LA, so we set the default limit per CPU relatively high.
[ x"$PARMAKE_LA_LIMIT" = x ] && PARMAKE_LA_LIMIT="`expr $NCPUS '*' 8`".0
# After all the tunable options above, this is the one which takes effect
# for actual builds with parallel phases. Specify a whitespace to neuter.
if [ -z "$PARMAKE_FLAGS" ]; then
PARMAKE_FLAGS="-j $NPARMAKES"
if LANG=C LC_ALL=C "$MAKE" --version 2>&1 | grep -E 'GNU Make|Free Software Foundation' > /dev/null ; then
PARMAKE_FLAGS="$PARMAKE_FLAGS -l $PARMAKE_LA_LIMIT"
echo "Parallel builds would spawn up to $NPARMAKES jobs (detected $NCPUS CPUs), or peak out at $PARMAKE_LA_LIMIT system load average" >&2
else
echo "Parallel builds would spawn up to $NPARMAKES jobs (detected $NCPUS CPUs)" >&2
fi
fi
# CI builds on Jenkins
[ -z "$NODE_LABELS" ] || \
for L in $NODE_LABELS ; do
case "$L" in
"NUT_BUILD_CAPS=cppunit=no")
[ -n "$CANBUILD_CPPUNIT_TESTS" ] || CANBUILD_CPPUNIT_TESTS=no ;;
"NUT_BUILD_CAPS=cppunit=no-gcc")
[ -n "$CANBUILD_CPPUNIT_TESTS" ] || CANBUILD_CPPUNIT_TESTS=no-gcc ;;
"NUT_BUILD_CAPS=cppunit=no-clang")
[ -n "$CANBUILD_CPPUNIT_TESTS" ] || CANBUILD_CPPUNIT_TESTS=no-clang ;;
"NUT_BUILD_CAPS=cppunit"|"NUT_BUILD_CAPS=cppunit=yes")
[ -n "$CANBUILD_CPPUNIT_TESTS" ] || CANBUILD_CPPUNIT_TESTS=yes ;;
# This should cover both the --with-nutconf tool setting
# and the cppunit tests for it (if active per above).
# By default we would nowadays guess (requires C++11).
"NUT_BUILD_CAPS=nutconf=no")
[ -n "$CANBUILD_NUTCONF" ] || CANBUILD_NUTCONF=no ;;
"NUT_BUILD_CAPS=nutconf=no-gcc")
[ -n "$CANBUILD_NUTCONF" ] || CANBUILD_NUTCONF=no-gcc ;;
"NUT_BUILD_CAPS=nutconf=no-clang")
[ -n "$CANBUILD_NUTCONF" ] || CANBUILD_NUTCONF=no-clang ;;
"NUT_BUILD_CAPS=nutconf"|"NUT_BUILD_CAPS=nutconf=yes")
[ -n "$CANBUILD_NUTCONF" ] || CANBUILD_NUTCONF=yes ;;
# Some (QEMU) builders have issues running valgrind as a tool
"NUT_BUILD_CAPS=valgrind=no")
[ -n "$CANBUILD_VALGRIND_TESTS" ] || CANBUILD_VALGRIND_TESTS=no ;;
"NUT_BUILD_CAPS=valgrind"|"NUT_BUILD_CAPS=valgrind=yes")
[ -n "$CANBUILD_VALGRIND_TESTS" ] || CANBUILD_VALGRIND_TESTS=yes ;;
"NUT_BUILD_CAPS=cppcheck=no")
[ -n "$CANBUILD_CPPCHECK_TESTS" ] || CANBUILD_CPPCHECK_TESTS=no ;;
"NUT_BUILD_CAPS=cppcheck"|"NUT_BUILD_CAPS=cppcheck=yes")
[ -n "$CANBUILD_CPPCHECK_TESTS" ] || CANBUILD_CPPCHECK_TESTS=yes ;;
# Some workers (presumably where several executors or separate
# Jenkins agents) are enabled randomly fail NIT tests, once in
# a hundred runs or so. This option allows isolated workers to
# proclaim they are safe places to "make check-NIT" (and we can
# see if that is true, over time).
"NUT_BUILD_CAPS=NIT=no")
[ -n "$CANBUILD_NIT_TESTS" ] || CANBUILD_NIT_TESTS=no ;;
"NUT_BUILD_CAPS=NIT"|"NUT_BUILD_CAPS=NIT=yes")
[ -n "$CANBUILD_NIT_TESTS" ] || CANBUILD_NIT_TESTS=yes ;;
"NUT_BUILD_CAPS=docs:man=no")
[ -n "$CANBUILD_DOCS_MAN" ] || CANBUILD_DOCS_MAN=no ;;
"NUT_BUILD_CAPS=docs:man"|"NUT_BUILD_CAPS=docs:man=yes")
[ -n "$CANBUILD_DOCS_MAN" ] || CANBUILD_DOCS_MAN=yes ;;
"NUT_BUILD_CAPS=docs:all=no")
[ -n "$CANBUILD_DOCS_ALL" ] || CANBUILD_DOCS_ALL=no ;;
"NUT_BUILD_CAPS=docs:all"|"NUT_BUILD_CAPS=docs:all=yes")
[ -n "$CANBUILD_DOCS_ALL" ] || CANBUILD_DOCS_ALL=yes ;;
"NUT_BUILD_CAPS=drivers:all=no")
[ -n "$CANBUILD_DRIVERS_ALL" ] || CANBUILD_DRIVERS_ALL=no ;;
"NUT_BUILD_CAPS=drivers:all"|"NUT_BUILD_CAPS=drivers:all=yes")
[ -n "$CANBUILD_DRIVERS_ALL" ] || CANBUILD_DRIVERS_ALL=yes ;;
"NUT_BUILD_CAPS=cgi=no")
[ -n "$CANBUILD_LIBGD_CGI" ] || CANBUILD_LIBGD_CGI=no ;;
"NUT_BUILD_CAPS=cgi"|"NUT_BUILD_CAPS=cgi=yes")
[ -n "$CANBUILD_LIBGD_CGI" ] || CANBUILD_LIBGD_CGI=yes ;;
# Currently for nut-scanner, might be more later - hence agnostic naming:
"NUT_BUILD_CAPS=libltdl=no")
[ -n "$CANBUILD_WITH_LIBLTDL" ] || CANBUILD_WITH_LIBLTDL=no ;;
"NUT_BUILD_CAPS=libltdl"|"NUT_BUILD_CAPS=libltdl=yes")
[ -n "$CANBUILD_WITH_LIBLTDL" ] || CANBUILD_WITH_LIBLTDL=yes ;;
esac
done
if [ -z "$CI_OS_NAME" ]; then
# Check for dynaMatrix node labels support and map into a simple
# classification styled after (compatible with) that in Travis CI
for CI_OS_HINT in \
"$OS_FAMILY-$OS_DISTRO" \
"`grep = /etc/os-release 2>/dev/null`" \
"`cat /etc/release 2>/dev/null`" \
"`uname -o 2>/dev/null`" \
"`uname -s -r -v 2>/dev/null`" \
"`uname -a`" \
"`uname`" \
; do
[ -z "$CI_OS_HINT" -o "$CI_OS_HINT" = "-" ] || break
done
case "`echo "$CI_OS_HINT" | tr 'A-Z' 'a-z'`" in
*freebsd*)
CI_OS_NAME="freebsd" ;;
*openbsd*)
CI_OS_NAME="openbsd" ;;
*netbsd*)
CI_OS_NAME="netbsd" ;;
*debian*|*ubuntu*)
CI_OS_NAME="debian" ;;
*centos*|*fedora*|*redhat*|*rhel*)
CI_OS_NAME="centos" ;;
*linux*)
CI_OS_NAME="linux" ;;
*msys2*)
CI_OS_NAME="windows-msys2" ;;
*mingw*64*)
CI_OS_NAME="windows-mingw64" ;;
*mingw*32*)
CI_OS_NAME="windows-mingw32" ;;
*windows*)
CI_OS_NAME="windows" ;;
*[Mm]ac*|*arwin*|*[Oo][Ss][Xx]*)
CI_OS_NAME="osx" ;;
*openindiana*)
CI_OS_NAME="openindiana" ;;
*omnios*)
CI_OS_NAME="omnios" ;;
*bsd*)
CI_OS_NAME="bsd" ;;
*illumos*)
CI_OS_NAME="illumos" ;;
*solaris*)
CI_OS_NAME="solaris" ;;
*sunos*)
CI_OS_NAME="sunos" ;;
"-") ;;
*) echo "WARNING: Could not recognize CI_OS_NAME from CI_OS_HINT='$CI_OS_HINT', update './ci_build.sh' if needed" >&2
if [ "$OS_FAMILY-$OS_DISTRO" != "-" ]; then
echo "WARNING: I was told that OS_FAMILY='$OS_FAMILY' and OS_DISTRO='$OS_DISTRO'" >&2
fi
;;
esac
[ -z "$CI_OS_NAME" ] || echo "INFO: Detected CI_OS_NAME='$CI_OS_NAME'" >&2
fi
# CI builds on Travis
[ -n "$CI_OS_NAME" ] || CI_OS_NAME="$TRAVIS_OS_NAME"
case "${CI_OS_NAME}" in
windows-msys2)
# No-op: we seem to pass builds on MSYS2 anyway even without
# these flags, and a populated CFLAGS happens to be toxic to
# ccache builds in that distribution (as of 2022-2025 at least)
;;
windows*)
# At the moment WIN32 builds are quite particular in their
# desires, for headers to declare what is needed, and yet
# there is currently not much real variation in supportable
# build environment (mingw variants). Lest we hardcode
# stuff in configure script, define some here:
case "$CFLAGS" in
*-D_POSIX=*) ;;
*) CFLAGS="$CFLAGS -D_POSIX=1" ;;
esac
case "$CFLAGS" in
*-D_POSIX_C_SOURCE=*) ;;
*) CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=200112L" ;;
esac
case "$CFLAGS" in
*-D_WIN32_WINNT=*) ;;
*) CFLAGS="$CFLAGS -D_WIN32_WINNT=0xffff" ;;
esac
case "$CXXFLAGS" in
*-D_POSIX=*) ;;
*) CXXFLAGS="$CXXFLAGS -D_POSIX=1" ;;
esac
case "$CXXFLAGS" in
*-D_POSIX_C_SOURCE=*) ;;
*) CXXFLAGS="$CXXFLAGS -D_POSIX_C_SOURCE=200112L" ;;
esac
case "$CXXFLAGS" in
*-D_WIN32_WINNT=*) ;;
*) CXXFLAGS="$CXXFLAGS -D_WIN32_WINNT=0xffff" ;;
esac
;;
esac
# Analyze some environmental choices
if [ -z "${CANBUILD_LIBGD_CGI-}" ]; then
# No prereq dll and headers on win so far
[[ "$CI_OS_NAME" = "windows" ]] && CANBUILD_LIBGD_CGI=no
# NUT CI farm with Jenkins can build it; Travis could not
[[ "$CI_OS_NAME" = "freebsd" ]] && CANBUILD_LIBGD_CGI=yes \
|| { [[ "$TRAVIS_OS_NAME" = "freebsd" ]] && CANBUILD_LIBGD_CGI=no ; }
# See also below for some compiler-dependent decisions
fi
detect_platform_CANBUILD_LIBGD_CGI() {
# Call after optional_prepare_compiler_family()!
if [ -z "${CANBUILD_LIBGD_CGI-}" ]; then
if [[ "$CI_OS_NAME" = "openindiana" ]] ; then
# For some reason, here gcc-4.x (4.4.4, 4.9) have a problem with
# configure-time checks of libgd; newer compilers fare okay.
# Feel free to revise this if the distro packages are fixed
# (or the way configure script and further build uses them).
# UPDATE: Per https://github.com/networkupstools/nut/pull/1089
# This is a systems issue (in current OpenIndiana 2021.04 built
# with a newer GCC version, the older GCC is not ABI compatible
# with the libgd shared object file). Maybe this warrants later
# caring about not just the CI_OS_NAME but also CI_OS_RELEASE...
if [[ "$COMPILER_FAMILY" = "GCC" ]]; then
case "`LANG=C $CC --version | head -1`" in
*[\ -][01234].*)
echo "WARNING: Seems we are running with gcc-4.x or older on $CI_OS_NAME, which last had known issues with libgd; disabling CGI for this build"
CANBUILD_LIBGD_CGI=no
;;
*)
case "${ARCH}${BITS}${ARCH_BITS}" in
*64*|*sparcv9*) ;;
*)
# GCC-7 (maybe other older compilers) could default
# to 32-bit builds, and the 32-bit libfontconfig.so
# and libfreetype.so are absent for some years now
# (while libgd.so still claims to exist).
echo "WARNING: Seems we are running with gcc on $CI_OS_NAME, which last had known issues with libgd on non-64-bit builds; making CGI optional for this build"
CANBUILD_LIBGD_CGI=auto
;;
esac
;;
esac
else
case "${ARCH}${BITS}${ARCH_BITS}" in
*64*|*sparcv9*) ;;
*)
echo "WARNING: Seems we are running with $COMPILER_FAMILY on $CI_OS_NAME, which last had known issues with libgd on non-64-bit builds; making CGI optional for this build"
CANBUILD_LIBGD_CGI=auto
;;
esac
fi
fi
fi
}
if [ -z "${PKG_CONFIG-}" ]; then
# Default to using one from PATH, if any - mostly for config tuning done
# below in this script
# DO NOT "export" it here so configure script can find one for the build
PKG_CONFIG="pkg-config"
fi
detect_platform_PKG_CONFIG_PATH_and_FLAGS() {
# Some systems want a custom PKG_CONFIG_PATH which would be prepended
# to whatever the callers might have provided as their PKG_CONFIG_PATH.
# Optionally provided by some CI build scenarios: DEFAULT_PKG_CONFIG_PATH
# On some platforms also barges in to CONFIG_OPTS[] (should exist!),
# PATH, CFLAGS, CXXFLAGS, LDFLAGS, XML_CATALOG_FILES et al.
#
# Caller can override by OVERRIDE_PKG_CONFIG_PATH (ignore other values
# then, including a PKG_CONFIG_PATH), where a "-" value leaves it empty.
SYS_PKG_CONFIG_PATH="" # Let the OS guess... usually
BUILTIN_PKG_CONFIG_PATH="`pkg-config --variable pc_path pkg-config`" || BUILTIN_PKG_CONFIG_PATH=""
case "`echo "$CI_OS_NAME" | tr 'A-Z' 'a-z'`" in
*openindiana*|*omnios*|*solaris*|*illumos*|*sunos*)
_ARCHES="${ARCH-}"
_BITS="${BITS-}"
_ISA1=""
[ -n "${_BITS}" ] || \
case "${CC}${CXX}${CFLAGS}${CXXFLAGS}${LDFLAGS}" in
*-m64*) _BITS=64 ;;
*-m32*) _BITS=32 ;;
*) case "${ARCH-}${ARCH_BITS-}" in
*64*|*sparcv9*) _BITS=64 ;;
*32*|*86*|*sparcv7*|*sparc) _BITS=32 ;;
*) _ISA1="`isainfo | awk '{print $1}'`"
case "${_ISA1}" in
*64*|*sparcv9*) _BITS=64 ;;
*32*|*86*|*sparcv7*|*sparc) _BITS=32 ;;
esac
;;
esac
;;
esac
# Consider also `gcc -v`/`clang -v`: their "Target:" line exposes the
# triplet compiler was built to run on, e.g. "x86_64-pc-solaris2.11"
case "${_ARCHES}${ARCH_BITS-}" in
*amd64*|*x86_64*) _ARCHES="amd64" ;;
*sparcv9*) _ARCHES="sparcv9" ;;
*86*) _ARCHES="i86pc i386" ;;
*sparcv7*|*sparc) _ARCHES="sparcv7 sparc" ;;
*) [ -n "${_ISA1}" ] || _ISA1="`isainfo | awk '{print $1}'`"
case "${_ISA1}" in
*amd64*|*x86_64*) _ARCHES="amd64" ;;
*sparcv9*) _ARCHES="sparcv9" ;;
*86*) _ARCHES="i86pc i386" ;;
*sparcv7*|*sparc) _ARCHES="sparcv7 sparc" ;;
esac
;;
esac
# Pile it on, strip extra ":" and dedup entries later
for D in \
"/opt/ooce/lib" \
"/usr/lib" \
; do
if [ -d "$D" ] ; then
_ADDSHORT=false
if [ -n "${_BITS}" ] ; then
if [ -d "${D}/${_BITS}/pkgconfig" ] ; then
SYS_PKG_CONFIG_PATH="${SYS_PKG_CONFIG_PATH}:${D}/${_BITS}/pkgconfig"
# Here and below: hot-fix for https://github.com/networkupstools/nut/issues/2782
# situation on OmniOS with Extra repository,
# assumed only useful if we use it via pkgconfig
case "${D}" in
/usr/lib) ;;
*) LDFLAGS="${LDFLAGS} -R${D}/${_BITS}" ;;
esac
else
if [ -d "${D}/pkgconfig" ] ; then
case "`LANG=C LC_ALL=C file $(ls -1 $D/*.so | head -1)`" in
*"ELF ${_BITS}-bit"*) _ADDSHORT=true ;;
esac
fi
fi
fi
for _ARCH in $_ARCHES ; do
if [ -d "${D}/${_ARCH}/pkgconfig" ] ; then
SYS_PKG_CONFIG_PATH="${SYS_PKG_CONFIG_PATH}:${D}/${_ARCH}/pkgconfig"
case "${D}" in
/usr/lib) ;;
*) LDFLAGS="${LDFLAGS} -R${D}/${_ARCH}" ;;
esac
else
if [ -d "${D}/pkgconfig" ] ; then
case "`LANG=C LC_ALL=C file $(ls -1 $D/*.so | head -1)`" in
*"ELF 32-bit"*" SPARC "*)
case "${_ARCH}" in
sparc|sparcv7) _ADDSHORT=true ;;
esac
;;
*"ELF 64-bit"*" SPARCV9 "*)
case "${_ARCH}" in
sparcv9) _ADDSHORT=true ;;
esac
;;
*"ELF 32-bit"*" 80386 "*)
case "${_ARCH}" in
i386|i86pc) _ADDSHORT=true ;;
esac
;;
*"ELF 64-bit"*" AMD64 "*)
case "${_ARCH}" in
amd64) _ADDSHORT=true ;;
esac
;;
esac
fi
fi
done
if [ "${_ADDSHORT}" = true ] ; then
SYS_PKG_CONFIG_PATH="${SYS_PKG_CONFIG_PATH}:${D}/pkgconfig"
case "${D}" in
/usr/lib) ;;
*) LDFLAGS="${LDFLAGS} -R${D}" ;;
esac
fi
fi
done
# Last option if others are lacking
if [ -d /usr/lib/pkgconfig ] ; then
SYS_PKG_CONFIG_PATH="${SYS_PKG_CONFIG_PATH}:/usr/lib/pkgconfig"
fi
unset _ADDSHORT _BITS _ARCH _ARCHES D
# OmniOS CE "Extra" repository
case "$PATH" in
/opt/ooce/bin|*:/opt/ooce/bin|/opt/ooce/bin:*|*:/opt/ooce/bin:*) ;;
*) if [ -d "/opt/ooce/bin" ] ; then PATH="/opt/ooce/bin:${PATH}" ; fi ;;
esac
;;
*darwin*|*macos*|*osx*)
# Architecture-dependent base dir, e.g.
# * /usr/local on macos x86
# * /opt/homebrew on macos Apple Silicon
if [ -n "${HOMEBREW_PREFIX-}" -a -d "${HOMEBREW_PREFIX-}" ]; then
echo "Homebrew: export general pkg-config location and C/C++/LD flags for the platform"
SYS_PKG_CONFIG_PATH="${HOMEBREW_PREFIX}/lib/pkgconfig"
CFLAGS="${CFLAGS-} -Wno-poison-system-directories -Wno-deprecated-declarations -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include"
#CPPFLAGS="${CPPFLAGS-} -Wno-poison-system-directories -Wno-deprecated-declarations -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include"
CXXFLAGS="${CXXFLAGS-} -Wno-poison-system-directories -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include"
LDFLAGS="${LDFLAGS-} -L${HOMEBREW_PREFIX}/lib"
# Net-SNMP "clashes" with system-provided tools (but no header/lib)
# so explicit args are needed
checkFSobj="${HOMEBREW_PREFIX}/opt/net-snmp/lib/pkgconfig"
if [ -d "$checkFSobj" -a ! -e "${HOMEBREW_PREFIX}/lib/pkgconfig/netsnmp.pc" ] ; then
echo "Homebrew: export pkg-config location for Net-SNMP"
SYS_PKG_CONFIG_PATH="$SYS_PKG_CONFIG_PATH:$checkFSobj"
#echo "Homebrew: export flags for Net-SNMP"
#CONFIG_OPTS+=("--with-snmp-includes=-isystem ${HOMEBREW_PREFIX}/opt/net-snmp/include -I${HOMEBREW_PREFIX}/opt/net-snmp/include")
#CONFIG_OPTS+=("--with-snmp-libs=-L${HOMEBREW_PREFIX}/opt/net-snmp/lib")
fi
if [ -d "${HOMEBREW_PREFIX}/opt/net-snmp/include" -a -d "${HOMEBREW_PREFIX}/include/openssl" ]; then
# TODO? Check netsnmp.pc for Libs.private with
# -L/opt/homebrew/opt/[email protected]/lib
# or
# -L/usr/local/opt/openssl@3/lib
# among other options to derive the exact version
# it wants, and serve that include path here
echo "Homebrew: export configure options for Net-SNMP with default OpenSSL headers (too intimate on Homebrew)"
CONFIG_OPTS+=("--with-snmp-includes=-isystem ${HOMEBREW_PREFIX}/opt/net-snmp/include -I${HOMEBREW_PREFIX}/opt/net-snmp/include -isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include")
CONFIG_OPTS+=("--with-snmp-libs=-L${HOMEBREW_PREFIX}/opt/net-snmp/lib -lnetsnmp")
fi
# A bit hackish to check this outside `configure`, but...
if [ -s "${HOMEBREW_PREFIX-}/include/ltdl.h" ] ; then
echo "Homebrew: export flags for LibLTDL"
# The m4 script clear default CFLAGS/LIBS so benefit from new ones
CONFIG_OPTS+=("--with-libltdl-includes=-isystem ${HOMEBREW_PREFIX}/include -I${HOMEBREW_PREFIX}/include")
CONFIG_OPTS+=("--with-libltdl-libs=-L${HOMEBREW_PREFIX}/lib -lltdl")
fi
if [ -z "${XML_CATALOG_FILES-}" ] ; then
checkFSobj="${HOMEBREW_PREFIX}/etc/xml/catalog"
if [ -e "$checkFSobj" ] ; then
echo "Homebrew: export XML_CATALOG_FILES='$checkFSobj' for asciidoc et al"
XML_CATALOG_FILES="$checkFSobj"
export XML_CATALOG_FILES
fi
fi
else
echo "WARNING: It seems you are building on MacOS, but HOMEBREW_PREFIX is not set or valid."
echo 'If you do use this build system, try running eval "$(brew shellenv)"'
echo "in your terminal or shell profile, it can help with auto-detection of some features!"
fi
;;
esac
if [ -n "${OVERRIDE_PKG_CONFIG_PATH-}" ] ; then
if [ x"${OVERRIDE_PKG_CONFIG_PATH}" = x- ] ; then
PKG_CONFIG_PATH=""
else
PKG_CONFIG_PATH="${OVERRIDE_PKG_CONFIG_PATH}"
fi
return
fi
# Do not check for existence of non-trivial values, we normalize the mess (if any)
PKG_CONFIG_PATH="`echo "${DEFAULT_PKG_CONFIG_PATH-}:${SYS_PKG_CONFIG_PATH-}:${PKG_CONFIG_PATH-}:${BUILTIN_PKG_CONFIG_PATH-}" | normalize_path`"
}
# Would hold full path to the CONFIGURE_SCRIPT="${SCRIPTDIR}/${CONFIGURE_SCRIPT_FILENAME}"
CONFIGURE_SCRIPT=""