xref: /dragonfly/nrelease/Makefile (revision ee21086c)
1#########################################################################
2#				ENHANCEMENTS				#
3#########################################################################
4
5# New method e.g. 'make gui release'.  A series of enhancement
6# targets may be specified which set make variables which enhance
7# the build in various ways.
8#
9# img is now the default (produces both the .iso and .img)
10#
11gui installer img nopkgs:
12
13#########################################################################
14#				 SETUP					#
15#########################################################################
16
17DPORTS_PATH?=	/usr/dports
18ISODIR?=	/usr/obj/release
19ISOROOT?=	${ISODIR}/root
20OBJSYS=		${.OBJDIR}/../sys
21GITURL_SRC?=	git://git.dragonflybsd.org/dragonfly.git
22GITURL_DPORTS?=	git://mirror-master.dragonflybsd.org/dports.git
23MAKE_JOBS?=	$$(sysctl -n hw.ncpu)
24
25# XXX makeshift fix to build the right kernel for the (target) architecture
26# We should configure this in the platform files somehow
27.if ${MACHINE_ARCH} == "x86_64"
28KERNCONF ?= X86_64_GENERIC
29.endif
30
31CHROOT_CMD?=		/usr/sbin/chroot ${ISOROOT} sh -c
32
33.if !make(nopkgs)
34# User may specify extra packages in addition to the defaults
35#
36DPORTS_EXTRA_PACKAGES?=
37
38# dports packages to be built and installed on the release ISO
39#
40DPORTS_PACKAGES?=	devel/git \
41			dns/bind-tools \
42			net/isc-dhcp43-server \
43			sysutils/cdrtools \
44			${DPORTS_EXTRA_PACKAGES}
45
46# dports options to use when building packages
47#
48DPORTS_OPTIONS+=		-DBATCH
49.if make(gui)
50DPORTS_OPTIONS.devel_git+=	-DWITH_GUI
51.else
52DPORTS_OPTIONS.devel_git+=	-DWITHOUT_CONTRIB -DWITHOUT_PERL
53.endif
54.endif
55
56# Specify which root skeletons are required, and let the user include
57# their own.  They are copied into ISODIR during the `customizeiso'
58# target; each overwrites the last.
59#
60REQ_ROOTSKELS=	${.CURDIR}/root
61ROOTSKELS?=	${REQ_ROOTSKELS}
62
63.if make(gui)
64# LIST OF PACKAGES NOT INCLUDED DUE TO BUILD ISSUES:
65#	chat/pidgin		textproc/enchant dependency is broken
66#	x11/rxvt-unicode	broken configure
67#	net/nmap		tries to access openssl/md2.h which does not
68#				exist.
69#	sysutils/idesk		dying on link __sync_fetch_and_add_4
70#
71ISOFILE?=		${ISODIR}/dfly-gui.iso
72IMGFILE?=		${ISODIR}/dfly-gui.img
73
74# NOTE: order important, do not sort package list
75#
76.if !make(nopkgs)
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
102
103ISOFILE ?= ${ISODIR}/dfly.iso
104IMGFILE ?= ${ISODIR}/dfly.img
105
106IMGMNT ?= ${ISODIR}/mnt
107
108# USB umass now probes starting at da8, so the usb stick is
109# probably sitting on da8.
110#
111IMGUSBDEV ?= da8
112
113# note: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
114# the additional '/nrelease' manually, as a safety measure.
115#
116NRLOBJDIR?= /usr/obj
117
118#########################################################################
119#				BASE ISO TARGETS			#
120#########################################################################
121
122release:	check clean buildworld1 buildkernel1 \
123		buildiso srcs customizeiso mkiso mkimg
124
125quickrel:	check clean buildworld2 buildkernel2 \
126		buildiso srcs customizeiso mkiso mkimg
127
128realquickrel:	check clean \
129		buildiso srcs customizeiso mkiso mkimg
130
131restartpkgs:	check customizeiso mkiso mkimg
132
133quick:		quickrel
134
135realquick:	realquickrel
136
137#########################################################################
138#			   CORE SUPPORT TARGETS 			#
139#########################################################################
140
141check:
142.if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
143	@echo
144	@echo "Your machine does not have cdrtools installed.  You can install it with:"
145	@echo "    pkg install cdrtools"
146.endif
147	@if [ ! -d ${DPORTS_PATH} ]; then \
148		echo "${DPORTS_PATH} does not exist."; \
149		echo ""; \
150		echo "Please set DPORTS_PATH to the dports tree that shall be used for"; \
151		echo "package building. The default is /usr/dports. See the Makefile in"; \
152		echo "/usr if you are unfamiliar with dports."; \
153		/usr/bin/false; \
154	fi
155.if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
156	@/usr/bin/false
157.endif
158	@echo "Using ${DPORTS_PATH} as the dports tree."
159
160buildworld1 buildworld2:
161	cd ${.CURDIR}/..; \
162	${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
163		make -j ${MAKE_JOBS} -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
164
165buildkernel1 buildkernel2:
166	cd ${.CURDIR}/..; \
167	for kernconf in ${KERNCONF}; do \
168		${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
169			make -j ${MAKE_JOBS} ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
170			KERNCONF=$${kernconf}; \
171	done
172
173# note that we do not want to mess with any /usr/obj directories not related
174# to buildworld, buildkernel, or nrelease, so we must supply the proper
175# MAKEOBJDIRPREFIX for targets that are not run through the buildworld and
176# buildkernel mechanism.
177#
178# Unconditionally clean out ${ISOROOT} so a previous img build
179# does not blow up a future quick iso build
180#
181# We install with INSTALLSTRIPPEDMODULES to make things fit into the ISO.
182# We leave the kernel's debug variables intact.
183#
184buildiso:
185	-chflags -R noschg ${ISOROOT}
186	rm -rf ${ISOROOT}
187	mkdir -p ${ISOROOT}
188	if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
189	( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
190	( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
191		make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
192	cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
193	cd ${.CURDIR}/..; \
194	for kernconf in ${KERNCONF}; do \
195		make DESTDIR=${ISOROOT} reinstallkernel KERNCONF=$${kernconf}; \
196	done
197	rm -rf ${ISOROOT}/boot/kernel.old
198	ln -sf kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
199	( cd ${.CURDIR}/..; make DESTDIR=${ISOROOT} initrd )
200	mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist -p ${ISOROOT}/var
201	dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
202
203# The GUI build includes the ports tree (~1G+) while the nominal release
204# build does not.
205#
206# The GUI build includes full sources while the nominal release build
207# only includes kernel sources (~27MB).
208#
209srcs:
210.if !defined(WITHOUT_SRCS)
211.if make(gui)
212	rm -f ${ISOROOT}/usr/src-sys.tgz
213	rm -f ${ISOROOT}/usr/src-sys.tar.bz2
214.if !empty(DPORTS_PACKAGES)
215	cd ${ISOROOT}/usr && make dports-create GITURL_DPORTS=${GITURL_DPORTS}
216	# NOTE: Adding the git gc --aggressive helps by significantly
217	#	reducing the disk space required.
218	#
219	cd ${ISOROOT}/usr/dports && git gc --aggressive
220.endif
221	cd ${ISOROOT}/usr && make src-create-repo GITURL_SRC=${GITURL_SRC}
222	# XXX: git gc --aggressive
223.else
224	rm -f ${ISOROOT}/usr/src-sys.tgz
225	rm -f ${ISOROOT}/usr/src-sys.tar.bz2
226	cd ${.CURDIR}/.. && tar --exclude .git -s '/^\./src/' \
227		-cf - ./Makefile ./Makefile.inc1 \
228		./crypto/libressl/include ./sys | \
229		bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2
230.endif
231.endif
232
233# Customize the ISO by copying rootskels in reverse priority order,
234# building packages, and doing other post-install tasks.
235#
236customizeiso:
237	# Copy the rootskels.  Allow sources to be owned by someone other
238	# than root (as is common when checked out via git).
239	#
240.for ROOTSKEL in ${ROOTSKELS}
241	cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
242	@test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
243	@test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
244.endfor
245	pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
246.for UPGRADE_ITEM in Makefile			\
247		     etc.${MACHINE_ARCH} 	\
248		     rc.d/Makefile		\
249		     periodic/Makefile		\
250		     periodic/daily/Makefile	\
251		     periodic/security/Makefile	\
252		     periodic/weekly/Makefile	\
253		     periodic/monthly/Makefile
254	cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
255.endfor
256	#
257	# Setup some things & mount dports tree.  Use defensive umounts and
258	# rm -rf's to allow restarts.  Allow /usr/dports to be read-only.
259	#
260	-@umount ${ISOROOT}/dev
261	mount_null /dev ${ISOROOT}/dev
262.if !empty(DPORTS_PACKAGES)
263	cp /etc/resolv.conf ${ISOROOT}/etc
264	${CHROOT_CMD} "ldconfig -elf /lib /usr/lib /usr/lib/gcc*"
265	-@umount ${ISOROOT}/usr/distfiles
266	-@umount ${ISOROOT}/usr/dports
267	rm -rf ${ISOROOT}/usr/obj/dports
268	#
269	# Mount /usr/dports, make sure /usr/distfiles is writable.
270	# Make /usr/dports read-only for safety, else a failed umount and
271	# our rm -rf will do bad things.
272	#
273	mkdir -p ${ISOROOT}/usr/dports
274	mkdir -p ${ISOROOT}/usr/distfiles
275	mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
276	cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
277	    || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
278	#
279	# Build and install packages, skip packages already installed
280	#
281.for PKG in ${DPORTS_PACKAGES}
282	${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} ${DPORTS_OPTIONS.${PKG:S/\//_/g}} install"
283.endfor
284.for PKG in ${DPORTS_PACKAGES}
285	${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
286.endfor
287	#
288	# Remove packages which nothing depends on, add a whatis database
289	# for dports manual pages, create an initial locate database and
290	# clean up
291	#
292	${CHROOT_CMD} "yes | pkg autoremove"
293	${CHROOT_CMD} "makewhatis /usr/local/man"
294	-umount ${ISOROOT}/usr/distfiles
295	umount ${ISOROOT}/usr/dports
296	rm -rf ${ISOROOT}/usr/dports
297	rm -rf ${ISOROOT}/usr/obj/dports
298	rm -rf ${ISOROOT}/usr/distfiles
299	rm -f ${ISOROOT}/etc/resolv.conf
300.endif
301	#
302	# Finally, update the locate(8) database, allow ISODIR
303	# to be on tmpfs (fails to create locate database then)
304	#
305	-${CHROOT_CMD} /etc/periodic/weekly/310.locate
306	umount ${ISOROOT}/dev
307	#
308	# Recopy files that dports may have updated in /etc into /etc.hdd
309	#
310	cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
311	cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
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 -eltorito-boot boot/efiboot.img -no-emul-boot \
328		-V "DragonFly `${.CURDIR}/../tools/gitrev.sh | cut -c -22`" . )
329	rm -f ${ISOROOT}/boot/efiboot.img
330
331mkimg:
332	if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
333	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
334	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
335.ifdef IMGSIZE
336	@echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
337	rm -f ${IMGFILE}
338	sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
339.else
340	@echo "STEP: Determine required image size in 1GB steps"
341	@echo "      Leave ~600MB of unused space"
342	sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;			\
343	    sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
344	    cut -f1 -d.`;						\
345	    sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`;		\
346	    rm -f ${IMGFILE};						\
347	    truncate -s $${sz}M ${IMGFILE};
348.endif
349	@echo "STEP: determine free vn device"
350	vnconfig -l | grep "not in use" | head -n 1 | 			\
351	    cut -f 1 -d: > ${ISODIR}/vn.which
352	vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
353	@echo "STEP: set up legacy MBR"
354	fdisk -IB `cat ${ISODIR}/vn.which`
355	fdisk -s `cat ${ISODIR}/vn.which` >${ISODIR}/fdisk.dat
356	awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
357	    ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
358	echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
359	awk '($$1=="1:"){printf("p 2 165 258048 %lu\n", $$3 - 258528);}' \
360	    ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
361	echo "a 2" >>${ISODIR}/fdisk.conf
362	fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
363	rm ${ISODIR}/fdisk.conf ${ISODIR}/fdisk.dat
364	newfs_msdos -F 32 -c 2 -L EFI -m 0xf8 `cat ${ISODIR}/vn.which`s1
365	mount_msdos /dev/`cat ${ISODIR}/vn.which`s1 ${IMGMNT}
366	mkdir -p ${IMGMNT}/EFI/BOOT
367	cp ${ISOROOT}/boot/boot1.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
368	umount ${IMGMNT}
369	@echo "STEP: write standard disklabel"
370	disklabel -w -r `cat ${ISODIR}/vn.which`s2 auto
371	@echo "STEP: read disklabel back"
372	disklabel -r `cat ${ISODIR}/vn.which`s2 > ${IMGFILE}.label
373	@echo "STEP: determine number of sectors of whole disk"
374	secs=`tail -n 1 ${IMGFILE}.label | cut -f 3 -w`;		\
375	    echo "  a:  $${secs} 0 4.2BSD" >> ${IMGFILE}.label;
376	@echo "STEP: write modified disklabel back"
377	disklabel -R -r `cat ${ISODIR}/vn.which`s2 ${IMGFILE}.label
378	rm ${IMGFILE}.label
379	disklabel -B `cat ${ISODIR}/vn.which`s2
380	newfs /dev/`cat ${ISODIR}/vn.which`s2a
381	mount /dev/`cat ${ISODIR}/vn.which`s2a ${IMGMNT}
382	cpdup ${ISOROOT} ${IMGMNT}
383	@echo "STEP: fixup ${IMGMNT}/etc/fstab"
384	echo "/dev/${IMGUSBDEV}s2a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
385	echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
386	echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
387	echo "dummy /var/run tmpfs rw,-C 0 0" >> ${IMGMNT}/etc/fstab
388	echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
389	echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
390	@echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
391	-fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
392	echo 'vfs.root.mountfrom="ufs:${IMGUSBDEV}s2a"' >> ${IMGMNT}/boot/loader.conf.new
393	mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
394	@echo "STEP: cleanup"
395	df ${IMGMNT}
396	sync
397	sleep 1
398	umount ${IMGMNT}
399	vnconfig -u `cat ${ISODIR}/vn.which`
400	rm -f ${ISODIR}/vn.which
401	rmdir ${IMGMNT}
402	@echo "STEP: done"
403
404clean:
405	sync
406	sleep 1
407	-umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
408	-umount ${ISOROOT}/usr/dports > /dev/null 2>&1
409	-umount ${ISOROOT}/dev > /dev/null 2>&1
410	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
411	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
412	if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
413	rm -rf ${ISOROOT}
414	rm -rf ${NRLOBJDIR}/nrelease
415	rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
416
417realclean:	clean
418	rm -rf ${OBJSYS}/${KERNCONF}
419	rm -rf ${ISODIR}/packages
420	rm -rf ${ISODIR}/distfiles
421
422help all:
423	@echo "Targets:"
424	@echo "  release     - full build from scratch"
425	@echo "  quick       - attempt to do an incremental rebuild"
426	@echo "  realquick   - attempt to restart after world & kernel"
427	@echo "  restartpkgs - attempt to restart at the pkg building stage"
428	@echo "NOTE: Add the optional 'gui' target to do a GUI release"
429	@echo ""
430	@echo "Variables:"
431	@echo "  DPORTS_EXTRA_PACKAGES: add additional packages"
432	@echo "  GITURL_SRC: override the Git URL to source repository"
433	@echo "  GITURL_DPORTS: override the Git URL to dports repository"
434	@echo "  IMGSIZE: override the size of .img (in 512-byte sectors)"
435	@echo "  MAKE_JOBS: override the default value (sysctl hw.ncpu)"
436
437.PHONY: release quickrel realquickrel
438.PHONY: installer
439.PHONY: quick realquick
440.PHONY: check buildworld1 buildworld2
441.PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
442.PHONY: clean realclean help all srcs
443
444.include <bsd.prog.mk>
445