xref: /freebsd/release/Makefile (revision 8881d206f4e68b564c2c5f50fc717086fc3e827a)
1# $FreeBSD$
2#
3# Makefile for building releases and release media.
4#
5# User-driven targets:
6#  cdrom: Builds release CD-ROM media (disc1.iso)
7#  dvdrom: Builds release DVD-ROM media (dvd1.iso)
8#  memstick: Builds memory stick image (memstick.img)
9#  mini-memstick: Builds minimal memory stick image (mini-memstick.img)
10#  ftp: Sets up FTP distribution area (ftp)
11#  release: Invokes real-release, vm-release, and cloudware-release targets
12#  real-release: Build all media and FTP distribution area
13#  vm-release: Build all virtual machine image targets
14#  cloudware-release: Build all cloud hosting provider targets
15#  install: Invokes the release-install and vm-install targets
16#  release-install: Copies all release installation media into ${DESTDIR}
17#  vm-install: Copies all virtual machine images into ${DESTDIR}
18#
19# Variables affecting the build process:
20#  WORLDDIR: location of src tree -- must have built world and default kernel
21#            (by default, the directory above this one)
22#  PORTSDIR: location of ports tree to distribute (default: /usr/ports)
23#  XTRADIR:  xtra-bits-dir argument for <arch>/mkisoimages.sh
24#  NOPKG:    if set, do not distribute third-party packages
25#  NOPORTS:  if set, do not distribute ports tree
26#  NOSRC:    if set, do not distribute source tree
27#  WITH_DVD: if set, generate dvd1.iso
28#  WITH_COMPRESSED_IMAGES: if set, compress installation images with xz(1)
29#		(uncompressed images are not removed)
30#  WITH_VMIMAGES: if set, build virtual machine images with the release
31#  WITH_COMPRESSED_VMIMAGES: if set, compress virtual machine disk images
32#  		with xz(1) (extremely time consuming)
33#  WITH_CLOUDWARE: if set, build cloud hosting disk images with the release
34#  TARGET/TARGET_ARCH: architecture of built release
35#
36
37WORLDDIR?=	${.CURDIR}/..
38PORTSDIR?=	/usr/ports
39
40.if !defined(TARGET) || empty(TARGET)
41TARGET=		${MACHINE}
42.endif
43.if !defined(TARGET_ARCH) || empty(TARGET_ARCH)
44.if ${TARGET} == ${MACHINE}
45TARGET_ARCH=	${MACHINE_ARCH}
46.else
47TARGET_ARCH=	${TARGET}
48.endif
49.endif
50IMAKE=		${MAKE} TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}
51DISTDIR=	dist
52
53# Define OSRELEASE by using newvers.sh
54.if !defined(OSRELEASE) || empty(OSRELEASE)
55.for _V in TYPE BRANCH REVISION
56${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
57.endfor
58.for _V in ${TARGET_ARCH}
59.if !empty(TARGET:M${_V})
60OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}
61VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET}
62.else
63OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}-${TARGET_ARCH}
64VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET_ARCH}
65.endif
66.endfor
67.endif
68
69.if !defined(VOLUME_LABEL) || empty(VOLUME_LABEL)
70VOLUME_LABEL=	FreeBSD_Install
71.endif
72
73.if !exists(${PORTSDIR})
74NOPORTS= true
75.endif
76
77EXTRA_PACKAGES=
78.if !defined(NOPORTS)
79EXTRA_PACKAGES+= ports.txz
80.endif
81.if !defined(NOSRC)
82EXTRA_PACKAGES+= src.txz
83.endif
84
85RELEASE_TARGETS= ftp
86IMAGES=
87.if exists(${.CURDIR}/${TARGET}/mkisoimages.sh)
88RELEASE_TARGETS+= cdrom
89IMAGES+=	disc1.iso bootonly.iso
90. if defined(WITH_DVD) && !empty(WITH_DVD)
91RELEASE_TARGETS+= dvdrom
92IMAGES+=	dvd1.iso
93. endif
94.endif
95.if exists(${.CURDIR}/${TARGET}/make-memstick.sh)
96RELEASE_TARGETS+= memstick.img
97RELEASE_TARGETS+= mini-memstick.img
98IMAGES+=	memstick.img
99IMAGES+=	mini-memstick.img
100.endif
101
102CLEANFILES=	packagesystem *.txz MANIFEST release ${IMAGES}
103.if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
104. for I in ${IMAGES}
105CLEANFILES+=	${I}.xz
106. endfor
107.endif
108.if defined(WITH_DVD) && !empty(WITH_DVD)
109CLEANFILES+=	pkg-stage
110.endif
111CLEANDIRS=	dist ftp disc1 bootonly dvd
112beforeclean:
113	chflags -R noschg .
114.include <bsd.obj.mk>
115clean: beforeclean
116
117base.txz:
118	mkdir -p ${DISTDIR}
119	cd ${WORLDDIR} && ${IMAKE} distributeworld DISTDIR=${.OBJDIR}/${DISTDIR}
120# TODO: Add NO_ROOT mode to mm-tree.sh and etcupdate
121.if !defined(NO_ROOT)
122# Set up mergemaster root database
123	sh ${.CURDIR}/scripts/mm-mtree.sh -m ${WORLDDIR} -F \
124	    "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET} ${.MAKE.JOBS:D-j${.MAKE.JOBS}}" \
125	    -D "${.OBJDIR}/${DISTDIR}/base"
126	etcupdate extract -B -M "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}" \
127	    -s ${WORLDDIR} -d "${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate"
128.endif
129# Package all components
130	cd ${WORLDDIR} && ${IMAKE} packageworld DISTDIR=${.OBJDIR}/${DISTDIR}
131	mv ${DISTDIR}/*.txz .
132
133kernel.txz:
134	mkdir -p ${DISTDIR}
135	cd ${WORLDDIR} && ${IMAKE} distributekernel packagekernel DISTDIR=${.OBJDIR}/${DISTDIR}
136	mv ${DISTDIR}/kernel*.txz .
137
138src.txz:
139	mkdir -p ${DISTDIR}/usr
140	ln -fs ${WORLDDIR} ${DISTDIR}/usr/src
141	cd ${DISTDIR} && tar cLvf - --exclude .svn --exclude .zfs \
142	    --exclude .git --exclude @ --exclude usr/src/release/dist usr/src | \
143	    ${XZ_CMD} > ${.OBJDIR}/src.txz
144
145ports.txz:
146	mkdir -p ${DISTDIR}/usr
147	ln -fs ${PORTSDIR} ${DISTDIR}/usr/ports
148	cd ${DISTDIR} && tar cLvf - \
149	    --exclude .git --exclude .svn \
150	    --exclude usr/ports/distfiles --exclude usr/ports/packages \
151	    --exclude 'usr/ports/INDEX*' --exclude work usr/ports | \
152	    ${XZ_CMD} > ${.OBJDIR}/ports.txz
153
154disc1: packagesystem
155# Install system
156	mkdir -p ${.TARGET}
157	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
158	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
159	    MK_INSTALLLIB=no MK_LIB32=no MK_MAIL=no \
160	    MK_TOOLCHAIN=no MK_PROFILE=no \
161	    MK_RESCUE=no MK_DICT=no \
162	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
163	    -DDB_FROM_SRC
164# Copy distfiles
165	mkdir -p ${.TARGET}/usr/freebsd-dist
166	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(base|lib32)-dbg'); \
167	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
168	done
169.if defined(NO_ROOT)
170	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
171	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(base|lib32)-dbg'); \
172	    do echo "./usr/freebsd-dist/$${dist} type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG; \
173	done
174.endif
175# Set up installation environment
176	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
177	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
178	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
179	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
180	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
181	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
182	cp ${.CURDIR}/rc.local ${.TARGET}/etc
183.if defined(NO_ROOT)
184	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
185	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
186	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
187	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
188	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
189.endif
190	touch ${.TARGET}
191
192bootonly: packagesystem
193# Install system
194	mkdir -p ${.TARGET}
195	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
196	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
197	    MK_GAMES=no \
198	    MK_INSTALLLIB=no MK_LIB32=no MK_MAIL=no \
199	    MK_TOOLCHAIN=no MK_PROFILE=no \
200	    MK_RESCUE=no MK_DICT=no \
201	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
202	    -DDB_FROM_SRC
203# Copy manifest only (no distfiles) to get checksums
204	mkdir -p ${.TARGET}/usr/freebsd-dist
205	cp MANIFEST ${.TARGET}/usr/freebsd-dist
206.if defined(NO_ROOT)
207	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
208	echo "./usr/freebsd-dist/MANIFEST type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
209.endif
210# Set up installation environment
211	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
212	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
213	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
214	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
215	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
216	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
217	cp ${.CURDIR}/rc.local ${.TARGET}/etc
218.if defined(NO_ROOT)
219	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
220	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
221	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
222	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
223	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
224.endif
225
226dvd: packagesystem
227# Install system
228	mkdir -p ${.TARGET}
229	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
230		DESTDIR=${.OBJDIR}/${.TARGET} MK_RESCUE=no MK_KERNEL_SYMBOLS=no \
231		MK_TESTS=no MK_DEBUG_FILES=no \
232		-DDB_FROM_SRC
233# Copy distfiles
234	mkdir -p ${.TARGET}/usr/freebsd-dist
235	for dist in MANIFEST $$(ls *.txz | grep -v -- '(base|lib32)-dbg'); \
236	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
237	done
238.if defined(NO_ROOT)
239	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
240	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(base|lib32)-dbg'); \
241	    do echo "./usr/freebsd-dist/$${dist} type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG; \
242	done
243.endif
244# Set up installation environment
245	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
246	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
247	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
248	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
249	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
250	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
251	cp ${.CURDIR}/rc.local ${.TARGET}/etc
252.if defined(NO_ROOT)
253	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
254	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
255	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
256	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
257	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
258.endif
259	touch ${.TARGET}
260
261release.iso: disc1.iso
262disc1.iso: disc1
263	cd disc1 && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_CD ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
264
265dvd1.iso: dvd pkg-stage
266	cd dvd && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_DVD ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
267
268bootonly.iso: bootonly
269	cd bootonly && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_BO ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
270
271memstick: memstick.img
272memstick.img: disc1
273	cd disc1 && sh ${.CURDIR}/${TARGET}/make-memstick.sh .${NO_ROOT:D/METALOG} ../${.TARGET}
274
275mini-memstick: mini-memstick.img
276mini-memstick.img: bootonly
277	cd bootonly && sh ${.CURDIR}/${TARGET}/make-memstick.sh .${NO_ROOT:D/METALOG} ../${.TARGET}
278
279packagesystem: base.txz kernel.txz ${EXTRA_PACKAGES}
280	sh ${.CURDIR}/scripts/make-manifest.sh *.txz > MANIFEST
281	touch ${.TARGET}
282
283pkg-stage:
284# TODO: Support for -DNO_ROOT
285.if !defined(NOPKG) || empty(NOPKG)
286	env PORTSDIR=${PORTSDIR} REPOS_DIR=${.CURDIR}/pkg_repos/ \
287		sh ${.CURDIR}/scripts/pkg-stage.sh
288	mkdir -p ${.OBJDIR}/dvd/packages/repos/
289	cp ${.CURDIR}/scripts/FreeBSD_install_cdrom.conf \
290		${.OBJDIR}/dvd/packages/repos/
291.endif
292	touch ${.TARGET}
293
294cdrom: disc1.iso bootonly.iso
295dvdrom: dvd1.iso
296ftp: packagesystem
297	rm -rf ftp
298	mkdir -p ftp
299	cp *.txz MANIFEST ftp
300
301release:	real-release vm-release cloudware-release
302	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} release-done
303	true
304
305release-done:
306	touch release
307
308real-release:
309	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} obj
310	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${RELEASE_TARGETS}
311
312install:	release-install vm-install
313
314release-install:
315.if defined(DESTDIR) && !empty(DESTDIR)
316	mkdir -p ${DESTDIR}
317.endif
318	cp -a ftp ${DESTDIR}/
319.if !empty(IMAGES)
320.for I in ${IMAGES}
321	cp -p ${I} ${DESTDIR}/${OSRELEASE}-${I}
322. if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
323	${XZ_CMD} -k ${DESTDIR}/${OSRELEASE}-${I}
324. endif
325.endfor
326	cd ${DESTDIR} && sha512 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA512
327	cd ${DESTDIR} && sha256 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA256
328.endif
329
330.include "${.CURDIR}/Makefile.inc1"
331.include "${.CURDIR}/Makefile.vm"
332