release.sh revision 262761
1251652Sgjb#!/bin/sh
2251652Sgjb#-
3262761Sgjb# Copyright (c) 2013, 2014 The FreeBSD Foundation
4251652Sgjb# Copyright (c) 2013 Glen Barber
5251652Sgjb# Copyright (c) 2011 Nathan Whitehorn
6251652Sgjb# All rights reserved.
7251652Sgjb#
8262761Sgjb# Portions of this software were developed by Glen Barber
9262761Sgjb# under sponsorship from the FreeBSD Foundation.
10262761Sgjb#
11251652Sgjb# Redistribution and use in source and binary forms, with or without
12251652Sgjb# modification, are permitted provided that the following conditions
13251652Sgjb# are met:
14251652Sgjb# 1. Redistributions of source code must retain the above copyright
15251652Sgjb#    notice, this list of conditions and the following disclaimer.
16251652Sgjb# 2. Redistributions in binary form must reproduce the above copyright
17251652Sgjb#    notice, this list of conditions and the following disclaimer in the
18251652Sgjb#    documentation and/or other materials provided with the distribution.
19251652Sgjb#
20251652Sgjb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21251652Sgjb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22251652Sgjb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23251652Sgjb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24251652Sgjb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25251652Sgjb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26251652Sgjb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27251652Sgjb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28251652Sgjb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29251652Sgjb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30251652Sgjb# SUCH DAMAGE.
31251652Sgjb#
32251652Sgjb# release.sh: check out source trees, and build release components with
33251652Sgjb#  totally clean, fresh trees.
34251652Sgjb# Based on release/generate-release.sh written by Nathan Whitehorn
35251652Sgjb#
36251652Sgjb# $FreeBSD: stable/10/release/release.sh 262761 2014-03-05 00:45:28Z gjb $
37251652Sgjb#
38251652Sgjb
39251652SgjbPATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
40251652Sgjbexport PATH
41251652Sgjb
42251652Sgjb# The directory within which the release will be built.
43251652SgjbCHROOTDIR="/scratch"
44251652Sgjb
45262761Sgjb# The default version control system command to obtain the sources.
46262761SgjbVCSCMD="svn checkout"
47262761Sgjb
48251652Sgjb# The default svn checkout server, and svn branches for src/, doc/,
49251652Sgjb# and ports/.
50262761SgjbSVNROOT="svn://svn.FreeBSD.org/"
51254293SgjbSRCBRANCH="base/head@rHEAD"
52254293SgjbDOCBRANCH="doc/head@rHEAD"
53254293SgjbPORTBRANCH="ports/head@rHEAD"
54251652Sgjb
55252846Sgjb# Sometimes one needs to checkout src with --force svn option.
56252846Sgjb# If custom kernel configs copied to src tree before checkout, e.g.
57252846SgjbSRC_FORCE_CHECKOUT=
58252846Sgjb
59251652Sgjb# The default make.conf and src.conf to use.  Set to /dev/null
60251652Sgjb# by default to avoid polluting the chroot(8) environment with
61251652Sgjb# non-default settings.
62251652SgjbMAKE_CONF="/dev/null"
63251652SgjbSRC_CONF="/dev/null"
64251652Sgjb
65251652Sgjb# The number of make(1) jobs, defaults to the number of CPUs available for
66251652Sgjb# buildworld, and half of number of CPUs available for buildkernel.
67262761SgjbWORLD_FLAGS="-j$(sysctl -n hw.ncpu)"
68262761SgjbKERNEL_FLAGS="-j$(( $(( $(sysctl -n hw.ncpu) + 1 )) / 2))"
69262761Sgjb
70251652SgjbMAKE_FLAGS="-s"
71251652Sgjb
72251652Sgjb# The name of the kernel to build, defaults to GENERIC.
73251652SgjbKERNEL="GENERIC"
74251652Sgjb
75251652Sgjb# Set to non-empty value to disable checkout of doc/ and/or ports/.  Disabling
76251652Sgjb# ports/ checkout also forces NODOC to be set.
77251652SgjbNODOC=
78251652SgjbNOPORTS=
79251652Sgjb
80259151Sgjb# Set to non-empty value to build dvd1.iso as part of the release.
81259151SgjbWITH_DVD=
82259151Sgjb
83251652Sgjbusage() {
84251652Sgjb	echo "Usage: $0 [-c release.conf]"
85251652Sgjb	exit 1
86251652Sgjb}
87251652Sgjb
88251652Sgjbwhile getopts c: opt; do
89251652Sgjb	case ${opt} in
90251652Sgjb	c)
91251652Sgjb		RELEASECONF="${OPTARG}"
92251652Sgjb		if [ ! -e "${RELEASECONF}" ]; then
93251652Sgjb			echo "ERROR: Configuration file ${RELEASECONF} does not exist."
94251652Sgjb			exit 1
95251652Sgjb		fi
96251652Sgjb		# Source the specified configuration file for overrides
97251652Sgjb		. ${RELEASECONF}
98251652Sgjb		;;
99251652Sgjb	\?)
100251652Sgjb		usage
101251652Sgjb		;;
102251652Sgjb	esac
103251652Sgjbdone
104251652Sgjbshift $(($OPTIND - 1))
105251652Sgjb
106262761Sgjb# Prefix the branches with the SVNROOT for the full checkout URL.
107262761SgjbSRCBRANCH="${SVNROOT}${SRCBRANCH}"
108262761SgjbDOCBRANCH="${SVNROOT}${DOCBRANCH}"
109262761SgjbPORTBRANCH="${SVNROOT}${PORTBRANCH}"
110262761Sgjb
111252846Sgjb# If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree
112252846Sgjb# is required to build the documentation set.
113252846Sgjbif [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then
114252846Sgjb	echo "*** NOTICE: Setting NODOC=1 since ports tree is required"
115252846Sgjb	echo "            and NOPORTS is set."
116252846Sgjb	NODOC=yes
117252846Sgjbfi
118252846Sgjb
119252846Sgjb# If NOPORTS and/or NODOC are unset, they must not pass to make as variables.
120252846Sgjb# The release makefile verifies definedness of NOPORTS/NODOC variables
121252846Sgjb# instead of their values.
122252846SgjbDOCPORTS=
123252846Sgjbif [ "x${NOPORTS}" != "x" ]; then
124259225Sgjb	DOCPORTS="NOPORTS=yes "
125252846Sgjbfi
126252846Sgjbif [ "x${NODOC}" != "x" ]; then
127259225Sgjb	DOCPORTS="${DOCPORTS}NODOC=yes"
128252846Sgjbfi
129252846Sgjb
130251652Sgjb# The aggregated build-time flags based upon variables defined within
131251652Sgjb# this file, unless overridden by release.conf.  In most cases, these
132251652Sgjb# will not need to be changed.
133251652SgjbCONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
134254293Sgjbif [ "x${TARGET}" != "x" ] && [ "x${TARGET_ARCH}" != "x" ]; then
135254293Sgjb	ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
136254293Sgjbelse
137254293Sgjb	ARCH_FLAGS=
138254293Sgjbfi
139260071SgjbCHROOT_MAKEENV="MAKEOBJDIRPREFIX=${CHROOTDIR}/tmp/obj"
140251652SgjbCHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
141251652SgjbCHROOT_IMAKEFLAGS="${CONF_FILES}"
142251652SgjbCHROOT_DMAKEFLAGS="${CONF_FILES}"
143251652SgjbRELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}"
144252846SgjbRELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}"
145252846SgjbRELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \
146259151Sgjb	${DOCPORTS} WITH_DVD=${WITH_DVD}"
147251652Sgjb
148252846Sgjb# Force src checkout if configured
149252846SgjbFORCE_SRC_KEY=
150252846Sgjbif [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then
151259225Sgjb	FORCE_SRC_KEY="--force"
152251652Sgjbfi
153251652Sgjb
154251652Sgjbif [ ! ${CHROOTDIR} ]; then
155251652Sgjb	echo "Please set CHROOTDIR."
156251652Sgjb	exit 1
157251652Sgjbfi
158251652Sgjb
159251652Sgjbif [ $(id -u) -ne 0 ]; then
160251652Sgjb	echo "Needs to be run as root."
161251652Sgjb	exit 1
162251652Sgjbfi
163251652Sgjb
164251652Sgjbset -e # Everything must succeed
165251652Sgjb
166251652Sgjbmkdir -p ${CHROOTDIR}/usr
167251652Sgjb
168262761Sgjb${VCSCMD} ${FORCE_SRC_KEY} ${SRCBRANCH} ${CHROOTDIR}/usr/src
169251652Sgjbif [ "x${NODOC}" = "x" ]; then
170262761Sgjb	${VCSCMD} ${DOCBRANCH} ${CHROOTDIR}/usr/doc
171251652Sgjbfi
172251652Sgjbif [ "x${NOPORTS}" = "x" ]; then
173262761Sgjb	${VCSCMD} ${PORTBRANCH} ${CHROOTDIR}/usr/ports
174251652Sgjbfi
175251652Sgjb
176251652Sgjbcd ${CHROOTDIR}/usr/src
177260071Sgjbenv ${CHROOT_MAKEENV} make ${CHROOT_WMAKEFLAGS} buildworld
178260071Sgjbenv ${CHROOT_MAKEENV} make ${CHROOT_IMAKEFLAGS} installworld \
179260071Sgjb	DESTDIR=${CHROOTDIR}
180260071Sgjbenv ${CHROOT_MAKEENV} make ${CHROOT_DMAKEFLAGS} distribution \
181260071Sgjb	DESTDIR=${CHROOTDIR}
182251652Sgjbmount -t devfs devfs ${CHROOTDIR}/dev
183260071Sgjbcp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
184251652Sgjbtrap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
185251652Sgjb
186260071Sgjb# If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null),
187260071Sgjb# copy them to the chroot.
188260071Sgjbif [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then
189260071Sgjb	mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF})
190260071Sgjb	cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF}
191260071Sgjbfi
192260071Sgjbif [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then
193260071Sgjb	mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF})
194260071Sgjb	cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF}
195260071Sgjbfi
196260071Sgjb
197260071Sgjbif [ -d ${CHROOTDIR}/usr/ports ]; then
198257776Sgjb	# Run ldconfig(8) in the chroot directory so /var/run/ld-elf*.so.hints
199257776Sgjb	# is created.  This is needed by ports-mgmt/pkg.
200257776Sgjb	chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart
201257776Sgjb
202251652Sgjb	## Trick the ports 'run-autotools-fixup' target to do the right thing.
203251652Sgjb	_OSVERSION=$(sysctl -n kern.osreldate)
204252846Sgjb	if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then
205258261Sgjb		PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes"
206258952Sgjb		PBUILD_FLAGS="${PBUILD_FLAGS}"
207251652Sgjb		chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \
208258952Sgjb			${PBUILD_FLAGS} OPTIONS_UNSET="FOP IGOR" install clean distclean
209251652Sgjb	fi
210252101Sgjbfi
211252101Sgjb
212251652Sgjbif [ "x${RELSTRING}" = "x" ]; then
213251652Sgjb	RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}"
214251652Sgjbfi
215251652Sgjb
216252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
217252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
218252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
219251652Sgjb	release RELSTRING=${RELSTRING}
220252846Sgjbeval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
221251652Sgjb	install DESTDIR=/R RELSTRING=${RELSTRING}
222