3 # Copyright (c) 2013 Glen Barber
4 # Copyright (c) 2011 Nathan Whitehorn
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # release.sh: check out source trees, and build release components with
29 # totally clean, fresh trees.
30 # Based on release/generate-release.sh written by Nathan Whitehorn
35 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
38 # The directory within which the release will be built.
41 # The default svn checkout server, and svn branches for src/, doc/,
43 SVNROOT="svn://svn.freebsd.org"
46 PORTBRANCH="ports/head"
48 # Sometimes one needs to checkout src with --force svn option.
49 # If custom kernel configs copied to src tree before checkout, e.g.
52 # The default src/, doc/, and ports/ revisions.
57 # The default make.conf and src.conf to use. Set to /dev/null
58 # by default to avoid polluting the chroot(8) environment with
59 # non-default settings.
63 # The number of make(1) jobs, defaults to the number of CPUs available for
64 # buildworld, and half of number of CPUs available for buildkernel.
65 WORLD_FLAGS="-j$(sysctl -n hw.ncpu)"
66 KERNEL_FLAGS="-j$(expr $(sysctl -n hw.ncpu) / 2)"
69 # The name of the kernel to build, defaults to GENERIC.
72 # The TARGET and TARGET_ARCH to build, defaults to the running system.
74 TARGET_ARCH="${TARGET}"
76 # Set to non-empty value to disable checkout of doc/ and/or ports/. Disabling
77 # ports/ checkout also forces NODOC to be set.
82 # Set up the OSVERSION, BRANCH, and REVISION based on the src/ tree
84 OSVERSION=$(grep '#define __FreeBSD_version' ${CHROOTDIR}/usr/src/sys/sys/param.h | awk '{print $3}')
85 BRANCH=$(grep '^BRANCH=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
86 | awk -F\= '{print $2}' | sed -e 's,",,g')
87 REVISION=$(grep '^REVISION=' ${CHROOTDIR}/usr/src/sys/conf/newvers.sh \
88 | awk -F\= '{print $2}' | sed -e 's,",,g')
89 OSRELEASE="${REVISION}-${BRANCH}"
93 echo "Usage: $0 [-c release.conf]"
97 while getopts c: opt; do
100 RELEASECONF="${OPTARG}"
101 if [ ! -e "${RELEASECONF}" ]; then
102 echo "ERROR: Configuration file ${RELEASECONF} does not exist."
105 # Source the specified configuration file for overrides
113 shift $(($OPTIND - 1))
115 # If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree
116 # is required to build the documentation set.
117 if [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then
118 echo "*** NOTICE: Setting NODOC=1 since ports tree is required"
119 echo " and NOPORTS is set."
123 # If NOPORTS and/or NODOC are unset, they must not pass to make as variables.
124 # The release makefile verifies definedness of NOPORTS/NODOC variables
125 # instead of their values.
127 if [ "x${NOPORTS}" != "x" ]; then
128 DOCPORTS="NOPORTS=yes "
130 if [ "x${NODOC}" != "x" ]; then
131 DOCPORTS="${DOCPORTS}NODOC=yes"
134 # The aggregated build-time flags based upon variables defined within
135 # this file, unless overridden by release.conf. In most cases, these
136 # will not need to be changed.
137 CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
138 ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
139 CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
140 CHROOT_IMAKEFLAGS="${CONF_FILES}"
141 CHROOT_DMAKEFLAGS="${CONF_FILES}"
142 RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}"
143 RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}"
144 RELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \
147 # Force src checkout if configured
149 if [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then
150 FORCE_SRC_KEY="--force"
153 if [ ! ${CHROOTDIR} ]; then
154 echo "Please set CHROOTDIR."
158 if [ $(id -u) -ne 0 ]; then
159 echo "Needs to be run as root."
163 set -e # Everything must succeed
165 mkdir -p ${CHROOTDIR}/usr
167 svn co ${FORCE_SRC_KEY} ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src $SRCREVISION
168 if [ "x${NODOC}" = "x" ]; then
169 svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc $DOCREVISION
171 if [ "x${NOPORTS}" = "x" ]; then
172 svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports $PORTREVISION
177 cd ${CHROOTDIR}/usr/src
178 make ${CHROOT_WMAKEFLAGS} buildworld
179 make ${CHROOT_IMAKEFLAGS} installworld DESTDIR=${CHROOTDIR}
180 make ${CHROOT_DMAKEFLAGS} distribution DESTDIR=${CHROOTDIR}
181 mount -t devfs devfs ${CHROOTDIR}/dev
182 trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
185 ## Trick the ports 'run-autotools-fixup' target to do the right thing.
186 _OSVERSION=$(sysctl -n kern.osreldate)
187 if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then
188 PBUILD_FLAGS="OSVERSION=${_OSVERSION} WITHOUT_JADETEX=yes WITHOUT_X11=yes BATCH=yes"
189 chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \
190 ${PBUILD_FLAGS} install clean distclean
194 # If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null),
195 # copy them to the chroot.
196 if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then
197 mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF})
198 cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF}
200 if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then
201 mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF})
202 cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF}
205 if [ -d ${CHROOTDIR}/usr/ports ]; then
206 cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
207 build_doc_ports ${CHROOTDIR}
210 if [ "x${RELSTRING}" = "x" ]; then
211 RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}"
214 eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
215 eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
216 eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
217 release RELSTRING=${RELSTRING}
218 eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
219 install DESTDIR=/R RELSTRING=${RELSTRING}
223 sha256 FreeBSD-* > CHECKSUM.SHA256
224 md5 FreeBSD-* > CHECKSUM.MD5