xref: /freebsd/release/Makefile (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
1# $FreeBSD$
2#
3# Makefile for building releases and release media.
4#
5# User-driven targets:
6#  cdrom: Builds release CD-ROM media (disc1.iso)
7#  dvdrom: Builds release DVD-ROM media (dvd1.iso)
8#  memstick: Builds memory stick image (memstick.img)
9#  mini-memstick: Builds minimal memory stick image (mini-memstick.img)
10#  ftp: Sets up FTP distribution area (ftp)
11#  release: Invokes real-release, vm-release, and cloudware-release targets
12#  real-release: Build all media and FTP distribution area
13#  vm-release: Build all virtual machine image targets
14#  cloudware-release: Build all cloud hosting provider targets
15#  install: Invokes the release-install and vm-install targets
16#  release-install: Copies all release installation media into ${DESTDIR}
17#  vm-install: Copies all virtual machine 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.if !defined(TARGET) || empty(TARGET)
41TARGET=		${MACHINE}
42.endif
43.if !defined(TARGET_ARCH) || empty(TARGET_ARCH)
44.if ${TARGET} == ${MACHINE}
45TARGET_ARCH=	${MACHINE_ARCH}
46.else
47TARGET_ARCH=	${TARGET}
48.endif
49.endif
50IMAKE=		${MAKE} TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}
51DISTDIR=	dist
52
53# Define OSRELEASE by using newvers.sh
54.if !defined(OSRELEASE) || empty(OSRELEASE)
55.for _V in TYPE BRANCH REVISION
56${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
57.endfor
58.for _V in ${TARGET_ARCH}
59.if !empty(TARGET:M${_V})
60OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}
61VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET}
62.else
63OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}-${TARGET_ARCH}
64VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET_ARCH}
65.endif
66.endfor
67.endif
68
69.if !defined(VOLUME_LABEL) || empty(VOLUME_LABEL)
70VOLUME_LABEL=	FreeBSD_Install
71.endif
72
73.if !exists(${PORTSDIR})
74NOPORTS= true
75.endif
76
77EXTRA_PACKAGES=
78.if !defined(NOPORTS)
79EXTRA_PACKAGES+= ports.txz
80.endif
81.if !defined(NOSRC)
82EXTRA_PACKAGES+= src.txz
83.endif
84
85RELEASE_TARGETS= ftp
86IMAGES=
87.if exists(${.CURDIR}/${TARGET}/mkisoimages.sh)
88RELEASE_TARGETS+= cdrom
89IMAGES+=	disc1.iso bootonly.iso
90. if defined(WITH_DVD) && !empty(WITH_DVD)
91RELEASE_TARGETS+= dvdrom
92IMAGES+=	dvd1.iso
93. endif
94.endif
95.if exists(${.CURDIR}/${TARGET}/make-memstick.sh)
96RELEASE_TARGETS+= memstick.img
97RELEASE_TARGETS+= mini-memstick.img
98IMAGES+=	memstick.img
99IMAGES+=	mini-memstick.img
100.endif
101
102CLEANFILES=	packagesystem *.txz MANIFEST release ${IMAGES}
103.if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
104. for I in ${IMAGES}
105CLEANFILES+=	${I}.xz
106. endfor
107.endif
108.if defined(WITH_DVD) && !empty(WITH_DVD)
109CLEANFILES+=	pkg-stage
110.endif
111CLEANDIRS=	dist ftp disc1 bootonly dvd
112beforeclean:
113	chflags -R noschg .
114.include <bsd.obj.mk>
115clean: beforeclean
116
117base.txz:
118	mkdir -p ${DISTDIR}
119	cd ${WORLDDIR} && ${IMAKE} distributeworld DISTDIR=${.OBJDIR}/${DISTDIR}
120# TODO: Add NO_ROOT mode to mm-tree.sh
121.if !defined(NO_ROOT)
122# Set up mergemaster root database
123	sh ${.CURDIR}/scripts/mm-mtree.sh -m ${WORLDDIR} -F \
124	    "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET} ${.MAKE.JOBS:D-j${.MAKE.JOBS}}" \
125	    -D "${.OBJDIR}/${DISTDIR}/base"
126.endif
127	sh ${WORLDDIR}/usr.sbin/etcupdate/etcupdate.sh extract -B \
128	    -m "${MAKE}" -M "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}" \
129	    -s ${WORLDDIR} -d "${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate" \
130	    ${NO_ROOT:D-N}
131.if defined(NO_ROOT)
132	echo "./var/db/etcupdate type=dir uname=root gname=wheel mode=0755" >> ${.OBJDIR}/${DISTDIR}/base.meta
133	sed -n 's,^\.,./var/db/etcupdate/current,p' ${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate/current/METALOG \
134	    >> ${.OBJDIR}/${DISTDIR}/base.meta
135	rm ${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate/current/METALOG
136.endif
137# Package all components
138	cd ${WORLDDIR} && ${IMAKE} packageworld DISTDIR=${.OBJDIR}/${DISTDIR}
139	mv ${DISTDIR}/*.txz .
140
141kernel.txz:
142	mkdir -p ${DISTDIR}
143	cd ${WORLDDIR} && ${IMAKE} distributekernel packagekernel DISTDIR=${.OBJDIR}/${DISTDIR}
144	mv ${DISTDIR}/kernel*.txz .
145
146src.txz:
147	mkdir -p ${DISTDIR}/usr
148	ln -fs ${WORLDDIR} ${DISTDIR}/usr/src
149	cd ${DISTDIR} && ${TAR_CMD} cLvf - --exclude .svn --exclude .zfs \
150	    --exclude .git --exclude @ --exclude usr/src/release/dist usr/src | \
151	    ${XZ_CMD} > ${.OBJDIR}/src.txz
152
153ports.txz:
154	mkdir -p ${DISTDIR}/usr
155	ln -fs ${PORTSDIR} ${DISTDIR}/usr/ports
156	cd ${DISTDIR} && ${TAR_CMD} cLvf - \
157	    --exclude .git --exclude .svn \
158	    --exclude usr/ports/distfiles --exclude usr/ports/packages \
159	    --exclude 'usr/ports/INDEX*' --exclude work usr/ports | \
160	    ${XZ_CMD} > ${.OBJDIR}/ports.txz
161
162disc1: packagesystem
163# Install system
164	mkdir -p ${.TARGET}
165	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
166	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
167	    MK_INSTALLLIB=no MK_LIB32=no MK_MAIL=no \
168	    MK_TOOLCHAIN=no MK_PROFILE=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|lib32)-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|lib32)-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	cp ${.CURDIR}/rc.local ${.TARGET}/etc
191.if defined(NO_ROOT)
192	echo "./etc/resolv.conf type=link uname=root gname=wheel mode=0644 link=/tmp/bsdinstall_etc/resolv.conf" >> ${.TARGET}/METALOG
193	echo "./etc/rc.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
194	echo "./etc/sysctl.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
195	echo "./boot/loader.conf type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
196	echo "./etc/rc.local type=file uname=root gname=wheel mode=0644" >> ${.TARGET}/METALOG
197.endif
198	touch ${.TARGET}
199
200bootonly: packagesystem
201# Install system
202	mkdir -p ${.TARGET}
203	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
204	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
205	    MK_GAMES=no \
206	    MK_INSTALLLIB=no MK_LIB32=no MK_MAIL=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	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|lib32)-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|lib32)-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	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: base.txz kernel.txz ${EXTRA_PACKAGES}
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