1#!/bin/sh 2#- 3# Copyright (c) 2013 Glen Barber 4# Copyright (c) 2011 Nathan Whitehorn 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 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. 15# 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 26# SUCH DAMAGE. 27# 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 31# 32# $FreeBSD$ 33# 34 35PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin" 36export PATH 37 38# The directory within which the release will be built. 39CHROOTDIR="/scratch" 40RELENGDIR="$(realpath $(dirname $(basename ${0})))" 41 42# The default svn checkout server, and svn branches for src/, doc/, 43# and ports/. 44SVNROOT="svn://svn.freebsd.org" 45SRCBRANCH="base/head@rHEAD" 46DOCBRANCH="doc/head@rHEAD" 47PORTBRANCH="ports/head@rHEAD" 48 49# Set for embedded device builds. 50EMBEDDEDBUILD= 51EMBEDDED_WORLD_FLAGS= 52 53# Sometimes one needs to checkout src with --force svn option. 54# If custom kernel configs copied to src tree before checkout, e.g. 55SRC_FORCE_CHECKOUT= 56 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. 60MAKE_CONF="/dev/null" 61SRC_CONF="/dev/null" 62 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. 65NCPU=$(sysctl -n hw.ncpu) 66if [ ${NCPU} -gt 1 ]; then 67 WORLD_FLAGS="-j${NCPU}" 68 KERNEL_FLAGS="-j$(expr ${NCPU} / 2)" 69fi 70MAKE_FLAGS="-s" 71 72# The name of the kernel to build, defaults to GENERIC. 73KERNEL="GENERIC" 74 75# Set to non-empty value to disable checkout of doc/ and/or ports/. Disabling 76# ports/ checkout also forces NODOC to be set. 77NODOC= 78NOPORTS= 79 80# Set to non-empty value to build dvd1.iso as part of the release. 81WITH_DVD= 82 83usage() { 84 echo "Usage: $0 [-c release.conf]" 85 exit 1 86} 87 88while getopts c: opt; do 89 case ${opt} in 90 c) 91 RELEASECONF="${OPTARG}" 92 if [ ! -e "${RELEASECONF}" ]; then 93 echo "ERROR: Configuration file ${RELEASECONF} does not exist." 94 exit 1 95 fi 96 # Source the specified configuration file for overrides 97 . ${RELEASECONF} 98 ;; 99 \?) 100 usage 101 ;; 102 esac 103done 104shift $(($OPTIND - 1)) 105 106if [ "x${EMBEDDEDBUILD}" != "x" ]; then 107 WITH_DVD= 108 NODOC=yes 109fi 110 111# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree 112# is required to build the documentation set. 113if [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then 114 echo "*** NOTICE: Setting NODOC=1 since ports tree is required" 115 echo " and NOPORTS is set." 116 NODOC=yes 117fi 118 119# If NOPORTS and/or NODOC are unset, they must not pass to make as variables. 120# The release makefile verifies definedness of NOPORTS/NODOC variables 121# instead of their values. 122DOCPORTS= 123if [ "x${NOPORTS}" != "x" ]; then 124 DOCPORTS="NOPORTS=yes " 125fi 126if [ "x${NODOC}" != "x" ]; then 127 DOCPORTS="${DOCPORTS}NODOC=yes" 128fi 129 130# The aggregated build-time flags based upon variables defined within 131# this file, unless overridden by release.conf. In most cases, these 132# will not need to be changed. 133CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}" 134if [ "x${TARGET}" != "x" ] && [ "x${TARGET_ARCH}" != "x" ]; then 135 ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}" 136else 137 ARCH_FLAGS= 138fi 139CHROOT_MAKEENV="MAKEOBJDIRPREFIX=${CHROOTDIR}/tmp/obj" 140CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES} ${EMBEDDED_WORLD_FLAGS}" 141CHROOT_IMAKEFLAGS="${CONF_FILES} ${EMBEDDED_WORLD_FLAGS}" 142CHROOT_DMAKEFLAGS="${CONF_FILES} ${EMBEDDED_WORLD_FLAGS}" 143RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}" 144RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}" 145RELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \ 146 ${DOCPORTS} WITH_DVD=${WITH_DVD}" 147 148# Force src checkout if configured 149FORCE_SRC_KEY= 150if [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then 151 FORCE_SRC_KEY="--force" 152fi 153 154if [ ! ${CHROOTDIR} ]; then 155 echo "Please set CHROOTDIR." 156 exit 1 157fi 158 159if [ $(id -u) -ne 0 ]; then 160 echo "Needs to be run as root." 161 exit 1 162fi 163 164set -e # Everything must succeed 165 166mkdir -p ${CHROOTDIR}/usr 167 168svn co ${FORCE_SRC_KEY} ${SVNROOT}/${SRCBRANCH} ${CHROOTDIR}/usr/src 169if [ "x${NODOC}" = "x" ]; then 170 svn co ${SVNROOT}/${DOCBRANCH} ${CHROOTDIR}/usr/doc 171fi 172if [ "x${NOPORTS}" = "x" ]; then 173 svn co ${SVNROOT}/${PORTBRANCH} ${CHROOTDIR}/usr/ports 174fi 175 176cd ${CHROOTDIR}/usr/src 177env ${CHROOT_MAKEENV} make ${CHROOT_WMAKEFLAGS} buildworld 178env ${CHROOT_MAKEENV} make ${CHROOT_IMAKEFLAGS} installworld \ 179 DESTDIR=${CHROOTDIR} 180env ${CHROOT_MAKEENV} make ${CHROOT_DMAKEFLAGS} distribution \ 181 DESTDIR=${CHROOTDIR} 182mount -t devfs devfs ${CHROOTDIR}/dev 183cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf 184trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit 185 186# If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null), 187# copy them to the chroot. 188if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then 189 mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF}) 190 cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF} 191fi 192if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then 193 mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF}) 194 cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF} 195fi 196 197# Embedded builds do not use the 'make release' target. 198if [ "X${EMBEDDEDBUILD}" != "X" ]; then 199 # If a crochet configuration file exists in *this* checkout of 200 # release/, copy it to the /tmp/external directory within the chroot. 201 # This allows building embedded releases without relying on updated 202 # scripts and/or configurations to exist in the branch being built. 203 if [ -e ${RELENGDIR}/tools/${XDEV}/crochet-${KERNEL}.conf ] && \ 204 [ -e ${RELENGDIR}/${XDEV}/release.sh ]; then 205 mkdir -p ${CHROOTDIR}/tmp/external/${XDEV}/ 206 cp ${RELENGDIR}/tools/${XDEV}/crochet-${KERNEL}.conf \ 207 ${CHROOTDIR}/tmp/external/${XDEV}/crochet-${KERNEL}.conf 208 /bin/sh ${RELENGDIR}/${XDEV}/release.sh 209 fi 210 # If the script does not exist for this architecture, exit. 211 # This probably should be checked earlier, but allowing the rest 212 # of the build process to get this far will at least set up the 213 # chroot environment for testing. 214 exit 0 215else 216 # Not embedded. 217 continue 218fi 219 220if [ -d ${CHROOTDIR}/usr/ports ]; then 221 # Run ldconfig(8) in the chroot directory so /var/run/ld-elf*.so.hints 222 # is created. This is needed by ports-mgmt/pkg. 223 chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart 224 225 ## Trick the ports 'run-autotools-fixup' target to do the right thing. 226 _OSVERSION=$(sysctl -n kern.osreldate) 227 if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then 228 PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes" 229 PBUILD_FLAGS="${PBUILD_FLAGS}" 230 chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \ 231 ${PBUILD_FLAGS} OPTIONS_UNSET="FOP IGOR" install clean distclean 232 fi 233fi 234 235if [ "x${RELSTRING}" = "x" ]; then 236 RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}" 237fi 238 239eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld 240eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel 241eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 242 release RELSTRING=${RELSTRING} 243eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \ 244 install DESTDIR=/R RELSTRING=${RELSTRING} 245