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