]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - release/release.sh
In release/Makefile, remove exclusion of CVS directories in the
[FreeBSD/FreeBSD.git] / release / release.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2013, 2014 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 PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin"
40 export PATH
41
42 # The directory within which the release will be built.
43 CHROOTDIR="/scratch"
44
45 # The default version control system command to obtain the sources.
46 VCSCMD="svn checkout"
47
48 # The default svn checkout server, and svn branches for src/, doc/,
49 # and ports/.
50 SVNROOT="svn://svn.FreeBSD.org/"
51 SRCBRANCH="base/head@rHEAD"
52 DOCBRANCH="doc/head@rHEAD"
53 PORTBRANCH="ports/head@rHEAD"
54
55 # Sometimes one needs to checkout src with --force svn option.
56 # If custom kernel configs copied to src tree before checkout, e.g.
57 SRC_FORCE_CHECKOUT=
58
59 # The default make.conf and src.conf to use.  Set to /dev/null
60 # by default to avoid polluting the chroot(8) environment with
61 # non-default settings.
62 MAKE_CONF="/dev/null"
63 SRC_CONF="/dev/null"
64
65 # The number of make(1) jobs, defaults to the number of CPUs available for
66 # buildworld, and half of number of CPUs available for buildkernel.
67 NCPU=$(sysctl -n hw.ncpu)
68 if [ ${NCPU} -gt 1 ]; then
69         WORLD_FLAGS="-j${NCPU}"
70         KERNEL_FLAGS="-j$(expr ${NCPU} / 2)"
71 fi
72 MAKE_FLAGS="-s"
73
74 # The name of the kernel to build, defaults to GENERIC.
75 KERNEL="GENERIC"
76
77 # Set to non-empty value to disable checkout of doc/ and/or ports/.  Disabling
78 # ports/ checkout also forces NODOC to be set.
79 NODOC=
80 NOPORTS=
81
82 # Set to non-empty value to build dvd1.iso as part of the release.
83 WITH_DVD=
84
85 usage() {
86         echo "Usage: $0 [-c release.conf]"
87         exit 1
88 }
89
90 while getopts c: opt; do
91         case ${opt} in
92         c)
93                 RELEASECONF="${OPTARG}"
94                 if [ ! -e "${RELEASECONF}" ]; then
95                         echo "ERROR: Configuration file ${RELEASECONF} does not exist."
96                         exit 1
97                 fi
98                 # Source the specified configuration file for overrides
99                 . ${RELEASECONF}
100                 ;;
101         \?)
102                 usage
103                 ;;
104         esac
105 done
106 shift $(($OPTIND - 1))
107
108 # Prefix the branches with the SVNROOT for the full checkout URL.
109 SRCBRANCH="${SVNROOT}${SRCBRANCH}"
110 DOCBRANCH="${SVNROOT}${DOCBRANCH}"
111 PORTBRANCH="${SVNROOT}${PORTBRANCH}"
112
113 # If PORTS is set and NODOC is unset, force NODOC=yes because the ports tree
114 # is required to build the documentation set.
115 if [ "x${NOPORTS}" != "x" ] && [ "x${NODOC}" = "x" ]; then
116         echo "*** NOTICE: Setting NODOC=1 since ports tree is required"
117         echo "            and NOPORTS is set."
118         NODOC=yes
119 fi
120
121 # If NOPORTS and/or NODOC are unset, they must not pass to make as variables.
122 # The release makefile verifies definedness of NOPORTS/NODOC variables
123 # instead of their values.
124 DOCPORTS=
125 if [ "x${NOPORTS}" != "x" ]; then
126         DOCPORTS="NOPORTS=yes "
127 fi
128 if [ "x${NODOC}" != "x" ]; then
129         DOCPORTS="${DOCPORTS}NODOC=yes"
130 fi
131
132 # The aggregated build-time flags based upon variables defined within
133 # this file, unless overridden by release.conf.  In most cases, these
134 # will not need to be changed.
135 CONF_FILES="__MAKE_CONF=${MAKE_CONF} SRCCONF=${SRC_CONF}"
136 if [ "x${TARGET}" != "x" ] && [ "x${TARGET_ARCH}" != "x" ]; then
137         ARCH_FLAGS="TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH}"
138 else
139         ARCH_FLAGS=
140 fi
141 CHROOT_MAKEENV="MAKEOBJDIRPREFIX=${CHROOTDIR}/tmp/obj"
142 CHROOT_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${CONF_FILES}"
143 CHROOT_IMAKEFLAGS="${CONF_FILES}"
144 CHROOT_DMAKEFLAGS="${CONF_FILES}"
145 RELEASE_WMAKEFLAGS="${MAKE_FLAGS} ${WORLD_FLAGS} ${ARCH_FLAGS} ${CONF_FILES}"
146 RELEASE_KMAKEFLAGS="${MAKE_FLAGS} ${KERNEL_FLAGS} KERNCONF=\"${KERNEL}\" ${ARCH_FLAGS} ${CONF_FILES}"
147 RELEASE_RMAKEFLAGS="${ARCH_FLAGS} KERNCONF=\"${KERNEL}\" ${CONF_FILES} \
148         ${DOCPORTS} WITH_DVD=${WITH_DVD}"
149
150 # Force src checkout if configured
151 FORCE_SRC_KEY=
152 if [ "x${SRC_FORCE_CHECKOUT}" != "x" ]; then
153         FORCE_SRC_KEY="--force"
154 fi
155
156 if [ ! ${CHROOTDIR} ]; then
157         echo "Please set CHROOTDIR."
158         exit 1
159 fi
160
161 if [ $(id -u) -ne 0 ]; then
162         echo "Needs to be run as root."
163         exit 1
164 fi
165
166 set -e # Everything must succeed
167
168 mkdir -p ${CHROOTDIR}/usr
169
170 ${VCSCMD} ${FORCE_SRC_KEY} ${SRCBRANCH} ${CHROOTDIR}/usr/src
171 if [ "x${NODOC}" = "x" ]; then
172         ${VCSCMD} ${DOCBRANCH} ${CHROOTDIR}/usr/doc
173 fi
174 if [ "x${NOPORTS}" = "x" ]; then
175         ${VCSCMD} ${PORTBRANCH} ${CHROOTDIR}/usr/ports
176 fi
177
178 cd ${CHROOTDIR}/usr/src
179 env ${CHROOT_MAKEENV} make ${CHROOT_WMAKEFLAGS} buildworld
180 env ${CHROOT_MAKEENV} make ${CHROOT_IMAKEFLAGS} installworld \
181         DESTDIR=${CHROOTDIR}
182 env ${CHROOT_MAKEENV} make ${CHROOT_DMAKEFLAGS} distribution \
183         DESTDIR=${CHROOTDIR}
184 mount -t devfs devfs ${CHROOTDIR}/dev
185 cp /etc/resolv.conf ${CHROOTDIR}/etc/resolv.conf
186 trap "umount ${CHROOTDIR}/dev" EXIT # Clean up devfs mount on exit
187
188 # If MAKE_CONF and/or SRC_CONF are set and not character devices (/dev/null),
189 # copy them to the chroot.
190 if [ -e ${MAKE_CONF} ] && [ ! -c ${MAKE_CONF} ]; then
191         mkdir -p ${CHROOTDIR}/$(dirname ${MAKE_CONF})
192         cp ${MAKE_CONF} ${CHROOTDIR}/${MAKE_CONF}
193 fi
194 if [ -e ${SRC_CONF} ] && [ ! -c ${SRC_CONF} ]; then
195         mkdir -p ${CHROOTDIR}/$(dirname ${SRC_CONF})
196         cp ${SRC_CONF} ${CHROOTDIR}/${SRC_CONF}
197 fi
198
199 if [ -d ${CHROOTDIR}/usr/ports ]; then
200         # Run ldconfig(8) in the chroot directory so /var/run/ld-elf*.so.hints
201         # is created.  This is needed by ports-mgmt/pkg.
202         chroot ${CHROOTDIR} /etc/rc.d/ldconfig forcerestart
203
204         ## Trick the ports 'run-autotools-fixup' target to do the right thing.
205         _OSVERSION=$(sysctl -n kern.osreldate)
206         if [ -d ${CHROOTDIR}/usr/doc ] && [ "x${NODOC}" = "x" ]; then
207                 PBUILD_FLAGS="OSVERSION=${_OSVERSION} BATCH=yes"
208                 PBUILD_FLAGS="${PBUILD_FLAGS}"
209                 chroot ${CHROOTDIR} make -C /usr/ports/textproc/docproj \
210                         ${PBUILD_FLAGS} OPTIONS_UNSET="FOP IGOR" install clean distclean
211         fi
212 fi
213
214 if [ "x${RELSTRING}" = "x" ]; then
215         RELSTRING="$(chroot ${CHROOTDIR} uname -s)-${OSRELEASE}-${TARGET_ARCH}"
216 fi
217
218 eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_WMAKEFLAGS} buildworld
219 eval chroot ${CHROOTDIR} make -C /usr/src ${RELEASE_KMAKEFLAGS} buildkernel
220 eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
221         release RELSTRING=${RELSTRING}
222 eval chroot ${CHROOTDIR} make -C /usr/src/release ${RELEASE_RMAKEFLAGS} \
223         install DESTDIR=/R RELSTRING=${RELSTRING}