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
|
# Design: this thing is intended to build two mksh binaries,
# mksh-full and mksh-static (with the latter being statical-
# ly linked), and lksh, according to DEB_BUILD_OPTIONS set:
# - nocheck: do not run mksh's regression test suite
# - noopt: build mksh with -O0, for glibc builds only
# - nodbg: do not build with debugging info
# - nostrip: handled by dh_strip, so ignored here
# - parallel=n: currently ignored, maybe -flto=jobserver could use it
# - mksh-firstbuilt: do not run a simple test for operational
# functionality, but use the first built binary (e.g. cross-builds)
# - mksh-static=x: use library x (comma-separated list) for this and lksh,
# values for x are: klibc dietlibc glibc
# - nomksh-small: do not build mksh-static with -DMKSH_SMALL
#
# Default values for mksh-static are:
# - if mksh-firstbuilt is set: glibc
# - possibly different, depending on state and arch, see below
# - otherwise: klibc,dietlibc,glibc
#
# If we are cross-building, mksh-firstbuilt will be set.
echo '
┌─┤ Dear buildd maintainers, ├───────────────────────┐
│ │
│ this package uses the Built-Using header as per │
│ Debian Policy 3.9.4 and later. This means that, │
│ while compilation will succeed even if your buildd │
│ chroot is not up to date, uploading may fail, and │
│ you will get a REJECT mail. In this case, please │
│ update your unstable buildd chroot to the latest │
│ sid versions of packages, or, for infrastructure │
│ (glibc, linux-libc-dev), versions that are known │
│ to be held in the archive anyway, such as these │
│ from stable, shortly after a release; later on, │
│ up-to-date sid ones are really recommended. │
│ │
│ Also remember /dev/tty and /dev/ptmx are needed. │
└────────────────────────────────────────────────────┘
'
# --- functions ---
buildok=0
normalise() {
varname=$1
eval varvalue=\$$varname
newvalue=
unset newvalue
for tmpvalue in $varvalue; do
newvalue=$newvalue${newvalue+ }$tmpvalue
done
eval $varname=\$newvalue
}
logbuildinfo() {
where=$1
{
echo "Build information for $where mksh"
fgrep 'set -A check_categories' builddir/$where/test.sh
echo "From: $startdate"
$CC --version 2>&1 | grep ^gcc
echo "Result: $buildinfo (broken<firstbuilt<checked<regressed)"
if test x"$buildinfo" = x"regressed"; then
echo "Regression test results:"
echo "$resultest" | sed 's/^/| /'
fi
echo "Variables used:"
for v in CC CFLAGS CPPFLAGS LDFLAGS LDSTATIC LIBS; do
eval x=\$$v
echo "| $v='$x'"
done
echo "Actual compilation options:"
fgrep main builddir/$where/Rebuild.sh | sed 's/^/] /'
echo "Resulting binary:"
size builddir/$where/?ksh 2>&1 | sed 's/^/| /'
echo "Date: $(date -u)"
} >builddir/buildinfo.$where
}
trybuild() {
where=$1; shift
normalise CC
normalise CFLAGS
normalise CPPFLAGS
normalise LDFLAGS
# do not normalise LDSTATIC
normalise LIBS
cd builddir/$where
echo "Attempting compilation of mksh in $where with CC='$CC'"
echo "CFLAGS='$CFLAGS' CPPFLAGS='$CPPFLAGS'"
echo "LDFLAGS='$LDFLAGS' LDSTATIC='$LDSTATIC' LIBS='$LIBS'"
buildok=0
arg=-r
testwrap=0
if test x"$where" = x"legacy"; then
arg="$arg -L"
tfn=lksh
else
tfn=mksh
if test 0 = "$iscross"; then
testwrap=1
fi
fi
buildinfo=broken
gotbin=0
startdate=$(date -u)
set -x
CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" \
LDSTATIC="$LDSTATIC" LIBS="$LIBS" sh ../../Build.sh $arg && \
test -f $tfn && gotbin=1
set +x
if test $gotbin = 0; then
echo "Build attempt failed."
cd ../..
return
fi
if test $testwrap = 1; then
echo "Got a binary, doing run-time checks."
set -- $(md5sum ../../debian/rtchecks)
test bd51f320dcb3970f0119db72f7ae6be4 = "$1" || {
echo "Testsuite corrupt."
exit 2
}
if ./$tfn ../../debian/rtchecks >rtchecks.out; then
set -- $(md5sum rtchecks.out)
test d5345290b8f3a343f6446710007d4e5a = "$1" || {
echo "Input:"
cat ../../debian/rtchecks
echo "Output:"
cat rtchecks.out
echo "Checks failed."
cd ../..
return
}
else
echo "Output:"
cat rtchecks.out
echo "Checks returned an error."
cd ../..
return
fi
fi
if test $firstbuilt = 1; then
echo "Got a binary, using first built."
buildinfo=firstbuilt
cd ../..
buildok=1
logbuildinfo $where
return
fi
echo "Running simple checks on the binary."
perl ../../check.pl -s ../../debian/mtest.t -p ./$tfn -v 2>&1 | \
tee mtest.log
if grep '^Total failed: 0$' mtest.log >/dev/null; then
echo "Simple tests okay."
else
echo "Simple tests failed."
cd ../..
return
fi
buildinfo=checked
if test $nocheck = 0; then
echo "Running mksh regression test suite."
if test x"$(uname -s)" = x"GNU"; then
# script(1) fails on Debian GNU/Hurd in pbuilder
if test -e ../../../attended; then
./test.sh -v
else
./test.sh -v -C regress:no-ctty
fi 2>&1 | tee utest.log
else
echo "This needs /dev/tty and /dev/ptmx in the chroot."
echo >test.wait
script -qc './test.sh -v 2>&1 | tee utest.log; x=$?; rm -f test.wait; exit $x'
maxwait=0
while test -e test.wait; do
sleep 1
maxwait=$(expr $maxwait + 1)
test $maxwait -lt 900 || break
done
fi
if grep '^pass .*:KSH_VERSION' utest.log >/dev/null 2>&1; then
echo "Regression test suite run."
else
echo "Regression tests apparently not run."
echo "Failing this build."
cd ../..
return
fi
buildinfo=regressed
resultest=$(grep -a '^[FPT]' utest.log 2>&1 | fgrep -a -v \
-e 'Testing mksh for conformance' \
-e 'This shell is actually')
fi
cd ../..
buildok=1
logbuildinfo $where
}
# --- main code ---
LC_ALL=C; export LC_ALL
topdir=$(pwd)
# get maximum of hardening flags
DEB_BUILD_MAINT_OPTIONS="hardening=+all"
export DEB_BUILD_MAINT_OPTIONS
# pull environment configuration
eval $(dpkg-architecture -s)
rm -rf builddir
mkdir builddir builddir/full builddir/static builddir/legacy
for where in legacy; do
cp debian/printf.c builddir/$where/
done
echo "Building the package 'mksh' on '$DEB_BUILD_ARCH' for '$DEB_HOST_ARCH'" \
"with DEB_BUILD_OPTIONS '$DEB_BUILD_OPTIONS'"
echo "Values (not used) from environment: CFLAGS='$CFLAGS' CPPFLAGS='$CPPFLAGS' LDFLAGS='$LDFLAGS'"
# parse options
nocheck=0
noopt=0
nodbg=0
firstbuilt=0
static=unset
small=1
if test x"$DEB_HOST_ARCH" = x"$DEB_BUILD_ARCH"; then
firstbuilt=0
iscross=0
else
echo Using first built binary because we are cross-compiling
echo "from $DEB_BUILD_GNU_TYPE to $DEB_HOST_GNU_TYPE here."
firstbuilt=1
iscross=1
fi
for i in $DEB_BUILD_OPTIONS; do
case $i in
(nocheck) nocheck=1 ;;
(noopt) noopt=1 ;;
(nodbg) nodbg=1 ;;
(mksh-firstbuilt) firstbuilt=1 ;;
(mksh-static=*) static=${i#*=} ;;
(nomksh-small) small=0 ;;
esac
done
# set default values for CC, CFLAGS, CPPFLAGS, LDFLAGS
case $iscross$CC in
0) dCC=gcc ;;
1) dCC=${DEB_HOST_GNU_TYPE}-gcc ;;
*) dCC=$CC ;;
esac
echo "Using compiler: '$dCC'"
if test $noopt = 1; then
x=-O0
else
x=-O2
fi
test $nodbg = 1 || x="$x -g"
dCFLAGS=$(dpkg-buildflags --get CFLAGS 2>/dev/null) || dCFLAGS=$x
dCPPFLAGS=$(dpkg-buildflags --get CPPFLAGS 2>/dev/null)
dLDFLAGS=$(dpkg-buildflags --get LDFLAGS 2>/dev/null)
echo "Values from dpkg-buildflags: CFLAGS='$dCFLAGS' CPPFLAGS='$dCPPFLAGS' LDFLAGS='$dLDFLAGS'"
dCFLAGS="$dCFLAGS -Wall -Wextra"
dLDFLAGS="$dLDFLAGS -Wl,--as-needed"
# Prevent the build system from adding this, as we provide it already
HAVE_CAN_WALL=0; export HAVE_CAN_WALL
# Debian #499139
dCPPFLAGS="$dCPPFLAGS -DMKSH_BINSHPOSIX -DMKSH_BINSHREDUCED"
# avoid needing a Build-Conflicts on libbsd-dev
HAVE_LIBUTIL_H=0; export HAVE_LIBUTIL_H
# avr32 currently has no locales
if test x"$DEB_HOST_ARCH" = x"avr32"; then
HAVE_SETLOCALE_CTYPE=0; export HAVE_SETLOCALE_CTYPE
fi
# set mksh-static default values if none given
if test x"$static" = x"unset"; then
static=glibc
case $firstbuilt$static:$DEB_HOST_ARCH in
(1*)
;;
(0*)
static=klibc,dietlibc,glibc
;;
esac
fi
# validate mksh-static arguments
static=$(echo x,"$static" | sed 's/^x,//' | tr , ' ')
for x in $static; do
case $x in
(klibc|dietlibc|glibc) ;;
(*)
echo "Error: invalid library '$x' in DEB_BUILD_OPTIONS"
exit 1
;;
esac
done
# create a locale if we are to run the testsuite
test x"$HAVE_SETLOCALE_CTYPE" != x"0" && if test $nocheck = 0; then
echo Creating locale for the regression tests
mkdir builddir/tloc
# cf. Debian #522776
localedef -i en_US -c -f UTF-8 builddir/tloc/en_US.UTF-8 || \
echo Warning: additional testsuite failures may be shown
LOCPATH=$topdir/builddir/tloc; export LOCPATH
fi
# build mksh-full
CC=$dCC
CFLAGS=$dCFLAGS
CPPFLAGS=$dCPPFLAGS
LDFLAGS=$dLDFLAGS
unset LDSTATIC
LIBS=
echo Building mksh-full...
trybuild full
if test $buildok = 0; then
echo Build of mksh-full failed.
exit 1
fi
bupkgs=
# no locale support in mksh-static or mksh-legacy needed
HAVE_SETLOCALE_CTYPE=0; export HAVE_SETLOCALE_CTYPE
# build mksh-static
sCC=$dCC
sCFLAGS=
# drop optimisation, debugging and PIC flags for mksh-static
for x in $dCFLAGS; do
case $x in
(-O*|-g*|-fPIE) ;;
(*) sCFLAGS="$sCFLAGS $x" ;;
esac
done
sCPPFLAGS=$dCPPFLAGS
sLDFLAGS=
for x in $dLDFLAGS; do
case $x in
(-pie|-fPIE) ;;
(*) sLDFLAGS="$sLDFLAGS $x" ;;
esac
done
sLIBS=
test $small = 0 || sCPPFLAGS="$sCPPFLAGS -DMKSH_SMALL"
buildok=0
for x in $static; do echo Building mksh-static with $x; case $x in
(klibc)
if test -z "$(which klcc 2>/dev/null)"; then
echo ... skipping, klcc not found
continue
fi
CC=klcc
CFLAGS="$sCFLAGS -fno-stack-protector -Os"
test $nodbg = 1 || CFLAGS="$CFLAGS -g"
CPPFLAGS="$sCPPFLAGS"
LDFLAGS="$sLDFLAGS"
LDSTATIC="-static"
LIBS=$sLIBS
HAVE_CAN_FSTACKPROTECTORSTRONG=0; export HAVE_CAN_FSTACKPROTECTORSTRONG
HAVE_CAN_FSTACKPROTECTORALL=0; export HAVE_CAN_FSTACKPROTECTORALL
trybuild static
unset HAVE_CAN_FSTACKPROTECTORSTRONG HAVE_CAN_FSTACKPROTECTORALL
# Collect gcc and klibc packages for Built-Using
if test $buildok = 1; then
x=$(dpkg -S "$(readlink -f "$($CC -print-libgcc-file-name)")")
bupkgs="$bupkgs ${x%%: *} libklibc-dev linux-libc-dev"
fi
;;
(dietlibc)
if test -z "$(which diet 2>/dev/null)"; then
echo ... skipping, diet not found
continue
fi
CC="diet -v -Os $sCC"
CFLAGS=$sCFLAGS
# debug builds are too fragile here, IIRC
CPPFLAGS=$sCPPFLAGS
LDFLAGS=$sLDFLAGS
LDSTATIC=" "
LIBS=$sLIBS
echo "Note: all warning: dereferencing pointer 'p' does break" \
"strict-aliasing rules come from dietlibc, not mksh!"
HAVE_CAN_FSTACKPROTECTORSTRONG=0; export HAVE_CAN_FSTACKPROTECTORSTRONG
HAVE_CAN_FSTACKPROTECTORALL=0; export HAVE_CAN_FSTACKPROTECTORALL
trybuild static
unset HAVE_CAN_FSTACKPROTECTORSTRONG HAVE_CAN_FSTACKPROTECTORALL
# Collect gcc and dietlibc packages for Built-Using
if test $buildok = 1; then
x=$(dpkg -S "$(readlink -f "$($CC -print-libgcc-file-name)")")
bupkgs="$bupkgs ${x%%: *} dietlibc-dev"
fi
;;
(glibc)
CC=$sCC
CFLAGS="-Os $sCFLAGS"
test $nodbg = 1 || CFLAGS="$CFLAGS -g"
CPPFLAGS=$sCPPFLAGS
LDFLAGS="$sLDFLAGS"
LDSTATIC="-static"
LIBS=$sLIBS
trybuild static
# Collect gcc and glibc packages for Built-Using
if test $buildok = 1; then
x=$(dpkg -S "$(readlink -f "$($CC -print-file-name=libgcc.a)")")
bupkgs="$bupkgs ${x%%: *}"
x=$(dpkg -S "$(readlink -f "$($CC -print-file-name=libc.a)")")
bupkgs="$bupkgs ${x%%: *}"
fi
;;
esac; test $buildok = 0 || break; done
if test $buildok = 0; then
echo Build of mksh-static failed.
exit 1
fi
# build mksh-legacy
lCC=$dCC
lCFLAGS=$dCFLAGS
lCPPFLAGS=$dCPPFLAGS
lLDFLAGS=$dLDFLAGS
lLIBS=
# Debian #532343, #539158
USE_PRINTF_BUILTIN=1; export USE_PRINTF_BUILTIN
buildok=0
for x in $static; do echo Building mksh-legacy with $x; case $x in
(klibc)
if test -z "$(which klcc 2>/dev/null)"; then
echo ... skipping, klcc not found
continue
fi
CC=klcc
CFLAGS=
for x in $lCFLAGS; do
case $x in
(-O*|-g*|-fPIE) ;;
(*) CFLAGS="$CFLAGS $x" ;;
esac
done
CFLAGS="$CFLAGS -fno-stack-protector -Os"
test $nodbg = 1 || CFLAGS="$CFLAGS -g"
CPPFLAGS="$lCPPFLAGS"
LDFLAGS=
for x in $lLDFLAGS; do
case $x in
(-pie|-fPIE) ;;
(*) LDFLAGS="$LDFLAGS $x" ;;
esac
done
LDSTATIC="-static"
LIBS=$lLIBS
HAVE_CAN_FSTACKPROTECTORSTRONG=0; export HAVE_CAN_FSTACKPROTECTORSTRONG
HAVE_CAN_FSTACKPROTECTORALL=0; export HAVE_CAN_FSTACKPROTECTORALL
trybuild legacy
unset HAVE_CAN_FSTACKPROTECTORSTRONG HAVE_CAN_FSTACKPROTECTORALL
# Collect gcc and klibc packages for Built-Using
if test $buildok = 1; then
x=$(dpkg -S "$(readlink -f "$($CC -print-libgcc-file-name)")")
bupkgs="$bupkgs ${x%%: *} libklibc-dev linux-libc-dev"
fi
;;
(dietlibc)
if test -z "$(which diet 2>/dev/null)"; then
echo ... skipping, diet not found
continue
fi
CC="diet -v -Os $lCC"
CFLAGS=
for x in $lCFLAGS; do
case $x in
(-O*|-g*|-fPIE) ;;
(*) CFLAGS="$CFLAGS $x" ;;
esac
done
# debug builds are too fragile here, IIRC
CPPFLAGS=$lCPPFLAGS
LDFLAGS=
for x in $lLDFLAGS; do
case $x in
(-pie|-fPIE) ;;
(*) LDFLAGS="$LDFLAGS $x" ;;
esac
done
LDSTATIC=" "
LIBS=$lLIBS
echo "Note: all warning: dereferencing pointer 'p' does break" \
"strict-aliasing rules come from dietlibc, not mksh!"
HAVE_CAN_FSTACKPROTECTORSTRONG=0; export HAVE_CAN_FSTACKPROTECTORSTRONG
HAVE_CAN_FSTACKPROTECTORALL=0; export HAVE_CAN_FSTACKPROTECTORALL
trybuild legacy
unset HAVE_CAN_FSTACKPROTECTORSTRONG HAVE_CAN_FSTACKPROTECTORALL
# Collect gcc and dietlibc packages for Built-Using
if test $buildok = 1; then
x=$(dpkg -S "$(readlink -f "$($CC -print-libgcc-file-name)")")
bupkgs="$bupkgs ${x%%: *} dietlibc-dev"
fi
;;
(glibc)
CC=$lCC
CFLAGS=$lCFLAGS
CPPFLAGS=$lCPPFLAGS
LDFLAGS=$lLDFLAGS
LDSTATIC=
LIBS=$lLIBS
trybuild legacy
;;
esac; test $buildok = 0 || break; done
if test $buildok = 0; then
echo Build of mksh-legacy failed.
exit 1
fi
echo Logging build information...
for x in $bupkgs; do
dpkg-query -Wf '${source:Package} (= ${source:Version})\n' "$x"
done | sort -u | {
buspkgs=
while IFS= read -r x; do
test -n "$x" || continue
test x"$x" = x" (= )" && continue
echo "Built Using: $x"
test -z "$buspkgs" || buspkgs="$buspkgs, "
buspkgs=$buspkgs$x
done
echo "mksh:B-U=$buspkgs" >builddir/substvars
}
pkgvsn=$(dpkg-parsechangelog -n1 | sed -n '/^Version: */s///p')
{
cat debian/README.Debian
echo Build information for mksh R${pkgvsn%-*}:
for v in DEB_BUILD_GNU_TYPE DEB_HOST_GNU_TYPE DEB_BUILD_OPTIONS; do
eval x=\$$v
echo "| $v='$x'"
done
echo Dependencies:
dpkg-query -W $(for wasn in ./usr/lib/libc.so ./usr/lib/*/libc.so \
linux-libc-dev locales .=diet .=klcc .=as .=ld .=strip; do
case $wasn in
(.=*) wasn=.$(which ${wasn#.=} 2>/dev/null) ;;
esac
case $wasn in
(./*)
for wasn in ${wasn#.}; do
test -e $wasn && dpkg -S $wasn | sed \
-e '/^diversion by/d' -e 's/: .*$//' \
-e 's/, /,/g' -e 'y/,/\n/'
done
;;
(.*) ;;
(*)
echo $wasn
;;
esac
done | sort -u) | column -t | sed 's/^/| /'
echo ----
cat builddir/buildinfo.full
echo ----
cat builddir/buildinfo.static
echo ----
cat builddir/buildinfo.legacy
echo ----
echo Version: $pkgvsn
date -R
} | gzip -n9 >builddir/README.Debian.gz
echo All builds complete.
exit 0
|