xref: /dragonfly/nrelease/Makefile (revision a9783bc6)
1#########################################################################
2#				ENHANCEMENTS				#
3#########################################################################
4
5# Optional targets may be specified which set make variables which enhance
6# the build in various ways.
7#
8gui nopkgs binpkgs:
9
10#########################################################################
11#				SETUP					#
12#########################################################################
13
14SRCDIR=		${.CURDIR}/..
15
16DPORTS_PATH?=	/usr/dports
17ISODIR?=	/usr/obj/release
18ISOROOT?=	${ISODIR}/root
19GITURL_SRC?=	git://git.dragonflybsd.org/dragonfly.git
20GITURL_DPORTS?=	git://mirror-master.dragonflybsd.org/dports.git
21MAKE_JOBS?=	$$(sysctl -n hw.ncpu)
22.if !defined(NOFSCHG)
23MTREE_FSCHG=	-i
24.endif
25
26GITREV!=	sh ${SRCDIR}/tools/gitrev.sh
27
28# The label/name of the disklabel64(5) slice in the ".img" file.  This is
29# used to identify the USB device with DragonFly installation image, avoiding
30# hardcoding the USB device name (e.g., "da8").
31#
32# This label is also used as the volume ID of the ".iso" file.
33#
34LABEL?=		DragonFly_${GITREV}
35
36CHROOT_CMD?=	/usr/sbin/chroot ${ISOROOT} sh -c
37
38ISOFILE?=	${ISODIR}/dfly.iso
39IMGFILE?=	${ISODIR}/dfly.img
40IMGMNT?=	${ISODIR}/mnt
41
42.if !make(nopkgs)
43# User may specify extra packages in addition to the defaults
44#
45DPORTS_EXTRA_PACKAGES?=
46
47# dports packages to be built and installed on the release ISO
48#
49DPORTS_PACKAGES?=	security/ca_root_nss \
50			devel/git-lite \
51			dns/bind-tools \
52			net/isc-dhcp44-server \
53			sysutils/cdrtools \
54			security/wpa_supplicant \
55			${DPORTS_EXTRA_PACKAGES}
56
57# dports options to use when building packages
58#
59DPORTS_OPTIONS+=	-DBATCH
60DPORTS_OPTIONS+=	dns_bind-tools_UNSET=PYTHON
61.endif
62
63# Specify which root skeletons are required, and let the user include
64# their own.  They are copied into ISODIR during the `customizeiso'
65# target; each overwrites the last.
66#
67REQ_ROOTSKELS=	${.CURDIR}/root
68ROOTSKELS?=	${REQ_ROOTSKELS}
69
70.if make(gui)
71ISOFILE?=		${ISODIR}/dfly-gui.iso
72IMGFILE?=		${ISODIR}/dfly-gui.img
73
74.if !make(nopkgs)
75# NOTE: order important, do not sort package list
76#
77DPORTS_PACKAGES+=	x11/xorg \
78			x11-wm/fluxbox \
79			x11-wm/fvwm \
80			www/firefox \
81			graphics/xpdf \
82			shells/zsh \
83			editors/emacs \
84			editors/vim \
85			irc/irssi \
86			lang/perl5 \
87			editors/nano \
88			shells/bash \
89			devel/ctags \
90			archivers/zip \
91			security/sudo \
92			www/links \
93			ftp/wget \
94			x11-fonts/terminus-font \
95			net/rsync \
96			x11-clocks/asclock \
97			sysutils/screen
98.endif
99
100ROOTSKELS+=		${.CURDIR}/gui
101.endif  # make(gui)
102
103# one port may have multiple binary packages (e.g., Python flavors) or have a
104# different name that may not be found by pkg(8), therefore, allow to specify
105# the exact binary package name for a port by setting 'PKG_<port>=<pkg-name>'.
106#
107.for PORT in ${DPORTS_PACKAGES}
108.if defined(PKG_${PORT})
109PACKAGES+=	${PKG_${PORT}}
110.else
111PACKAGES+=	${PORT}
112.endif
113.endfor
114
115#########################################################################
116#				BASE ISO TARGETS			#
117#########################################################################
118
119release:	check clean buildworld1 buildkernel1 \
120		buildiso customizeiso pkgs srcs mkiso mkimg
121
122quickrel:	check clean buildworld2 buildkernel2 \
123		buildiso customizeiso pkgs srcs mkiso mkimg
124
125realquickrel:	check clean \
126		buildiso customizeiso pkgs srcs mkiso mkimg
127
128restartpkgs:	check pkgs srcs mkiso mkimg
129
130quick:		quickrel
131
132realquick:	realquickrel
133
134#########################################################################
135#			CORE SUPPORT TARGETS				#
136#########################################################################
137
138check:
139.if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
140	@echo
141	@echo "Your machine does not have cdrtools installed.  You can install it with:"
142	@echo "    pkg install cdrtools"
143.endif
144	@if [ ! -d ${DPORTS_PATH} ]; then \
145		echo "${DPORTS_PATH} does not exist."; \
146		echo ""; \
147		echo "Please set DPORTS_PATH to the dports tree that shall be used for"; \
148		echo "package building. The default is /usr/dports. See the Makefile in"; \
149		echo "/usr if you are unfamiliar with dports."; \
150		/usr/bin/false; \
151	fi
152.if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
153	@/usr/bin/false
154.endif
155	@echo "Using ${DPORTS_PATH} as the dports tree."
156
157buildworld1 buildworld2:
158	( cd ${SRCDIR}; \
159		${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
160			make -j ${MAKE_JOBS} -DWANT_INSTALLER \
161			${.TARGET:C/build(.*)2/quick\1/:C/1//} )
162
163buildkernel1 buildkernel2:
164	( cd ${SRCDIR}; \
165		${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
166			make -j ${MAKE_JOBS} \
167			${.TARGET:C/build(.*)2/quick\1/:C/1//} )
168
169# Unconditionally clean out ${ISOROOT} so a previous img build
170# does not blow up a future quick iso build
171#
172buildiso:
173	-chflags -R noschg ${ISOROOT}
174	rm -rf ${ISOROOT}
175	mkdir -p ${ISOROOT}
176	( cd ${SRCDIR}; \
177		make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
178	# Do not mess with any /usr/obj directories not related to
179	# buildworld, buildkernel, or nrelease.
180	( cd ${SRCDIR}/etc && \
181		tmpdir=`mktemp -d -t nrelease` && \
182		MAKEOBJDIRPREFIX=$${tmpdir} \
183			make -m ${SRCDIR}/share/mk \
184			DESTDIR=${ISOROOT} distribution && \
185		rm -rf $${tmpdir} )
186	cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
187	( cd ${SRCDIR}; make DESTDIR=${ISOROOT} reinstallkernel )
188	rm -rf ${ISOROOT}/boot/kernel.old
189	ln -sf kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
190	mtree ${MTREE_FSCHG} -deU -f ${SRCDIR}/etc/mtree/BSD.var.dist \
191		-p ${ISOROOT}/var
192	dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
193	${CHROOT_CMD} "rcrestart ldconfig"
194
195# The GUI build includes the full system source (~500 MB) and the full
196# dports tree (~250 MB).  The nominal release build only includes the
197# kernel source (~30 MB).
198#
199srcs:
200	rm -rf ${ISOROOT}/usr/dports
201	rm -f ${ISOROOT}/usr/src-sys.tar.bz2
202.if !defined(WITHOUT_SRCS)
203.if make(gui)
204	( cd ${ISOROOT}/usr && \
205		make dports-create-shallow GITURL_DPORTS=${GITURL_DPORTS} )
206	( cd ${ISOROOT}/usr && \
207		make src-create-shallow GITURL_SRC=${GITURL_SRC} )
208.else
209	( cd ${SRCDIR} && \
210		tar --exclude .git -s '/^\./src/' -cf - \
211			./Makefile ./Makefile.inc1 ./sys \
212			./share/syscons/fonts | \
213			bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2 )
214.endif
215.endif
216
217# Customize the ISO by copying rootskels in reverse priority order.
218#
219customizeiso:
220	# Copy the rootskels.  Allow sources to be owned by someone other
221	# than root (as is common when checked out via git).
222	#
223.for ROOTSKEL in ${ROOTSKELS}
224	cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
225	@test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
226	@test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
227.endfor
228	pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
229.for UPGRADE_ITEM in Makefile			\
230		     etc.${MACHINE_ARCH} 	\
231		     rc.d/Makefile		\
232		     periodic/Makefile		\
233		     periodic/daily/Makefile	\
234		     periodic/security/Makefile	\
235		     periodic/weekly/Makefile	\
236		     periodic/monthly/Makefile
237	cp -R ${SRCDIR}/etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
238.endfor
239
240# Install packages by using pkg(8) or building from dports.
241#
242pkgs:
243.if !empty(DPORTS_PACKAGES)
244	cp /etc/resolv.conf ${ISOROOT}/etc
245	-@umount ${ISOROOT}/dev
246	mount_null /dev ${ISOROOT}/dev
247
248.if make(binpkgs)
249	${CHROOT_CMD} "cd /usr && make pkg-bootstrap-force"
250	${CHROOT_CMD} "pkg update"
251.for PKG in ${PACKAGES}
252	@${CHROOT_CMD} "pkg search --exact --search name ${PKG}" || \
253	${CHROOT_CMD} "pkg search --exact --search origin ${PKG}" || \
254	{ \
255		echo "ERROR: Cannot find the package for port '${PKG}'!"; \
256		echo "-----> Use 'pkg_${PKG}=<pkg-name>' to specify the package name."; \
257		false; \
258	}
259.endfor
260	${CHROOT_CMD} "pkg install --yes ${PACKAGES}"
261
262.else  # !make(binpkgs)
263	-@umount ${ISOROOT}/usr/distfiles
264	-@umount ${ISOROOT}/usr/dports
265	rm -rf ${ISOROOT}/usr/obj/dports
266
267	mkdir -p ${ISOROOT}/usr/dports
268	mkdir -p ${ISOROOT}/usr/distfiles
269
270	# Mount /usr/dports read-only for safety, else a failed umount
271	# and our rm -rf will do bad things.
272	mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
273
274	# Make sure /usr/distfiles is writable
275	cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
276	    || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
277
278.for PKG in ${DPORTS_PACKAGES}
279.if make(restartpkgs)
280	${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} deinstall"
281.endif
282	${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} install"
283.endfor
284.for PKG in ${DPORTS_PACKAGES}
285	${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
286.endfor
287
288	${CHROOT_CMD} "yes | pkg autoremove"
289
290	-umount ${ISOROOT}/usr/distfiles
291	umount ${ISOROOT}/usr/dports
292
293	rm -rf ${ISOROOT}/usr/dports
294	rm -rf ${ISOROOT}/usr/distfiles
295	rm -rf ${ISOROOT}/usr/obj/dports
296.endif  # make(binpkgs)
297
298	# Update the locate(8) and whatis(1) databases, allow ISODIR
299	# to be on tmpfs (fails to create locate database then)
300	#
301	-${CHROOT_CMD} /etc/periodic/weekly/310.locate
302	-${CHROOT_CMD} /etc/periodic/weekly/320.whatis
303
304	umount ${ISOROOT}/dev
305	rm -f ${ISOROOT}/etc/resolv.conf
306
307	# Recopy files that dports may have updated in /etc into /etc.hdd
308	#
309	cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
310	cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
311.endif
312
313mkiso:
314	if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
315	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
316	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
317	newfs_msdos -C 400k -F 12 -L EFI -m 0xf8 ${ISOROOT}/boot/efiboot.img
318	vnconfig -l | grep "not in use" | head -n 1 | 			\
319	    cut -f 1 -d: > ${ISODIR}/vn.which
320	vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${ISOROOT}/boot/efiboot.img
321	mount_msdos /dev/`cat ${ISODIR}/vn.which` ${IMGMNT}
322	mkdir -p ${IMGMNT}/EFI/BOOT
323	cp ${ISOROOT}/boot/loader.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
324	umount ${IMGMNT}
325	( cd ${ISOROOT}; mkisofs -R -J -o ${ISOFILE} \
326	    -b boot/cdboot -no-emul-boot \
327	    -eltorito-alt-boot -eltorito-platform efi \
328	    -eltorito-boot boot/efiboot.img -no-emul-boot \
329	    -V ${LABEL:C/(^.{32}).*/\1/} . )  # cut label to <= 32 characters
330	rm -f ${ISOROOT}/boot/efiboot.img
331
332mkimg:
333	if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
334	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
335	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
336.ifdef IMGSIZE
337	@echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
338	rm -f ${IMGFILE}
339	sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
340.else
341	@echo "STEP: Determine required image size in 1GB steps"
342	@echo "      Leave ~600MB of unused space"
343	sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;			\
344	    sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
345	    cut -f1 -d.`;						\
346	    sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`;		\
347	    rm -f ${IMGFILE};						\
348	    truncate -s $${sz}M ${IMGFILE};
349.endif
350	@echo "STEP: determine free vn device"
351	vnconfig -l | grep "not in use" | head -n 1 | 			\
352	    cut -f 1 -d: > ${ISODIR}/vn.which
353	vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
354	@echo "STEP: set up legacy MBR"
355	fdisk -b ${ISOROOT}/boot/mbr -IB `cat ${ISODIR}/vn.which`
356	fdisk -s `cat ${ISODIR}/vn.which` >${ISODIR}/fdisk.dat
357	awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
358	    ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
359	echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
360	awk '($$1=="1:"){printf("p 2 165 258048 %lu\n", $$3 - 258528);}' \
361	    ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
362	echo "a 2" >>${ISODIR}/fdisk.conf
363	fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
364	rm ${ISODIR}/fdisk.conf ${ISODIR}/fdisk.dat
365	newfs_msdos -F 32 -c 2 -L EFI -m 0xf8 `cat ${ISODIR}/vn.which`s1
366	mount_msdos /dev/`cat ${ISODIR}/vn.which`s1 ${IMGMNT}
367	mkdir -p ${IMGMNT}/EFI/BOOT
368	cp ${ISOROOT}/boot/boot1.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
369	umount ${IMGMNT}
370	@echo "STEP: write standard disklabel"
371	disklabel -w -r `cat ${ISODIR}/vn.which`s2 auto
372	@echo "STEP: read disklabel back"
373	disklabel -r `cat ${ISODIR}/vn.which`s2 > ${IMGFILE}.label
374	@echo "STEP: set disklabel name"
375	echo "label: ${LABEL}" >> ${IMGFILE}.label
376	@echo "STEP: add slice parition"
377	echo "a: * * 4.2BSD" >> ${IMGFILE}.label;
378	@echo "STEP: write modified disklabel back"
379	disklabel -R -r `cat ${ISODIR}/vn.which`s2 ${IMGFILE}.label
380	rm ${IMGFILE}.label
381	disklabel -B -b ${ISOROOT}/boot/boot1_64 -s ${ISOROOT}/boot/boot2_64 \
382	    `cat ${ISODIR}/vn.which`s2
383	newfs /dev/`cat ${ISODIR}/vn.which`s2a
384	mount /dev/`cat ${ISODIR}/vn.which`s2a ${IMGMNT}
385	cpdup ${ISOROOT} ${IMGMNT}
386	@echo "STEP: fixup ${IMGMNT}/etc/fstab"
387	echo "/dev/part-by-label/${LABEL}.a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
388	echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
389	echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
390	echo "dummy /var/run tmpfs rw,-C 0 0" >> ${IMGMNT}/etc/fstab
391	echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
392	echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
393	@echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
394	-fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
395	echo 'vfs.root.mountfrom="ufs:part-by-label/${LABEL}.a"' >> ${IMGMNT}/boot/loader.conf.new
396	mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
397	@echo "STEP: cleanup"
398	df ${IMGMNT}
399	sync
400	sleep 1
401	umount ${IMGMNT}
402	vnconfig -u `cat ${ISODIR}/vn.which`
403	rm -f ${ISODIR}/vn.which
404	rmdir ${IMGMNT}
405	@echo "STEP: done, image files are in ${ISODIR}"
406
407clean:
408	sync
409	sleep 1
410	-umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
411	-umount ${ISOROOT}/usr/dports > /dev/null 2>&1
412	-umount ${ISOROOT}/dev > /dev/null 2>&1
413	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
414	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
415	if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
416	rm -rf ${ISOROOT}
417	rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
418
419realclean:	clean
420	rm -rf ${ISODIR}/packages
421	rm -rf ${ISODIR}/distfiles
422
423help all:
424	@echo "Targets:"
425	@echo "  release     - full build from scratch"
426	@echo "  quick       - attempt to do an incremental rebuild"
427	@echo "  realquick   - attempt to restart after world & kernel"
428	@echo "  restartpkgs - attempt to restart at the pkg building stage"
429	@echo ""
430	@echo "Optional targets:"
431	@echo "  nopkgs      - do not install any packages"
432	@echo "  binpkgs     - use binary packages with pkg(8)"
433	@echo "  gui         - do a GUI release"
434	@echo ""
435	@echo "Variables:"
436	@echo "  DPORTS_EXTRA_PACKAGES: add additional packages"
437	@echo "  GITURL_SRC: override the Git URL to source repository"
438	@echo "  GITURL_DPORTS: override the Git URL to dports repository"
439	@echo "  IMGSIZE: override the size of .img (in 512-byte sectors)"
440	@echo "  MAKE_JOBS: override the default value (sysctl hw.ncpu)"
441	@echo "  PKG_<port>: specify the package name for port <port>"
442	@echo "  WITHOUT_SRCS: do not package source code if set"
443	@echo ""
444
445.PHONY: release quickrel realquickrel
446.PHONY: quick realquick
447.PHONY: check buildworld1 buildworld2
448.PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
449.PHONY: clean realclean help all srcs pkgs
450