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