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