regpkgset revision 1.19 1 1.1 agc #! /bin/sh
2 1.1 agc #
3 1.19 nia # $NetBSD: regpkgset,v 1.19 2024/04/22 14:41:25 nia Exp $
4 1.1 agc #
5 1.11 agc # Copyright (c) 2003,2009 The NetBSD Foundation, Inc.
6 1.11 agc # All rights reserved.
7 1.11 agc #
8 1.11 agc # This code is derived from software contributed to The NetBSD Foundation
9 1.11 agc # by Alistair Crooks (agc (at] NetBSD.org)
10 1.1 agc #
11 1.1 agc # Redistribution and use in source and binary forms, with or without
12 1.1 agc # modification, are permitted provided that the following conditions
13 1.1 agc # are met:
14 1.1 agc # 1. Redistributions of source code must retain the above copyright
15 1.1 agc # notice, this list of conditions and the following disclaimer.
16 1.1 agc # 2. Redistributions in binary form must reproduce the above copyright
17 1.1 agc # notice, this list of conditions and the following disclaimer in the
18 1.1 agc # documentation and/or other materials provided with the distribution.
19 1.11 agc #
20 1.11 agc # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.11 agc # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.11 agc # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.11 agc # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.11 agc # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.11 agc # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.11 agc # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.11 agc # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.11 agc # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.11 agc # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.11 agc # POSSIBILITY OF SUCH DAMAGE.
31 1.1 agc #
32 1.1 agc
33 1.6 apb # Usage: regpkgset [options] set
34 1.6 apb #
35 1.6 apb # Options:
36 1.6 apb # -q Quiet.
37 1.6 apb # -v Verbose.
38 1.6 apb # -f Force.
39 1.6 apb # -m Ignore errors from missing files.
40 1.6 apb # -u Update.
41 1.6 apb # -c Cache some information in ${BUILD_INFO_CACHE}.
42 1.6 apb # -d destdir Sets DESTDIR.
43 1.6 apb # -t binpkgdir Create a binary package (in *.tgz format) in the
44 1.6 apb # specified directory. Without this option, a binary
45 1.6 apb # package is not created.
46 1.6 apb # -M metalog Use the specified metalog file to override file
47 1.6 apb # or directory attributes when creating a binary package.
48 1.6 apb # -N etcdir Use the specified directory for passwd and group files.
49 1.1 agc
50 1.6 apb prog="${0##*/}"
51 1.6 apb toppid=$$
52 1.5 apb rundir="$(dirname "$0")" # ${0%/*} isn't good enough when there's no "/"
53 1.6 apb . "${rundir}/sets.subr"
54 1.6 apb
55 1.8 apb : ${TARGET_ENDIANNESS:="$(arch_to_endian "${MACHINE_ARCH}")"}
56 1.7 apb export TARGET_ENDIANNESS
57 1.7 apb
58 1.6 apb bomb()
59 1.6 apb {
60 1.6 apb kill ${toppid} # in case we were invoked from a subshell
61 1.6 apb exit 1
62 1.6 apb }
63 1.3 erh
64 1.6 apb # A literal newline
65 1.6 apb nl='
66 1.6 apb '
67 1.1 agc
68 1.6 apb #
69 1.6 apb # cleanup() deletes temporary files.
70 1.6 apb #
71 1.6 apb es=0
72 1.8 apb cleanup()
73 1.6 apb {
74 1.6 apb trap - 0
75 1.6 apb [ x"${BUILD_INFO_CACHE}" != x ] && rm -f "${BUILD_INFO_CACHE}"
76 1.6 apb exit ${es}
77 1.6 apb }
78 1.6 apb trap 'es=128; cleanup' 1 2 3 13 15 # HUP INT QUIT PIPE TERM
79 1.6 apb trap 'es=$?; cleanup' 0 # EXIT
80 1.6 apb
81 1.6 apb #
82 1.6 apb # Parse command line args.
83 1.6 apb #
84 1.6 apb verbose=false
85 1.6 apb quiet=false
86 1.6 apb force=false
87 1.6 apb allowmissing=false
88 1.6 apb update=false
89 1.6 apb cache=false
90 1.6 apb pkgdir=""
91 1.6 apb metalog=""
92 1.6 apb etcdir=""
93 1.6 apb all_options=""
94 1.1 agc while [ $# -gt 1 ]; do
95 1.6 apb # XXX: ${all_options} doesn't correctly handle args with
96 1.6 apb # embedded shell special characters.
97 1.5 apb case "$1" in
98 1.8 apb -q) quiet=true; verbose=false ;;
99 1.8 apb -v) verbose=true; quiet=false ;;
100 1.6 apb -f) force=true ;;
101 1.6 apb -m) allowmissing=true ;;
102 1.6 apb -u) update=true ;;
103 1.6 apb -c) cache=true ;;
104 1.8 apb -d) DESTDIR="$2"; all_options="${all_options} $1"; shift ;;
105 1.6 apb -d*) DESTDIR="${1#-?}" ;;
106 1.8 apb -t) pkgdir="$2"; all_options="${all_options} $1"; shift ;;
107 1.6 apb -t*) pkgdir="${1#-?}" ;;
108 1.8 apb -M) metalog="$2"; all_options="${all_options} $1"; shift ;;
109 1.6 apb -M*) metalog="${1#-?}" ;;
110 1.8 apb -N) etcdir="$2"; all_options="${all_options} $1"; shift ;;
111 1.6 apb -N*) etcdir="${1#-?}" ;;
112 1.8 apb -*) echo "Usage: regpkgset [options] set ..."; bomb ;;
113 1.1 agc *) break ;;
114 1.1 agc esac
115 1.6 apb all_options="${all_options} $1"
116 1.1 agc shift
117 1.1 agc done
118 1.6 apb export DESTDIR
119 1.1 agc
120 1.1 agc if [ $# -lt 1 ]; then
121 1.6 apb echo "Usage: regpkgset [options] set ..."
122 1.6 apb bomb
123 1.1 agc fi
124 1.1 agc
125 1.5 apb case "$1" in
126 1.19 nia all) list="base base32 base64 comp dtb etc games gpufw man manhtml misc modules rescue tests text xbase xcomp xetc xfont xserver" ;;
127 1.5 apb *) list="$*" ;;
128 1.1 agc esac
129 1.1 agc
130 1.8 apb if ${cache}; then
131 1.6 apb BUILD_INFO_CACHE="$(${MKTEMP} "/var/tmp/${prog}-BUILD_INFO.XXXXXX")"
132 1.2 dyoung export BUILD_INFO_CACHE
133 1.2 dyoung {
134 1.6 apb # These variables describe the build
135 1.6 apb # environment, not the target.
136 1.5 apb echo "OPSYS=$(${UNAME} -s)"
137 1.5 apb echo "OS_VERSION=$(${UNAME} -r)"
138 1.9 apb ${MAKE} -B -f- all <<EOF
139 1.2 dyoung .include <bsd.own.mk>
140 1.2 dyoung all:
141 1.2 dyoung @echo OBJECT_FMT=${OBJECT_FMT}
142 1.2 dyoung @echo MACHINE_ARCH=${MACHINE_ARCH}
143 1.2 dyoung @echo MACHINE_GNU_ARCH=${MACHINE_GNU_ARCH}
144 1.2 dyoung EOF
145 1.5 apb } > "${BUILD_INFO_CACHE}"
146 1.2 dyoung fi
147 1.2 dyoung
148 1.6 apb #
149 1.6 apb # For each pkgset mentioned in ${list}, get a list of all pkgs in the pkgset.
150 1.6 apb #
151 1.6 apb # Sort all the pkgs into dependency order (with prerequisite pkgs before
152 1.6 apb # pkgs that depend on them).
153 1.6 apb #
154 1.6 apb # Invoke ${rundir}/regpkg for each pkg, taking care to do it in dependency
155 1.6 apb # order. If there were any pkgs for which we failed to find dependency
156 1.6 apb # information, handle them at the end.
157 1.6 apb #
158 1.8 apb pkgs="$(for pkgset in ${list}; do
159 1.6 apb ${HOST_SH} "${rundir}/listpkgs" "${pkgset}" || bomb
160 1.8 apb done)"
161 1.8 apb tsort_input="$(${AWK} '{print $2 " " $1}' <"${rundir}/deps" || bomb)"
162 1.8 apb tsort_output="$(echo "${tsort_input}" | ${TSORT} || bomb)"
163 1.8 apb for pkg in ${tsort_output}; do
164 1.6 apb case "${nl}${pkgs}${nl}" in
165 1.6 apb *"${nl}${pkg}${nl}"*)
166 1.6 apb # We want this pkg.
167 1.6 apb pkgset="${pkg%%-*}"
168 1.6 apb ${verbose} && echo "${prog}: registering ${pkg}"
169 1.6 apb ${HOST_SH} "${rundir}/regpkg" ${all_options} \
170 1.6 apb "${pkgset}" "${pkg}" || bomb
171 1.6 apb ;;
172 1.6 apb *) # pkg is mentioned in ${tsort_output} but not in ${pkgs}.
173 1.6 apb # We do not want this pkg.
174 1.6 apb ;;
175 1.6 apb esac
176 1.6 apb done
177 1.8 apb for pkg in ${pkgs}; do
178 1.6 apb case "${nl}${tsort_output}${nl}" in
179 1.6 apb *"${nl}${pkg}${nl}"*)
180 1.6 apb # pkg was in the tsort output, so it would have been
181 1.6 apb # handled above.
182 1.6 apb ;;
183 1.6 apb *) # This pkg was not in the tsort output.
184 1.6 apb # This is probably an error, but process the
185 1.6 apb # pkg anyway.
186 1.6 apb echo >&2 "${prog}: WARNING: ${pkg} is not mentioned in deps file"
187 1.6 apb pkgset="${pkg%%-*}"
188 1.6 apb ${verbose} && echo "${prog}: registering ${pkg}"
189 1.6 apb ${HOST_SH} "${rundir}/regpkg" ${all_options} \
190 1.6 apb "${pkgset}" "${pkg}" || bomb
191 1.6 apb ;;
192 1.6 apb esac
193 1.1 agc done
194 1.1 agc
195 1.1 agc exit 0
196