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