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 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 security/wpa_supplicant \
55 ${DPORTS_EXTRA_PACKAGES}
57 # dports options to use when building packages
59 DPORTS_OPTIONS+= -DBATCH
60 DPORTS_OPTIONS+= dns_bind-tools_UNSET=PYTHON
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}
71 ISOFILE?= ${ISODIR}/dfly-gui.iso
72 IMGFILE?= ${ISODIR}/dfly-gui.img
75 # NOTE: order important, do not sort package list
77 DPORTS_PACKAGES+= x11/xorg \
94 x11-fonts/terminus-font \
100 ROOTSKELS+= ${.CURDIR}/gui
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>'.
107 .for PORT in ${DPORTS_PACKAGES}
108 .if defined(PKG_${PORT})
109 PACKAGES+= ${PKG_${PORT}}
115 #########################################################################
117 #########################################################################
119 release: check clean buildworld1 buildkernel1 \
120 buildiso customizeiso pkgs srcs mkiso mkimg
122 quickrel: check clean buildworld2 buildkernel2 \
123 buildiso customizeiso pkgs srcs mkiso mkimg
125 realquickrel: check clean \
126 buildiso customizeiso pkgs srcs mkiso mkimg
128 restartpkgs: check pkgs srcs mkiso mkimg
132 realquick: realquickrel
134 #########################################################################
135 # CORE SUPPORT TARGETS #
136 #########################################################################
139 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
141 @echo "Your machine does not have cdrtools installed. You can install it with:"
142 @echo " pkg install cdrtools"
144 @if [ ! -d ${DPORTS_PATH} ]; then \
145 echo "${DPORTS_PATH} does not exist."; \
147 echo "Please set DPORTS_PATH to the dports tree that shall be used for"; \
148 echo "package building. The default is /usr/dports. See the Makefile in"; \
149 echo "/usr if you are unfamiliar with dports."; \
152 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
155 @echo "Using ${DPORTS_PATH} as the dports tree."
157 buildworld1 buildworld2:
159 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
160 make -j ${MAKE_JOBS} -DWANT_INSTALLER \
161 ${.TARGET:C/build(.*)2/quick\1/:C/1//} )
163 buildkernel1 buildkernel2:
165 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
166 make -j ${MAKE_JOBS} \
167 ${.TARGET:C/build(.*)2/quick\1/:C/1//} )
169 # Unconditionally clean out ${ISOROOT} so a previous img build
170 # does not blow up a future quick iso build
173 -chflags -R noschg ${ISOROOT}
177 make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
178 # Do not mess with any /usr/obj directories not related to
179 # buildworld, buildkernel, or nrelease.
180 ( cd ${SRCDIR}/etc && \
181 tmpdir=`mktemp -d -t nrelease` && \
182 MAKEOBJDIRPREFIX=$${tmpdir} \
183 make -m ${SRCDIR}/share/mk \
184 DESTDIR=${ISOROOT} distribution && \
186 cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
187 ( cd ${SRCDIR}; make DESTDIR=${ISOROOT} reinstallkernel )
188 rm -rf ${ISOROOT}/boot/kernel.old
189 ln -sf kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
190 mtree ${MTREE_FSCHG} -deU -f ${SRCDIR}/etc/mtree/BSD.var.dist \
192 dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
193 ${CHROOT_CMD} "rcrestart ldconfig"
195 # The GUI build includes the full system source (~500 MB) and the full
196 # dports tree (~250 MB). The nominal release build only includes the
197 # kernel source (~30 MB).
200 rm -rf ${ISOROOT}/usr/dports
201 rm -f ${ISOROOT}/usr/src-sys.tar.bz2
202 .if !defined(WITHOUT_SRCS)
204 ( cd ${ISOROOT}/usr && \
205 make dports-create-shallow GITURL_DPORTS=${GITURL_DPORTS} )
206 ( cd ${ISOROOT}/usr && \
207 make src-create-shallow GITURL_SRC=${GITURL_SRC} )
210 tar --exclude .git -s '/^\./src/' -cf - \
211 ./Makefile ./Makefile.inc1 ./sys | \
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))
227 pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
228 .for UPGRADE_ITEM in Makefile \
229 etc.${MACHINE_ARCH} \
232 periodic/daily/Makefile \
233 periodic/security/Makefile \
234 periodic/weekly/Makefile \
235 periodic/monthly/Makefile
236 cp -R ${SRCDIR}/etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
239 # Install packages by using pkg(8) or building from dports.
242 .if !empty(DPORTS_PACKAGES)
243 cp /etc/resolv.conf ${ISOROOT}/etc
244 -@umount ${ISOROOT}/dev
245 mount_null /dev ${ISOROOT}/dev
248 ${CHROOT_CMD} "cd /usr && make pkg-bootstrap-force"
249 ${CHROOT_CMD} "pkg update"
250 .for PKG in ${PACKAGES}
251 @${CHROOT_CMD} "pkg search --exact --search name ${PKG}" || \
252 ${CHROOT_CMD} "pkg search --exact --search origin ${PKG}" || \
254 echo "ERROR: Cannot find the package for port '${PKG}'!"; \
255 echo "-----> Use 'pkg_${PKG}=<pkg-name>' to specify the package name."; \
259 ${CHROOT_CMD} "pkg install --yes ${PACKAGES}"
261 .else # !make(binpkgs)
262 -@umount ${ISOROOT}/usr/distfiles
263 -@umount ${ISOROOT}/usr/dports
264 rm -rf ${ISOROOT}/usr/obj/dports
266 mkdir -p ${ISOROOT}/usr/dports
267 mkdir -p ${ISOROOT}/usr/distfiles
269 # Mount /usr/dports read-only for safety, else a failed umount
270 # and our rm -rf will do bad things.
271 mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
273 # Make sure /usr/distfiles is writable
274 cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
275 || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
277 .for PKG in ${DPORTS_PACKAGES}
278 .if make(restartpkgs)
279 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} deinstall"
281 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} install"
283 .for PKG in ${DPORTS_PACKAGES}
284 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
287 ${CHROOT_CMD} "yes | pkg autoremove"
289 -umount ${ISOROOT}/usr/distfiles
290 umount ${ISOROOT}/usr/dports
292 rm -rf ${ISOROOT}/usr/dports
293 rm -rf ${ISOROOT}/usr/distfiles
294 rm -rf ${ISOROOT}/usr/obj/dports
295 .endif # make(binpkgs)
297 # Update the locate(8) and whatis(1) databases, allow ISODIR
298 # to be on tmpfs (fails to create locate database then)
300 -${CHROOT_CMD} /etc/periodic/weekly/310.locate
301 -${CHROOT_CMD} /etc/periodic/weekly/320.whatis
303 umount ${ISOROOT}/dev
304 rm -f ${ISOROOT}/etc/resolv.conf
306 # Recopy files that dports may have updated in /etc into /etc.hdd
308 cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
309 cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
313 if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
314 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
315 vnconfig -u `cat ${ISODIR}/vn.which`; fi
316 newfs_msdos -C 400k -F 12 -L EFI -m 0xf8 ${ISOROOT}/boot/efiboot.img
317 vnconfig -l | grep "not in use" | head -n 1 | \
318 cut -f 1 -d: > ${ISODIR}/vn.which
319 vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${ISOROOT}/boot/efiboot.img
320 mount_msdos /dev/`cat ${ISODIR}/vn.which` ${IMGMNT}
321 mkdir -p ${IMGMNT}/EFI/BOOT
322 cp ${ISOROOT}/boot/loader.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
324 ( cd ${ISOROOT}; mkisofs -R -J -o ${ISOFILE} \
325 -b boot/cdboot -no-emul-boot \
326 -eltorito-alt-boot -eltorito-platform efi \
327 -eltorito-boot boot/efiboot.img -no-emul-boot \
328 -V ${LABEL:C/(^.{32}).*/\1/} . ) # cut label to <= 32 characters
329 rm -f ${ISOROOT}/boot/efiboot.img
332 if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
333 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
334 vnconfig -u `cat ${ISODIR}/vn.which`; fi
336 @echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
338 sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
340 @echo "STEP: Determine required image size in 1GB steps"
341 @echo " Leave ~600MB of unused space"
342 sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`; \
343 sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
345 sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`; \
347 truncate -s $${sz}M ${IMGFILE};
349 @echo "STEP: determine free vn device"
350 vnconfig -l | grep "not in use" | head -n 1 | \
351 cut -f 1 -d: > ${ISODIR}/vn.which
352 vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
353 @echo "STEP: set up legacy MBR"
354 fdisk -b ${ISOROOT}/boot/mbr -IB `cat ${ISODIR}/vn.which`
355 fdisk -s `cat ${ISODIR}/vn.which` >${ISODIR}/fdisk.dat
356 awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
357 ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
358 echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
359 awk '($$1=="1:"){printf("p 2 165 258048 %lu\n", $$3 - 258528);}' \
360 ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
361 echo "a 2" >>${ISODIR}/fdisk.conf
362 fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
363 rm ${ISODIR}/fdisk.conf ${ISODIR}/fdisk.dat
364 newfs_msdos -F 32 -c 2 -L EFI -m 0xf8 `cat ${ISODIR}/vn.which`s1
365 mount_msdos /dev/`cat ${ISODIR}/vn.which`s1 ${IMGMNT}
366 mkdir -p ${IMGMNT}/EFI/BOOT
367 cp ${ISOROOT}/boot/boot1.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
369 @echo "STEP: write standard disklabel"
370 disklabel -w -r `cat ${ISODIR}/vn.which`s2 auto
371 @echo "STEP: read disklabel back"
372 disklabel -r `cat ${ISODIR}/vn.which`s2 > ${IMGFILE}.label
373 @echo "STEP: set disklabel name"
374 echo "label: ${LABEL}" >> ${IMGFILE}.label
375 @echo "STEP: add slice parition"
376 echo "a: * * 4.2BSD" >> ${IMGFILE}.label;
377 @echo "STEP: write modified disklabel back"
378 disklabel -R -r `cat ${ISODIR}/vn.which`s2 ${IMGFILE}.label
380 disklabel -B -b ${ISOROOT}/boot/boot1_64 -s ${ISOROOT}/boot/boot2_64 \
381 `cat ${ISODIR}/vn.which`s2
382 newfs /dev/`cat ${ISODIR}/vn.which`s2a
383 mount /dev/`cat ${ISODIR}/vn.which`s2a ${IMGMNT}
384 cpdup ${ISOROOT} ${IMGMNT}
385 @echo "STEP: fixup ${IMGMNT}/etc/fstab"
386 echo "/dev/part-by-label/${LABEL}.a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
387 echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
388 echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
389 echo "dummy /var/run tmpfs rw,-C 0 0" >> ${IMGMNT}/etc/fstab
390 echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
391 echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
392 @echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
393 -fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
394 echo 'vfs.root.mountfrom="ufs:part-by-label/${LABEL}.a"' >> ${IMGMNT}/boot/loader.conf.new
395 mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
396 @echo "STEP: cleanup"
401 vnconfig -u `cat ${ISODIR}/vn.which`
402 rm -f ${ISODIR}/vn.which
404 @echo "STEP: done, image files are in ${ISODIR}"
409 -umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
410 -umount ${ISOROOT}/usr/dports > /dev/null 2>&1
411 -umount ${ISOROOT}/dev > /dev/null 2>&1
412 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
413 vnconfig -u `cat ${ISODIR}/vn.which`; fi
414 if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
416 rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
419 rm -rf ${ISODIR}/packages
420 rm -rf ${ISODIR}/distfiles
424 @echo " release - full build from scratch"
425 @echo " quick - attempt to do an incremental rebuild"
426 @echo " realquick - attempt to restart after world & kernel"
427 @echo " restartpkgs - attempt to restart at the pkg building stage"
429 @echo "Optional targets:"
430 @echo " nopkgs - do not install any packages"
431 @echo " binpkgs - use binary packages with pkg(8)"
432 @echo " gui - do a GUI release"
435 @echo " DPORTS_EXTRA_PACKAGES: add additional packages"
436 @echo " GITURL_SRC: override the Git URL to source repository"
437 @echo " GITURL_DPORTS: override the Git URL to dports repository"
438 @echo " IMGSIZE: override the size of .img (in 512-byte sectors)"
439 @echo " MAKE_JOBS: override the default value (sysctl hw.ncpu)"
440 @echo " PKG_<port>: specify the package name for port <port>"
441 @echo " WITHOUT_SRCS: do not package source code if set"
444 .PHONY: release quickrel realquickrel
445 .PHONY: quick realquick
446 .PHONY: check buildworld1 buildworld2
447 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
448 .PHONY: clean realclean help all srcs pkgs