1 #########################################################################
3 #########################################################################
5 # Optional targets may be specified which set make variables which enhance
6 # the build in various ways.
10 #########################################################################
12 #########################################################################
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)
26 GITREV!= sh ${SRCDIR}/tools/gitrev.sh
28 # The label/name of the disklabel64(5) slice in the ".img" file. This is
29 # used to identify the USB device with DragonFly installation image, avoiding
30 # hardcoding the USB device name (e.g., "da8").
32 # This label is also used as the volume ID of the ".iso" file.
34 LABEL?= DragonFly_${GITREV}
36 CHROOT_CMD?= /usr/sbin/chroot ${ISOROOT} sh -c
38 ISOFILE?= ${ISODIR}/dfly.iso
39 IMGFILE?= ${ISODIR}/dfly.img
40 IMGMNT?= ${ISODIR}/mnt
43 # User may specify extra packages in addition to the defaults
45 DPORTS_EXTRA_PACKAGES?=
47 # dports packages to be built and installed on the release ISO
49 DPORTS_PACKAGES?= security/ca_root_nss \
52 net/isc-dhcp44-server \
54 ${DPORTS_EXTRA_PACKAGES}
56 # dports options to use when building packages
58 DPORTS_OPTIONS+= -DBATCH
59 DPORTS_OPTIONS+= dns_bind-tools_UNSET=PYTHON
62 # Specify which root skeletons are required, and let the user include
63 # their own. They are copied into ISODIR during the `customizeiso'
64 # target; each overwrites the last.
66 REQ_ROOTSKELS= ${.CURDIR}/root
67 ROOTSKELS?= ${REQ_ROOTSKELS}
70 ISOFILE?= ${ISODIR}/dfly-gui.iso
71 IMGFILE?= ${ISODIR}/dfly-gui.img
74 # NOTE: order important, do not sort package list
76 DPORTS_PACKAGES+= x11/xorg \
93 x11-fonts/terminus-font \
99 ROOTSKELS+= ${.CURDIR}/gui
102 # one port may have multiple binary packages (e.g., Python flavors) or have a
103 # different name that may not be found by pkg(8), therefore, allow to specify
104 # the exact binary package name for a port by setting 'PKG_<port>=<pkg-name>'.
106 .for PORT in ${DPORTS_PACKAGES}
107 .if defined(PKG_${PORT})
108 PACKAGES+= ${PKG_${PORT}}
114 #########################################################################
116 #########################################################################
118 release: check clean buildworld1 buildkernel1 \
119 buildiso customizeiso pkgs srcs mkiso mkimg
121 quickrel: check clean buildworld2 buildkernel2 \
122 buildiso customizeiso pkgs srcs mkiso mkimg
124 realquickrel: check clean \
125 buildiso customizeiso pkgs srcs mkiso mkimg
127 restartpkgs: check pkgs srcs mkiso mkimg
131 realquick: realquickrel
133 #########################################################################
134 # CORE SUPPORT TARGETS #
135 #########################################################################
138 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
140 @echo "Your machine does not have cdrtools installed. You can install it with:"
141 @echo " pkg install cdrtools"
143 @if [ ! -d ${DPORTS_PATH} ]; then \
144 echo "${DPORTS_PATH} does not exist."; \
146 echo "Please set DPORTS_PATH to the dports tree that shall be used for"; \
147 echo "package building. The default is /usr/dports. See the Makefile in"; \
148 echo "/usr if you are unfamiliar with dports."; \
151 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
154 @echo "Using ${DPORTS_PATH} as the dports tree."
156 buildworld1 buildworld2:
158 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
159 make -j ${NREL_MAKE_JOBS} -DWANT_INSTALLER \
160 ${.TARGET:C/build(.*)2/quick\1/:C/1//} )
162 buildkernel1 buildkernel2:
164 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
165 make -j ${NREL_MAKE_JOBS} \
166 ${.TARGET:C/build(.*)2/quick\1/:C/1//} )
168 # Unconditionally clean out ${ISOROOT} so a previous img build
169 # does not blow up a future quick iso build
172 -chflags -R noschg ${ISOROOT}
176 make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
177 # Do not mess with any /usr/obj directories not related to
178 # buildworld, buildkernel, or nrelease.
179 ( cd ${SRCDIR}/etc && \
180 tmpdir=`mktemp -d -t nrelease` && \
181 MAKEOBJDIRPREFIX=$${tmpdir} \
182 make -m ${SRCDIR}/share/mk \
183 DESTDIR=${ISOROOT} distribution && \
185 cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
186 ( cd ${SRCDIR}; make DESTDIR=${ISOROOT} reinstallkernel )
187 rm -rf ${ISOROOT}/boot/kernel.old
188 ln -sf kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
189 mtree ${MTREE_FSCHG} -deU -f ${SRCDIR}/etc/mtree/BSD.var.dist \
191 dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
192 ${CHROOT_CMD} "rcrestart ldconfig"
194 # The GUI build includes the full system source (~500 MB) and the full
195 # dports tree (~250 MB). The nominal release build only includes the
196 # kernel source (~30 MB).
199 rm -rf ${ISOROOT}/usr/dports
200 rm -f ${ISOROOT}/usr/src-sys.tar.bz2
201 .if !defined(WITHOUT_SRCS)
203 ( cd ${ISOROOT}/usr && \
204 make dports-create-shallow GITURL_DPORTS=${GITURL_DPORTS} )
205 ( cd ${ISOROOT}/usr && \
206 make src-create-shallow GITURL_SRC=${GITURL_SRC} )
209 tar --exclude .git -s '/^\./src/' -cf - \
210 ./Makefile ./Makefile.inc1 ./sys \
211 ./share/syscons/fonts | \
212 bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2 )
216 # Customize the ISO by copying rootskels in reverse priority order.
219 # Copy the rootskels. Allow sources to be owned by someone other
220 # than root (as is common when checked out via git).
222 .for ROOTSKEL in ${ROOTSKELS}
223 cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
224 @test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
225 @test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
228 pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
229 pw -V ${ISOROOT}/etc useradd installer -o -u 0 -g 0 \
230 -c "DragonFly Installer" -d /root -s /usr/sbin/installer
231 ${CHROOT_CMD} "chpass -p '' root"
232 ${CHROOT_CMD} "chpass -p '' installer"
234 .for UPGRADE_ITEM in Makefile \
235 etc.${MACHINE_ARCH} \
238 periodic/daily/Makefile \
239 periodic/security/Makefile \
240 periodic/weekly/Makefile \
241 periodic/monthly/Makefile
242 cp -R ${SRCDIR}/etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
245 # Install packages by using pkg(8) or building from dports.
248 .if !empty(DPORTS_PACKAGES)
249 cp /etc/resolv.conf ${ISOROOT}/etc
250 -@umount ${ISOROOT}/dev
251 mount_null /dev ${ISOROOT}/dev
254 ${CHROOT_CMD} "cd /usr && make pkg-bootstrap-force"
255 ${CHROOT_CMD} "pkg update"
256 .for PKG in ${PACKAGES}
257 @${CHROOT_CMD} "pkg search --exact --search name ${PKG}" || \
258 ${CHROOT_CMD} "pkg search --exact --search origin ${PKG}" || \
260 echo "ERROR: Cannot find the package for port '${PKG}'!"; \
261 echo "-----> Use 'PKG_${PKG}=<pkg-name>' to specify the package name."; \
265 ${CHROOT_CMD} "pkg install --yes ${PACKAGES}"
267 .else # !make(binpkgs)
268 -@umount ${ISOROOT}/usr/distfiles
269 -@umount ${ISOROOT}/usr/dports
270 rm -rf ${ISOROOT}/usr/obj/dports
272 mkdir -p ${ISOROOT}/usr/dports
273 mkdir -p ${ISOROOT}/usr/distfiles
275 # Mount /usr/dports read-only for safety, else a failed umount
276 # and our rm -rf will do bad things.
277 mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
279 # Make sure /usr/distfiles is writable
280 cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
281 || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
283 .for PKG in ${DPORTS_PACKAGES}
284 .if make(restartpkgs)
285 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} deinstall"
287 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} install"
289 .for PKG in ${DPORTS_PACKAGES}
290 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
293 ${CHROOT_CMD} "pkg autoremove --yes"
295 -umount ${ISOROOT}/usr/distfiles
296 umount ${ISOROOT}/usr/dports
298 rm -rf ${ISOROOT}/usr/dports
299 rm -rf ${ISOROOT}/usr/distfiles
300 rm -rf ${ISOROOT}/usr/obj/dports
301 .endif # make(binpkgs)
303 # Update the locate(8) and whatis(1) databases, allow ISODIR
304 # to be on tmpfs (fails to create locate database then)
306 -${CHROOT_CMD} /etc/periodic/weekly/310.locate
307 -${CHROOT_CMD} /etc/periodic/weekly/320.whatis
309 umount ${ISOROOT}/dev
310 rm -f ${ISOROOT}/etc/resolv.conf
312 .if exists(${ISOROOT}/usr/local/etc)
313 echo "dummy /usr/local/etc tmpfs rw,-C 0 0" >> ${ISOROOT}/etc/fstab
316 # Recopy files that dports may have updated in /etc into /etc.hdd
318 cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
319 cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
320 cpdup ${ISOROOT}/etc/passwd ${ISOROOT}/etc.hdd/passwd
321 cpdup ${ISOROOT}/etc/master.passwd ${ISOROOT}/etc.hdd/master.passwd
322 .endif # !empty(DPORTS_PACKAGES)
325 if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
326 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
327 vnconfig -u `cat ${ISODIR}/vn.which`; fi
328 newfs_msdos -C 400k -F 12 -L EFI -m 0xf8 ${ISOROOT}/boot/efiboot.img
329 vnconfig -l | grep "not in use" | head -n 1 | \
330 cut -f 1 -d: > ${ISODIR}/vn.which
331 vnconfig -e `cat ${ISODIR}/vn.which` ${ISOROOT}/boot/efiboot.img
332 mount_msdos /dev/`cat ${ISODIR}/vn.which` ${IMGMNT}
333 mkdir -p ${IMGMNT}/EFI/BOOT
334 cp ${ISOROOT}/boot/loader.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
336 ( cd ${ISOROOT}; mkisofs -R -J -o ${ISOFILE} \
337 -b boot/cdboot -no-emul-boot \
338 -eltorito-alt-boot -eltorito-platform efi \
339 -eltorito-boot boot/efiboot.img -no-emul-boot \
340 -V ${LABEL:C/(^.{32}).*/\1/} . ) # cut label to <= 32 characters
341 rm -f ${ISOROOT}/boot/efiboot.img
344 if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
345 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
346 vnconfig -u `cat ${ISODIR}/vn.which`; fi
348 @echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
350 sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
352 @echo "STEP: Determine required image size in 1GB steps"
353 @echo " Leave ~600MB of unused space"
354 sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`; \
355 sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
357 sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`; \
359 truncate -s $${sz}M ${IMGFILE};
361 @echo "STEP: determine free vn device"
362 vnconfig -l | grep "not in use" | head -n 1 | \
363 cut -f 1 -d: > ${ISODIR}/vn.which
364 vnconfig -e `cat ${ISODIR}/vn.which` ${IMGFILE}
365 @echo "STEP: set up legacy MBR"
366 fdisk -b ${ISOROOT}/boot/mbr -IB `cat ${ISODIR}/vn.which`
367 fdisk -s `cat ${ISODIR}/vn.which` >${ISODIR}/fdisk.dat
368 awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
369 ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
370 echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
371 awk '($$1=="1:"){printf("p 2 108 258048 %lu\n", $$3 - 258528);}' \
372 ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
373 echo "a 2" >>${ISODIR}/fdisk.conf
374 fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
375 rm ${ISODIR}/fdisk.conf ${ISODIR}/fdisk.dat
376 newfs_msdos -F 32 -c 2 -L EFI -m 0xf8 `cat ${ISODIR}/vn.which`s1
377 mount_msdos /dev/`cat ${ISODIR}/vn.which`s1 ${IMGMNT}
378 mkdir -p ${IMGMNT}/EFI/BOOT
379 cp ${ISOROOT}/boot/boot1.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
381 @echo "STEP: write standard disklabel"
382 disklabel -w -r `cat ${ISODIR}/vn.which`s2 auto
383 @echo "STEP: read disklabel back"
384 disklabel -r `cat ${ISODIR}/vn.which`s2 > ${IMGFILE}.label
385 @echo "STEP: set disklabel name"
386 echo "label: ${LABEL}" >> ${IMGFILE}.label
387 @echo "STEP: add slice parition"
388 echo "a: * * 4.2BSD" >> ${IMGFILE}.label;
389 @echo "STEP: write modified disklabel back"
390 disklabel -R -r `cat ${ISODIR}/vn.which`s2 ${IMGFILE}.label
392 disklabel -B -b ${ISOROOT}/boot/boot1_64 -s ${ISOROOT}/boot/boot2_64 \
393 `cat ${ISODIR}/vn.which`s2
394 newfs /dev/`cat ${ISODIR}/vn.which`s2a
395 mount /dev/`cat ${ISODIR}/vn.which`s2a ${IMGMNT}
396 cpdup ${ISOROOT} ${IMGMNT}
397 @echo "STEP: fixup ${IMGMNT}/etc/fstab"
398 echo "/dev/part-by-label/${LABEL}.a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
399 echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
400 echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
401 echo "dummy /var/run tmpfs rw,-C 0 0" >> ${IMGMNT}/etc/fstab
402 echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
403 echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
404 @echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
405 -fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
406 echo 'vfs.root.mountfrom="ufs:part-by-label/${LABEL}.a"' >> ${IMGMNT}/boot/loader.conf.new
407 mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
408 @echo "STEP: cleanup"
413 vnconfig -u `cat ${ISODIR}/vn.which`
414 rm -f ${ISODIR}/vn.which
416 @echo "STEP: done, image files are in ${ISODIR}"
421 -umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
422 -umount ${ISOROOT}/usr/dports > /dev/null 2>&1
423 -umount ${ISOROOT}/dev > /dev/null 2>&1
424 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
425 vnconfig -u `cat ${ISODIR}/vn.which`; fi
426 if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
428 rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
431 rm -rf ${ISODIR}/packages
432 rm -rf ${ISODIR}/distfiles
437 @echo " release - full build from scratch"
438 @echo " quick - attempt to do an incremental rebuild"
439 @echo " realquick - attempt to restart after world & kernel"
440 @echo " restartpkgs - attempt to restart at the pkg building stage"
442 @echo "Optional targets:"
443 @echo " nopkgs - do not install any packages"
444 @echo " binpkgs - use binary packages with pkg(8)"
445 @echo " gui - do a GUI release"
448 @echo " DPORTS_EXTRA_PACKAGES: add additional packages"
449 @echo " GITURL_SRC: override the Git URL to source repository"
450 @echo " GITURL_DPORTS: override the Git URL to dports repository"
451 @echo " IMGSIZE: override the size of .img (in 512-byte sectors)"
452 @echo " NREL_MAKE_JOBS: override the default value (sysctl hw.ncpu)"
453 @echo " PKG_<port>: specify the package name for port <port>"
454 @echo " WITHOUT_SRCS: do not package source code if set"
457 .PHONY: release quickrel realquickrel
458 .PHONY: quick realquick
459 .PHONY: check buildworld1 buildworld2
460 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
461 .PHONY: clean realclean help all srcs pkgs