xref: /freebsd/release/Makefile (revision 38d120bc13ac1de5b739b67b87016b9122149374)
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: Build all media and FTP distribution area
12#  install: Copies all release media into ${DESTDIR}
13#
14# Variables affecting the build process:
15#  WORLDDIR: location of src tree -- must have built world and default kernel
16#            (by default, the directory above this one)
17#  PORTSDIR: location of ports tree to distribute (default: /usr/ports)
18#  DOCDIR:   location of doc tree (default: /usr/doc)
19#  NOPKG:    if set, do not distribute third-party packages
20#  NOPORTS:  if set, do not distribute ports tree
21#  NOSRC:    if set, do not distribute source tree
22#  NODOC:    if set, do not generate release documentation
23#  WITH_DVD: if set, generate dvd1.iso
24#  WITH_COMPRESSED_IMAGES: if set, compress installation images with xz(1)
25#		(uncompressed images are not removed)
26#  WITH_VMIMAGES: if set, build virtual machine images with the release
27#  WITH_COMPRESSED_VMIMAGES: if set, compress virtual machine disk images
28#  		with xz(1) (extremely time consuming)
29#  TARGET/TARGET_ARCH: architecture of built release
30#
31
32WORLDDIR?=	${.CURDIR}/..
33PORTSDIR?=	/usr/ports
34DOCDIR?=	/usr/doc
35RELNOTES_LANG?= en_US.ISO8859-1
36XZCMD?=		/usr/bin/xz
37
38.if !defined(TARGET) || empty(TARGET)
39TARGET=		${MACHINE}
40.endif
41.if !defined(TARGET_ARCH) || empty(TARGET_ARCH)
42.if ${TARGET} == ${MACHINE}
43TARGET_ARCH=	${MACHINE_ARCH}
44.else
45TARGET_ARCH=	${TARGET}
46.endif
47.endif
48IMAKE=		${MAKE} TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}
49DISTDIR=	dist
50
51# Define OSRELEASE by using newvars.sh
52.if !defined(OSRELEASE) || empty(OSRELEASE)
53.for _V in TYPE BRANCH REVISION
54${_V}!=	eval $$(awk '/^${_V}=/{print}' ${.CURDIR}/../sys/conf/newvers.sh); echo $$${_V}
55.endfor
56.for _V in ${TARGET_ARCH}
57.if !empty(TARGET:M${_V})
58OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}
59VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET}
60.else
61OSRELEASE=	${TYPE}-${REVISION}-${BRANCH}-${TARGET}-${TARGET_ARCH}
62VOLUME_LABEL=	${REVISION:C/[.-]/_/g}_${BRANCH:C/[.-]/_/g}_${TARGET_ARCH}
63.endif
64.endfor
65.endif
66
67.if !defined(VOLUME_LABEL) || empty(VOLUME_LABEL)
68VOLUME_LABEL=	FreeBSD_Install
69.endif
70
71.if !exists(${DOCDIR})
72NODOC= true
73.endif
74.if !exists(${PORTSDIR})
75NOPORTS= true
76.endif
77
78EXTRA_PACKAGES=
79.if !defined(NOPORTS)
80EXTRA_PACKAGES+= ports.txz
81.endif
82.if !defined(NOSRC)
83EXTRA_PACKAGES+= src.txz
84.endif
85.if !defined(NODOC)
86EXTRA_PACKAGES+= reldoc
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
106VMTARGETS=	vm-base vm-image
107VMFORMATS?=	vhd vmdk qcow2 raw
108VMSIZE?=	20G
109VMBASE?=	vm
110AZURECONF?=	${.CURDIR}/tools/azure.conf
111
112CLEANFILES=	packagesystem *.txz MANIFEST system ${IMAGES}
113.if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
114. for I in ${IMAGES}
115CLEANFILES+=	${I}.xz
116. endfor
117.endif
118.if defined(WITH_DVD) && !empty(WITH_DVD)
119CLEANFILES+=	pkg-stage
120.endif
121.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
122CLEANFILES+=	${VMBASE}.img
123. for FORMAT in ${VMFORMATS}
124CLEANFILES+=	${VMBASE}.${FORMAT}
125. endfor
126.endif
127CLEANDIRS=	dist ftp release bootonly dvd
128.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
129CLEANDIRS+=	${VMTARGETS}
130.endif
131.if exists(${.CURDIR}/${TARGET}/mk-azure.sh)
132CLEANFILES+=	${OSRELEASE}.vhd \
133		${OSRELEASE}.vhd.raw \
134		azure.img
135CLEANDIRS+=	vm-azure
136.endif
137beforeclean:
138	chflags -R noschg .
139.include <bsd.obj.mk>
140clean: beforeclean
141
142base.txz:
143	mkdir -p ${DISTDIR}
144	cd ${WORLDDIR} && ${IMAKE} distributeworld DISTDIR=${.OBJDIR}/${DISTDIR}
145# Set up mergemaster root database
146	sh ${.CURDIR}/scripts/mm-mtree.sh -m ${WORLDDIR} -F \
147	    "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}" -D "${.OBJDIR}/${DISTDIR}/base"
148	etcupdate extract -B -M "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}" \
149	    -s ${WORLDDIR} -d "${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate"
150# Package all components
151	cd ${WORLDDIR} && ${IMAKE} packageworld DISTDIR=${.OBJDIR}/${DISTDIR}
152	mv ${DISTDIR}/*.txz .
153
154kernel.txz:
155	mkdir -p ${DISTDIR}
156	cd ${WORLDDIR} && ${IMAKE} distributekernel packagekernel DISTDIR=${.OBJDIR}/${DISTDIR}
157	mv ${DISTDIR}/kernel*.txz .
158
159src.txz:
160	mkdir -p ${DISTDIR}/usr
161	ln -fs ${WORLDDIR} ${DISTDIR}/usr/src
162	cd ${DISTDIR} && tar cLvJf ${.OBJDIR}/src.txz --exclude .svn --exclude .zfs \
163	    --exclude .git --exclude @ --exclude usr/src/release/dist usr/src
164
165ports.txz:
166	mkdir -p ${DISTDIR}/usr
167	ln -fs ${PORTSDIR} ${DISTDIR}/usr/ports
168	cd ${DISTDIR} && tar cLvJf ${.OBJDIR}/ports.txz \
169	    --exclude .git --exclude .svn \
170	    --exclude usr/ports/distfiles --exclude usr/ports/packages \
171	    --exclude 'usr/ports/INDEX*' --exclude work usr/ports
172
173reldoc:
174	cd ${.CURDIR}/doc && ${MAKE} all install clean 'FORMATS=html txt' \
175	    INSTALL_COMPRESSED='' URLS_ABSOLUTE=YES DOCDIR=${.OBJDIR}/rdoc
176	mkdir -p reldoc
177.for i in hardware readme relnotes errata
178	ln -f rdoc/${RELNOTES_LANG}/${i}/article.txt reldoc/${i:tu}.TXT
179	ln -f rdoc/${RELNOTES_LANG}/${i}/article.html reldoc/${i:tu}.HTM
180.endfor
181	cp rdoc/${RELNOTES_LANG}/readme/docbook.css reldoc
182
183system: packagesystem
184# Install system
185	mkdir -p release
186	cd ${WORLDDIR} && ${IMAKE} installkernel installworld distribution \
187		DESTDIR=${.OBJDIR}/release MK_RESCUE=no MK_KERNEL_SYMBOLS=no \
188		MK_PROFILE=no MK_SENDMAIL=no MK_TESTS=no MK_LIB32=no \
189		MK_DEBUG_FILES=no
190# Copy distfiles
191	mkdir -p release/usr/freebsd-dist
192	for dist in MANIFEST $$(ls *.txz | grep -v -- '-dbg'); \
193	    do cp $${dist} release/usr/freebsd-dist; \
194	done
195# Copy documentation, if generated
196.if !defined(NODOC)
197	cp reldoc/* release
198.endif
199# Set up installation environment
200	ln -fs /tmp/bsdinstall_etc/resolv.conf release/etc/resolv.conf
201	echo sendmail_enable=\"NONE\" > release/etc/rc.conf
202	echo hostid_enable=\"NO\" >> release/etc/rc.conf
203	echo debug.witness.trace=0 >> release/etc/sysctl.conf
204	cp ${.CURDIR}/rc.local release/etc
205	touch ${.TARGET}
206
207bootonly: packagesystem
208# Install system
209	mkdir -p bootonly
210	cd ${WORLDDIR} && ${IMAKE} installkernel installworld distribution \
211	    DESTDIR=${.OBJDIR}/bootonly MK_AMD=no MK_AT=no \
212	    MK_GAMES=no MK_GROFF=no \
213	    MK_INSTALLLIB=no MK_LIB32=no MK_MAIL=no \
214	    MK_NCP=no MK_TOOLCHAIN=no MK_PROFILE=no \
215	    MK_INSTALLIB=no MK_RESCUE=no MK_DICT=no \
216	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no
217# Copy manifest only (no distfiles) to get checksums
218	mkdir -p bootonly/usr/freebsd-dist
219	cp MANIFEST bootonly/usr/freebsd-dist
220# Copy documentation, if generated
221.if !defined(NODOC)
222	cp reldoc/* bootonly
223.endif
224# Set up installation environment
225	ln -fs /tmp/bsdinstall_etc/resolv.conf bootonly/etc/resolv.conf
226	echo sendmail_enable=\"NONE\" > bootonly/etc/rc.conf
227	echo hostid_enable=\"NO\" >> bootonly/etc/rc.conf
228	echo debug.witness.trace=0 >> bootonly/etc/sysctl.conf
229	cp ${.CURDIR}/rc.local bootonly/etc
230
231dvd:
232# Install system
233	mkdir -p ${.TARGET}
234	cd ${WORLDDIR} && ${IMAKE} installkernel installworld distribution \
235		DESTDIR=${.OBJDIR}/${.TARGET} MK_RESCUE=no MK_KERNEL_SYMBOLS=no \
236		MK_TESTS=no MK_DEBUG_FILES=no
237# Copy distfiles
238	mkdir -p ${.TARGET}/usr/freebsd-dist
239	for dist in MANIFEST $$(ls *.txz | grep -v -- '-dbg'); \
240	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
241	done
242# Copy documentation, if generated
243.if !defined(NODOC)
244	cp reldoc/* ${.TARGET}
245.endif
246# Set up installation environment
247	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
248	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
249	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
250	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
251	cp ${.CURDIR}/rc.local ${.TARGET}/etc
252	touch ${.TARGET}
253
254release.iso: disc1.iso
255disc1.iso: system
256	sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_CD ${.TARGET} release
257
258dvd1.iso: dvd pkg-stage
259	sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_DVD ${.TARGET} dvd
260
261bootonly.iso: bootonly
262	sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_BO ${.TARGET} bootonly
263
264memstick: memstick.img
265memstick.img: system
266	sh ${.CURDIR}/${TARGET}/make-memstick.sh release ${.TARGET}
267
268mini-memstick: mini-memstick.img
269mini-memstick.img: system
270	sh ${.CURDIR}/${TARGET}/make-memstick.sh bootonly ${.TARGET}
271
272packagesystem: base.txz kernel.txz ${EXTRA_PACKAGES}
273	sh ${.CURDIR}/scripts/make-manifest.sh *.txz > MANIFEST
274	touch ${.TARGET}
275
276pkg-stage:
277.if !defined(NOPKG)
278	env REPOS_DIR=${.CURDIR}/pkg_repos/ \
279		sh ${.CURDIR}/scripts/pkg-stage.sh
280	mkdir -p ${.OBJDIR}/dvd/packages/repos/
281	cp ${.CURDIR}/scripts/FreeBSD_install_cdrom.conf \
282		${.OBJDIR}/dvd/packages/repos/
283.endif
284	touch ${.TARGET}
285
286cdrom: disc1.iso bootonly.iso
287dvdrom: dvd1.iso
288ftp: packagesystem
289	rm -rf ftp
290	mkdir -p ftp
291	cp *.txz MANIFEST ftp
292
293release:
294	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} obj
295	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${RELEASE_TARGETS}
296.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
297	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${VMTARGETS}
298.endif
299
300install:
301.if defined(DESTDIR) && !empty(DESTDIR)
302	mkdir -p ${DESTDIR}
303.endif
304	cp -a ftp ${DESTDIR}/
305.for I in ${IMAGES}
306	cp -p ${I} ${DESTDIR}/${OSRELEASE}-${I}
307. if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
308	${XZCMD} -k ${DESTDIR}/${OSRELEASE}-${I}
309. endif
310.endfor
311	cd ${DESTDIR} && sha256 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA256
312	cd ${DESTDIR} && md5 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.MD5
313.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
314	mkdir -p ${DESTDIR}/vmimages
315. for FORMAT in ${VMFORMATS}
316	cp -p ${VMBASE}.${FORMAT} \
317		${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
318. endfor
319. if defined(WITH_COMPRESSED_VMIMAGES) && !empty(WITH_COMPRESSED_VMIMAGES)
320# This is very time consuming, so defer it after the images are moved to
321# the DESTDIR.
322.  for FORMAT in ${VMFORMATS}
323	# Don't keep the originals.  There is a copy in ${.OBJDIR} if needed.
324	${XZCMD} ${DESTDIR}/vmimages/${OSRELEASE}.${FORMAT}
325.  endfor
326. endif
327	cd ${DESTDIR}/vmimages && sha256 ${OSRELEASE}* > \
328		${DESTDIR}/vmimages/CHECKSUM.SHA256
329	cd ${DESTDIR}/vmimages && md5 ${OSRELEASE}* > \
330		${DESTDIR}/vmimages/CHECKSUM.MD5
331.endif
332
333vm-base:
334.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
335. if exists(${.CURDIR}/${TARGET}/mk-vmimage.sh)
336	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
337		${.CURDIR}/${TARGET}/mk-vmimage.sh ${.TARGET} \
338		${VMBASE}.img ${WORLDDIR} ${.OBJDIR}/${.TARGET} ${VMSIZE}
339. endif
340.endif
341	touch ${.TARGET}
342
343vm-image: vm-base
344.if defined(WITH_VMIMAGES) && !empty(WITH_VMIMAGES)
345. if exists(${.CURDIR}/${TARGET}/mk-vmimage.sh)
346.  for FORMAT in ${VMFORMATS}
347	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \
348		${.CURDIR}/${TARGET}/mk-vmimage.sh ${.TARGET} \
349		${VMBASE}.img ${FORMAT} ${VMBASE}.${FORMAT}
350.  endfor
351. endif
352.endif
353	touch ${.TARGET}
354
355vm-azure:
356.if exists(${.CURDIR}/${TARGET}/mk-azure.sh)
357	env TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} AZURECONF=${AZURECONF} \
358		${.CURDIR}/${TARGET}/mk-azure.sh ${.TARGET} azure.img \
359		${WORLDDIR} ${.TARGET} ${VMSIZE} ${OSRELEASE}.vhd
360.endif
361	touch ${.TARGET}
362