xref: /freebsd/release/Makefile (revision f7c32ed617858bcd22f8d1b03199099d50125721)
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# Set up mergemaster root database
121	sh ${.CURDIR}/scripts/mm-mtree.sh -m ${WORLDDIR} -F \
122	    "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET} ${.MAKE.JOBS:D-j${.MAKE.JOBS}}" \
123	    -D "${.OBJDIR}/${DISTDIR}/base"
124	etcupdate extract -B -M "TARGET_ARCH=${TARGET_ARCH} TARGET=${TARGET}" \
125	    -s ${WORLDDIR} -d "${.OBJDIR}/${DISTDIR}/base/var/db/etcupdate"
126# Package all components
127	cd ${WORLDDIR} && ${IMAKE} packageworld DISTDIR=${.OBJDIR}/${DISTDIR}
128	mv ${DISTDIR}/*.txz .
129
130kernel.txz:
131	mkdir -p ${DISTDIR}
132	cd ${WORLDDIR} && ${IMAKE} distributekernel packagekernel DISTDIR=${.OBJDIR}/${DISTDIR}
133	mv ${DISTDIR}/kernel*.txz .
134
135src.txz:
136	mkdir -p ${DISTDIR}/usr
137	ln -fs ${WORLDDIR} ${DISTDIR}/usr/src
138	cd ${DISTDIR} && tar cLvf - --exclude .svn --exclude .zfs \
139	    --exclude .git --exclude @ --exclude usr/src/release/dist usr/src | \
140	    ${XZ_CMD} > ${.OBJDIR}/src.txz
141
142ports.txz:
143	mkdir -p ${DISTDIR}/usr
144	ln -fs ${PORTSDIR} ${DISTDIR}/usr/ports
145	cd ${DISTDIR} && tar cLvf - \
146	    --exclude .git --exclude .svn \
147	    --exclude usr/ports/distfiles --exclude usr/ports/packages \
148	    --exclude 'usr/ports/INDEX*' --exclude work usr/ports | \
149	    ${XZ_CMD} > ${.OBJDIR}/ports.txz
150
151disc1: packagesystem
152# Install system
153	mkdir -p ${.TARGET}
154	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
155	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
156	    MK_INSTALLLIB=no MK_LIB32=no MK_MAIL=no \
157	    MK_TOOLCHAIN=no MK_PROFILE=no \
158	    MK_RESCUE=no MK_DICT=no \
159	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
160	    -DDB_FROM_SRC
161# Copy distfiles
162	mkdir -p ${.TARGET}/usr/freebsd-dist
163	for dist in MANIFEST $$(ls *.txz | grep -vE -- '(base|lib32)-dbg'); \
164	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
165	done
166# Set up installation environment
167	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
168	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
169	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
170	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
171	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
172	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
173	cp ${.CURDIR}/rc.local ${.TARGET}/etc
174	touch ${.TARGET}
175
176bootonly: packagesystem
177# Install system
178	mkdir -p ${.TARGET}
179	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
180	    DESTDIR=${.OBJDIR}/${.TARGET} MK_AT=no \
181	    MK_GAMES=no \
182	    MK_INSTALLLIB=no MK_LIB32=no MK_MAIL=no \
183	    MK_TOOLCHAIN=no MK_PROFILE=no \
184	    MK_RESCUE=no MK_DICT=no \
185	    MK_KERNEL_SYMBOLS=no MK_TESTS=no MK_DEBUG_FILES=no \
186	    -DDB_FROM_SRC
187# Copy manifest only (no distfiles) to get checksums
188	mkdir -p ${.TARGET}/usr/freebsd-dist
189	cp MANIFEST ${.TARGET}/usr/freebsd-dist
190# Set up installation environment
191	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
192	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
193	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
194	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
195	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
196	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
197	cp ${.CURDIR}/rc.local ${.TARGET}/etc
198
199dvd: packagesystem
200# Install system
201	mkdir -p ${.TARGET}
202	cd ${WORLDDIR} && ${IMAKE} installworld installkernel distribution \
203		DESTDIR=${.OBJDIR}/${.TARGET} MK_RESCUE=no MK_KERNEL_SYMBOLS=no \
204		MK_TESTS=no MK_DEBUG_FILES=no \
205		-DDB_FROM_SRC
206# Copy distfiles
207	mkdir -p ${.TARGET}/usr/freebsd-dist
208	for dist in MANIFEST $$(ls *.txz | grep -v -- '(base|lib32)-dbg'); \
209	    do cp $${dist} ${.TARGET}/usr/freebsd-dist; \
210	done
211# Set up installation environment
212	ln -fs /tmp/bsdinstall_etc/resolv.conf ${.TARGET}/etc/resolv.conf
213	echo sendmail_enable=\"NONE\" > ${.TARGET}/etc/rc.conf
214	echo hostid_enable=\"NO\" >> ${.TARGET}/etc/rc.conf
215	echo debug.witness.trace=0 >> ${.TARGET}/etc/sysctl.conf
216	echo vfs.mountroot.timeout=\"10\" >> ${.TARGET}/boot/loader.conf
217	echo kernels_autodetect=\"NO\" >> ${.TARGET}/boot/loader.conf
218	cp ${.CURDIR}/rc.local ${.TARGET}/etc
219	touch ${.TARGET}
220
221release.iso: disc1.iso
222disc1.iso: disc1
223	sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_CD ${.TARGET} disc1 ${XTRADIR}
224
225dvd1.iso: dvd pkg-stage
226	sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_DVD ${.TARGET} dvd ${XTRADIR}
227
228bootonly.iso: bootonly
229	sh ${.CURDIR}/${TARGET}/mkisoimages.sh -b ${VOLUME_LABEL}_BO ${.TARGET} bootonly ${XTRADIR}
230
231memstick: memstick.img
232memstick.img: disc1
233	sh ${.CURDIR}/${TARGET}/make-memstick.sh disc1 ${.TARGET}
234
235mini-memstick: mini-memstick.img
236mini-memstick.img: bootonly
237	sh ${.CURDIR}/${TARGET}/make-memstick.sh bootonly ${.TARGET}
238
239packagesystem: base.txz kernel.txz ${EXTRA_PACKAGES}
240	sh ${.CURDIR}/scripts/make-manifest.sh *.txz > MANIFEST
241	touch ${.TARGET}
242
243pkg-stage:
244.if !defined(NOPKG) || empty(NOPKG)
245	env PORTSDIR=${PORTSDIR} REPOS_DIR=${.CURDIR}/pkg_repos/ \
246		sh ${.CURDIR}/scripts/pkg-stage.sh
247	mkdir -p ${.OBJDIR}/dvd/packages/repos/
248	cp ${.CURDIR}/scripts/FreeBSD_install_cdrom.conf \
249		${.OBJDIR}/dvd/packages/repos/
250.endif
251	touch ${.TARGET}
252
253cdrom: disc1.iso bootonly.iso
254dvdrom: dvd1.iso
255ftp: packagesystem
256	rm -rf ftp
257	mkdir -p ftp
258	cp *.txz MANIFEST ftp
259
260release:	real-release vm-release cloudware-release
261	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} release-done
262	true
263
264release-done:
265	touch release
266
267real-release:
268	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} obj
269	${MAKE} -C ${.CURDIR} ${.MAKEFLAGS} ${RELEASE_TARGETS}
270
271install:	release-install vm-install
272
273release-install:
274.if defined(DESTDIR) && !empty(DESTDIR)
275	mkdir -p ${DESTDIR}
276.endif
277	cp -a ftp ${DESTDIR}/
278.if !empty(IMAGES)
279.for I in ${IMAGES}
280	cp -p ${I} ${DESTDIR}/${OSRELEASE}-${I}
281. if defined(WITH_COMPRESSED_IMAGES) && !empty(WITH_COMPRESSED_IMAGES)
282	${XZ_CMD} -k ${DESTDIR}/${OSRELEASE}-${I}
283. endif
284.endfor
285	cd ${DESTDIR} && sha512 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA512
286	cd ${DESTDIR} && sha256 ${OSRELEASE}* > ${DESTDIR}/CHECKSUM.SHA256
287.endif
288
289.include "${.CURDIR}/Makefile.inc1"
290.include "${.CURDIR}/Makefile.vm"
291