Skip to content

Commit 59040e5

Browse files
riastradhriastradh
authored andcommitted
build.sh: Experimental new target pkg=CATEGORY/PACKAGE.
Cross-builds a binary package of CATEGORY/PACKAGE from pkgsrc, bootstrapping pkgsrc as necessary for the cross-build. Requires pkgsrc, which can be specified by either: - setting PKGSRCDIR with -V or in the environment - having it at ./pkgsrc - having it at ../pkgsrc - having it at /usr/pkgsrc This isn't perfect -- it'd be better if we had some kind of manifest for the packages you want built and/or included in install images -- but I've been sitting on this for months; let's just give it a try and see where this goes. We can take it out again if the experiment turns out not to be fruitful. PR toolchain/58536: build.sh should support cross-building packages into images
1 parent f833854 commit 59040e5

File tree

1 file changed

+146
-2
lines changed

1 file changed

+146
-2
lines changed

build.sh

Lines changed: 146 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#! /usr/bin/env sh
2-
# $NetBSD: build.sh,v 1.379 2024/07/23 20:46:40 riastradh Exp $
2+
# $NetBSD: build.sh,v 1.380 2024/11/29 16:55:24 riastradh Exp $
33
#
44
# Copyright (c) 2001-2023 The NetBSD Foundation, Inc.
55
# All rights reserved.
@@ -557,6 +557,7 @@ level of source directory"
557557
do_sets=false
558558
do_sourcesets=false
559559
do_syspkgs=false
560+
do_pkg=false
560561
do_iso_image=false
561562
do_iso_image_source=false
562563
do_live_image=false
@@ -985,6 +986,18 @@ safe_unsetmakeenv()
985986
unsetmakeenv "$1"
986987
}
987988

989+
# Clear all variables defined in makeenv. Used to run a subprocess
990+
# outside the usual NetBSD build's make environment.
991+
#
992+
clearmakeenv()
993+
{
994+
local var
995+
996+
for var in ${makeenv}; do
997+
unset ${var}
998+
done
999+
}
1000+
9881001
# Given a variable name in $1, modify the variable in place as follows:
9891002
# For each space-separated word in the variable, call resolvepath.
9901003
#
@@ -1078,6 +1091,7 @@ help()
10781091
sourcesets Create source sets in RELEASEDIR/source/sets.
10791092
syspkgs Create syspkgs in
10801093
RELEASEDIR/RELEASEMACHINEDIR/binary/syspkgs.
1094+
pkg=CATEGORY/PKG (EXPERIMENT) Build a package CATEGORY/PKG from pkgsrc.
10811095
iso-image Create CD-ROM image in RELEASEDIR/images.
10821096
iso-image-source Create CD-ROM image with source in RELEASEDIR/images.
10831097
live-image Create bootable live image in
@@ -1433,6 +1447,13 @@ parseoptions()
14331447

14341448
;;
14351449

1450+
pkg=*)
1451+
arg=${op#*=}
1452+
op=${op%%=*}
1453+
[ -n "${arg}" ] ||
1454+
bomb "Must supply category/package with 'pkg=...'"
1455+
;;
1456+
14361457
install=*|installmodules=*)
14371458
arg=${op#*=}
14381459
op=${op%%=*}
@@ -1562,6 +1583,24 @@ sanitycheck()
15621583
done
15631584
bomb "Asked to build X11 but no xsrc"
15641585
done
1586+
1587+
while $do_pkg; do # not really a loop
1588+
test -n "${PKGSRCDIR}" && {
1589+
test -f "${PKGSRCDIR}/mk/bsd.pkg.mk" ||
1590+
bomb "PKGSRCDIR (${PKGSRCDIR}) does not exist"
1591+
break
1592+
}
1593+
for _pd in \
1594+
"${NETBSDSRCDIR%/*}/pkgsrc" \
1595+
"${NETBSDSRCDIR}/pkgsrc" \
1596+
/usr/pkgsrc
1597+
do
1598+
test -f "${_pd}/mk/bsd.pkg.mk" &&
1599+
setmakeenv PKGSRCDIR "${_pd}" &&
1600+
break 2
1601+
done
1602+
bomb "Asked to build package but no pkgsrc"
1603+
done
15651604
}
15661605

15671606
# print_tooldir_program --
@@ -2031,7 +2070,7 @@ createmakewrapper()
20312070
eval cat <<EOF ${makewrapout}
20322071
#! ${HOST_SH}
20332072
# Set proper variables to allow easy "make" building of a NetBSD subtree.
2034-
# Generated from: \$NetBSD: build.sh,v 1.379 2024/07/23 20:46:40 riastradh Exp $
2073+
# Generated from: \$NetBSD: build.sh,v 1.380 2024/11/29 16:55:24 riastradh Exp $
20352074
# with these arguments: ${_args}
20362075
#
20372076
@@ -2245,6 +2284,103 @@ builddtb()
22452284
statusmsg "Successful build of devicetree blobs for NetBSD/${MACHINE} ${DISTRIBVER}"
22462285
}
22472286

