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