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