2287+
buildpkg()
2288+
{
2289+
local catpkg
2290+
local pkgroot
2291+
local makejobsarg
2292+
local makejobsvar
2293+
local quiet
2294+
local opsys_version
2295+
2296+
catpkg="$1"
2297+
2298+
pkgroot="${TOP_objdir:-${TOP}}/pkgroot"
2299+
${runcmd} mkdir -p "${pkgroot}" ||
2300+
bomb "Can't create package root" "${pkgroot}"
2301+
2302+
# Get a symlink-free absolute path to pkg -- pkgsrc wants this.
2303+
#
2304+
# XXX See TOP= above regarding pwd -P.
2305+
pkgroot=$(unset PWD; cd "${pkgroot}" &&
2306+
((exec pwd -P 2>/dev/null) || (exec pwd 2>/dev/null)))
2307+
2308+
case $parallel in
2309+
"-j "*)
2310+
makejobsarg="--make-jobs ${parallel#-j }"
2311+
makejobsvar="MAKE_JOBS=${parallel#-j }"
2312+
;;
2313+
*) makejobsarg=""
2314+
makejobsvar=""
2315+
;;
2316+
esac
2317+
2318+
if [ "${MAKEVERBOSE}" -eq 0 ]; then
2319+
quiet="--quiet"
2320+
else
2321+
quiet=""
2322+
fi
2323+
2324+
# Derived from pkgsrc/mk/bsd.prefs.mk rev. 1.451.
2325+
opsys_version=$(echo "${DISTRIBVER}" |
2326+
awk -F. '{major=int($1); minor=int($2); if (minor>=100) minor=99; patch=int($3); if (patch>=100) patch=99; printf "%02d%02d%02d", major, minor, patch}')
2327+
2328+
# Bootstrap pkgsrc if needed.
2329+
#
2330+
# XXX Redo this if it's out-of-date, not just if it's missing.
2331+
if ! [ -x "${pkgroot}/pkg/bin/bmake" ]; then
2332+
statusmsg "Bootstrapping pkgsrc"
2333+
2334+
cat >"${pkgroot}/mk.conf-fragment" <<EOF
2335+
USE_CROSS_COMPILE?= no
2336+
TOOLDIR= ${TOOLDIR}
2337+
CROSS_DESTDIR= ${DESTDIR}
2338+
CROSS_MACHINE_ARCH= ${MACHINE_ARCH}
2339+
CROSS_OPSYS= NetBSD
2340+
CROSS_OS_VERSION= ${DISTRIBVER}
2341+
CROSS_OPSYS_VERSION= ${opsys_version}
2342+
CROSS_LOWER_OPSYS= netbsd
2343+
CROSS_LOWER_OPSYS_VERSUFFIX= # empty
2344+
CROSS_LOWER_OS_VARIANT= # empty
2345+
CROSS_LOWER_VARIANT_VERSION= # empty
2346+
CROSS_LOWER_VENDOR= # empty
2347+
CROSS_OBJECT_FMT= ELF
2348+
2349+
ALLOW_VULNERABLE_PACKAGES= yes
2350+
BINPKG_SITES= # empty
2351+
FAILOVER_FETCH= yes
2352+
FETCH_TIMEOUT= 1800
2353+
PASSIVE_FETCH= yes
2354+
2355+
DISTDIR= ${pkgroot}/distfiles
2356+
PACKAGES= ${pkgroot}/packages
2357+
WRKOBJDIR= ${pkgroot}/work
2358+
2359+
.-include "${MAKECONF}"
2360+
2361+
MKDEBUG= no # interferes with pkgsrc builds
2362+
EOF
2363+
2364+
# XXX Set --abi for mips and whatever else needs it?
2365+
# XXX Unprivileged native tools, privileged cross.
2366+
(cd "${PKGSRCDIR}" && clearmakeenv && ./bootstrap/bootstrap \
2367+
${makejobsarg} \
2368+
--mk-fragment "${pkgroot}/mk.conf-fragment" \
2369+
--prefix "${pkgroot}/pkg" \
2370+
${quiet} \
2371+
--unprivileged \
2372+
--workdir "${pkgroot}/bootwork") \
2373+
|| bomb "Failed to bootstrap pkgsrc"
2374+
fi
2375+
2376+
# Build the package.
2377+
(cd "${PKGSRCDIR}/${catpkg}" && clearmakeenv && \
2378+
"${pkgroot}/pkg/bin/bmake" package \
2379+
USE_CROSS_COMPILE=yes \
2380+
${makejobsvar}) \
2381+
|| bomb "Failed to build ${catpkg}"
2382+
}
2383+
22482384
installmodules()
22492385
{
22502386
dir="$1"
@@ -2562,6 +2698,14 @@ main()
25622698
buildmodules
25632699
;;
25642700

2701+
pkg=*)
2702+
arg=${op#*=}
2703+
if ! [ -d "$PKGSRCDIR"/"$arg" ]; then
2704+
bomb "no such package ${arg}"
2705+
fi
2706+
buildpkg "${arg}"
2707+
;;
2708+
25652709
installmodules=*)
25662710
arg=${op#*=}
25672711
if [ "${arg}" = "/" ] && \

0 commit comments

Comments
 (0)