forked from LogicalTrust/fuzzrump.sh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildrump.sh
executable file
·1655 lines (1457 loc) · 40.7 KB
/
buildrump.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 sh
#
# Copyright (c) 2013, 2014, 2015 Antti Kantee <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
set -u
#
# scrub necessary parts of the env
BUILDRUMP_CPPCACHE=
CCWRAPPER_MANGLE=
# defaults, can be overriden by probes
RUMP_VIRTIF=no
HIJACK=false
SYS_SUNOS=false
NEED_LDSCRIPT=false
TARBALLMODE=
# empty before proven contentful
EXTRA_CFLAGS=
EXTRA_LDFLAGS=
EXTRA_AFLAGS=
EXTRA_CPPFLAGS=
EXTRA_CWARNFLAGS=
EXTRA_RUMPUSER=
EXTRA_RUMPCOMMON=
EXTRA_RUMPCLIENT=
RUMPKERN_UNDEF=
BUILDSH_VARGS=
#
# support routines
#
helpme ()
{
echo "Usage: $0 [-h] [options] [command] [command...]"
printf "supported options:\n"
printf "\t-d: location for headers/libs. default: PWD/rump\n"
printf "\t-o: location for build-time files. default: PWD/obj\n"
printf "\t-T: location for tools+rumpmake. default: PWD/obj/tooldir\n"
printf "\t-s: location of source tree. default: PWD/src\n"
echo
printf "\t-j: value of -j specified to make. default: ${JNUM}\n"
printf "\t-q: quiet build, less compiler output. default: noisy\n"
printf "\t-r: release build (no -g, DIAGNOSTIC, etc.). default: no\n"
printf "\t-D: increase debugginess. default: -O2 -g\n"
printf "\t-k: only kernel (no POSIX hypercalls). default: all\n"
echo
printf "\t-H: ignore diagnostic checks (expert-only). default: no\n"
printf "\t-V: specify -V arguments to NetBSD build (expert-only)\n"
printf "\t-F: specify build flags with -F XFLAGS=value\n"
printf "\t possible values for XFLAGS:\n"
printf "\t CFLAGS, AFLAGS, LDFLAGS, ACFLAGS, ACLFLAGS,\n"
printf "\t CPPFLAGS, CWARNFLAGS, DBG\n"
echo
printf "supported commands (default => checkout+fullbuild+tests):\n"
printf "\tcheckoutgit:\tfetch NetBSD sources to srcdir from github\n"
printf "\tcheckoutcvs:\tfetch NetBSD sources to srcdir from anoncvs\n"
printf "\tcheckout:\talias for checkoutgit\n"
printf "\ttools:\t\tbuild necessary tools to tooldir\n"
printf "\tbuild:\t\tbuild everything related to rump kernels\n"
printf "\tinstall:\tinstall rump kernel components into destdir\n"
printf "\ttests:\t\trun tests to verify installation is functional\n"
printf "\tfullbuild:\talias for \"tools build install\"\n"
exit 1
}
DIAGOUT=echo
diagout ()
{
if [ "${1:-}" != '-r' ]; then
${DIAGOUT} -n '>> '
else
shift
fi
${DIAGOUT} $*
}
#
# toolchain creation helper routines
#
printoneconfig ()
{
[ -z "${2}" ] || printf "%-5s %-18s: %s\n" "${1}" "${2}" "${3}"
}
appendmkconf ()
{
if [ ! -z "${2}" ]; then
# cheat a bit: output BUILDRUMP_CFLAGS/AFLAGS without
# the prefix as the name so to as not confuse the user
# (the reason why it's BUILDRUMP_CFLAGS instead of
# CFLAGS is so that we get the flags right for
# the RUMPCOMP_USER case)
case $3 in
'BUILDRUMP_CFLAGS'|'BUILDRUMP_AFLAGS')
name=${3#BUILDRUMP_}
;;
*)
name=${3}
esac
val=${2# }
printoneconfig "${1}" "${name}" "${val}"
echo "${3}${4:-}=${val}" >> "${MKCONF}"
fi
}
appendvar_fs ()
{
vname="${1}"
fs="${2}"
shift 2
if [ -z "$(eval echo \${${vname}:-})" ]; then
eval ${vname}="\${*}"
else
eval ${vname}="\"\${${vname}}"\${fs}"\${*}\""
fi
}
appendvar ()
{
vname="$1"
shift
appendvar_fs "${vname}" ' ' $*
}
#
# Not all platforms have the same set of crt files. for some
# reason unbeknownst to me, if the file does not exist,
# at least gcc --print-file-name just echoes the input parameter.
# Try to detect this and tell the NetBSD makefiles that the crtfile
# in question should be left empty.
chkcrt ()
{
tst=`${CC} --print-file-name=crt${1}.o`
up=`echo ${1} | tr [a-z] [A-Z]`
[ -z "${tst%crt${1}.o}" ] \
&& echo "_GCC_CRT${up}=" >>"${MKCONF}"
}
probeld ()
{
linkervers=$(LANG=C ${CC} ${EXTRA_LDFLAGS} -Wl,--version 2>&1)
if echo ${linkervers} | grep -q 'GNU ld' ; then
LD_FLAVOR=GNU
LD_AS_NEEDED='-Wl,--no-as-needed'
elif echo ${linkervers} | grep -q 'GNU gold' ; then
LD_FLAVOR=gold
LD_AS_NEEDED='-Wl,--no-as-needed'
elif echo ${linkervers} | grep -q 'Solaris Link Editor' ; then
LD_FLAVOR=sun
SHLIB_MKMAP=no
appendvar_fs CCWRAPPER_MANGLE : '-Wl,-x'
else
diagout 'output from linker:'
diagout -r ${linkervers}
die 'GNU or Solaris ld required'
fi
# use traditional link sets for freestanding targets,
# use __attribute__((constructor)) elsewhere
if ${KERNONLY}; then
LDSCRIPT='no'
elif ! ${NEED_LDSCRIPT}; then
LDSCRIPT='ctor'
fi
}
# Check if $NM outputs the format we except, i.e. if symbols
# are the alone in the last whitespace-separated column.
# GNU and OpenBSD nm do this, e.g. Solaris does not.
probenm ()
{
echo 'void testsym(void); void testsym(void) {return;}' \
| ${CC} ${EXTRA_CFLAGS} -x c -c - -o ${OBJDIR}/probenm.o
lastfield=$(${NM} -go ${OBJDIR}/probenm.o | awk '/testsym/{print $NF}')
if [ "${lastfield}" != 'testsym' ]; then
diagout nm: expected \"testsym\", got \"${lastfield}\"
die incompatible output from probing \"${NM}\"
fi
rm -f ${OBJDIR}/probenm.o
}
# For ar, we just check the --version. Works so far. If it breaks,
# need to start building archives ...
probear ()
{
# Check for GNU/BSD ar
if ! ${AR} -V 2>/dev/null | egrep '(GNU|BSD) ar' > /dev/null ; then
die Need GNU or BSD ar "(`type ${AR}`)"
fi
}
#
# Check if cpp defines $1 (with any value).
# If $# > 1, use the remaining args as args to cc.
#
cppdefines ()
{
var=${1}
shift
if [ $# -eq 0 ]; then
if [ -z "${BUILDRUMP_CPPCACHE}" ]; then
BUILDRUMP_CPPCACHE=$(${CC} ${EXTRA_CPPFLAGS} \
${EXTRA_CFLAGS} -E -Wp,-dM - < /dev/null)
fi
cpplist="${BUILDRUMP_CPPCACHE}"
else
cpplist=$(${CC} ${EXTRA_CPPFLAGS} ${EXTRA_CFLAGS} \
-E -Wp,-dM "$@" - < /dev/null)
fi
(
IFS=' '
echo ${cpplist} | awk '$2 == "'$var'"{exit 37}'
exit $?
)
[ $? -eq 37 ]
return
}
# check if C snippet given as first argument will build
# arguments [2..n] are passed to the compiler
doesitbuild ()
{
theprog="${1}"
shift
warnflags="-Wmissing-prototypes -Wstrict-prototypes -Wimplicit -Werror"
printf "${theprog}" \
| ${CC} ${warnflags} ${EXTRA_LDFLAGS} ${EXTRA_CFLAGS} \
-x c - -o /dev/null $* > /dev/null 2>&1
}
doesitbuild_host ()
{
theprog="${1}"
shift
printf "${theprog}" \
| ${HOST_CC} -Wall -Werror -x c - -o /dev/null $* > /dev/null 2>&1
}
# like doesitbuild, except with c++
doesitcxx ()
{
${HAVECXX} || die internal error: doesitcxx called without cxx
theprog="${1}"
shift
printf "${theprog}" \
| ${CXX} -Werror ${EXTRA_LDFLAGS} ${EXTRA_CFLAGS} \
-x c++ - -o /dev/null $* > /dev/null 2>&1
}
checkcheckout ()
{
[ -x "${SRCDIR}/build.sh" ] || die "Cannot find ${SRCDIR}/build.sh!"
[ ! -z "${TARBALLMODE}" ] && return
if ! ${BRDIR}/checkout.sh checkcheckout ${SRCDIR} \
&& ! ${TITANMODE}; then
die 'revision mismatch, run checkout (or -H to override)'
fi
}
checkcompiler ()
{
# Iron out the clang version differences.
if [ "${CC_FLAVOR}" = 'clang' ]; then
doesitbuild 'int main(void) {return 0;}\n' -c \
-Wtautological-pointer-compare
if [ $? -ne 0 ]; then
appendvar_fs CCWRAPPER_MANGLE : \
"-Wno-error=tautological-pointer-compare -Wno-error=tautological-compare"
fi
fi
if ! ${KERNONLY}; then
doesitbuild 'int main(void) {return 0;}\n' \
${EXTRA_RUMPUSER} ${EXTRA_RUMPCOMMON}
[ $? -eq 0 ] || ${TITANMODE} || \
die 'Probe cannot build a binary'
fi
}
probe_rumpuserbits ()
{
# Do we need -lrt for time related stuff?
# Old glibc and Solaris need it, but newer glibc and most
# other systems do not need or have librt.
for l in '' '-lrt' ; do
doesitbuild '#include <time.h>\n
int main(void) {
struct timespec ts;
return clock_gettime(CLOCK_REALTIME, &ts);}' $l
if [ $? -eq 0 ]; then
EXTRA_RUMPUSER="$l"
break
fi
done
# Do we need -lpthread for threads?
# Most systems do, but Android does not have it at all and
# Musl does not require it
doesitbuild '#include <pthread.h>\n
#include <stddef.h>\n
static void *t(void *arg) {return NULL;}\n
int main(void)\n
{pthread_t p;return pthread_create(&p,NULL,t,NULL);}\n'
if [ $? -eq 0 ]; then
appendvar_fs CCWRAPPER_MANGLE : '-lpthread'
fi
[ -x ${SRCDIR}/lib/librumpuser/configure ] \
|| die 'librumpuser configure script missing (source dir too old)'
if [ ! -f ${BRTOOLDIR}/autoconf/rumpuser_config.h ]; then
diagout '>> running librumpuser configure script'
diagout
mkdir -p ${BRTOOLDIR}/autoconf
( export CFLAGS="${EXTRA_CFLAGS}"
export LDFLAGS="${EXTRA_LDFLAGS}"
export CPPFLAGS="${EXTRA_CPPFLAGS}"
cd ${BRTOOLDIR}/autoconf \
&& ${SRCDIR}/lib/librumpuser/configure \
$( ! ${NATIVEBUILD} && echo --host ${CC_TARGET} ) )
[ $? -eq 0 ] || die configure script failed
fi
echo "CPPFLAGS+=-DRUMPUSER_CONFIG=yes" >> "${MKCONF}"
echo "CPPFLAGS+=-I${BRTOOLDIR}/autoconf" >> "${MKCONF}"
}
writeproberes ()
{
probevars='
HAVE_LLVM
HAVE_PCC
MACHINE
MACHINE_GNU_ARCH
'
for x in ${probevars}; do
printf 'BUILDRUMP_%s="%s"\n' ${x} $(eval echo \${${x}:-})
done
}
WRAPPERBODY='int
main(int argc, const char *argv[])
{
int i, j, k;
for (i = 1; i < argc; i++) {
for (j = 0; j < sizeof(mngl_from)/sizeof(mngl_from[0]); j++) {
if (strcmp(argv[i], mngl_from[j]) == 0) {
if (strlen(mngl_to[j]) == 0) {
for (k = i; k < argc; k++) {
argv[k] = argv[k+1];
}
argv[k] = '\0';
argc--;
} else {
argv[i] = mngl_to[j];
}
break;
}
}
}
'
maketoolwrapper ()
{
musthave=$1
tool=$2
eval evaldtool=\${${tool}}
fptool=$(which ${evaldtool})
if [ ! -x ${fptool} ]; then
if ! ${musthave}; then
return
else
die Internal error: mandatory tool ${tool} not found
fi
fi
# ok, it's not really --netbsd, but let's make-believe!
if [ ${tool} = CC ]; then
lcx=${CC_FLAVOR}
elif [ ${tool} = CXX ]; then
case ${CC_FLAVOR} in
gcc)
lcx=c++
;;
clang)
lcx=clang++
;;
esac
else
lcx=$(echo ${tool} | tr '[A-Z]' '[a-z]')
fi
tname=${BRTOOLDIR}/bin/${MACHINE_GNU_ARCH}--netbsd${TOOLABI}-${lcx}
printoneconfig 'Tool' "${tool}" "${fptool}"
# Mangle wrapper arguments from what NetBSD does to what the
# toolchain we use supports. In case we need mangling, do it
# with a C wrapper to preserve all quoting etc. (couldn't
# figure out how to get that right with a shell.
if [ "${tool}" != 'CC' -a "${tool}" != 'CXX' \
-o -z "${CCWRAPPER_MANGLE}" ]; then
printf '#!/bin/sh\n' > ${tname}
printf 'exec %s "$@"\n' ${fptool} >> ${tname}
else
rm -f ${OBJDIR}/wrapper.c
exec 3>&1 1>${OBJDIR}/wrapper.c
printf '#include <inttypes.h>\n'
printf '#include <string.h>\n'
printf '#include <unistd.h>\n\n'
printf 'static const char *mngl_from[] = {\n'
(
IFS=:
for xf in ${CCWRAPPER_MANGLE}; do
IFS=' '
set -- ${xf}
printf '\t"%s",\n' ${1}
done
)
printf '};\nstatic const char *mngl_to[] ={\n'
(
IFS=:
for xf in ${CCWRAPPER_MANGLE}; do
IFS=' '
set -- ${xf}
printf '\t"%s",\n' ${2:-}
done
)
printf '};\n\n'
( IFS=' ' printf '%s' "${WRAPPERBODY}" )
printf '\targv[0] = "%s";\n' ${fptool}
printf '\texecvp(argv[0], (void *)(uintptr_t)argv);\n'
printf '\treturn 0;\n}\n'
exec 1>&3 3>&-
${HOST_CC} ${OBJDIR}/wrapper.c -o ${tname} \
|| die failed to build wrapper for ${tool}
rm -f ${OBJDIR}/wrapper.c
fi
chmod 755 ${tname}
}
#
# Create tools and wrappers. This step needs to be run at least once.
# The routine is run if the "tools" argument is specified.
#
# You might want to skip it because:
# 1) iteration speed on a slow-ish host
# 2) making manual modifications to the tools for testing and avoiding
# the script nuking them on the next iteration
#
# external toolchain links are created in the format that
# build.sh expects.
#
maketools ()
{
checkcheckout
probeld
probenm
probear
${HAVECXX} && probecxx
cd ${OBJDIR}
# Create mk.conf. Create it under a temp name first so as to
# not affect the tool build with its contents
MKCONF="${BRTOOLDIR}/mk.conf.building"
> "${MKCONF}"
mkconf_final="${BRTOOLDIR}/mk.conf"
> ${mkconf_final}
# nuke fakelibz (compat for old libz hack, the following line can
# be removed e.g. in 2017)
rm -f ${OBJDIR}/libz.a
# We now require a host zlib for tools. nb. we explicitly whine
# about this one here since the NetBSD tools build process gets
# very confused if you start the build, it bombs, you add zlib,
# and retry.
doesitbuild_host '#include <zlib.h>
#include <stdlib.h>
int main() {gzopen(NULL, NULL); return 0;}' -lz \
|| die 'Host zlib (libz, -lz) required, please install one!'
${KERNONLY} || probe_rumpuserbits
checkcompiler
#
# Create external toolchain wrappers.
mkdir -p ${BRTOOLDIR}/bin || die "cannot create ${BRTOOLDIR}/bin"
for x in CC AR NM OBJCOPY; do
maketoolwrapper true $x
done
for x in AS LD OBJDUMP RANLIB READELF SIZE STRINGS STRIP; do
maketoolwrapper false $x
done
${HAVECXX} && maketoolwrapper false CXX
# create a cpp wrapper, but run it via cc -E
if [ "${CC_FLAVOR}" = 'clang' ]; then
cppname=clang-cpp
else
cppname=cpp
fi
tname=${BRTOOLDIR}/bin/${MACHINE_GNU_ARCH}--netbsd${TOOLABI}-${cppname}
printf '#!/bin/sh\n\nexec %s -E -x c "${@}"\n' ${CC} > ${tname}
chmod 755 ${tname}
for x in 1 2 3; do
! ${HOST_CC} -o ${BRTOOLDIR}/bin/brprintmetainfo \
-DSTATHACK${x} ${BRDIR}/brlib/utils/printmetainfo.c \
>/dev/null 2>&1 || break
done
[ -x ${BRTOOLDIR}/bin/brprintmetainfo ] \
|| die failed to build brprintmetainfo
${HOST_CC} -o ${BRTOOLDIR}/bin/brrealpath \
${BRDIR}/brlib/utils/realpath.c || die failed to build brrealpath
cat >> "${MKCONF}" << EOF
BUILDRUMP_IMACROS=${BRIMACROS}
.if \${BUILDRUMP_SYSROOT:Uno} == "yes"
BUILDRUMP_CPPFLAGS=--sysroot=\${BUILDRUMP_STAGE}
.else
BUILDRUMP_CPPFLAGS=-I\${BUILDRUMP_STAGE}/usr/include
.endif
BUILDRUMP_CPPFLAGS+=${EXTRA_CPPFLAGS}
LIBDO.pthread=_external
INSTPRIV=-U
AFLAGS+=-Wa,--noexecstack
MKPROFILE=no
MKARZERO=no
USE_SSP=no
MKHTML=no
MKCATPAGES=yes
MKNLS=no
RUMP_NPF_TESTING?=no
RUMPRUN=yes
EOF
if ! ${KERNONLY}; then
# queue.h is not available on all systems, but we need it for
# the hypervisor build. So, we make it available in tooldir.
mkdir -p ${BRTOOLDIR}/compat/include/sys \
|| die create ${BRTOOLDIR}/compat/include/sys
cp -p ${SRCDIR}/sys/sys/queue.h ${BRTOOLDIR}/compat/include/sys
echo "CPPFLAGS+=-I${BRTOOLDIR}/compat/include" >> "${MKCONF}"
fi
printoneconfig 'Cmd' "SRCDIR" "${SRCDIR}"
printoneconfig 'Cmd' "DESTDIR" "${DESTDIR}"
printoneconfig 'Cmd' "OBJDIR" "${OBJDIR}"
printoneconfig 'Cmd' "BRTOOLDIR" "${BRTOOLDIR}"
appendmkconf 'Cmd' "${RUMP_DIAGNOSTIC:-}" "RUMP_DIAGNOSTIC"
appendmkconf 'Cmd' "${RUMP_DEBUG:-}" "RUMP_DEBUG"
appendmkconf 'Cmd' "${RUMP_LOCKDEBUG:-}" "RUMP_LOCKDEBUG"
appendmkconf 'Cmd' "${DBG:-}" "DBG"
printoneconfig 'Cmd' "make -j[num]" "-j ${JNUM}"
if ${KERNONLY}; then
appendmkconf Cmd yes RUMPKERN_ONLY
fi
if ${KERNONLY} && ! cppdefines __NetBSD__; then
appendmkconf 'Cmd' '-D__NetBSD__' 'CPPFLAGS' +
appendmkconf 'Probe' "${RUMPKERN_UNDEF}" 'CPPFLAGS' +
else
appendmkconf 'Probe' "${RUMPKERN_UNDEF}" "RUMPKERN_UNDEF"
fi
appendmkconf 'Probe' "${RUMP_CURLWP:-}" 'RUMP_CURLWP' ?
appendmkconf 'Probe' "${CTASSERT:-}" "CPPFLAGS" +
appendmkconf 'Probe' "${RUMP_VIRTIF:-}" "RUMP_VIRTIF"
appendmkconf 'Probe' "${EXTRA_CWARNFLAGS}" "CWARNFLAGS" +
appendmkconf 'Probe' "${EXTRA_LDFLAGS}" "LDFLAGS" +
appendmkconf 'Probe' "${EXTRA_CPPFLAGS}" "CPPFLAGS" +
appendmkconf 'Probe' "${EXTRA_CFLAGS}" "BUILDRUMP_CFLAGS"
appendmkconf 'Probe' "${EXTRA_AFLAGS}" "BUILDRUMP_AFLAGS"
_tmpvar=
for x in ${EXTRA_RUMPUSER} ${EXTRA_RUMPCOMMON}; do
appendvar _tmpvar "${x#-l}"
done
appendmkconf 'Probe' "${_tmpvar}" "RUMPUSER_EXTERNAL_DPLIBS" +
_tmpvar=
for x in ${EXTRA_RUMPCLIENT} ${EXTRA_RUMPCOMMON}; do
appendvar _tmpvar "${x#-l}"
done
appendmkconf 'Probe' "${_tmpvar}" "RUMPCLIENT_EXTERNAL_DPLIBS" +
appendmkconf 'Probe' "${LDSCRIPT:-}" "RUMP_LDSCRIPT"
appendmkconf 'Probe' "${SHLIB_MKMAP:-}" 'SHLIB_MKMAP'
appendmkconf 'Probe' "${SHLIB_WARNTEXTREL:-}" "SHLIB_WARNTEXTREL"
appendmkconf 'Probe' "${MKSTATICLIB:-}" "MKSTATICLIB"
appendmkconf 'Probe' "${MKPIC:-}" "MKPIC"
appendmkconf 'Probe' "${MKSOFTFLOAT:-}" "MKSOFTFLOAT"
appendmkconf 'Probe' $(${HAVECXX} && echo yes || echo no) _BUILDRUMP_CXX
printoneconfig 'Mode' "${TARBALLMODE}" 'yes'
rm -f ${BRTOOLDIR}/toolchain-conf.mk
exec 3>&1 1>${BRTOOLDIR}/toolchain-conf.mk
printf 'BUILDRUMP_TOOL_CFLAGS=%s\n' "${EXTRA_CFLAGS}"
printf 'BUILDRUMP_TOOL_CXXFLAGS=%s\n' "${EXTRA_CFLAGS}"
printf 'BUILDRUMP_TOOL_CPPFLAGS=-D__NetBSD__ %s %s\n' \
"${EXTRA_CPPFLAGS}" "${RUMPKERN_UNDEF}"
exec 1>&3 3>&-
chkcrt begins
chkcrt ends
chkcrt i
chkcrt n
# add vars from env last (so that they can be used for overriding)
cat >> "${MKCONF}" << EOF
CPPFLAGS+=\${BUILDRUMP_CPPFLAGS}
CFLAGS+=\${BUILDRUMP_CFLAGS}
AFLAGS+=\${BUILDRUMP_AFLAGS}
LDFLAGS+=\${BUILDRUMP_LDFLAGS}
EOF
if ! ${KERNONLY}; then
echo >> "${MKCONF}"
cat >> "${MKCONF}" << EOF
# Support for NetBSD Makefiles which use <bsd.prog.mk>
# It's mostly a question of erasing dependencies that we don't
# expect to see
.ifdef PROG
LIBCRT0=
LIBCRTBEGIN=
LIBCRTEND=
LIBCRTI=
LIBC=
LDFLAGS+= -L\${BUILDRUMP_STAGE}/usr/lib -Wl,-R${DESTDIR}/lib
LDADD+= ${EXTRA_RUMPCOMMON} ${EXTRA_RUMPUSER} ${EXTRA_RUMPCLIENT}
EOF
appendmkconf 'Probe' "${LD_AS_NEEDED}" LDFLAGS +
echo '.endif # PROG' >> "${MKCONF}"
fi
# Run build.sh. Use some defaults.
# The html pages would be nice, but result in too many broken
# links, since they assume the whole NetBSD man page set to be present.
cd ${SRCDIR}
# create user-usable wrapper script
makemake ${BRTOOLDIR}/rumpmake ${BRTOOLDIR}/dest makewrapper
# create wrapper script to be used during buildrump.sh, plus tools
makemake ${RUMPMAKE} ${OBJDIR}/dest.stage tools
# Just set no MSI in imacros universally now.
# Need to:
# a) migrate more defines there
# b) set no MSI only when necessary
printf '#define NO_PCI_MSI_MSIX\n' > ${BRIMACROS}.building
# tool build done. flip mk.conf name so that it gets picked up
omkconf="${MKCONF}"
MKCONF="${mkconf_final}"
mv "${omkconf}" "${MKCONF}"
unset omkconf mkconf_final
# set new BRIMACROS only if the contents change (avoids
# full rebuild, since every file in the rump kernel depends on the
# contents of BRIMACROS
if ! diff "${BRIMACROS}" "${BRIMACROS}.building" > /dev/null 2>&1; then
mv "${BRIMACROS}.building" "${BRIMACROS}"
fi
}
makemake ()
{
wrapper=$1
stage=$2
cmd=$3
CFLAGS= HOST_LDFLAGS=-L${OBJDIR} ./build.sh \
-m ${MACHINE} -u \
-D ${stage} -w ${wrapper} \
-T ${BRTOOLDIR} -j ${JNUM} \
${HAVE_LLVM:+-V HAVE_LLVM=${HAVE_LLVM}} \
${HAVE_PCC:+-V HAVE_PCC=${HAVE_PCC}} \
${BEQUIET} \
-E -Z S \
-V EXTERNAL_TOOLCHAIN=${BRTOOLDIR} -V TOOLCHAIN_MISSING=yes \
-V TOOLS_BUILDRUMP=yes \
-V MKGROFF=no \
-V MKLINT=no \
-V MKZFS=no \
-V MKDYNAMICROOT=no \
-V MKDTRACE=no -V MKCTF=no \
-V MKPIE=no \
-V TOPRUMP="${SRCDIR}/sys/rump" \
-V MAKECONF="${mkconf_final}" \
-V MAKEOBJDIR="\${.CURDIR:C,^(${SRCDIR}|${BRDIR}),${OBJDIR},}" \
-V BUILDRUMP_STAGE=${stage} \
${BUILDSH_VARGS} \
${cmd}
[ $? -ne 0 ] && die build.sh ${cmd} failed
}
makebuild ()
{
checkcheckout
# ensure we're in SRCDIR, in case "tools" wasn't run
cd ${SRCDIR}
targets="obj includes dependall install"
#
# Building takes 4 passes, just like when
# building NetBSD the regular way. The passes are:
# 1) obj
# 2) includes
# 3) dependall
# 4) install
#
DIRS_first='lib/librumpuser'
DIRS_second='lib/librump'
DIRS_third="lib/librumpdev lib/librumpnet lib/librumpvfs
sys/rump/dev sys/rump/fs sys/rump/kern sys/rump/net
sys/rump/include ${BRDIR}/brlib"
# sys/rump/share was added to ${SRCDIR} 11/2014
[ -d ${SRCDIR}/sys/rump/share ] \
&& appendvar DIRS_second ${SRCDIR}/sys/rump/share
if [ ${MACHINE} = "i386" -o ${MACHINE} = "amd64" \
-o ${MACHINE#evbearm} != ${MACHINE} \
-o ${MACHINE#evbppc} != ${MACHINE} ]; then
DIRS_emul=sys/rump/kern/lib/libsys_linux
fi
${SYS_SUNOS} && appendvar DIRS_emul sys/rump/kern/lib/libsys_sunos
if ${HIJACK}; then
DIRS_final="lib/librumphijack"
else
DIRS_final=
fi
DIRS_third="${DIRS_third} ${DIRS_emul}"
if ${KERNONLY}; then
mkmakefile ${OBJDIR}/Makefile.all \
sys/rump ${DIRS_emul} ${BRDIR}/brlib
else
DIRS_third="lib/librumpclient ${DIRS_third}"
mkmakefile ${OBJDIR}/Makefile.first ${DIRS_first}
mkmakefile ${OBJDIR}/Makefile.second ${DIRS_second}
mkmakefile ${OBJDIR}/Makefile.third ${DIRS_third}
mkmakefile ${OBJDIR}/Makefile.final ${DIRS_final}
mkmakefile ${OBJDIR}/Makefile.all \
${DIRS_first} ${DIRS_second} ${DIRS_third} ${DIRS_final}
fi
# try to minimize the amount of domake invocations. this makes a
# difference especially on systems with a large number of slow cores
for target in ${targets}; do
if [ ${target} = "dependall" ] && ! ${KERNONLY}; then
domake ${OBJDIR}/Makefile.first ${target}
domake ${OBJDIR}/Makefile.second ${target}
domake ${OBJDIR}/Makefile.third ${target}
domake ${OBJDIR}/Makefile.final ${target}
else
domake ${OBJDIR}/Makefile.all ${target}
fi
done
if ! ${KERNONLY}; then
mkmakefile ${OBJDIR}/Makefile.utils \
usr.bin/rump_server usr.bin/rump_allserver \
usr.bin/rump_wmd
for target in ${targets}; do
domake ${OBJDIR}/Makefile.utils ${target}
done
fi
}
makeinstall ()
{
# ensure we run this in a directory that does not have a
# Makefile that could confuse rumpmake
stage=$(cd ${BRTOOLDIR} && ${RUMPMAKE} -V '${BUILDRUMP_STAGE}')
(cd ${stage}/usr ; tar -cf - .) | (cd ${DESTDIR} ; tar -xf -)
}
#
# install kernel headers.
# Note: Do _NOT_ do this unless you want to install a
# full rump kernel application stack
#
makekernelheaders ()
{
dodirs=$(cd ${SRCDIR}/sys && \
${RUMPMAKE} -V '${SUBDIR:Narch:Nmodules:Ncompat:Nnetnatm}' includes)
# missing some architectures
appendvar dodirs arch/amd64/include arch/i386/include arch/x86/include
appendvar dodirs arch/arm/include arch/arm/include/arm32
appendvar dodirs arch/evbarm64/include arch/aarch64/include
appendvar dodirs arch/evbppc/include arch/powerpc/include
appendvar dodirs arch/evbmips/include arch/mips/include
appendvar dodirs arch/riscv/include
for dir in ${dodirs}; do
(cd ${SRCDIR}/sys/${dir} && ${RUMPMAKE} obj)
(cd ${SRCDIR}/sys/${dir} && ${RUMPMAKE} includes)
done
# create machine symlink
(cd ${SRCDIR}/sys/arch && ${RUMPMAKE} NOSUBDIR=1 includes)
}
settool ()
{
tool=$1
crossnames=$2
eval evaldtool=\${${tool}:-}
if [ -n "${evaldtool}" ]; then
# if it's set in the env, we require it to exist
if ! type ${evaldtool} > /dev/null; then
die ${tool} set in env but not found
fi
else
# else, set a default value, existence to be checked
# and consequences evaluated later
lcname=$(echo ${tool} | tr '[A-Z]' '[a-z]')
if ${crossnames}; then
eval ${tool}=${CC_TARGET}-${lcname}
else
eval ${tool}=${lcname}
fi
fi
}
evaltoolchain ()
{
# is the compiler which targets the host "cc" or something else
: ${HOST_CC:=cc}
type ${HOST_CC} >/dev/null 2>&1 \
|| die '${HOST_CC}' not found "(tried \"${HOST_CC}\")"
# target compiler
: ${CC:=cc}
type ${CC} > /dev/null 2>&1 \
|| die cannot find \$CC: \"${CC}\". check env.
# check that compiler want to compile at all
doesitbuild 'int main(void) { return 0; }' -c \
|| die simple cc test failed using: ${CC} ${EXTRA_CFLAGS}
# check for crossbuild
if ${KERNONLY}; then
NATIVEBUILD=false
else
printf 'int main(void) { return 0; }' \
| ${CC} ${EXTRA_CFLAGS} ${EXTRA_LDFLAGS} -x c - \
-o ${OBJDIR}/canrun > /dev/null 2>&1
[ $? -eq 0 ] && ${OBJDIR}/canrun
if [ $? -eq 0 ]; then
NATIVEBUILD=true
diagout NATIVE build environment probed
else
NATIVEBUILD=false
diagout CROSS build environment probed
fi
rm -f ${OBJDIR}/canrun
fi
# Check for variant of compiler.
# XXX: why can't all cc's that are gcc actually tell me
# that they're gcc with cc --version?!?
unset HAVE_LLVM HAVE_PCC
ccver=$(${CC} --version)
if echo ${ccver} | grep -q 'Free Software Foundation'; then
CC_FLAVOR=gcc
elif echo ${ccver} | grep -q clang; then
CC_FLAVOR=clang
HAVE_LLVM=yes
elif echo ${ccver} | grep -q pcc; then
CC_FLAVOR=pcc
HAVE_PCC=yes
else
die Unsupported \${CC} "(`type ${CC}`)"
fi
# See if we have a c++ compiler. If CXX is not set,
# try to guess what it could be. In the latter case, do
# not treat a missing c++ compiler as an error.
if [ -n "${CXX:-}" ]; then
type ${CXX} > /dev/null 2>&1 \
|| die \$CXX set \(${CXX}\) but not found
HAVECXX=true
else
cxxguess=
case ${CC} in
*gcc*)
cxxguess=$(echo $CC | sed 's/gcc$/g++/')
;;
*clang*)
cxxguess=$(echo $CC | sed 's/clang$/clang++/')
;;
*cc)
cxxguess=$(echo $CC | sed 's/cc$/c++/')
;;
esac
if [ -n "${cxxguess}" ] && type ${cxxguess} >/dev/null 2>&1
then
CXX=${cxxguess}
HAVECXX=true
else
HAVECXX=false
fi
fi
# Check the arch we're building for so as to work out the necessary
# NetBSD machine code we need to use. First try -dumpmachine,
# and if that works, be happy with it. Not all compilers support
# it (e.g. older versions of clang), so if that doesn't work,
# try parsing the output of -v
if ! CC_TARGET=$(${CC} -dumpmachine 2>/dev/null) ; then
# first check "${CC} -v" ... just in case it fails, we want a
# sensible return value instead of it being lost in the pipeline
# (this is easier than adjusting IFS)
if ${CC} -v >/dev/null 2>&1 ; then
# then actually process the output of ${CC} -v
CC_TARGET=$(LC_ALL=C ${CC} -v 2>&1 \
| sed -n 's/^Target: //p' )
[ -z "${CC_TARGET}" ] \
&& die failed to probe target of \"${CC}\"
else
# this might be pcc
${CC} -v 2>&1 | grep pcc > /dev/null || \
die \"${CC} -v failed\". Check \"${CC}\"
CC_TARGET=$(${CC} -v 2>&1 \
| sed -n -e 's/^pcc.*for //' -e 's/,.*//p' )
fi
fi
MACHINE_GNU_ARCH=$(echo ${CC_TARGET} | sed 's/-.*//' )