forked from newrelic/newrelic-php-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildit
executable file
·3150 lines (2697 loc) · 107 KB
/
buildit
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
# {[ # DO NOT REMOVE (vim file spanning brace matching)
help_info() {
cat <<EOF
Usage:
./buildit [flags]
Build the nrcamp (compiler) stack
Flags are:
--help Print out this help message and exit.
--prefix=path default=/opt/nr/camp where to install software
--full Build expect, tcl, dejagnu and llvmtest.
--brief Just build step1 of the gcc bootstrap.
--bloat Do not strip the binaries, including executables and libraries.
--debug Compile -g2 (default is to compile -g1)
--campver=version default 1.X camp version number, generally tied to the Hudson build number.
--resume=N Resume the build at the step named N, as for example when step N failed on the last build.
--stop=N Stop build before trying the step named N.
EOF
}
systype="unknown"
systype_qualifier=""
unames=`uname -s`
unamem=`uname -m`
case "${unames}:${unamem}" in
[Dd][Aa][Rr][Ww][Ii][Nn]*)
systype="darwin"
kern_osrelease=$(uname -a | sed -e 's/.*Darwin Kernel Version \([0-9.]*\):.*/\1/')
#
# See this page
# http://stackoverflow.com/questions/11072804/how-do-i-determine-the-os-version-at-runtime-in-os-x-or-ios-without-using-gesta
# For a mapping between marketing names, OSX release names, and kernel release names
#
case "${kern_osrelease}" in
15.*.*) systype_qualifier="El Capitan" ;; # 10.11
14.*.*) systype_qualifier="Yosemite" ;; # 10.10
13.*.*) systype_qualifier="Mavericks" ;; # 10.9
12.*.*) systype_qualifier="Mountain Lion" ;; # 10.8
11.*.*) systype_qualifier="Lion" ;; # 10.7
10.*.*) systype_qualifier="Snow Leopard" ;; # 10.6
9.*.*) systype_qualifier="Leopard" ;; # 10.5
esac
;;
[Ss][Oo][Ll][Aa][Rr][Ii][Ss]* | [Ss][Uu][Nn][Oo][Ss]*)
systype="solaris"
#
# follow what's done in C function nr_system_os_is_smartos
#
if [ -e /etc/release ] && grep -i smartos < /etc/release > /dev/null ; then
systype_qualifier="smartos"
fi
;;
[Ll][Ii][Nn][Uu][Xx]:x86_64 | [Ll][Ii][Nn][Uu][Xx]:amd*)
systype="linux64"
;;
[Ll][Ii][Nn][Uu][Xx]:i[345678]86)
systype="linux32"
;;
[Ff][Rr][Ee][Ee][Bb][Ss][Dd]:x86_64 |[Ff][Rr][Ee][Ee][Bb][Ss][Dd]:amd*)
systype="freebsd64"
;;
[Ff][Rr][Ee][Ee][Bb][Ss][Dd]:i[345678]86)
systype="freebsd32"
;;
*) error "machine type '${unames}:${unamem}' not supported by this script"
esac
#
# nrcamp builds on Yosemite on 07Jun2015 iff we use brew's gcc-5
#
if [ "${systype_qualifier}" = "Yosemite" -o "${systype_qualifier}" = "El Capitan" ] ; then
if [ ! -x /usr/local/bin/gcc-5 ] ; then
brew install gcc # That's right, the brew keg is just "gcc"
fi
: ${CC:=gcc-5}
: ${CXX:=g++-5}
else
: ${CC:=gcc}
: ${CXX:=g++}
fi
: ${CFLAGS:=-O0}
: ${CXXFLAGS:=-O0}
# : ${PARALLEL:=8}
#
# Figure out the available hardware parallelism
# See http://stackoverflow.com/questions/6481005/obtain-the-number-of-cpus-cores-in-linux
# for a discussion about both linux and macosx
#
if [ -x /usr/bin/nproc ] ; then
: ${PARALLEL:=$(/usr/bin/nproc)} # linux
elif [ -e /proc/cpuinfo ] ; then
: ${PARALLEL:=$(cat /proc/cpuinfo | grep -c vendor_id)}
elif [ -e /usr/sbin/psrinfo ] ; then
: ${PARALLEL:=$(psrinfo -p)} # solaris and smartos
elif [ "${systype}" = "darwin" ] ; then
: ${PARALLEL:=$(sysctl -n hw.logicalcpu_max)}
elif [ "${systype}" = "freebsd64" ]; then
: ${PARALLEL:=$(sysctl -n hw.ncpu)}
else
echo "can not figure out hardware parallelism. Using 3"
# Watch out, since compiling llvm is a real pig on memory consumption
: ${PARALLEL:=3}
fi
echo PARALLEL=${PARALLEL}
topstart=`date -u +%s`
CONFIG_SHELL="${BASH}"
SHELL="${BASH}"
export CONFIG_SHELL SHELL
error() {
echo ""
echo "ERROR: $@"
exit 1
}
campver="1.X"
campdate=`date +%Y%m%d`
mode=quick
pfx=/opt/nr/camp
step_resume=
step_stop=
step_number=0
step_name="?"
brief=no
do_strip=yes
do_debug=no
do_clean=yes
while [ $# -gt 0 ]; do
case "$1" in
--help)
help_info
exit 1
;;
--prefix=*)
pfx=${1#*=}
;;
--full)
mode=full
;;
--brief)
brief=yes
;;
--resume=*)
step_resume=${1#*=}
;;
--stop=*)
step_stop=${1#*=}
;;
--campver=*)
campver=${1#*=}
;;
--bloat)
do_strip=no
;;
--no-clean)
do_clean=no
;;
--debug)
do_debug=yes
;;
*) error "unknown argument '$1'"
;;
esac
shift
done
echo "Building NRCAMP version ${campver} with mode=${mode} do_debug=${do_debug} do_clean=${do_clean} do_strip=${do_strip} prefix=${pfx}"
verfile=versions
if [ -e versions.$systype ] ; then
verfile=versions.$systype
fi
[ -d patches -a -f ${verfile} -a -f versions.full ] || error "invoked from incorrect directory"
topdir="${PWD}"
[ -d sources ] || error "getstuff not run"
#
# Read in and parse the versions file(s). If we are being run in full mode
# we have a few extra packages to deal with; those are enumerated in versions.full
#
if [ "${mode}" = "quick" ]; then
verfiles="${topdir}/${verfile}"
else
verfiles="${topdir}/${verfile} ${topdir}/versions.full"
fi
if [ "$do_strip" == "yes" ] ; then
gcc_strip=-s
else
gcc_strip=
fi
if [ "$do_debug" == "yes" ] ; then
gcc_gflag="-g2" # the default level
else
gcc_gflag="-g1" # enough for minimal backtracing
fi
pkglist=`sed -e '/^#/d' -e 's/=".*//' $verfiles`
for vf in $verfiles; do
. $vf
done
for pkg in ${pkglist}; do
pi=`eval echo "\\$${pkg}"`
ver="${pi%^*}"
url="${pi#*^}"
file="${url##*/}"
subdir=${file%.tar.*}
subdir=${subdir%-src}
#
# Have to special case these due to a bug in the naming of the tar file
# relative to the naming of the top level directory unpacked from the tar file.
#
if [ "${subdir}" = "texinfo-4.13a" ] ; then
subdir="texinfo-4.13"
fi
if [ "${subdir}" = "flex-2.5.4a" ] ; then
subdir="flex-2.5.4"
fi
if [ "${subdir}" = "clang-3.4.src" ] ; then
subdir="clang-3.4"
fi
if [ "${subdir}" = "llvm-3.4.src" ] ; then
subdir="llvm-3.4"
fi
eval ${pkg}_ver="$ver"
eval ${pkg}_file="$file"
eval ${pkg}_dir="$subdir"
if [ ! -f sources/$file ]; then
error "getstuff not run to completion"
fi
done
bld="${topdir}/BUILD"
bld="/opt/nr/camp.BUILD"
if [ ! -d "${bld}" ] ; then
mkdir -p ${bld}
fi
iroot="${bld}/initial"
srcroot="${bld}/src"
logdir="${bld}/logs"
xpath="$PATH"
dpath="$PATH"
xifs="$IFS"
mypatch="${iroot}/bin/nr-patch"
mymake=make
mymjf=
libsfx=
libsfx32=
localbld=
tar=tar
do_32_bit=no
initial="yes"
socklibs=
rtlibs=
#
# Add a directory to the front of PATH if its not already there.
#
pathmunge() {
local p="$1"
case "$PATH" in
${p}:* | *:${p} | *:${p}:*) ;;
*) PATH="${p}:${PATH}"
export PATH
;;
esac
}
#
# Determine the system we are running on. The rest of the script uses the
# values defined here. We currently support:
# linux32 - 32-bit Linux (CentOS 5.4)
# linux64 - 64-bit Linux (CentOS 5.4)
# darwin - Apple MacOSX
# solaris - Oracle Solaris 11.1
# freebsd32 - 32-bit FreeBSD (Newest, currently 10.1 -- UNSUPPORTED on 32 bit)
# freebsd64 - 64-bit FreeBSD (Newest, currently 10.1)
#
# On all of the 64-bit targets that support it, the tools will be constructed
# to support 32-bit compilation as well. For all platforms except for Solaris
# and Darwin this is just a convenience. On Solaris, which we only support
# running this script on a 64-bit system, we *must* support both -m64 and -m32
# to switch between the two compilation models. All of the tools themselves
# will be compiled as 64-bit binaries, however. On Darwin we need to multilib
# in order to support producing "fat" or "universal" binaries.
#
case "${unames}:${unamem}" in
[Dd][Aa][Rr][Ww][Ii][Nn]*)
systype="darwin"
cfgbuild="x86_64-apple-darwin12"
cfgbuild32="i386-apple-darwin12"
#
# Mike LaSpina writes (31May2014):
#
# We have two choices, build NRLAMP with
# MACOSX_DEPLOYMENT_TARGET=10.5 and _DARWIN_USE_64_BIT_INODE=1, or
# raise the deployment target to 10.6. The latter option is safer
# because we don't know whether Apple compiled PHP on OSX 10.5 with
# 64-bit inode support. We know for certain this is the case for
# 10.9 and 10.8. I strongly suspect this is also the case for 10.7
# and 10.6. I also presume this is the case for MAMP.
#
# Whether 64-bit inode support is enabled or not depends on
# three preprocessor symbols (_DARWIN_FEATURE_ONLY_64_BIT_INODE,
# _DARWIN_USE_64_BIT_INODE, and _DARWIN_NO_64_BIT_INODE), and the
# deployment target. The stat(2) man page has a nice table that
# documents the effects of various combinations of these symbols
# and the deployment target. I've validated the accuracy of the
# documentation on my local system. For the curious it's worth a
# read.
#
export MACOSX_DEPLOYMENT_TARGET=10.6
localbld=-mmacosx-version-min=${MACOSX_DEPLOYMENT_TARGET}
libsfx32="/i386"
#
# valgrind < 3.10.0 isn't supported well on osx darwin mavericks 10.9
# Although valgrind 3.10 reports to do "better".
#
darwin_version=$(uname -r | sed -e 's/\..*//')
if (( darwin_version >= 13 )) ; then
do_valgrind=no
do_valgrind=yes # Try out valgrind 3.10.0
else
do_valgrind=yes
fi
do_32_bit=yes
do_32_bit=no # As of Spring, 2014, we no longer support 32-bit darwin
;;
[Ss][Oo][Ll][Aa][Rr][Ii][Ss]* | [Ss][Uu][Nn][Oo][Ss]*)
systype="solaris"
cfgbuild="x86_64-pc-solaris2.11"
cfgbuild32="i386-pc-solaris2.11"
libsfx="/amd64"
localbld="-m64"
tar=gtar
pathmunge /opt/local/bin
pathmunge /usr/gnu/bin
pathmunge /usr/perl5/bin
dpath="${PATH}"
do_valgrind=no
do_32_bit=yes
socklibs="-lsocket -lnsl"
;;
[Ll][Ii][Nn][Uu][Xx]:x86_64 | [Ll][Ii][Nn][Uu][Xx]:amd*)
systype="linux64"
cfgbuild="x86_64-pc-linux"
cfgbuild32="i686-pc-linux"
localbld="-m64"
libsfx="64"
[ -d /lib/i386-linux-gnu ] && {
libsfx="/i386-linux-gnu"
}
[ -d /lib/x86_64-linux-gnu ] && {
libsfx="/x86_64-linux-gnu"
libsfx32="/i386-linux-gnu"
}
do_valgrind=yes
rtlibs="-lrt"
;;
[Ll][Ii][Nn][Uu][Xx]:i[345678]86)
systype="linux32"
cfgbuild="i686-pc-linux"
do_valgrind=yes
rtlibs="-lrt"
[ -d /lib/i386-linux-gnu ] && {
libsfx="/i386-linux-gnu"
}
;;
[Ff][Rr][Ee][Ee][Bb][Ss][Dd]:x86_64 |[Ff][Rr][Ee][Ee][Bb][Ss][Dd]:amd*)
systype="freebsd64"
cfgbuild="x86_64-pc-freebsd10"
localbld="-m64"
mymake=gmake
do_valgrind=no
;;
[Ff][Rr][Ee][Ee][Bb][Ss][Dd]:i[345678]86)
systype="freebsd32"
cfgbuild="i686-pc-freebsd10"
mymake=gmake
do_valgrind=no
;;
*) error "machine type '${unames}:${unamem}' not supported by this script"
esac
#
# Add a mechanism for cleaning up on exit, as well as for reporting where we
# were in the script in case we want to resume from a failed build.
#
declare -a cleanup_items
cleanup_on_exit() {
topend=`date -u +%s`
for i in "${cleanup_items[@]}"; do
eval $i
done
[ -n "${step_number}" ] && {
echo ""
echo "Exiting script. If this was an abnormal termination and you wish to"
echo "make changes and resume the script, you can resume at the current"
echo "stage using ./buildit --resume=${step_name}"
}
echo ""
let tdiff="$topend - $topstart"
echo "Script took ${tdiff} second to run."
echo ""
if [ -f ${bld}/nrcamp-${systype}-${campver}.tar.bz2 ]; then
pushd "${bld}" > /dev/null 2>&1 # {
ls -l nrcamp-*.tar.bz2
popd > /dev/null 2>&1 # }
fi
PATH="${xpath}"
IFS="${xifs}"
}
cleanup() {
local c=${#cleanup_items[*]}
cleanup_items[$c]="$*"
}
trap cleanup_on_exit 0
echo_progress() {
local msg=$1
echo "$(date): $msg"
}
echo_done_step() {
echo "--------------------------"
}
#
# Execute a given function if we have no resume or the current resume count
# has reached the correct step number.
#
resume() {
local stepstart
local stepend
local duration
step_name=$1 # a global
shift
# echo "step_name=$1"
# echo "others=$@"
let step_number="${step_number} + 1"
# [ "${step_resume}" = "${step_number}" ] && step_resume=
[ "${step_resume}" = "${step_name}" ] && step_resume=
[ -z "${step_resume}" ] && {
echo_progress "Step ${step_name} (step number ${step_number}) "
stepstart=`date -u +%s`
"$@"
stepend=`date -u +%s`
let duration="${stepend} - ${stepstart}"
echo_progress "Step ${step_name} (step number ${step_number}) done (elapsed time ${duration})"
echo_done_step
}
[ -n "${step_stop}" ] && {
[ "${step_name}" = "${step_stop}" ] && exit 0
}
}
#
# We now have all of the packages we need to compile, and various variables
# set up for each package. What follows is a function for doing each package.
# These will be called in the correct order by the control function at the
# end of this script file.
#
#
# We will need a directory into which we install the initial versions of things
# like binutils, and possibly others. These are compiled without optimizations
# using the existing system compiler.
#
initial_setup() {
echo_progress "setup: "
[ -d "$bld" ] && {
[ ! -d "$bld.save" ] && {
mv -f "$bld" "$bld.save" || error "could not preserve existing BUILD directory"
}
}
rm -fr "$bld" || error "could not clean old BUILD directory"
mkdir "$bld" || error "could not create top level BUILD directory"
mkdir "$bld/logs" || error "could not create top level logs directory"
mkdir "$bld/logs2" || error "could not create top level logs2 directory"
mkdir "$bld/src" || error "could not create top level src directory"
mkdir "$bld/initial" || error "could not create initial root directory"
mkdir "$bld/initial/bin" || error "could not create initial bin directory"
mkdir "$bld/initial/lib" || error "could not create initial lib directory"
mkdir "$bld/initial/lib/pic" || error "could not create initial lib directory"
[ -n "${libsfx}" ] && {
mkdir "$bld/initial/lib${libsfx}" || error "could not create initial lib${libsfx} directory"
mkdir "$bld/initial/lib${libsfx}/pic" || error "could not create initial lib${libsfx}/pic directory"
}
}
#
# Extract all of the sources.
#
extract_sources() {
echo_progress "extract: "
pushd "${srcroot}" > /dev/null 2>&1 || error "failed to change to source root" # {
for pkg in ${pkglist}; do
eval pdir=\$${pkg}_dir
eval pfile=\$${pkg}_file
[ -d "${pdir}" ] || {
echo_progress "${pkg}..."
case "${pfile}" in
*.tar.gz)
gzip -dc "${topdir}/sources/${pfile}" | $tar -xf - > /dev/null 2>&1 || {
rm -fr "${srcroot}/${pdir}" > /dev/null 2>&1
error "failed to unpack ${pfile}"
}
;;
*.tar.bz2)
bzip2 -dc "${topdir}/sources/${pfile}" | $tar -xf - > /dev/null 2>&1 || {
rm -fr "${srcroot}/${pdir}" > /dev/null 2>&1
error "failed to unpack ${pfile}"
}
;;
*.tar.xz)
xz --decompress --stdout "${topdir}/sources/${pfile}" | $tar -xf - > /dev/null 2>&1 || {
rm -fr "${srcroot}/${pdir}" > /dev/null 2>&1
error "failed to unpack ${pfile}"
}
;;
*)
error "unsupported extension for file ${pfile}"
;;
esac
[ -d "${pdir}" ] || error "failed to extract ${pdir}"
}
done
popd > /dev/null 2>&1 # }
}
#
# A lot of the packages below all follow the same pattern: configure, build,
# install, clean. Rather than repeat all those code each time we have a general
# purpose function here that does all that work. The various step functions
# will use this to do their work. The parameters are:
#
# $1 - the name of the package
# $2 - the name of the build directory
# $3 - the name of the source directory
# $4 - the log file prefix
# $@ - arguments for the configure script
#
# Note that we always explicitly call bash on the configure script. This will
# cater for packages like flex that are extremely old and whose configure
# scripts do not re-exec themselves with a capable shell, and on at least
# FreeBSD, /bin/sh is not bash or even remotely bash-like (it's a true Bourne
# shell) and this causes configure to fail if we just exec it directly.
#
common_compile() {
local thisname="$1"
local thisbld="$2"
local thissrc="$3"
local thislog="$4"
shift 4
echo_progress "${thisname}: "
[ -d "${srcroot}/${thissrc}" ] || error "${thissrc} source directory missing"
rm -fr "${bld}/${thisbld}" > /dev/null 2>&1
mkdir "${bld}/${thisbld}" || error "failed to create ${thisbld} build directory"
pushd "${bld}/${thisbld}" > /dev/null 2>&1 || error "failed to change to ${thisbld} build directory" # {
echo_progress "configure..."
${BASH} ${srcroot}/${thissrc}/configure $@ > ${logdir}/${thislog}.configure 2>&1 || error "${thisbld} configure failed"
echo_progress "build..."
${mymake} ${mymjf} > ${logdir}/${thislog}.build 2>&1 || error "${thisbld} build failed"
echo_progress "install..."
${mymake} install > ${logdir}/${thislog}.install 2>&1 || error "${thisbld} build failed"
popd > /dev/null 2>&1 # }
if [ "${do_clean}" == "yes" ] ; then
echo_progress "clean..."
rm -fr "${bld}/${thisbld}" > /dev/null 2>&1
fi
}
#
# Most of the packages below will either accept a --program-prefix argument or
# the scripts will arrange to move things such that they have one. However, we
# also want things available by their original name, because that is how other
# scripts may search for them. This relies on our bin directory being first
# on the user's PATH which is easy enough to mandate. This function will be
# given the name of a parent directory under our prefix, followed by a list of
# file names which should have compatibility links created for them. So for
# example: common_link bin ar nm ld
#
# would create a link from nr-ar to ar, nr-nm to nm and nr-ld to ld in the
# $prefix/bin directory.
#
common_link() {
local ldir=$1; shift
local ftl=
local tf=
local lf=
echo_progress "links..."
for ftl in $@; do
tf="${iroot}/${ldir}/${ftl}"
lf="${iroot}/${ldir}/nr-${ftl}"
[ -h "${tf}" -o -f "${tf}" ] && {
rm -f "${tf}" > /dev/null 2>&1 || error "failed to remove ${tf}"
}
[ -f "${lf}" ] && {
ln -sf "${lf}" "${tf}" > /dev/null 2>&1 || error "failed to link ${lf} to ${tf}"
}
done
}
#
# This function is used to create various links between installed libraries.
# It preserves the original name, as well as adding a version with the nr
# prefix, and it copies the various -pic versions of the library into a pic
# directory which applications can direct to with the right -L flags.
#
common_lib_link() {
local tf=
local df=
echo_progress "libs..."
for tf in $@; do
rm -f "${iroot}/lib${libsfx}/libnr${tf}.a" "${iroot}/lib${libsfx}/libnr${tf}-pic.a"
rm -f "${iroot}/lib${libsfx}/pic/libnr${tf}.a" "${iroot}/lib${libsfx}/pic/libnr${tf}-pic.a" "${iroot}/lib${libsfx}/pic/lib${tf}.a"
ln -sf "${iroot}/lib${libsfx}/lib${tf}.a" "${iroot}/lib${libsfx}/libnr${tf}.a"
ln -sf "${iroot}/lib${libsfx}/lib${tf}-pic.a" "${iroot}/lib${libsfx}/libnr${tf}-pic.a"
ln -sf "${iroot}/lib${libsfx}/lib${tf}-pic.a" "${iroot}/lib${libsfx}/pic/lib${tf}-pic.a"
ln -sf "${iroot}/lib${libsfx}/lib${tf}-pic.a" "${iroot}/lib${libsfx}/pic/libnr${tf}-pic.a"
ln -sf "${iroot}/lib${libsfx}/lib${tf}-pic.a" "${iroot}/lib${libsfx}/pic/libnr${tf}.a"
ln -sf "${iroot}/lib${libsfx}/lib${tf}-pic.a" "${iroot}/lib${libsfx}/pic/lib${tf}.a"
if [ "${do_32_bit}" = "yes" ]; then
rm -f "${iroot}/lib${libsfx32}/libnr${tf}.a" "${iroot}/lib${libsfx32}/libnr${tf}-pic.a"
rm -f "${iroot}/lib${libsfx32}/pic/libnr${tf}.a" "${iroot}/lib${libsfx32}/pic/libnr${tf}-pic.a" "${iroot}/lib${libsfx32}/pic/lib${tf}.a"
ln -sf "${iroot}/lib${libsfx32}/lib${tf}.a" "${iroot}/lib${libsfx32}/libnr${tf}.a"
ln -sf "${iroot}/lib${libsfx32}/lib${tf}-pic.a" "${iroot}/lib${libsfx32}/libnr${tf}-pic.a"
ln -sf "${iroot}/lib${libsfx32}/lib${tf}-pic.a" "${iroot}/lib${libsfx32}/pic/lib${tf}-pic.a"
ln -sf "${iroot}/lib${libsfx32}/lib${tf}-pic.a" "${iroot}/lib${libsfx32}/pic/libnr${tf}-pic.a"
ln -sf "${iroot}/lib${libsfx32}/lib${tf}-pic.a" "${iroot}/lib${libsfx32}/pic/libnr${tf}.a"
ln -sf "${iroot}/lib${libsfx32}/lib${tf}-pic.a" "${iroot}/lib${libsfx32}/pic/lib${tf}.a"
fi
done
}
#
# We need a modern GNU patch. Compile one.
#
compile_gnu_patch() {
common_compile gpatch gpatch ${gpatch_dir} gpatch \
--prefix=${iroot} \
--build=${cfgbuild} \
--program-prefix=nr- \
--disable-dependency-tracking
common_link bin patch
}
#
# Ensure we have a reasonable make.
#
compile_gnu_make() {
common_compile gmake make ${make_dir} make \
--prefix=${iroot} \
--build=${cfgbuild} \
--program-prefix=nr- \
--disable-nls \
--disable-dependency-tracking
common_link bin make
}
#
# Some of the patches change *.texi files, and the make rules will want to
# rebuild the *.info files. Therefore, we need to make sure that texinfo is
# compiled and available before we bootstrap.
#
compile_texinfo() {
common_compile texinfo texinfo ${texinfo_dir} texinfo \
--prefix=${iroot} \
--build=${cfgbuild} \
--disable-nls \
--program-prefix=nr- \
--disable-dependency-tracking
common_link bin info infokey install-info makeinfo pdftexi2dvi texi2dvi texi2pdf texindex
}
#
# The various autoconf/automake tools and Bison all require a modern version
# of the M4 macro processor. Most systems provide one but it is an extra
# package to install. Therefore we compile our own and make sure that the
# other tools in NRCAMP use this version.
#
# Modern versions of m4 want to link against libsigsegv, the rationale
# given, murky at best, is it is a way to differentiate bugs in m4 from
# legitimate stack overruns. Unfortunately, there is no way to disable
# this attempt to link against libsigsegv.so at m4 configuration time.
# Unfortunately, libsigsegv is on some of our compiler build machines,
# but not on our product build machines, as for example solaris vs
# joyent.
#
# On 10Apr2014 rrh renamed /usr/lib/64/*libsigsegv*.so*, as the only
# use of that that he could determine was for m4. It appears that some
# set of .so files were installed on the build machine which are not
# commonly part of solaris. In this way binaries built on solaris could
# run on joyent.
#
compile_m4() {
common_compile m4 m4 ${m4_dir} m4 \
--prefix=${iroot} \
--build=${cfgbuild} \
--disable-nls \
--program-prefix=nr- \
--disable-dependency-tracking
common_link bin m4
}
#
# help2man is needed to build manpages for modern bison 3.
# Modern bison3 is needed to build PHP from github source,
# as for example for php7.
#
compile_help2man() {
common_compile help2man help2man ${help2man_dir} help2man \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--program-prefix=nr-
# common_link bin bison yacc
}
#
# Bison is needed for anything that needs to generate parsers
# Various parts of NRCAMP need bison.
# bison (built from bison3) is needed to build PHP from the github source tree.
# bison-2 is needed to build percona in NRLAMP
#
compile_bison2() {
common_compile bison2 bison2 ${bison2_dir} bison2 \
--program-suffix=-2 \
--datadir=${iroot}/share/bison-2 \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--disable-nls \
--program-prefix=nr-
common_link bin bison-2 yacc-2
}
compile_bison() {
common_compile bison bison ${bison_dir} bison \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--disable-nls \
--program-prefix=nr-
common_link bin bison yacc
}
#
# Flex provides a tool for producing a lexical scanner and tokenizer. It is
# required by PHP 5.1 builds as well as parts of NRCAMP itself.
#
compile_flex() {
common_compile flex flex ${flex_dir} flex \
--prefix=${iroot} \
--disable-nls
echo_progress "link..."
# Flex does not provide a --program-prefix option so we need to manually
# rename the installed binaries to have the nr- prefix.
rm -f ${iroot}/bin/nr-flex ${iroot}/bin/nr-flex++ ${iroot}/bin/flex++ > /dev/null 2>&1
mv -f ${iroot}/bin/flex ${iroot}/bin/nr-flex > /dev/null 2>&1
ln -s ${iroot}/bin/nr-flex ${iroot}/bin/flex > /dev/null 2>&1
ln -s ${iroot}/bin/nr-flex ${iroot}/bin/flex++ > /dev/null 2>&1
ln -s ${iroot}/bin/nr-flex ${iroot}/bin/nr-flex++ > /dev/null 2>&1
# It also doesn't provide a --libdir option so it will have installed its
# support library in the wrong place. Move it.
[ -n "${libsfx}" ] && {
mv -f ${iroot}/lib/libfl.a ${iroot}/lib${libsfx}/libfl.a > /dev/null 2>&1 || error "failed to move libfl.a to lib directory"
}
}
compile_re2c() {
common_compile re2c re2c ${re2c_dir} re2c \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--disable-nls \
--program-prefix=nr- \
--disable-dependency-tracking
common_link bin re2c
}
compile_ragel() {
common_compile ragel ragel ${ragel_dir} ragel \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--disable-nls \
--program-prefix=nr- \
--disable-dependency-tracking
common_link bin ragel
}
compile_ctags() {
common_compile ctags ctags ${ctags_dir} ctags \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--disable-nls \
--program-prefix=nr-
# common_link bin ctags
}
compile_protobuf() {
# TODO(rrh): couldn't get to compile and link on solaris/joyent
return
common_compile protobuf protobuf ${protobuf_dir} protobuf \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--disable-nls \
--program-prefix=nr- \
--disable-dependency-tracking
common_link bin protoc
}
compile_protobuf_c() {
# TODO(rrh): couldn't get to compile and link on solaris/joyent
return
common_compile protobuf_c protobuf_c ${protobuf_c_dir} protobuf_c \
--prefix=${iroot} \
--build=${cfgbuild} \
--libdir=${iroot}/lib${libsfx} \
--disable-nls \
--program-prefix=nr- \
--disable-dependency-tracking
common_link bin protoc-c
}
#
# Apply any patches.
#
patch_sources() {
echo_progress "apply patches: "
pushd "${srcroot}" > /dev/null 2>&1 || error "failed to change to source root" # {
for pkg in ${pkglist}; do
eval pdir=\$${pkg}_dir
eval pver=\$${pkg}_ver
if [ -d "${pdir}" ] ; then
local pfiles="${topdir}/patches/${pkg}.${pver}.patch ${topdir}/patches/${pkg}.patch"
local found_patch=no
for pfile in ${pfiles} ; do
if [ -f "${pfile}" ]; then
local fmt=$(printf "%20s patched with %s" "${pkg}" "${pfile}")
echo_progress "${fmt}"
$mypatch -b -z .nrpatch -p 1 -Z -s -d ${pdir} -i "${pfile}" > /dev/null 2>&1 || error "patching ${pkg} failed"
found_patch=yes
break
fi
done
if [ "${found_patch}" = "no" ] ; then
error "No patch file found: ${pfiles}"
fi
else
error "no patch directory ${pdir}"
fi
done
#
# GCC provides no clean way of doing this so we have to hack ...
#
sed -e '/^PPLLIBS =/d' "${gcc_dir}/gcc/Makefile.in" > "${gcc_dir}/gcc/Makefile.in.noppl"
cp -f "${gcc_dir}/gcc/Makefile.in" "${gcc_dir}/gcc/Makefile.in.withppl"
popd > /dev/null 2>&1 # }
}
#
# Before we can bootstrap gcc there are a few libraries we need to compile.
# In theory, we are supposed to be able to simply link these in to the GCC
# tree and have it do the right thing. However, this fails with MPC. The
# reason is that it assumes that MPFR is a flat source tree (which it is in
# version 2.x). However, we want to use the latest MPFR, which has its source
# in the src/ directory. It is complicated to patch gcc to address this so the
# path of least resistance is to compile GMP, MPFR and MPC with the system
# compiler and install them, before we attempt to bootstrap GCC. That is what
# the following six steps do.
#
# None of these libraries are required or provided outside of the NRCAMP build
# itself. In particular, we make no attempt to multilib these libraries as they
# are statically linked in to GCC. In order to avoid having them erroneously
# put 64-bit libraries in the 32-bit library space, we use a special prefix
# inside ${iroot}. This is called "ofb" which stands for "only for build".
# At the very end of the NRCAMP run we remove this entire prefix.
#
compile_gmp() {
common_compile GMP gmp ${gmp_dir} gmp \
--build=${cfgbuild} \
--prefix=${iroot}/ofb \
--enable-cxx \
--disable-shared
}
compile_mpfr() {
common_compile MPFR mpfr ${mpfr_dir} mpfr \
--build=${cfgbuild} \
--prefix=${iroot}/ofb \
--disable-shared \
--with-gmp=${iroot}/ofb \
--disable-maintainer-mode \
--disable-dependency-tracking
}
compile_mpc() {
common_compile MPC mpc ${mpc_dir} mpc \
--build=${cfgbuild} \
--prefix=${iroot}/ofb \
--disable-shared \
--with-gmp=${iroot}/ofb \
--with-mpfr=${iroot}/ofb \
--disable-maintainer-mode \
--disable-dependency-tracking