release.sh revision 264141
1130860Srik#!/bin/sh 2130860Srik#- 3123159Simp# Copyright (c) 2013, 2014 The FreeBSD Foundation 423462Sjmg# Copyright (c) 2013 Glen Barber 5123159Simp# Copyright (c) 2011 Nathan Whitehorn 6123159Simp# All rights reserved. 7123159Simp# 8123159Simp# Portions of this software were developed by Glen Barber 9123159Simp# under sponsorship from the FreeBSD Foundation. 10123159Simp# 11123159Simp# Redistribution and use in source and binary forms, with or without 12123159Simp# modification, are permitted provided that the following conditions 13130860Srik# are met: 1450476Speter# 1. Redistributions of source code must retain the above copyright 1523462Sjmg# notice, this list of conditions and the following disclaimer. 16358804Semaste# 2. Redistributions in binary form must reproduce the above copyright 17123943Sru# notice, this list of conditions and the following disclaimer in the 1879538Sru# documentation and/or other materials provided with the distribution. 1920782Smpp# 2060442Sphantom# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21148145Strhodes# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2268854Sru# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23151046Strhodes# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24152569Sru# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25148220Strhodes# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26148145Strhodes# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27123159Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28148145Strhodes# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29152569Sru# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30151046Strhodes# SUCH DAMAGE. 31151046Strhodes# 32148145Strhodes# release.sh: check out source trees, and build release components with 33148145Strhodes# totally clean, fresh trees. 34148145Strhodes# Based on release/generate-release.sh written by Nathan Whitehorn 35148145Strhodes# 3620782Smpp# $FreeBSD: stable/9/release/release.sh 264141 2014-04-04 22:20:33Z gjb $ 37123159Simp# 38123159Simp 39123159SimpPATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" 40123159Simpexport PATH 41123159Simp 4284877Syokota# The directory within which the release will be built. 4384877SyokotaCHROOTDIR="/scratch" 4484877SyokotaRELENGDIR="$(realpath $(dirname $(basename ${0})))" 4584877Syokota 4684877Syokota# The default version control system command to obtain the sources. 4784877SyokotaVCSCMD="svn checkout" 48358804Semaste 49358804Semaste# The default svn checkout server, and svn branches for src/, doc/, 50358804Semaste# and ports/. 51358804SemasteSVNROOT="svn://svn.FreeBSD.org/" 52358804SemasteSRCBRANCH="base/head@rHEAD" 53358804SemasteDOCBRANCH="doc/head@rHEAD" 54123159SimpPORTBRANCH="ports/head@rHEAD" 55123159Simp 56123159Simp# Set for embedded device builds. 57123159SimpEMBEDDEDBUILD= 58123159Simp 59130582Sru# Sometimes one needs to checkout src with --force svn option. 60123159Simp# If custom kernel configs copied to src tree before checkout, e.g. 61130582SruSRC_FORCE_CHECKOUT= 62130582Sru 63130582Sru# The default make.conf and src.conf to use. Set to /dev/null 64123159Simp# by default to avoid polluting the chroot(8) environment with 65123159Simp# non-default settings. 66123159SimpMAKE_CONF="/dev/null" 67123159SimpSRC_CONF="/dev/null" 68126499Sbrueffer 69126499Sbrueffer# The number of make(1) jobs, defaults to the number of CPUs available for 70123159Simp# buildworld, and half of number of CPUs available for buildkernel. 71123159SimpWORLD_FLAGS="-j$(sysctl -n hw.ncpu)" 7284877SyokotaKERNEL_FLAGS="-j$(( $(( $(sysctl -n hw.ncpu) + 1 )) / 2))" 73126897Sbrueffer 7484877SyokotaMAKE_FLAGS="-s" 75126499Sbrueffer 76126897Sbrueffer# The name of the kernel to build, defaults to GENERIC. 77123159SimpKERNEL="GENERIC" 78123159Simp 7920782Smpp# Set to non-empty value to disable checkout of doc/ and/or ports/. Disabling 80123159Simp# ports/ checkout also forces NODOC to be set. 81123159SimpNODOC= 824910SwollmanNOPORTS= 83123159Simp 844910Swollman# Set to non-empty value to build dvd1.iso as part of the release. 85123159SimpWITH_DVD= 864910Swollman 8770466Sruusage() { 8820782Smpp echo "Usage: $0 [-c release.conf]" 8976175Sschweikh exit 1 90123159Simp} 91123159Simp 92126499Sbruefferwhile getopts c: opt; do 93123159Simp case ${opt} in 94126499Sbrueffer c) 95126499Sbrueffer RELEASECONF="${OPTARG}" 9620782Smpp if [ ! -e "${RELEASECONF}" ]; then 97126499Sbrueffer echo "ERROR: Configuration file ${RELEASECONF} does not exist." 98123159Simp exit 1 99123159Simp fi 100123159Simp # Source the specified configuration file for overrides 101123159Simp . ${RELEASECONF} 102131752Ssimon ;; 103131752Ssimon \?) 104131752Ssimon usage 105131752Ssimon ;; 106131752Ssimon esac 107131752Ssimondone 108131752Ssimonshift $(($OPTIND - 1)) 109131752Ssimon 110131752Ssimon# Fix for backwards-compatibility with release.conf that does not have the 111131752Ssimon# trailing '/'. 112131752Ssimoncase ${SVNROOT} in 113131752Ssimon *svn*) 114131752Ssimon SVNROOT="${SVNROOT}/" 115131752Ssimon ;; 116131752Ssimon *) 117131752Ssimon ;; 118131752Ssimonesac 119131752Ssimon 120131752Ssimon# Prefix the branches with the SVNROOT for the full checkout URL. 121123159SimpSRCBRANCH="${SVNROOT}${SRCBRANCH}" 122130860SrikDOCBRANCH="${SVNROOT}${DOCBRANCH}" 123130860SrikPORTBRANCH="${SVNROOT}${PORTBRANCH}" 124130582Sru 125130582Sruif [ -n "${EMBEDDEDBUILD}" ]; then 126130582Sru if [ -z "${XDEV}" ] || [ -z "${XDEV_ARCH}" ]; then 127123159Simp echo "ERROR: XDEV and XDEV_ARCH must be set in ${RELEASECONF}." 128123159Simp exit 1 12976175Sschweikh fi 130123159Simp WITH_DVD= 131123159Simp NODOC=yes 132130860Srikfi 133130860Srik 134130860Srik# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree 135126499Sbrueffer# is required to build the documentation set. 136123159Simpif [ -n "${NOPORTS}" ] && [ -z "${NODOC}" ]; then 137123159Simp echo "*** NOTICE: Setting NODOC=1 since ports tree is required" 138123159Simp echo " and NOPORTS is set." 139123159Simp NODOC=yes 140123159Simpfi 141123159Simp 142123159Simp# If NOPORTS and/or NODOC are unset, they must not pass to make as variables. 143123159Simp# The release makefile verifies definedness of NOPORTS/NODOC variables 144123159Simp# instead of their values. 145123159SimpDOCPORTS= 146if [ -n "${NOPORTS}" ]; then 147 DOCPORTS="NOPORTS=yes " 148fi 149if [ -n "${NODOC}" ]; then 150 DOCPORTS="${DOCPORTS}NODOC=yes" 151fi 152 153# The aggregated build-time flags based upon variables defined within 154# this file, unless overridden by release.conf. In most cases, these 155# will not need to be changed. 156CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}" 157if [ -n "${TARGET}" ] && [ -n "${TARGET_ARCH}" ]; then 158 ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" 159else 160 ARCH_FLAGS= 161fi 162CHROOT_MAKEENV="${CHROOT_MAKEENV} MAKEOBJDIRPREFIX=${CHROOTDIR}/tmp/obj" 163CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}" 164CHROOT_IMAKEFLAGS="${CONF_FILES}" 165CHROOT_DMAKEFLAGS="${CONF_FILES}" 166RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}" 167RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}" 168RELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \ 169 ${DOCPORTS} WITH_DVD=${WITH_DVD}" 170 171# Force src checkout if configured 172FORCE_SRC_KEY= 173if [ -n "${SRC_FORCE_CHECKOUT}" ]; then 174 FORCE_SRC_KEY="--force" 175fi 176 177if [ -z "${CHROOTDIR}" ]; then 178 echo "Please set CHROOTDIR." 179 exit 1 180fi 181 182if [ $(id -u) -ne 0 ]; then 183 echo "Needs to be run as root." 184 exit 1 185fi 186 187set -e # Everything must succeed 188 189mkdir -p ${CHROOTDIR}/usr 190 191${VCSCMD} ${FORCE_SRC_KEY} ${SRCBRANCH} ${CHROOTDIR}/usr/src 192if [ -z "${NODOC}" ]; then 193 ${VCSCMD} ${DOCBRANCH} ${CHROOTDIR}/usr/doc 194fi 195if [ -z "${NOPORTS}" ]; then 196 ${VCSCMD} ${PORTBRANCH} ${CHROOTDIR}/usr/ports 197fi 198 199if [ -z "${CHROOTBUILD_SKIP}" ]; then 200 cd ${CHROOTDIR}/usr/src 201 env ${CHROOT_MAKEENV} make ${CHROOT_WMAKEFLAGS} buildworld 202 env ${CHROOT_MAKEENV} make ${CHROOT_IMAKEFLAGS} installworld \ 203 DESTDIR=${CHROOTDIR} 204 env ${CHROOT_MAKEENV} make ${CHROOT_DMAKEFLAGS} distribution \ 205 DESTDIR=${CHROOTDIR} 206fi 207mount -t devfs devfs ${CHROOTDIR}/dev 208cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf 209trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit 210 211# If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null), 212# copy them to the chroot. 213if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then 214 mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF}) 215 cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF} 216fi 217if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then 218 mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF}) 219 cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF} 220fi 221 222# Embedded builds do not use the 'make release' target. 223if [ -n "${EMBEDDEDBUILD}" ]; then 224 # If a crochet configuration file exists in *this* checkout of 225 # release/, copy it to the /tmp/external directory within the chroot. 226 # This allows building embedded releases without relying on updated 227 # scripts and/or configurations to exist in the branch being built. 228 if [ -e ${RELENGDIR}/tools/${XDEV}/crochet-${KERNEL}.conf ] && \ 229 [ -e ${RELENGDIR}/${XDEV}/release.sh ]; then 230 mkdir -p ${CHROOTDIR}/tmp/external/${XDEV}/ 231 cp ${RELENGDIR}/tools/${XDEV}/crochet-${KERNEL}.conf \ 232 ${CHROOTDIR}/tmp/external/${XDEV}/crochet-${KERNEL}.conf 233 /bin/sh ${RELENGDIR}/${XDEV}/release.sh 234 fi 235 # If the script does not exist for this architecture, exit. 236 # This probably should be checked earlier, but allowing the rest 237 # of the build process to get this far will at least set up the 238 # chroot environment for testing. 239 exit 0 240else 241 # Not embedded. 242 continue 243fi 244 245if [ -d ${CHROOTDIR}/usr/ports ]; then 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 chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart 249 250 ## Trick the ports 'run-autotools-fixup' target to do the right thing. 251 _OSVERSION=$(sysctl -n kern.osreldate) 252 if [ -d ${CHROOTDIR}/usr/doc ] && [ -z "${NODOC}" ]; then 253 PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes" 254 PBUILD_FLAGS="${PBUILD_FLAGS}" 255 chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \ 256 ${PBUILD_FLAGS} OPTIONS_UNSET="FOP IGOR" install clean distclean 257 fi 258fi 259 260eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld 261eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel 262eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 263 release 264eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 265 install DESTDIR=/R 266