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