xref: /dragonfly/nrelease/Makefile (revision 19380330)
1#########################################################################
2#				ENHANCEMENTS	 			#
3#########################################################################
4
5# New method e.g. 'make gui release'.  A series of enhancement
6# targes 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
17ISODIR?=	/usr/release
18ISOROOT?=	${ISODIR}/root
19OBJSYS=		${.OBJDIR}/../sys
20GITHOST?=	git.dragonflybsd.org
21
22MAKE_JOBS?=	$$(sysctl -n hw.ncpu)
23
24# temporary until everybody has converted to x86_64
25.if ${MACHINE_ARCH} == "amd64"
26MACHINE_ARCH=	x86_64
27.makeenv MACHINE_ARCH
28.endif
29
30# XXX makeshift fix to build the right kernel for the (target) architecture
31# We should configure this in the platform files somehow
32.if ${MACHINE_ARCH} == "i386"
33KERNCONF ?= GENERIC
34.else
35KERNCONF ?= X86_64_GENERIC
36.endif
37
38PKGSRC_PREFIX?=		/usr/pkg
39PKGBIN_PKG_ADD?=	${PKGSRC_PREFIX}/sbin/pkg_add
40PKGBIN_PKG_DELETE?=	${PKGSRC_PREFIX}/sbin/pkg_delete
41PKGBIN_PKG_ADMIN?=	${PKGSRC_PREFIX}/sbin/pkg_admin
42PKGBIN_MKISOFS?=	${PKGSRC_PREFIX}/bin/mkisofs
43PKGSRC_PKG_PATH?=	${ISODIR}/packages
44
45# We use env -i in the chroot, so that environment variables won't
46# disturb any (pkgsrc) build.  This has happened for TARGET_ARCH,
47# which is used by gmake in completely different context.
48#
49CHROOT_CMD?=		env -i CCVER=${CCVER:Q} /usr/sbin/chroot ${ISOROOT} sh -c
50
51# User may specify extra packages in addition to the defaults
52#
53PKGSRC_EXTRA_PACKAGES?=
54
55# Pkgsrc packages to be built and installed on the release ISO
56#
57PKGSRC_PACKAGES?=	pkgtools/pkg_leaves \
58			pkgtools/pkg_tarup \
59			pkgtools/pkgin \
60			devel/scmgit \
61			net/bind96 \
62			net/isc-dhcp4 \
63			net/isc-dhcpd4 \
64			sysutils/cdrtools \
65			net/csup \
66			${PKGSRC_EXTRA_PACKAGES}
67
68# pkgsrc options to use when building packages
69#
70PKGSRC_OPTIONS+=	MAKE_JOBS=${MAKE_JOBS}
71PKGSRC_OPTIONS+=	WRKOBJDIR=/usr/pkgobj
72PKGSRC_OPTIONS+=	PKG_DEFAULT_OPTIONS='dri inet6'
73.if !make(gui)
74PKGSRC_OPTIONS+=	PKG_OPTIONS.scmgit='-python'
75.endif
76
77# Even though buildiso wipes the packages, our check target has to run
78# first and old packages (listed as they appear in pkg_info) must be
79# cleaned out in order for the pkg_add -n test we use in the check target
80# to operate properly.
81#
82OLD_PKGSRC_PACKAGES?=	cdrtools-2.01.01.27nb1 \
83			cdrecord-2.00.3nb2 \
84			bootstrap-kit-20070205 \
85			dfuibe_installer-1.1.6 \
86			gettext-lib-0.14.5 \
87			dfuibe_installer-1.1.7nb1 \
88			dfuife_curses-1.5 \
89			gettext-lib-0.14.6 \
90			gettext-tools-0.14.6nb1 \
91			libaura-3.1 \
92			libdfui-4.2 \
93			libinstaller-5.1 \
94			bootstrap-kit-20080211 \
95			cdrtools-ossdvd-2.01.1.36nb2 \
96			isc-dhcp-base-4.0.0 \
97			isc-dhcp-server-4.0.0
98
99# Specify which root skeletons are required, and let the user include
100# their own.  They are copied into ISODIR during the `customizeiso'
101# target; each overwrites the last.
102#
103REQ_ROOTSKELS=	${.CURDIR}/root
104ROOTSKELS?=	${REQ_ROOTSKELS}
105
106# LIST OF PACKAGES NOT INCLUDED DUE TO BUILD ISSUES:
107#	chat/pidgin		textproc/enchant dependency is broken
108#	x11/rxvt-unicode	broken configure
109#	net/nmap		tries to access openssl/md2.h which does not
110#				exist.
111#	sysutils/idesk		dying on link __sync_fetch_and_add_4
112#
113.if make(gui)
114ISOFILE?=		${ISODIR}/dfly-gui.iso
115IMGFILE?=		${ISODIR}/dfly-gui.img
116
117# NOTE: order important, do not sort package list
118#
119# Apps we want in the gui build but which have problems building:
120#	chat/xchat	link error on x86-64, something about ___progname
121#
122#
123.if !make(nopkgs)
124PKGSRC_PACKAGES+=	meta-pkgs/modular-xorg-libs \
125			meta-pkgs/modular-xorg-fonts \
126			meta-pkgs/modular-xorg-apps \
127			meta-pkgs/modular-xorg-drivers \
128			x11/libXinerama \
129			wm/fluxbox \
130			wm/fvwm \
131			www/firefox \
132			print/xpdf \
133			shells/zsh \
134			editors/emacs \
135			editors/vim \
136			chat/irssi \
137			x11/modular-xorg-server \
138			x11/eterm \
139			lang/perl5 \
140			editors/nano \
141			shells/bash \
142			devel/exctags \
143			archivers/zip \
144			security/sudo \
145			www/links-gui \
146			net/wget \
147			fonts/terminus-font \
148			net/rsync \
149			time/asclock \
150			misc/screen \
151			devel/scmgit-gitk
152.endif
153
154ROOTSKELS+=		${.CURDIR}/gui
155.endif
156
157ISOFILE ?= ${ISODIR}/dfly.iso
158IMGFILE ?= ${ISODIR}/dfly.img
159
160IMGMNT ?= ${ISODIR}/mnt
161
162# USB umass now probes starting at da8, so the usb stick is
163# probably sitting on da8.
164#
165IMGUSBDEV ?= da8
166
167# note: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
168# the additional '/nrelease' manually, as a safety measure.
169#
170NRLOBJDIR?= /usr/obj
171
172#########################################################################
173#				BASE ISO TARGETS 			#
174#########################################################################
175
176release:	check clean buildworld1 buildkernel1 \
177		buildiso srcs customizeiso mkiso mkimg
178
179quickrel:	check clean buildworld2 buildkernel2 \
180		buildiso srcs customizeiso mkiso mkimg
181
182realquickrel:	check clean \
183		buildiso srcs customizeiso mkiso mkimg
184
185restartpkgs:	check customizeiso mkiso mkimg
186
187quick:		quickrel
188
189realquick:	realquickrel
190
191
192#########################################################################
193#			   CORE SUPPORT TARGETS 			#
194#########################################################################
195
196check:
197.if !exists(${PKGBIN_PKG_ADMIN})
198	@echo "You never bootstrapped pkgsrc on your machine.  You can install it with:"
199	@echo "    make pkgsrc_bootstrap"
200.endif
201.if !exists (${PKGBIN_MKISOFS})
202	@echo
203	@echo "Your machine does not have cdrtools installed.  You can install it with:"
204	@echo "    make pkgsrc_cdrecord"
205.endif
206.if !defined(PKGSRC_PATH)
207	@echo "Please set PKGSRC_PATH to the pkgsrc tree that shall be used for"
208	@echo "package building.  For example /usr/pkgsrc.  See the Makefile"
209	@echo "in /usr if you are unfamiliar with pkgsrc."
210.endif
211.if !exists (${PKGBIN_MKISOFS})
212	@exit 1
213.endif
214.if !defined(PKGSRC_PATH)
215	@exit 1
216.endif
217
218buildworld1 buildworld2:
219	cd ${.CURDIR}/..; \
220	${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
221		make -j ${MAKE_JOBS} -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
222
223buildkernel1 buildkernel2:
224	cd ${.CURDIR}/..; \
225	for kernconf in ${KERNCONF}; do \
226		${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
227			make -j ${MAKE_JOBS} ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
228			KERNCONF=$${kernconf}; \
229	done
230
231# note that we do not want to mess with any /usr/obj directories not related
232# to buildworld, buildkernel, or nrelease, so we must supply the proper
233# MAKEOBJDIRPREFIX for targets that are not run through the buildworld and
234# buildkernel mechanism.
235#
236# Unconditionally clean out /usr/release/root so a previous img build
237# does not blow up a future quick iso build
238#
239# We install with INSTALLSTRIPPEDMODULES to make things fit into the ISO.
240# We leave the kernel's debug variables intact.
241#
242buildiso:
243	-rm -rf ${ISOROOT}
244	-chflags -R noschg ${ISOROOT}
245	rm -rf ${ISOROOT}
246	mkdir -p ${ISOROOT}
247	if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
248	( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
249	( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
250		make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
251	cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
252	cd ${.CURDIR}/..; \
253	for kernconf in ${KERNCONF}; do \
254		make DESTDIR=${ISOROOT} installkernel KERNCONF=$${kernconf}; \
255	done
256	rm -rf ${ISOROOT}/boot/kernel.old
257	ln -s kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
258	mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.local.dist -p ${ISOROOT}/usr/local/
259	mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist -p ${ISOROOT}/var
260	dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
261
262# The GUI build includes the pkgsrc tree (~1G+) while the nominal release
263# build does not.
264#
265# The GUI build includes full sources while the nominal release build
266# only includes kernel sources (~27MB).
267#
268srcs:
269.if !defined(WITHOUT_SRCS)
270.if make(gui)
271	rm -f ${ISOROOT}/usr/src-sys.tgz
272	rm -f ${ISOROOT}/usr/src-sys.tar.bz2
273	cd ${ISOROOT}/usr && make pkgsrc-create-repo GITHOST=${GITHOST}
274	cd ${ISOROOT}/usr && make src-create-repo GITHOST=${GITHOST}
275.else
276	rm -f ${ISOROOT}/usr/src-sys.tgz
277	rm -f ${ISOROOT}/usr/src-sys.tar.bz2
278	cd ${.CURDIR}/.. && tar --exclude .git -s '/^\./src/' \
279		-cf - ./Makefile ./Makefile.inc1 ./sys | \
280		bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2
281.endif
282.endif
283
284# Customize the ISO by copying rootskels in reverse priority order,
285# building packages, and doing other post-install tasks.
286#
287customizeiso:
288	# Copy the rootskels.  Allow sources to be owned by someone other
289	# than root (as is common when checked out via git).
290	#
291.for ROOTSKEL in ${ROOTSKELS}
292	cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
293	@test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
294	@test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
295.endfor
296	pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
297.for UPGRADE_ITEM in Makefile			\
298		     etc.${MACHINE_ARCH} 	\
299		     rc.d/Makefile		\
300		     periodic/Makefile		\
301		     periodic/daily/Makefile	\
302		     periodic/security/Makefile	\
303		     periodic/weekly/Makefile	\
304		     periodic/monthly/Makefile
305	cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
306.endfor
307	#
308	# Setup some things & mount pkgsrc tree.  Use defensive umounts and
309	# rm -rf's to allow restarts.  Allow /usr/pkgsrc to be read-only.
310	#
311	# If we did not get past the bootstrap we clean out the entire
312	# /usr/pkg infrastructure.  Otherwise we attempt to pick up where
313	# we left off.
314	#
315	cp -p /etc/resolv.conf ${ISOROOT}/etc
316	${CHROOT_CMD} "ldconfig -elf /usr/lib /usr/lib/gcc* /usr/lib/compat"
317	-@umount ${ISOROOT}/usr/pkgsrc/distfiles
318	-@umount ${ISOROOT}/usr/pkgsrc
319	-@umount ${ISOROOT}/dev
320	mkdir -p ${ISODIR}/distfiles
321	rm -rf ${ISOROOT}/usr/pkgobj
322	#
323	# Mount /usr/pkgsrc, make sure /usr/pkgsrc/distfiles is writable.
324	# Make /usr/pkgsrc read-only for safety, else a failed umount and
325	# our rm -rf will do bad things.
326	#
327	mkdir -p ${ISOROOT}/usr/pkgobj
328	mkdir -p ${ISOROOT}/usr/pkgobj/bootstrap
329	mkdir -p ${ISOROOT}/usr/pkgsrc
330	mount_null -o ro ${PKGSRC_PATH} ${ISOROOT}/usr/pkgsrc
331	mount_null /dev ${ISOROOT}/dev
332	cp /etc/shells ${ISOROOT}/usr/pkgsrc/distfiles/.test > /dev/null 2>&1 \
333	    || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/pkgsrc/distfiles
334	#
335	# Bootstrap, if not already installed, and add licenses needed
336	# for the gui release
337	#
338	test -e ${ISODIR}/.didbootstrap || \
339	    rm -rf ${ISOROOT}/usr/pkg ${ISOROOT}/var/db/pkg \
340		    ${ISOROOT}/var/db/pkg.refcount
341	test -e ${ISODIR}/.didbootstrap || \
342	    ${CHROOT_CMD} "cd /usr/pkgsrc/bootstrap;    \
343		export share_dir=/usr/pkgobj/bootstrap/work/share; \
344		env USE_DESTDIR=no ./bootstrap --workdir /usr/pkgobj/bootstrap/work"
345	test -e ${ISODIR}/.didbootstrap || \
346	    echo ".ifdef BSD_PKG_MK	# added by nrelease" \
347		>> ${ISOROOT}/usr/pkg/etc/mk.conf
348	test -e ${ISODIR}/.didbootstrap || \
349	    echo "PKG_DEFAULT_OPTIONS=dri inet6" \
350		>> ${ISOROOT}/usr/pkg/etc/mk.conf
351.if make(gui)
352	test -e ${ISODIR}/.didbootstrap || \
353	    echo "ACCEPTABLE_LICENSES+=openmotif-license" \
354		>> ${ISOROOT}/usr/pkg/etc/mk.conf
355	test -e ${ISODIR}/.didbootstrap || \
356	    echo "ACCEPTABLE_LICENSES+=vim-license" \
357		>> ${ISOROOT}/usr/pkg/etc/mk.conf
358.endif
359	test -e ${ISODIR}/.didbootstrap || \
360	    echo ".endif			# added by nrelease" \
361		>> ${ISOROOT}/usr/pkg/etc/mk.conf
362	test -e ${ISODIR}/.didbootstrap || sync
363	test -e ${ISODIR}/.didbootstrap || touch ${ISODIR}/.didbootstrap
364	#
365	# Build and install packages, skip packages already installed
366	#
367.for PKG in ${PKGSRC_PACKAGES}
368	${CHROOT_CMD} "cd /usr/pkgsrc/${PKG} && \
369	    (bmake check > /dev/null 2>&1 || \
370	    env USE_DESTDIR=no bmake ${PKGSRC_OPTIONS} clean build install)"
371.endfor
372	#
373	# Remove packages which nothing depends on, add a whatis database
374	# for pkgsrc manual pages, create an initial locate database and
375	# clean up
376	#
377	${CHROOT_CMD} "pkg_leaves | xargs pkg_delete -R"
378	${CHROOT_CMD} "makewhatis /usr/pkg/man"
379	-umount ${ISOROOT}/usr/pkgsrc/distfiles
380	umount ${ISOROOT}/usr/pkgsrc
381	rm -rf ${ISOROOT}/usr/pkgobj
382	rm -f ${ISOROOT}/etc/resolv.conf
383	${CHROOT_CMD} /etc/periodic/weekly/310.locate
384	umount ${ISOROOT}/dev
385	#
386	# Recopy files that pkgsrc may have updated in /etc into /etc.hdd
387	#
388	cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
389	cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
390
391mkiso:
392	( cd ${ISOROOT}; ${PKGBIN_MKISOFS} -b boot/cdboot -no-emul-boot \
393		-R -J -o ${ISOFILE} \
394		-V "DragonFly `${.CURDIR}/../tools/gitrev.sh | cut -c -22`" . )
395
396mkimg:
397	if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
398	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
399	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
400.ifdef IMGSIZE
401	@echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
402	rm -f ${IMGFILE}
403	sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
404.else
405	@echo "STEP: Determine required image size in 1GB steps"
406	@echo "      Leave ~600MB of unused space"
407	sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;			\
408	    sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
409	    cut -f1 -d.`;						\
410	    sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`;		\
411	    rm -f ${IMGFILE};						\
412	    truncate -s $${sz}M ${IMGFILE};
413.endif
414	fdisk -IB -p ${IMGFILE}
415	@echo "STEP: determine free vn device"
416	vnconfig -l | grep "not in use" | head -n 1 | 			\
417	    cut -f 1 -d: > ${ISODIR}/vn.which
418	vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
419	@echo "STEP: write standard disklabel"
420	disklabel -w -r `cat ${ISODIR}/vn.which`s1 auto
421	@echo "STEP: read disklabel back"
422	disklabel -r `cat ${ISODIR}/vn.which`s1 > ${IMGFILE}.label
423	@echo "STEP: determine number of sectors of whole disk"
424	secs=`tail -n 1 ${IMGFILE}.label | cut -f 3 -w`;		\
425	    echo "  a:  $${secs} 0 4.2BSD" >> ${IMGFILE}.label;
426	@echo "STEP: write modified disklabel back"
427	disklabel -R -r `cat ${ISODIR}/vn.which`s1 ${IMGFILE}.label
428	rm ${IMGFILE}.label
429	@echo "STEP: write bootsector"
430	disklabel -B `cat ${ISODIR}/vn.which`s1
431	boot0cfg -B -o noupdate `cat ${ISODIR}/vn.which`
432	newfs /dev/`cat ${ISODIR}/vn.which`s1a
433	mount /dev/`cat ${ISODIR}/vn.which`s1a ${IMGMNT}
434	cpdup ${ISOROOT} ${IMGMNT}
435	@echo "STEP: fixup ${IMGMNT}/etc/fstab"
436	echo "/dev/${IMGUSBDEV}s1a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
437	echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
438	echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
439	echo "dummy /var/run tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
440	echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
441	echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
442	@echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
443	-fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
444	echo 'vfs.root.mountfrom="ufs:${IMGUSBDEV}s1a"' >> ${IMGMNT}/boot/loader.conf.new
445	mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
446	@echo "STEP: cleanup"
447	df ${IMGMNT}
448	umount ${IMGMNT}
449	vnconfig -u `cat ${ISODIR}/vn.which`
450	rm -f ${ISODIR}/vn.which
451	rmdir ${IMGMNT}
452	@echo "STEP: done"
453
454clean:
455	-umount ${ISOROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
456	-umount ${ISOROOT}/usr/pkgsrc > /dev/null 2>&1
457	-umount ${ISOROOT}/dev > /dev/null 2>&1
458	-if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; 		\
459	    vnconfig -u `cat ${ISODIR}/vn.which`; fi
460	if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
461	rm -rf ${ISOROOT}
462	rm -rf ${NRLOBJDIR}/nrelease
463	rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
464
465realclean:	clean
466	rm -rf ${OBJSYS}/${KERNCONF}
467	#
468	# do not use PKGSRC_PKG_PATH here, we do not want to destroy an
469	# override location.
470	#
471	rm -rf ${ISODIR}/packages
472	rm -rf ${ISODIR}/distfiles
473
474pkgsrc_bootstrap:
475	mkdir -p /usr/release/bootstrap
476	(cd ${PKGSRC_PATH}/bootstrap; \
477	    export share_dir=/usr/release/bootstrap/share; \
478	    ./bootstrap --workdir /usr/release/bootstrap)
479
480pkgsrc_cdrecord:
481.if !exists (${PKGBIN_MKISOFS})
482	(cd ${PKGSRC_PATH}/sysutils/cdrtools; bmake clean build install)
483.endif
484
485help all:
486	@echo "make [gui] release   - complete build from scratch"
487	@echo "make [gui] quick     - attempt to do an incremental rebuild"
488	@echo "make [gui] realquick - attempt to restart after world & kernel"
489	@echo "make [gui] restartpkgs - attempt to restart at the pkg building stage"
490	@echo ""
491	@echo "PKGSRC_EXTRA_PACKAGES may be used to add additional pkgs"
492	@echo "GITHOST may be used to override git.dragonflybsd.org"
493	@echo "IMGSIZE may be used to override the .img (in 512-byte sectors)"
494
495.PHONY: release quickrel realquickrel
496.PHONY: installer
497.PHONY: quick realquick
498.PHONY: check buildworld1 buildworld2
499.PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
500.PHONY: clean realclean help all srcs
501
502.include <bsd.prog.mk>
503