]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/release.sh
release: permanently remove the 'reldoc' target and associates
[FreeBSD/FreeBSD.git] / release / release.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2013-2018 The FreeBSD Foundation
4 # Copyright (c) 2013 Glen Barber
5 # Copyright (c) 2011 Nathan Whitehorn
6 # All rights reserved.
7 #
8 # Portions of this software were developed by Glen Barber
9 # under sponsorship from the FreeBSD Foundation.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 #    notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 #    notice, this list of conditions and the following disclaimer in the
18 #    documentation and/or other materials provided with the distribution.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 # SUCH DAMAGE.
31 #
32 # release.sh: check out source trees, and build release components with
33 #  totally clean, fresh trees.
34 # Based on release/generate-release.sh written by Nathan Whitehorn
35 #
36 # $FreeBSD$
37 #
38
39 export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
40
41 VERSION=2
42
43 # Prototypes that can be redefined per-chroot or per-target.
44 load_chroot_env() { }
45 load_target_env() { }
46 buildenv_setup() { }
47
48 usage() {
49         echo "Usage: $0 [-c release.conf]"
50         exit 1
51 }
52
53 # env_setup(): Set up the default build environment variables, such as the
54 # CHROOTDIR, VCSCMD, SVNROOT, etc.  This is called before the release.conf
55 # file is sourced, if '-c <release.conf>' is specified.
56 env_setup() {
57         # The directory within which the release will be built.
58         CHROOTDIR="/scratch"
59         RELENGDIR="$(dirname $(realpath ${0}))"
60
61         # The default version control system command to obtain the sources.
62         for _dir in /usr/bin /usr/local/bin; do
63                 for _svn in svn svnlite; do
64                         [ -x "${_dir}/${_svn}" ] && VCSCMD="${_dir}/${_svn}"
65                         [ ! -z "${VCSCMD}" ] && break 2
66                 done
67         done
68         VCSCMD="${VCSCMD} checkout"
69
70         # The default svn checkout server, and svn branches for src/, doc/,
71         # and ports/.
72         SVNROOT="svn://svn.FreeBSD.org/"
73         SRCBRANCH="base/stable/12@rHEAD"
74         PORTBRANCH="main"
75         GITROOT="https://git.FreeBSD.org/"
76         GITPORTS="ports.git"
77
78         # Set for embedded device builds.
79         EMBEDDEDBUILD=
80
81         # Sometimes one needs to checkout src with --force svn option.
82         # If custom kernel configs copied to src tree before checkout, e.g.
83         SRC_FORCE_CHECKOUT=
84
85         # The default make.conf and src.conf to use.  Set to /dev/null
86         # by default to avoid polluting the chroot(8) environment with
87         # non-default settings.
88         MAKE_CONF="/dev/null"
89         SRC_CONF="/dev/null"
90
91         # The number of make(1) jobs, defaults to the number of CPUs available
92         # for buildworld, and half of number of CPUs available for buildkernel.
93         WORLD_FLAGS="-j$(sysctl -n hw.ncpu)"
94         KERNEL_FLAGS="-j$(( $(( $(sysctl -n hw.ncpu) + 1 )) / 2))"
95
96         MAKE_FLAGS="-s"
97
98         # The name of the kernel to build, defaults to GENERIC.
99         KERNEL="GENERIC"
100
101         # Set to non-empty value to disable checkout of doc/ and/or ports/.
102         NOPORTS=
103
104         # Set to non-empty value to disable distributing source tree.
105         NOSRC=
106
107         # Set to non-empty value to build dvd1.iso as part of the release.
108         WITH_DVD=
109         WITH_COMPRESSED_IMAGES=
110
111         # Set to non-empty value to build virtual machine images as part of
112         # the release.
113         WITH_VMIMAGES=
114         WITH_COMPRESSED_VMIMAGES=
115         XZ_THREADS=0
116
117         # Set to non-empty value to build virtual machine images for various
118         # cloud providers as part of the release.
119         WITH_CLOUDWARE=
120
121         return 0
122 } # env_setup()
123
124 # env_check(): Perform sanity tests on the build environment, such as ensuring
125 # files/directories exist, as well as adding backwards-compatibility hacks if
126 # necessary.  This is called unconditionally, and overrides the defaults set
127 # in env_setup() if '-c <release.conf>' is specified.
128 env_check() {
129         chroot_build_release_cmd="chroot_build_release"
130         # Fix for backwards-compatibility with release.conf that does not have
131         # the trailing '/'.
132         case ${SVNROOT} in
133                 *svn*)
134                         SVNROOT="${SVNROOT}/"
135                         ;;
136                 *)
137                         ;;
138         esac
139
140         # Prefix the branches with the SVNROOT for the full checkout URL.
141         SRCBRANCH="${SVNROOT}${SRCBRANCH}"
142         # Prefix the branches with the GITROOT for the full checkout URL.
143         PORT="${GITROOT}${GITPORTS}"
144
145         if [ -n "${EMBEDDEDBUILD}" ]; then
146                 WITH_DVD=
147                 WITH_COMPRESSED_IMAGES=
148                 case ${EMBEDDED_TARGET}:${EMBEDDED_TARGET_ARCH} in
149                         arm:arm*|arm64:aarch64)
150                                 chroot_build_release_cmd="chroot_arm_build_release"
151                                 ;;
152                         *)
153                                 ;;
154                 esac
155         fi
156
157         # If NOSRC and/or NOPORTS are unset, they must not pass to make
158         # as variables.  The release makefile verifies definedness of the
159         # NOPORTS variable instead of its value.
160         SRCPORTS=
161         if [ -n "${NOPORTS}" ]; then
162                 SRCPORTS="NOPORTS=yes"
163         fi
164         if [ -n "${NOSRC}" ]; then
165                 SRCPORTS="${SRCPORTS}${SRCPORTS:+ }NOSRC=yes"
166         fi
167
168         # The aggregated build-time flags based upon variables defined within
169         # this file, unless overridden by release.conf.  In most cases, these
170         # will not need to be changed.
171         CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
172         if [ -n "${TARGET}" ] && [ -n "${TARGET_ARCH}" ]; then
173                 ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
174         else
175                 ARCH_FLAGS=
176         fi
177         # Force src checkout if configured
178         FORCE_SRC_KEY=
179         if [ -n "${SRC_FORCE_CHECKOUT}" ]; then
180                 FORCE_SRC_KEY="--force"
181         fi
182
183         if [ -z "${CHROOTDIR}" ]; then
184                 echo "Please set CHROOTDIR."
185                 exit 1
186         fi
187
188         if [ $(id -u) -ne 0 ]; then
189                 echo "Needs to be run as root."
190                 exit 1
191         fi
192
193         # Unset CHROOTBUILD_SKIP if the chroot(8) does not appear to exist.
194         if [ ! -z "${CHROOTBUILD_SKIP}" -a ! -e ${CHROOTDIR}/bin/sh ]; then
195                 CHROOTBUILD_SKIP=
196         fi
197
198         CHROOT_MAKEENV="${CHROOT_MAKEENV} \
199                 MAKEOBJDIRPREFIX=${CHROOTDIR}/tmp/obj"
200         CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
201         CHROOT_IMAKEFLAGS="${WORLD_FLAGS} ${CONF_FILES}"
202         CHROOT_DMAKEFLAGS="${WORLD_FLAGS} ${CONF_FILES}"
203         RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} \
204                 ${CONF_FILES}"
205         RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} \
206                 KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}"
207         RELEASE_RMAKEFLAGS="${ARCH_FLAGS} \
208                 KERNCONF=\"${KERNEL}\" ${CONF_FILES} ${SRCPORTS} \
209                 WITH_DVD=${WITH_DVD} WITH_VMIMAGES=${WITH_VMIMAGES} \
210                 WITH_CLOUDWARE=${WITH_CLOUDWARE} XZ_THREADS=${XZ_THREADS}"
211
212         return 0
213 } # env_check()
214
215 # chroot_setup(): Prepare the build chroot environment for the release build.
216 chroot_setup() {
217         load_chroot_env
218         mkdir -p ${CHROOTDIR}/usr
219
220         if [ -z "${SRC_UPDATE_SKIP}" ]; then
221                 ${VCSCMD} ${FORCE_SRC_KEY} ${SRCBRANCH} ${CHROOTDIR}/usr/src
222         fi
223         if [ -z "${NOPORTS}" ] && [ -z "${PORTS_UPDATE_SKIP}" ]; then
224                 ${VCSCMD} ${PORTBRANCH} ${CHROOTDIR}/usr/ports
225         fi
226
227         if [ -z "${CHROOTBUILD_SKIP}" ]; then
228                 cd ${CHROOTDIR}/usr/src
229                 env ${CHROOT_MAKEENV} make ${CHROOT_WMAKEFLAGS} buildworld
230                 env ${CHROOT_MAKEENV} make ${CHROOT_IMAKEFLAGS} installworld \
231                         DESTDIR=${CHROOTDIR}
232                 env ${CHROOT_MAKEENV} make ${CHROOT_DMAKEFLAGS} distribution \
233                         DESTDIR=${CHROOTDIR}
234         fi
235
236         return 0
237 } # chroot_setup()
238
239 # extra_chroot_setup(): Prepare anything additional within the build
240 # necessary for the release build.
241 extra_chroot_setup() {
242         mkdir -p ${CHROOTDIR}/dev
243         mount -t devfs devfs ${CHROOTDIR}/dev
244         [ -e /etc/resolv.conf -a ! -e ${CHROOTDIR}/etc/resolv.conf ] && \
245                 cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
246         # Run ldconfig(8) in the chroot directory so /var/run/ld-elf*.so.hints
247         # is created.  This is needed by ports-mgmt/pkg.
248         eval chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart
249
250         # If MAKE_CONF and/or SRC_CONF are set and not character devices
251         # (/dev/null), copy them to the chroot.
252         if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then
253                 mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF})
254                 cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF}
255         fi
256         if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then
257                 mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF})
258                 cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF}
259         fi
260
261         if [ -z "${NOGIT}" ]; then
262                 # Install git from ports or packages if the ports tree is
263                 # available and VCSCMD is unset.
264                 _gitcmd="$(which git)"
265                 if [ -d ${CHROOTDIR}/usr/ports -a -z "${_gitcmd}" ]; then
266                         # Trick the ports 'run-autotools-fixup' target to do the right
267                         # thing.
268                         _OSVERSION=$(chroot ${CHROOTDIR} /usr/bin/uname -U)
269                         REVISION=$(chroot ${CHROOTDIR} make -C /usr/src/release -V REVISION)
270                         BRANCH=$(chroot ${CHROOTDIR} make -C /usr/src/release -V BRANCH)
271                         UNAME_r=${REVISION}-${BRANCH}
272                         GITUNSETOPTS="CONTRIB CURL CVS GITWEB GUI HTMLDOCS"
273                         GITUNSETOPTS="${GITUNSETOPTS} ICONV NLS P4 PERL"
274                         GITUNSETOPTS="${GITUNSETOPTS} SEND_EMAIL SUBTREE SVN"
275                         GITUNSETOPTS="${GITUNSETOPTS} PCRE PCRE2"
276                         PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes"
277                         PBUILD_FLAGS="${PBUILD_FLAGS} UNAME_r=${UNAME_r}"
278                         PBUILD_FLAGS="${PBUILD_FLAGS} OSREL=${REVISION}"
279                         PBUILD_FLAGS="${PBUILD_FLAGS} WRKDIRPREFIX=/tmp/ports"
280                         PBUILD_FLAGS="${PBUILD_FLAGS} DISTDIR=/tmp/distfiles"
281                         eval chroot ${CHROOTDIR} env OPTIONS_UNSET=\"${GITUNSETOPTS}\" \
282                                 ${PBUILD_FLAGS} \
283                                 make -C /usr/ports/devel/git FORCE_PKG_REGISTER=1 \
284                                 WRKDIRPREFIX=/tmp/ports \
285                                 DISTDIR=/tmp/distfiles \
286                                 install clean distclean
287                 else
288                         eval chroot ${CHROOTDIR} env ASSUME_ALWAYS_YES=yes \
289                                 pkg install -y devel/git
290                         eval chroot ${CHROOTDIR} env ASSUME_ALWAYS_YES=yes \
291                                 pkg clean -y
292                 fi
293         fi
294
295         if [ ! -z "${EMBEDDEDPORTS}" ]; then
296                 _OSVERSION=$(chroot ${CHROOTDIR} /usr/bin/uname -U)
297                 REVISION=$(chroot ${CHROOTDIR} make -C /usr/src/release -V REVISION)
298                 BRANCH=$(chroot ${CHROOTDIR} make -C /usr/src/release -V BRANCH)
299                 PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes"
300                 PBUILD_FLAGS="${PBUILD_FLAGS} UNAME_r=${UNAME_r}"
301                 PBUILD_FLAGS="${PBUILD_FLAGS} OSREL=${REVISION}"
302                 PBUILD_FLAGS="${PBUILD_FLAGS} WRKDIRPREFIX=/tmp/ports"
303                 PBUILD_FLAGS="${PBUILD_FLAGS} DISTDIR=/tmp/distfiles"
304                 for _PORT in ${EMBEDDEDPORTS}; do
305                         eval chroot ${CHROOTDIR} env ${PBUILD_FLAGS} make -C \
306                                 /usr/ports/${_PORT} \
307                                 FORCE_PKG_REGISTER=1 deinstall install clean distclean
308                 done
309         fi
310
311         buildenv_setup
312
313         return 0
314 } # extra_chroot_setup()
315
316 # chroot_build_target(): Build the userland and kernel for the build target.
317 chroot_build_target() {
318         load_target_env
319         if [ ! -z "${EMBEDDEDBUILD}" ]; then
320                 RELEASE_WMAKEFLAGS="${RELEASE_WMAKEFLAGS} \
321                         TARGET=${EMBEDDED_TARGET} \
322                         TARGET_ARCH=${EMBEDDED_TARGET_ARCH}"
323                 RELEASE_KMAKEFLAGS="${RELEASE_KMAKEFLAGS} \
324                         TARGET=${EMBEDDED_TARGET} \
325                         TARGET_ARCH=${EMBEDDED_TARGET_ARCH}"
326         fi
327         eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
328         eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
329
330         return 0
331 } # chroot_build_target
332
333 # chroot_build_release(): Invoke the 'make release' target.
334 chroot_build_release() {
335         load_target_env
336         if [ ! -z "${WITH_VMIMAGES}" ]; then
337                 if [ -z "${VMFORMATS}" ]; then
338                         VMFORMATS="$(eval chroot ${CHROOTDIR} \
339                                 make -C /usr/src/release -V VMFORMATS)"
340                 fi
341                 if [ -z "${VMSIZE}" ]; then
342                         VMSIZE="$(eval chroot ${CHROOTDIR} \
343                                 make -C /usr/src/release -V VMSIZE)"
344                 fi
345                 RELEASE_RMAKEFLAGS="${RELEASE_RMAKEFLAGS} \
346                         VMFORMATS=\"${VMFORMATS}\" VMSIZE=${VMSIZE}"
347         fi
348         eval chroot ${CHROOTDIR} make -C /usr/src/release \
349                 ${RELEASE_RMAKEFLAGS} release
350         eval chroot ${CHROOTDIR} make -C /usr/src/release \
351                 ${RELEASE_RMAKEFLAGS} install DESTDIR=/R \
352                 WITH_COMPRESSED_IMAGES=${WITH_COMPRESSED_IMAGES} \
353                 WITH_COMPRESSED_VMIMAGES=${WITH_COMPRESSED_VMIMAGES}
354
355         return 0
356 } # chroot_build_release()
357
358 efi_boot_name()
359 {
360         case $1 in
361                 arm)
362                         echo "bootarm.efi"
363                         ;;
364                 arm64)
365                         echo "bootaa64.efi"
366                         ;;
367                 amd64)
368                         echo "bootx64.efi"
369                         ;;
370         esac
371 }
372
373 # chroot_arm_build_release(): Create arm SD card image.
374 chroot_arm_build_release() {
375         load_target_env
376         case ${EMBEDDED_TARGET} in
377                 arm|arm64)
378                         if [ -e "${RELENGDIR}/tools/arm.subr" ]; then
379                                 . "${RELENGDIR}/tools/arm.subr"
380                         fi
381                         ;;
382                 *)
383                         ;;
384         esac
385         [ ! -z "${RELEASECONF}" ] && . "${RELEASECONF}"
386         export MAKE_FLAGS="${MAKE_FLAGS} TARGET=${EMBEDDED_TARGET}"
387         export MAKE_FLAGS="${MAKE_FLAGS} TARGET_ARCH=${EMBEDDED_TARGET_ARCH}"
388         export MAKE_FLAGS="${MAKE_FLAGS} ${CONF_FILES}"
389         eval chroot ${CHROOTDIR} env WITH_UNIFIED_OBJDIR=1 make ${MAKE_FLAGS} -C /usr/src/release obj
390         export WORLDDIR="$(eval chroot ${CHROOTDIR} make ${MAKE_FLAGS} -C /usr/src/release -V WORLDDIR)"
391         export OBJDIR="$(eval chroot ${CHROOTDIR} env WITH_UNIFIED_OBJDIR=1 make ${MAKE_FLAGS} -C /usr/src/release -V .OBJDIR)"
392         export DESTDIR="${OBJDIR}/${KERNEL}"
393         export IMGBASE="${CHROOTDIR}/${OBJDIR}/${BOARDNAME}.img"
394         export OSRELEASE="$(eval chroot ${CHROOTDIR} make ${MAKE_FLAGS} -C /usr/src/release \
395                 TARGET=${EMBEDDED_TARGET} TARGET_ARCH=${EMBEDDED_TARGET_ARCH} \
396                 -V OSRELEASE)"
397         chroot ${CHROOTDIR} mkdir -p ${DESTDIR}
398         chroot ${CHROOTDIR} truncate -s ${IMAGE_SIZE} ${IMGBASE##${CHROOTDIR}}
399         export mddev=$(chroot ${CHROOTDIR} \
400                 mdconfig -f ${IMGBASE##${CHROOTDIR}} ${MD_ARGS})
401         arm_create_disk
402         arm_install_base
403         arm_install_boot
404         arm_install_uboot
405         mdconfig -d -u ${mddev}
406         chroot ${CHROOTDIR} rmdir ${DESTDIR}
407         mv ${IMGBASE} ${CHROOTDIR}/${OBJDIR}/${OSRELEASE}-${BOARDNAME}.img
408         chroot ${CHROOTDIR} mkdir -p /R
409         chroot ${CHROOTDIR} cp -p ${OBJDIR}/${OSRELEASE}-${BOARDNAME}.img \
410                 /R/${OSRELEASE}-${BOARDNAME}.img
411         chroot ${CHROOTDIR} xz -T ${XZ_THREADS} /R/${OSRELEASE}-${BOARDNAME}.img
412         cd ${CHROOTDIR}/R && sha512 ${OSRELEASE}* \
413                 > CHECKSUM.SHA512
414         cd ${CHROOTDIR}/R && sha256 ${OSRELEASE}* \
415                 > CHECKSUM.SHA256
416
417         return 0
418 } # chroot_arm_build_release()
419
420 # main(): Start here.
421 main() {
422         set -e # Everything must succeed
423         env_setup
424         while getopts c: opt; do
425                 case ${opt} in
426                         c)
427                                 RELEASECONF="$(realpath ${OPTARG})"
428                                 ;;
429                         \?)
430                                 usage
431                                 ;;
432                 esac
433         done
434         shift $(($OPTIND - 1))
435         if [ ! -z "${RELEASECONF}" ]; then
436                 if [ -e "${RELEASECONF}" ]; then
437                         . ${RELEASECONF}
438                 else
439                         echo "Nonexistent configuration file: ${RELEASECONF}"
440                         echo "Using default build environment."
441                 fi
442         fi
443         env_check
444         trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
445         chroot_setup
446         extra_chroot_setup
447         chroot_build_target
448         ${chroot_build_release_cmd}
449
450         return 0
451 } # main()
452
453 main "${@}"