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