xref: /dragonfly/nrelease/Makefile (revision 083f5c48)
19b29c40aSMatthew Dillon#########################################################################
29b29c40aSMatthew Dillon#				ENHANCEMENTS				#
39b29c40aSMatthew Dillon#########################################################################
49b29c40aSMatthew Dillon
5f4ec1279SSascha Wildner# New method e.g. 'make gui release'.  A series of enhancement
64931b8b1SSascha Wildner# targets may be specified which set make variables which enhance
79b29c40aSMatthew Dillon# the build in various ways.
89b29c40aSMatthew Dillon#
91a8bb5ebSMatthew Dillon# img is now the default (produces both the .iso and .img)
101a8bb5ebSMatthew Dillon#
1188821fa4SMatthew Dillongui installer img nopkgs:
129b29c40aSMatthew Dillon
139b29c40aSMatthew Dillon#########################################################################
149b29c40aSMatthew Dillon#				SETUP					#
159b29c40aSMatthew Dillon#########################################################################
169b29c40aSMatthew Dillon
17bd0ab7aaSMatthew DillonDPORTS_PATH?=	/usr/dports
18a291abfbSMatthew DillonISODIR?=	/usr/obj/release
195ec00f8aSSascha WildnerISOROOT?=	${ISODIR}/root
206ca9a59cSMatthew DillonOBJSYS=		${.OBJDIR}/../sys
218126e4efSAaron LIGITURL_SRC?=	git://git.dragonflybsd.org/dragonfly.git
228126e4efSAaron LIGITURL_DPORTS?=	git://mirror-master.dragonflybsd.org/dports.git
235cb6cda9SSascha WildnerMAKE_JOBS?=	$$(sysctl -n hw.ncpu)
243fff415bSSascha Wildner
25702a95ccSSimon Schubert# XXX makeshift fix to build the right kernel for the (target) architecture
26702a95ccSSimon Schubert# We should configure this in the platform files somehow
27dd7331feSSascha Wildner.if ${MACHINE_ARCH} == "x86_64"
2891856cf5SSascha WildnerKERNCONF?=	X86_64_GENERIC
29702a95ccSSimon Schubert.endif
306ca9a59cSMatthew Dillon
319d8dda4aSAaron LIGITREV!=	sh ${.CURDIR}/../tools/gitrev.sh
329d8dda4aSAaron LI
333ac64890SAaron LI# The label/name of the disklabel64(5) slice in the ".img" file.  This is
343ac64890SAaron LI# used to identify the USB device with DragonFly installation image, avoiding
353ac64890SAaron LI# hardcoding the USB device name (e.g., "da8").
363ac64890SAaron LI#
379d8dda4aSAaron LI# This label is also used as the volume ID of the ".iso" file.
389d8dda4aSAaron LI#
399d8dda4aSAaron LILABEL?=		DragonFly_${GITREV}
403ac64890SAaron LI
41c36c5990SSascha WildnerCHROOT_CMD?=	/usr/sbin/chroot ${ISOROOT} sh -c
42cc55a235SSimon Schubert
43*083f5c48SAaron LIISOFILE?=	${ISODIR}/dfly.iso
44*083f5c48SAaron LIIMGFILE?=	${ISODIR}/dfly.img
45*083f5c48SAaron LIIMGMNT?=	${ISODIR}/mnt
46*083f5c48SAaron LI
47*083f5c48SAaron LI# NOTE: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
48*083f5c48SAaron LI# the additional '/nrelease' manually, as a safety measure.
49*083f5c48SAaron LI#
50*083f5c48SAaron LINRLOBJDIR?=	/usr/obj
51*083f5c48SAaron LI
52165b1c14SSascha Wildner.if !make(nopkgs)
538abe78a1SMatthew Dillon# User may specify extra packages in addition to the defaults
5495b64753SMatthew Dillon#
55c36c5990SSascha WildnerDPORTS_EXTRA_PACKAGES?=
56fbc26094SSascha Wildner
572f36664eSSascha Wildner# dports packages to be built and installed on the release ISO
582f36664eSSascha Wildner#
59c36c5990SSascha WildnerDPORTS_PACKAGES?=	devel/git \
600e561611SJustin C. Sherrill			dns/bind-tools \
6120d2e8bdSAntonio Huete Jimenez			net/isc-dhcp44-server \
62c36c5990SSascha Wildner			sysutils/cdrtools \
63bcd3ea29SMatthew Dillon			security/wpa_supplicant \
6444c4f44aSSascha Wildner			${DPORTS_EXTRA_PACKAGES}
65c36c5990SSascha Wildner
66c36c5990SSascha Wildner# dports options to use when building packages
67c36c5990SSascha Wildner#
68c36c5990SSascha WildnerDPORTS_OPTIONS+=		-DBATCH
69255a0279SMichael Neumann.if make(gui)
70cd98d260SSascha WildnerDPORTS_OPTIONS.devel_git+=	-DWITH_GUI
71255a0279SMichael Neumann.else
72cd98d260SSascha WildnerDPORTS_OPTIONS.devel_git+=	-DWITHOUT_CONTRIB -DWITHOUT_PERL
73fbc26094SSascha Wildner.endif
74165b1c14SSascha Wildner.endif
758188de86SMatthew Dillon
768188de86SMatthew Dillon# Specify which root skeletons are required, and let the user include
77e2dbfa0bSThomas Nikolajsen# their own.  They are copied into ISODIR during the `customizeiso'
788188de86SMatthew Dillon# target; each overwrites the last.
798188de86SMatthew Dillon#
808f51ac0bSSascha WildnerREQ_ROOTSKELS=	${.CURDIR}/root
81cc224c64SJoerg SonnenbergerROOTSKELS?=	${REQ_ROOTSKELS}
82cc224c64SJoerg Sonnenberger
83255a0279SMichael Neumann.if make(gui)
84bfe20b28SSascha WildnerISOFILE?=		${ISODIR}/dfly-gui.iso
85b9c3e754SMichael NeumannIMGFILE?=		${ISODIR}/dfly-gui.img
8688821fa4SMatthew Dillon
87*083f5c48SAaron LI.if !make(nopkgs)
880e176309SMatthew Dillon# NOTE: order important, do not sort package list
890e176309SMatthew Dillon#
90255a0279SMichael NeumannDPORTS_PACKAGES+=	x11/xorg \
91255a0279SMichael Neumann			x11-wm/fluxbox \
92255a0279SMichael Neumann			x11-wm/fvwm \
9330e27f66SMatthew Dillon			www/firefox \
94255a0279SMichael Neumann			graphics/xpdf \
95fbc26094SSascha Wildner			shells/zsh \
96fbc26094SSascha Wildner			editors/emacs \
97fbc26094SSascha Wildner			editors/vim \
98255a0279SMichael Neumann			irc/irssi \
99fbc26094SSascha Wildner			lang/perl5 \
100fbc26094SSascha Wildner			editors/nano \
101fbc26094SSascha Wildner			shells/bash \
102255a0279SMichael Neumann			devel/ctags \
103fbc26094SSascha Wildner			archivers/zip \
104fbc26094SSascha Wildner			security/sudo \
105255a0279SMichael Neumann			www/links \
106255a0279SMichael Neumann			ftp/wget \
107255a0279SMichael Neumann			x11-fonts/terminus-font \
108fbc26094SSascha Wildner			net/rsync \
109255a0279SMichael Neumann			x11-clocks/asclock \
110255a0279SMichael Neumann			sysutils/screen
11188821fa4SMatthew Dillon.endif
11288821fa4SMatthew Dillon
113bfe20b28SSascha WildnerROOTSKELS+=		${.CURDIR}/gui
114bfe20b28SSascha Wildner.endif
115bfe20b28SSascha Wildner
1168188de86SMatthew Dillon#########################################################################
1178188de86SMatthew Dillon#				BASE ISO TARGETS			#
1188188de86SMatthew Dillon#########################################################################
1196ca9a59cSMatthew Dillon
1207ebbae99SSascha Wildnerrelease:	check clean buildworld1 buildkernel1 \
12131d5c88cSSascha Wildner		buildiso srcs customizeiso mkiso mkimg
1226ca9a59cSMatthew Dillon
1237ebbae99SSascha Wildnerquickrel:	check clean buildworld2 buildkernel2 \
12431d5c88cSSascha Wildner		buildiso srcs customizeiso mkiso mkimg
1258188de86SMatthew Dillon
12603e2a3c5SSascha Wildnerrealquickrel:	check clean \
12731d5c88cSSascha Wildner		buildiso srcs customizeiso mkiso mkimg
1286ca9a59cSMatthew Dillon
12931d5c88cSSascha Wildnerrestartpkgs:	check customizeiso mkiso mkimg
1305af45f85SMatthew Dillon
1319b29c40aSMatthew Dillonquick:		quickrel
1329b29c40aSMatthew Dillon
1339b29c40aSMatthew Dillonrealquick:	realquickrel
1349b29c40aSMatthew Dillon
1359b29c40aSMatthew Dillon#########################################################################
1369b29c40aSMatthew Dillon#			CORE SUPPORT TARGETS				#
1379b29c40aSMatthew Dillon#########################################################################
1389b29c40aSMatthew Dillon
139d2582113SChris Presseycheck:
140c36c5990SSascha Wildner.if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
1410936984eSMatthew Dillon	@echo
1420936984eSMatthew Dillon	@echo "Your machine does not have cdrtools installed.  You can install it with:"
143218b6b69SMarkus Pfeiffer	@echo "    pkg install cdrtools"
1440936984eSMatthew Dillon.endif
145aa3eeb12SSascha Wildner	@if [ ! -d ${DPORTS_PATH} ]; then \
146aa3eeb12SSascha Wildner		echo "${DPORTS_PATH} does not exist."; \
147aa3eeb12SSascha Wildner		echo ""; \
148aa3eeb12SSascha Wildner		echo "Please set DPORTS_PATH to the dports tree that shall be used for"; \
149aa3eeb12SSascha Wildner		echo "package building. The default is /usr/dports. See the Makefile in"; \
150aa3eeb12SSascha Wildner		echo "/usr if you are unfamiliar with dports."; \
151aa3eeb12SSascha Wildner		/usr/bin/false; \
152aa3eeb12SSascha Wildner	fi
153c36c5990SSascha Wildner.if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
1543da8e88fSJohn Marino	@/usr/bin/false
155fbc26094SSascha Wildner.endif
156aa3eeb12SSascha Wildner	@echo "Using ${DPORTS_PATH} as the dports tree."
1572e3f8f38SMatthew Dillon
158588a679cSSimon Schubertbuildworld1 buildworld2:
1593fff415bSSascha Wildner	cd ${.CURDIR}/..; \
1603fff415bSSascha Wildner	${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
1613fff415bSSascha Wildner		make -j ${MAKE_JOBS} -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
1626ca9a59cSMatthew Dillon
163588a679cSSimon Schubertbuildkernel1 buildkernel2:
164588a679cSSimon Schubert	cd ${.CURDIR}/..; \
165588a679cSSimon Schubert	for kernconf in ${KERNCONF}; do \
166448b21e7SSimon Schubert		${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
1673fff415bSSascha Wildner			make -j ${MAKE_JOBS} ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
168ee7f6ff2SSascha Wildner			KERNCONF=$${kernconf}; \
169588a679cSSimon Schubert	done
1706ca9a59cSMatthew Dillon
171*083f5c48SAaron LI# Note that we do not want to mess with any /usr/obj directories not related
1725b22b655SMatthew Dillon# to buildworld, buildkernel, or nrelease, so we must supply the proper
1735b22b655SMatthew Dillon# MAKEOBJDIRPREFIX for targets that are not run through the buildworld and
1745b22b655SMatthew Dillon# buildkernel mechanism.
1755b22b655SMatthew Dillon#
1762b43b38cSSascha Wildner# Unconditionally clean out ${ISOROOT} so a previous img build
17792b0ebb9SMatthew Dillon# does not blow up a future quick iso build
17892b0ebb9SMatthew Dillon#
179fe70af21SMatthew Dillon# We install with INSTALLSTRIPPEDMODULES to make things fit into the ISO.
180fe70af21SMatthew Dillon# We leave the kernel's debug variables intact.
181fe70af21SMatthew Dillon#
1826ca9a59cSMatthew Dillonbuildiso:
18392b0ebb9SMatthew Dillon	-chflags -R noschg ${ISOROOT}
18492b0ebb9SMatthew Dillon	rm -rf ${ISOROOT}
18592b0ebb9SMatthew Dillon	mkdir -p ${ISOROOT}
1865b22b655SMatthew Dillon	if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
187f4ec1279SSascha Wildner	( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
188ab64cf06SSimon Schubert	( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
189ab64cf06SSimon Schubert		make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
19021aa02d0SChris Pressey	cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
191bc897c50SAaron LI	( cd ${.CURDIR}/..; \
192588a679cSSimon Schubert		for kernconf in ${KERNCONF}; do \
1931c9d98d0SAntonio Huete Jimenez			make DESTDIR=${ISOROOT} reinstallkernel KERNCONF=$${kernconf}; \
194bc897c50SAaron LI		done )
19591856cf5SSascha Wildner	rm -rf ${ISOROOT}/boot/kernel.old
1961c9d98d0SAntonio Huete Jimenez	ln -sf kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
1976ca9a59cSMatthew Dillon	mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist -p ${ISOROOT}/var
1986ca9a59cSMatthew Dillon	dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
1998188de86SMatthew Dillon
200255a0279SMichael Neumann# The GUI build includes the ports tree (~1G+) while the nominal release
201fe70af21SMatthew Dillon# build does not.
202fe70af21SMatthew Dillon#
203fe70af21SMatthew Dillon# The GUI build includes full sources while the nominal release build
204fe70af21SMatthew Dillon# only includes kernel sources (~27MB).
20519d86faaSMatthew Dillon#
206e2dbfa0bSThomas Nikolajsensrcs:
207e2dbfa0bSThomas Nikolajsen.if !defined(WITHOUT_SRCS)
208255a0279SMichael Neumann.if make(gui)
2093342e40aSMatthew Dillon	rm -f ${ISOROOT}/usr/src-sys.tgz
2103342e40aSMatthew Dillon	rm -f ${ISOROOT}/usr/src-sys.tar.bz2
211165b1c14SSascha Wildner.if !empty(DPORTS_PACKAGES)
2128126e4efSAaron LI	cd ${ISOROOT}/usr && make dports-create GITURL_DPORTS=${GITURL_DPORTS}
213c59cfa66SSascha Wildner	# NOTE: Adding the git gc --aggressive helps by significantly
214c59cfa66SSascha Wildner	#	reducing the disk space required.
215c59cfa66SSascha Wildner	#
216255a0279SMichael Neumann	cd ${ISOROOT}/usr/dports && git gc --aggressive
217165b1c14SSascha Wildner.endif
218d20f3e98SAntonio Huete Jimenez	cd ${ISOROOT}/usr && make src-create GITURL_SRC=${GITURL_SRC}
219255a0279SMichael Neumann	# XXX: git gc --aggressive
220c19c746bSMatthew Dillon.else
221e2dbfa0bSThomas Nikolajsen	rm -f ${ISOROOT}/usr/src-sys.tgz
222fe70af21SMatthew Dillon	rm -f ${ISOROOT}/usr/src-sys.tar.bz2
223cacf78aaSSascha Wildner	cd ${.CURDIR}/.. && tar --exclude .git -s '/^\./src/' \
224cebb579bSMatthew Dillon		-cf - ./Makefile ./Makefile.inc1 \
225cebb579bSMatthew Dillon		./crypto/libressl/include ./sys | \
226fe70af21SMatthew Dillon		bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2
227c19c746bSMatthew Dillon.endif
22866b79064SMatthew Dillon.endif
22919d86faaSMatthew Dillon
2305af45f85SMatthew Dillon# Customize the ISO by copying rootskels in reverse priority order,
2315af45f85SMatthew Dillon# building packages, and doing other post-install tasks.
2325af45f85SMatthew Dillon#
2338188de86SMatthew Dilloncustomizeiso:
2345af45f85SMatthew Dillon	# Copy the rootskels.  Allow sources to be owned by someone other
2353cf4b4a1SSascha Wildner	# than root (as is common when checked out via git).
2365af45f85SMatthew Dillon	#
2378188de86SMatthew Dillon.for ROOTSKEL in ${ROOTSKELS}
2388188de86SMatthew Dillon	cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
2395af45f85SMatthew Dillon	@test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
2405af45f85SMatthew Dillon	@test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
2418188de86SMatthew Dillon.endfor
2427249926bSMatthew Dillon	pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
2434fba3387SChris Pressey.for UPGRADE_ITEM in Makefile			\
2444fba3387SChris Pressey		     etc.${MACHINE_ARCH} 	\
2454fba3387SChris Pressey		     rc.d/Makefile		\
2464fba3387SChris Pressey		     periodic/Makefile		\
2474fba3387SChris Pressey		     periodic/daily/Makefile	\
2484fba3387SChris Pressey		     periodic/security/Makefile	\
2494fba3387SChris Pressey		     periodic/weekly/Makefile	\
2504fba3387SChris Pressey		     periodic/monthly/Makefile
2514fba3387SChris Pressey	cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
2524fba3387SChris Pressey.endfor
2538abe78a1SMatthew Dillon	#
254c36c5990SSascha Wildner	# Setup some things & mount dports tree.  Use defensive umounts and
255c36c5990SSascha Wildner	# rm -rf's to allow restarts.  Allow /usr/dports to be read-only.
2568abe78a1SMatthew Dillon	#
257165b1c14SSascha Wildner	-@umount ${ISOROOT}/dev
258165b1c14SSascha Wildner	mount_null /dev ${ISOROOT}/dev
259165b1c14SSascha Wildner.if !empty(DPORTS_PACKAGES)
2601c9d98d0SAntonio Huete Jimenez	cp /etc/resolv.conf ${ISOROOT}/etc
2619af692c6SSascha Wildner	${CHROOT_CMD} "ldconfig -elf /lib /usr/lib /usr/lib/gcc*"
2625e885f07SSascha Wildner	-@umount ${ISOROOT}/usr/distfiles
2632f36664eSSascha Wildner	-@umount ${ISOROOT}/usr/dports
2642f36664eSSascha Wildner	rm -rf ${ISOROOT}/usr/obj/dports
2658abe78a1SMatthew Dillon	#
266c36c5990SSascha Wildner	# Mount /usr/dports, make sure /usr/distfiles is writable.
267c36c5990SSascha Wildner	# Make /usr/dports read-only for safety, else a failed umount and
2681eeae16fSMatthew Dillon	# our rm -rf will do bad things.
2698abe78a1SMatthew Dillon	#
2702f36664eSSascha Wildner	mkdir -p ${ISOROOT}/usr/dports
2715e885f07SSascha Wildner	mkdir -p ${ISOROOT}/usr/distfiles
2722f36664eSSascha Wildner	mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
273c36c5990SSascha Wildner	cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
274c36c5990SSascha Wildner	    || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
2758abe78a1SMatthew Dillon	#
2768abe78a1SMatthew Dillon	# Build and install packages, skip packages already installed
2778abe78a1SMatthew Dillon	#
278c36c5990SSascha Wildner.for PKG in ${DPORTS_PACKAGES}
279c36c5990SSascha Wildner	${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} ${DPORTS_OPTIONS.${PKG:S/\//_/g}} install"
28020585f87SMatthew Dillon.endfor
2812f36664eSSascha Wildner.for PKG in ${DPORTS_PACKAGES}
282c36c5990SSascha Wildner	${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
2832f36664eSSascha Wildner.endfor
2848abe78a1SMatthew Dillon	#
28531d5c88cSSascha Wildner	# Remove packages which nothing depends on, add a whatis database
286c36c5990SSascha Wildner	# for dports manual pages, create an initial locate database and
28731d5c88cSSascha Wildner	# clean up
2888abe78a1SMatthew Dillon	#
2892f36664eSSascha Wildner	${CHROOT_CMD} "yes | pkg autoremove"
290c36c5990SSascha Wildner	${CHROOT_CMD} "makewhatis /usr/local/man"
2915e885f07SSascha Wildner	-umount ${ISOROOT}/usr/distfiles
2922f36664eSSascha Wildner	umount ${ISOROOT}/usr/dports
2935e885f07SSascha Wildner	rm -rf ${ISOROOT}/usr/dports
2942f36664eSSascha Wildner	rm -rf ${ISOROOT}/usr/obj/dports
2955e885f07SSascha Wildner	rm -rf ${ISOROOT}/usr/distfiles
296fbc26094SSascha Wildner	rm -f ${ISOROOT}/etc/resolv.conf
297165b1c14SSascha Wildner.endif
2982f36664eSSascha Wildner	#
299b34d3b9bSzrj	# Finally, update the locate(8) database, allow ISODIR
300b34d3b9bSzrj	# to be on tmpfs (fails to create locate database then)
3012f36664eSSascha Wildner	#
302b34d3b9bSzrj	-${CHROOT_CMD} /etc/periodic/weekly/310.locate
30331d5c88cSSascha Wildner	umount ${ISOROOT}/dev
304d68fa6c5SMatthew Dillon	#
30544c4f44aSSascha Wildner	# Recopy files that dports may have updated in /etc into /etc.hdd
306d68fa6c5SMatthew Dillon	#
307d68fa6c5SMatthew Dillon	cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
308d68fa6c5SMatthew Dillon	cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
3098398ca17SSascha Wildner
3106ca9a59cSMatthew Dillonmkiso:
3115fa778d7SSascha Wildner	if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
3125fa778d7SSascha Wildner	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
3135fa778d7SSascha Wildner	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
3145fa778d7SSascha Wildner	newfs_msdos -C 400k -F 12 -L EFI -m 0xf8 ${ISOROOT}/boot/efiboot.img
3155fa778d7SSascha Wildner	vnconfig -l | grep "not in use" | head -n 1 | 			\
3165fa778d7SSascha Wildner	    cut -f 1 -d: > ${ISODIR}/vn.which
3175fa778d7SSascha Wildner	vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${ISOROOT}/boot/efiboot.img
3185fa778d7SSascha Wildner	mount_msdos /dev/`cat ${ISODIR}/vn.which` ${IMGMNT}
3195fa778d7SSascha Wildner	mkdir -p ${IMGMNT}/EFI/BOOT
3205fa778d7SSascha Wildner	cp ${ISOROOT}/boot/loader.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
3215fa778d7SSascha Wildner	umount ${IMGMNT}
3225fa778d7SSascha Wildner	( cd ${ISOROOT}; mkisofs -R -J -o ${ISOFILE} \
3235fa778d7SSascha Wildner	    -b boot/cdboot -no-emul-boot \
3249d8dda4aSAaron LI	    -eltorito-alt-boot -eltorito-platform efi \
3259d8dda4aSAaron LI	    -eltorito-boot boot/efiboot.img -no-emul-boot \
3269d8dda4aSAaron LI	    -V ${LABEL:C/(^.{32}).*/\1/} . )  # cut label to <= 32 characters
3275fa778d7SSascha Wildner	rm -f ${ISOROOT}/boot/efiboot.img
328b9c3e754SMichael Neumann
329b9c3e754SMichael Neumannmkimg:
33060b68cbbSMichael Neumann	if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
3319a122c9aSMatthew Dillon	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
3329a122c9aSMatthew Dillon	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
333fe70af21SMatthew Dillon.ifdef IMGSIZE
334fe70af21SMatthew Dillon	@echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
335fe70af21SMatthew Dillon	rm -f ${IMGFILE}
336fe70af21SMatthew Dillon	sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
337fe70af21SMatthew Dillon.else
3383342e40aSMatthew Dillon	@echo "STEP: Determine required image size in 1GB steps"
3393342e40aSMatthew Dillon	@echo "      Leave ~600MB of unused space"
34060b68cbbSMichael Neumann	sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;			\
3413342e40aSMatthew Dillon	    sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
342fe70af21SMatthew Dillon	    cut -f1 -d.`;						\
343c843f8b0SMatthew Dillon	    sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`;		\
344fe70af21SMatthew Dillon	    rm -f ${IMGFILE};						\
345fe70af21SMatthew Dillon	    truncate -s $${sz}M ${IMGFILE};
346fe70af21SMatthew Dillon.endif
3479a122c9aSMatthew Dillon	@echo "STEP: determine free vn device"
3489a122c9aSMatthew Dillon	vnconfig -l | grep "not in use" | head -n 1 | 			\
3499a122c9aSMatthew Dillon	    cut -f 1 -d: > ${ISODIR}/vn.which
3509a122c9aSMatthew Dillon	vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
3515fa778d7SSascha Wildner	@echo "STEP: set up legacy MBR"
352cc3c231bSMatthew Dillon	fdisk -b ${ISOROOT}/boot/mbr -IB `cat ${ISODIR}/vn.which`
3535fa778d7SSascha Wildner	fdisk -s `cat ${ISODIR}/vn.which` >${ISODIR}/fdisk.dat
3545fa778d7SSascha Wildner	awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
3555fa778d7SSascha Wildner	    ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
3565fa778d7SSascha Wildner	echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
3575fa778d7SSascha Wildner	awk '($$1=="1:"){printf("p 2 165 258048 %lu\n", $$3 - 258528);}' \
3585fa778d7SSascha Wildner	    ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
3595fa778d7SSascha Wildner	echo "a 2" >>${ISODIR}/fdisk.conf
3605fa778d7SSascha Wildner	fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
3615fa778d7SSascha Wildner	rm ${ISODIR}/fdisk.conf ${ISODIR}/fdisk.dat
3625fa778d7SSascha Wildner	newfs_msdos -F 32 -c 2 -L EFI -m 0xf8 `cat ${ISODIR}/vn.which`s1
3635fa778d7SSascha Wildner	mount_msdos /dev/`cat ${ISODIR}/vn.which`s1 ${IMGMNT}
3645fa778d7SSascha Wildner	mkdir -p ${IMGMNT}/EFI/BOOT
3655fa778d7SSascha Wildner	cp ${ISOROOT}/boot/boot1.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
3665fa778d7SSascha Wildner	umount ${IMGMNT}
3679a122c9aSMatthew Dillon	@echo "STEP: write standard disklabel"
3685fa778d7SSascha Wildner	disklabel -w -r `cat ${ISODIR}/vn.which`s2 auto
3699a122c9aSMatthew Dillon	@echo "STEP: read disklabel back"
3705fa778d7SSascha Wildner	disklabel -r `cat ${ISODIR}/vn.which`s2 > ${IMGFILE}.label
3713ac64890SAaron LI	@echo "STEP: set disklabel name"
3723ac64890SAaron LI	echo "label: ${LABEL}" >> ${IMGFILE}.label
3733ac64890SAaron LI	@echo "STEP: add slice parition"
3743ac64890SAaron LI	echo "a: * * 4.2BSD" >> ${IMGFILE}.label;
3759a122c9aSMatthew Dillon	@echo "STEP: write modified disklabel back"
3765fa778d7SSascha Wildner	disklabel -R -r `cat ${ISODIR}/vn.which`s2 ${IMGFILE}.label
3779a122c9aSMatthew Dillon	rm ${IMGFILE}.label
378cc3c231bSMatthew Dillon	disklabel -B -b ${ISOROOT}/boot/boot1_64 -s ${ISOROOT}/boot/boot2_64 \
379cc3c231bSMatthew Dillon	    `cat ${ISODIR}/vn.which`s2
3805fa778d7SSascha Wildner	newfs /dev/`cat ${ISODIR}/vn.which`s2a
3815fa778d7SSascha Wildner	mount /dev/`cat ${ISODIR}/vn.which`s2a ${IMGMNT}
3829a122c9aSMatthew Dillon	cpdup ${ISOROOT} ${IMGMNT}
3839a122c9aSMatthew Dillon	@echo "STEP: fixup ${IMGMNT}/etc/fstab"
3843ac64890SAaron LI	echo "/dev/part-by-label/${LABEL}.a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
3853342e40aSMatthew Dillon	echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
3863342e40aSMatthew Dillon	echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
387d4c25c30SSascha Wildner	echo "dummy /var/run tmpfs rw,-C 0 0" >> ${IMGMNT}/etc/fstab
3883342e40aSMatthew Dillon	echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
3899a122c9aSMatthew Dillon	echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
3909a122c9aSMatthew Dillon	@echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
3919a122c9aSMatthew Dillon	-fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
3923ac64890SAaron LI	echo 'vfs.root.mountfrom="ufs:part-by-label/${LABEL}.a"' >> ${IMGMNT}/boot/loader.conf.new
3939a122c9aSMatthew Dillon	mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
3949a122c9aSMatthew Dillon	@echo "STEP: cleanup"
3959a122c9aSMatthew Dillon	df ${IMGMNT}
396836f3129SMatthew Dillon	sync
397836f3129SMatthew Dillon	sleep 1
3989a122c9aSMatthew Dillon	umount ${IMGMNT}
3999a122c9aSMatthew Dillon	vnconfig -u `cat ${ISODIR}/vn.which`
4009a122c9aSMatthew Dillon	rm -f ${ISODIR}/vn.which
40160b68cbbSMichael Neumann	rmdir ${IMGMNT}
4029a122c9aSMatthew Dillon	@echo "STEP: done"
403b9c3e754SMichael Neumann
4046ca9a59cSMatthew Dillonclean:
405836f3129SMatthew Dillon	sync
406836f3129SMatthew Dillon	sleep 1
4075e885f07SSascha Wildner	-umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
4082f36664eSSascha Wildner	-umount ${ISOROOT}/usr/dports > /dev/null 2>&1
4099a122c9aSMatthew Dillon	-umount ${ISOROOT}/dev > /dev/null 2>&1
4109a122c9aSMatthew Dillon	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
4119a122c9aSMatthew Dillon	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
4126ca9a59cSMatthew Dillon	if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
413c19c746bSMatthew Dillon	rm -rf ${ISOROOT}
414c19c746bSMatthew Dillon	rm -rf ${NRLOBJDIR}/nrelease
4159a122c9aSMatthew Dillon	rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
4166ca9a59cSMatthew Dillon
4176ca9a59cSMatthew Dillonrealclean:	clean
4183ebedc5eSMatthew Dillon	rm -rf ${OBJSYS}/${KERNCONF}
419c19c746bSMatthew Dillon	rm -rf ${ISODIR}/packages
420c19c746bSMatthew Dillon	rm -rf ${ISODIR}/distfiles
4216ca9a59cSMatthew Dillon
422e2dbfa0bSThomas Nikolajsenhelp all:
4238126e4efSAaron LI	@echo "Targets:"
4248126e4efSAaron LI	@echo "  release     - full build from scratch"
4258126e4efSAaron LI	@echo "  quick       - attempt to do an incremental rebuild"
4268126e4efSAaron LI	@echo "  realquick   - attempt to restart after world & kernel"
4278126e4efSAaron LI	@echo "  restartpkgs - attempt to restart at the pkg building stage"
4288126e4efSAaron LI	@echo "NOTE: Add the optional 'gui' target to do a GUI release"
4298abe78a1SMatthew Dillon	@echo ""
4308126e4efSAaron LI	@echo "Variables:"
4318126e4efSAaron LI	@echo "  DPORTS_EXTRA_PACKAGES: add additional packages"
4328126e4efSAaron LI	@echo "  GITURL_SRC: override the Git URL to source repository"
4338126e4efSAaron LI	@echo "  GITURL_DPORTS: override the Git URL to dports repository"
4348126e4efSAaron LI	@echo "  IMGSIZE: override the size of .img (in 512-byte sectors)"
4358126e4efSAaron LI	@echo "  MAKE_JOBS: override the default value (sysctl hw.ncpu)"
436588a679cSSimon Schubert
437e2dbfa0bSThomas Nikolajsen.PHONY: release quickrel realquickrel
438e2dbfa0bSThomas Nikolajsen.PHONY: installer
4399b29c40aSMatthew Dillon.PHONY: quick realquick
440e2dbfa0bSThomas Nikolajsen.PHONY: check buildworld1 buildworld2
44131d5c88cSSascha Wildner.PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
442796fd273SYONETANI Tomokazu.PHONY: clean realclean help all srcs
443cc224c64SJoerg Sonnenberger
4446ca9a59cSMatthew Dillon.include <bsd.prog.mk>
445