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