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