xref: /freebsd/release/Makefile (revision ba3c1f5972d7b90feb6e6da47905ff2757e0fe57)
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.include "${WORLDDIR}/share/mk/bsd.compat.pre.mk"
41
42.if !defined(TARGET) || empty(TARGET)
43TARGET=		${MACHINE}
44.endif
45.if !defined(TARGET_ARCH) || empty(TARGET_ARCH)
46.if ${TARGET} == ${MACHINE}
47TARGET_ARCH=	${MACHINE_ARCH}
48.else
49TARGET_ARCH=	${TARGET}
50.endif
51.endif
52IMAKE=		${MAKE} TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}
53DISTDIR=	dist
54
55# Define OSRELEASE by using newvers.sh
56.if !defined(OSRELEASE) || empty(OSRELEASE)
57.for _V in TYPE BRANCH REVISION
58${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
59.endfor
60.for _V in ${TARGET_ARCH}
61.if !empty(TARGET:M${_V})
62OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}
63VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET}
64.else
65OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}-${TARGET_ARCH}
66VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET_ARCH}
67.endif
68.endfor
69.endif
70
71.if !defined(VOLUME_LABEL) || empty(VOLUME_LABEL)
72VOLUME_LABEL=	FreeBSD_Install
73.endif
74
75.if !exists(${PORTSDIR})
76NOPORTS= true
77.endif
78
79EXTRA_PACKAGES=
80.if !defined(NOPORTS)
81EXTRA_PACKAGES+= ports.txz
82.endif
83.if !defined(NOSRC)
84EXTRA_PACKAGES+= src.txz
85.endif
86
87RELEASE_TARGETS= ftp
88IMAGES=
89.if exists(${.CURDIR}/${TARGET}/mkisoimages.sh)
90RELEASE_TARGETS+= cdrom
91IMAGES+=	disc1.iso bootonly.iso
92. if defined(WITH_DVD) && !empty(WITH_DVD)
93RELEASE_TARGETS+= dvdrom
94IMAGES+=	dvd1.iso
95. endif
96.endif
97.if exists(${.CURDIR}/${TARGET}/make-memstick.sh)
98RELEASE_TARGETS+= memstick.img
99RELEASE_TARGETS+= mini-memstick.img
100IMAGES+=	memstick.img
101IMAGES+=	mini-memstick.img
102.endif
103
104CLEANFILES=	packagesystem *.txz MANIFEST release ${IMAGES}
105.if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
106. for I in ${IMAGES}
107CLEANFILES+=	${I}.xz
108. endfor
109.endif
110.if defined(WITH_DVD) && !empty(WITH_DVD)
111CLEANFILES+=	pkg-stage
112.endif
113CLEANDIRS=	dist ftp disc1 bootonly dvd
114beforeclean:
115	chflags -R noschg .
116.include <bsd.obj.mk>
117clean: beforeclean
118
119base.txz:
120	mkdir -p ${DISTDIR}
121	cd ${WORLDDIR} && ${IMAKE} distributeworld DISTDIR=${.OBJDIR}/${DISTDIR}
122# TODO: Add NO_ROOT mode to mm-tree.sh
123.if !defined(NO_ROOT)
124# Set up mergemaster root database
125	sh ${.CURDIR}/scripts/mm-mtree.sh -m ${WORLDDIR} -F \
126	    "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET} ${.MAKE.JOBS:D-j${.MAKE.JOBS}}" \
127	    -D "${.OBJDIR}/${DISTDIR}/base"
128.endif
129	sh ${WORLDDIR}/usr.sbin/etcupdate/etcupdate.sh extract -B \
130	    -m "${MAKE}" -M "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}" \
131	    -s ${WORLDDIR} -d "${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate" \
132	    ${NO_ROOT:D-N}
133.if defined(NO_ROOT)
134	echo "./var/db/etcupdate type=dir uname=root gname=wheel mode=0755" >> ${.OBJDIR}/${DISTDIR}/base.meta
135	sed -n 's,^\.,./var/db/etcupdate/current,p' ${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate/current/METALOG \
136	    >> ${.OBJDIR}/${DISTDIR}/base.meta
137	rm ${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate/current/METALOG
138.endif
139# Package all components
140	cd ${WORLDDIR} && ${IMAKE} packageworld DISTDIR=${.OBJDIR}/${DISTDIR}
141	mv ${DISTDIR}/*.txz .
142
143kernel.txz:
144	mkdir -p ${DISTDIR}
145	cd ${WORLDDIR} && ${IMAKE} distributekernel packagekernel DISTDIR=${.OBJDIR}/${DISTDIR}
146	mv ${DISTDIR}/kernel*.txz .
147
148src.txz:
149	mkdir -p ${DISTDIR}/usr
150	ln -fs ${WORLDDIR} ${DISTDIR}/usr/src
151	cd ${DISTDIR} && ${TAR_CMD} cLvf - --exclude .svn --exclude .zfs \
152	    --exclude .git --exclude @ --exclude usr/src/release/dist usr/src | \
153	    ${XZ_CMD} > ${.OBJDIR}/src.txz
154
155ports.txz:
156	mkdir -p ${DISTDIR}/usr
157	ln -fs ${PORTSDIR} ${DISTDIR}/usr/ports
158	cd ${DISTDIR} && ${TAR_CMD} cLvf - \
159	    --exclude .git --exclude .svn \
160	    --exclude usr/ports/distfiles --exclude usr/ports/packages \
161	    --exclude 'usr/ports/INDEX*' --exclude work usr/ports | \
162	    ${XZ_CMD} > ${.OBJDIR}/ports.txz
163
164disc1: packagesystem
165# Install system
166	mkdir -p ${.TARGET}
167	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
168	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
169	    MK_INSTALLLIB=no MK_MAIL=no \
170	    ${_ALL_LIBCOMPATS:@v@MK_LIB$v=no@} \
171	    MK_TOOLCHAIN=no MK_PROFILE=no \
172	    MK_RESCUE=no MK_DICT=no \
173	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
174	    -DDB_FROM_SRC
175# Copy distfiles
176	mkdir -p ${.TARGET}/usr/freebsd-dist
177	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
178	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
179	done
180.if defined(NO_ROOT)
181	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
182	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
183	    do echo "./usr/freebsd-dist/$${dist} type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG; \
184	done
185.endif
186# Set up installation environment
187	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
188	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
189	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
190	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
191	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
192	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
193	echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf
194	cp ${.CURDIR}/rc.local ${.TARGET}/etc
195.if defined(NO_ROOT)
196	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
197	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
198	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
199	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
200	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
201.endif
202	touch ${.TARGET}
203
204bootonly: packagesystem
205# Install system
206	mkdir -p ${.TARGET}
207	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
208	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
209	    MK_GAMES=no \
210	    MK_INSTALLLIB=no MK_MAIL=no \
211	    ${_ALL_LIBCOMPATS:@v@MK_LIB$v=no@} \
212	    MK_TOOLCHAIN=no MK_PROFILE=no \
213	    MK_RESCUE=no MK_DICT=no \
214	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
215	    -DDB_FROM_SRC
216# Copy manifest only (no distfiles) to get checksums
217	mkdir -p ${.TARGET}/usr/freebsd-dist
218	cp MANIFEST ${.TARGET}/usr/freebsd-dist
219.if defined(NO_ROOT)
220	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
221	echo "./usr/freebsd-dist/MANIFEST type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
222.endif
223# Set up installation environment
224	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
225	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
226	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
227	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
228	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
229	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
230	echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf
231	cp ${.CURDIR}/rc.local ${.TARGET}/etc
232.if defined(NO_ROOT)
233	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
234	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
235	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
236	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
237	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
238.endif
239
240dvd: packagesystem
241# Install system
242	mkdir -p ${.TARGET}
243	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
244		DESTDIR=${.OBJDIR}/${.TARGET} MK_RESCUE=no MK_KERNEL_SYMBOLS=no \
245		MK_TESTS=no MK_DEBUG_FILES=no \
246		-DDB_FROM_SRC
247# Copy distfiles
248	mkdir -p ${.TARGET}/usr/freebsd-dist
249	for dist in MANIFEST $$(ls *.txz | grep -v -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
250	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
251	done
252.if defined(NO_ROOT)
253	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
254	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
255	    do echo "./usr/freebsd-dist/$${dist} type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG; \
256	done
257.endif
258# Set up installation environment
259	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
260	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
261	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
262	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
263	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
264	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
265	echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf
266	cp ${.CURDIR}/rc.local ${.TARGET}/etc
267.if defined(NO_ROOT)
268	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
269	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
270	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
271	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
272	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
273.endif
274	touch ${.TARGET}
275
276release.iso: disc1.iso
277disc1.iso: disc1
278	cd disc1 && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_CD ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
279
280dvd1.iso: dvd pkg-stage
281	cd dvd && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_DVD ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
282
283bootonly.iso: bootonly
284	cd bootonly && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_BO ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
285
286memstick: memstick.img
287memstick.img: disc1
288	cd disc1 && sh ${.CURDIR}/${TARGET}/make-memstick.sh .${NO_ROOT:D/METALOG} ../${.TARGET}
289
290mini-memstick: mini-memstick.img
291mini-memstick.img: bootonly
292	cd bootonly && sh ${.CURDIR}/${TARGET}/make-memstick.sh .${NO_ROOT:D/METALOG} ../${.TARGET}
293
294packagesystem: base.txz kernel.txz ${EXTRA_PACKAGES}
295	sh ${.CURDIR}/scripts/make-manifest.sh *.txz > MANIFEST
296	touch ${.TARGET}
297
298pkg-stage:
299# TODO: Support for -DNO_ROOT
300.if !defined(NOPKG) || empty(NOPKG)
301	env PORTSDIR=${PORTSDIR} REPOS_DIR=${.CURDIR}/pkg_repos/ \
302		sh ${.CURDIR}/scripts/pkg-stage.sh
303	mkdir -p ${.OBJDIR}/dvd/packages/repos/
304	cp ${.CURDIR}/scripts/FreeBSD_install_cdrom.conf \
305		${.OBJDIR}/dvd/packages/repos/
306.endif
307	touch ${.TARGET}
308
309cdrom: disc1.iso bootonly.iso
310dvdrom: dvd1.iso
311ftp: packagesystem
312	rm -rf ftp
313	mkdir -p ftp
314	cp *.txz MANIFEST ftp
315
316release:	real-release vm-release cloudware-release
317	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} release-done
318	true
319
320release-done:
321	touch release
322
323real-release:
324	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} obj
325	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${RELEASE_TARGETS}
326
327install:	release-install vm-install
328
329release-install:
330.if defined(DESTDIR) && !empty(DESTDIR)
331	mkdir -p ${DESTDIR}
332.endif
333	cp -a ftp ${DESTDIR}/
334.if !empty(IMAGES)
335.for I in ${IMAGES}
336	cp -p ${I} ${DESTDIR}/${OSRELEASE}-${I}
337. if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
338	${XZ_CMD} -k ${DESTDIR}/${OSRELEASE}-${I}
339. endif
340.endfor
341	cd ${DESTDIR} && sha512 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA512
342	cd ${DESTDIR} && sha256 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA256
343.endif
344
345.include "${.CURDIR}/Makefile.inc1"
346.include "${.CURDIR}/Makefile.vm"
347