xref: /freebsd/release/Makefile (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
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
78DISTRIBUTIONS= base.txz kernel.txz
79.if !defined(NOPORTS)
80DISTRIBUTIONS+= ports.txz
81.endif
82.if !defined(NOSRC)
83DISTRIBUTIONS+= 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 disc1-disc1 disc1-memstick bootonly bootonly-bootonly bootonly-memstick 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	# Bootstrap etcupdate(8) database.
122	sh ${WORLDDIR}/usr.sbin/etcupdate/etcupdate.sh extract -B \
123	    -m "${MAKE}" -M "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}" \
124	    -s ${WORLDDIR} -d "${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate" \
125	    ${NO_ROOT:D-N}
126.if defined(NO_ROOT)
127	echo "./var/db/etcupdate type=dir uname=root gname=wheel mode=0755" >> ${.OBJDIR}/${DISTDIR}/base.meta
128	sed -n 's,^\.,./var/db/etcupdate/current,p' ${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate/current/METALOG \
129	    >> ${.OBJDIR}/${DISTDIR}/base.meta
130	rm ${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate/current/METALOG
131.endif
132# Package all components
133	( cd ${WORLDDIR} && ${IMAKE} packageworld DISTDIR=${.OBJDIR}/${DISTDIR} )
134	mv ${DISTDIR}/*.txz .
135
136kernel.txz:
137	mkdir -p ${DISTDIR}
138	( cd ${WORLDDIR} && ${IMAKE} distributekernel DISTDIR=${.OBJDIR}/${DISTDIR} )
139	( cd ${WORLDDIR} && ${IMAKE} packagekernel DISTDIR=${.OBJDIR}/${DISTDIR} )
140	mv ${DISTDIR}/kernel*.txz .
141
142src.txz:
143	mkdir -p ${DISTDIR}/usr
144	ln -fs ${WORLDDIR} ${DISTDIR}/usr/src
145	( cd ${DISTDIR} && ${TAR_CMD} cLvf - --exclude .svn --exclude .zfs \
146	    --exclude .git --exclude @ --exclude usr/src/release/dist usr/src | \
147	    ${XZ_CMD} > ${.OBJDIR}/src.txz )
148
149ports.txz:
150	mkdir -p ${DISTDIR}/usr
151	ln -fs ${PORTSDIR} ${DISTDIR}/usr/ports
152	( cd ${DISTDIR} && ${TAR_CMD} cLvf - \
153	    --exclude .git --exclude .svn \
154	    --exclude usr/ports/distfiles --exclude usr/ports/packages \
155	    --exclude 'usr/ports/INDEX*' --exclude work usr/ports | \
156	    ${XZ_CMD} > ${.OBJDIR}/ports.txz )
157
158disc1: packagesystem
159# Install system
160	mkdir -p ${.TARGET}
161	( cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
162	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
163	    MK_INSTALLLIB=no MK_MAIL=no \
164	    ${_ALL_LIBCOMPATS:@v@MK_LIB$v=no@} \
165	    MK_TOOLCHAIN=no MK_PROFILE=no \
166	    MK_RESCUE=no MK_DICT=no \
167	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
168	    -DDB_FROM_SRC )
169# Copy distfiles
170	mkdir -p ${.TARGET}/usr/freebsd-dist
171	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
172	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
173	done
174.if defined(NO_ROOT)
175	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
176	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
177	    do echo "./usr/freebsd-dist/$${dist} type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG; \
178	done
179.endif
180# Set up installation environment
181	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
182	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
183	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
184	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
185	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
186	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
187	echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf
188	cp ${.CURDIR}/rc.local ${.TARGET}/etc
189.if defined(NO_ROOT)
190	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
191	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
192	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
193	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
194	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
195.endif
196	touch ${.TARGET}
197
198bootonly: packagesystem
199# Install system
200	mkdir -p ${.TARGET}
201	( cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
202	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
203	    MK_GAMES=no \
204	    MK_INSTALLLIB=no MK_MAIL=no \
205	    ${_ALL_LIBCOMPATS:@v@MK_LIB$v=no@} \
206	    MK_TOOLCHAIN=no MK_PROFILE=no \
207	    MK_RESCUE=no MK_DICT=no \
208	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
209	    -DDB_FROM_SRC )
210# Copy manifest only (no distfiles) to get checksums
211	mkdir -p ${.TARGET}/usr/freebsd-dist
212	cp MANIFEST ${.TARGET}/usr/freebsd-dist
213.if defined(NO_ROOT)
214	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
215	echo "./usr/freebsd-dist/MANIFEST type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
216.endif
217# Set up installation environment
218	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
219	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
220	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
221	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
222	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
223	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
224	echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf
225	cp ${.CURDIR}/rc.local ${.TARGET}/etc
226.if defined(NO_ROOT)
227	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
228	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
229	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
230	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
231	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
232.endif
233
234dvd: packagesystem
235# Install system
236	mkdir -p ${.TARGET}
237	( cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
238		DESTDIR=${.OBJDIR}/${.TARGET} MK_RESCUE=no MK_KERNEL_SYMBOLS=no \
239		MK_TESTS=no MK_DEBUG_FILES=no \
240		-DDB_FROM_SRC )
241# Copy distfiles
242	mkdir -p ${.TARGET}/usr/freebsd-dist
243	for dist in MANIFEST $$(ls *.txz | grep -v -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
244	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
245	done
246.if defined(NO_ROOT)
247	echo "./usr/freebsd-dist type=dir uname=root gname=wheel mode=0755" >> ${.TARGET}/METALOG
248	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(${base ${_ALL_libcompats}:L:ts|})-dbg'); \
249	    do echo "./usr/freebsd-dist/$${dist} type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG; \
250	done
251.endif
252# Set up installation environment
253	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
254	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
255	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
256	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
257	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
258	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
259	echo loader_menu_multi_user_prompt=\"Installer\" >> ${.TARGET}/boot/loader.conf
260	cp ${.CURDIR}/rc.local ${.TARGET}/etc
261.if defined(NO_ROOT)
262	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
263	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
264	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
265	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
266	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
267.endif
268	touch ${.TARGET}
269
270disc1-disc1 disc1-memstick: disc1
271	mkdir ${.TARGET}
272	tar -cf- -C disc1 . | tar -xf- -C ${.TARGET}
273
274bootonly-bootonly bootonly-memstick: bootonly
275	mkdir ${.TARGET}
276	tar -cf- -C bootonly . | tar -xf- -C ${.TARGET}
277
278release.iso: disc1.iso
279disc1.iso: disc1-disc1
280	cd disc1-disc1 && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_CD ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
281
282dvd1.iso: dvd pkg-stage
283	cd dvd && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_DVD ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
284
285bootonly.iso: bootonly-bootonly
286	cd bootonly-bootonly && sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_BO ../${.TARGET} .${NO_ROOT:D/METALOG} ${XTRADIR}
287
288memstick: memstick.img
289memstick.img: disc1-memstick
290	cd disc1-memstick && sh ${.CURDIR}/${TARGET}/make-memstick.sh .${NO_ROOT:D/METALOG} ../${.TARGET}
291
292mini-memstick: mini-memstick.img
293mini-memstick.img: bootonly-memstick
294	cd bootonly-memstick && sh ${.CURDIR}/${TARGET}/make-memstick.sh .${NO_ROOT:D/METALOG} ../${.TARGET}
295
296packagesystem: ${DISTRIBUTIONS}
297	sh ${.CURDIR}/scripts/make-manifest.sh *.txz > MANIFEST
298	touch ${.TARGET}
299
300pkg-stage: dvd
301# TODO: Support for -DNO_ROOT
302.if !defined(NOPKG) || empty(NOPKG)
303	env PORTSDIR=${PORTSDIR} REPOS_DIR=${.CURDIR}/pkg_repos/ \
304		sh ${.CURDIR}/scripts/pkg-stage.sh
305	mkdir -p ${.OBJDIR}/dvd/packages/repos/
306	cp ${.CURDIR}/scripts/FreeBSD_install_cdrom.conf \
307		${.OBJDIR}/dvd/packages/repos/
308.endif
309	touch ${.TARGET}
310
311cdrom: disc1.iso bootonly.iso
312dvdrom: dvd1.iso
313ftp: packagesystem
314	rm -rf ftp
315	mkdir -p ftp
316	cp *.txz MANIFEST ftp
317
318release:	real-release vm-release cloudware-release
319	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} release-done
320	true
321
322release-done:
323	touch release
324
325real-release:
326	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} obj
327	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${RELEASE_TARGETS}
328
329install:	release-install vm-install
330
331release-install:
332.if defined(DESTDIR) && !empty(DESTDIR)
333	mkdir -p ${DESTDIR}
334.endif
335	cp -a ftp ${DESTDIR}/
336.if !empty(IMAGES)
337.for I in ${IMAGES}
338	cp -p ${I} ${DESTDIR}/${OSRELEASE}-${I}
339. if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
340	${XZ_CMD} -k ${DESTDIR}/${OSRELEASE}-${I}
341. endif
342.endfor
343	( cd ${DESTDIR} && sha512 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA512 )
344	( cd ${DESTDIR} && sha256 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA256 )
345.endif
346
347.include "${.CURDIR}/Makefile.inc1"
348.include "${.CURDIR}/Makefile.vm"
349