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