1 #########################################################################
3 #########################################################################
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.
9 # img is now the default (produces both the .iso and .img)
11 gui installer img nopkgs:
13 #########################################################################
15 #########################################################################
17 DPORTS_PATH?= /usr/dports
18 ISODIR?= /usr/obj/release
19 ISOROOT?= ${ISODIR}/root
20 OBJSYS= ${.OBJDIR}/../sys
21 GITURL_SRC?= git://git.dragonflybsd.org/dragonfly.git
22 GITURL_DPORTS?= git://mirror-master.dragonflybsd.org/dports.git
23 MAKE_JOBS?= $$(sysctl -n hw.ncpu)
28 # XXX makeshift fix to build the right kernel for the (target) architecture
29 # We should configure this in the platform files somehow
30 .if ${MACHINE_ARCH} == "x86_64"
31 KERNCONF?= X86_64_GENERIC
34 GITREV!= sh ${.CURDIR}/../tools/gitrev.sh
36 # The label/name of the disklabel64(5) slice in the ".img" file. This is
37 # used to identify the USB device with DragonFly installation image, avoiding
38 # hardcoding the USB device name (e.g., "da8").
40 # This label is also used as the volume ID of the ".iso" file.
42 LABEL?= DragonFly_${GITREV}
44 CHROOT_CMD?= /usr/sbin/chroot ${ISOROOT} sh -c
46 ISOFILE?= ${ISODIR}/dfly.iso
47 IMGFILE?= ${ISODIR}/dfly.img
48 IMGMNT?= ${ISODIR}/mnt
50 # NOTE: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
51 # the additional '/nrelease' manually, as a safety measure.
56 # User may specify extra packages in addition to the defaults
58 DPORTS_EXTRA_PACKAGES?=
60 # dports packages to be built and installed on the release ISO
62 DPORTS_PACKAGES?= security/ca_root_nss \
65 net/isc-dhcp44-server \
67 security/wpa_supplicant \
68 ${DPORTS_EXTRA_PACKAGES}
70 # dports options to use when building packages
72 DPORTS_OPTIONS+= -DBATCH
73 DPORTS_OPTIONS+= dns_bind-tools_UNSET=PYTHON
76 # Specify which root skeletons are required, and let the user include
77 # their own. They are copied into ISODIR during the `customizeiso'
78 # target; each overwrites the last.
80 REQ_ROOTSKELS= ${.CURDIR}/root
81 ROOTSKELS?= ${REQ_ROOTSKELS}
84 ISOFILE?= ${ISODIR}/dfly-gui.iso
85 IMGFILE?= ${ISODIR}/dfly-gui.img
88 # NOTE: order important, do not sort package list
90 DPORTS_PACKAGES+= x11/xorg \
107 x11-fonts/terminus-font \
113 ROOTSKELS+= ${.CURDIR}/gui
116 #########################################################################
118 #########################################################################
120 release: check clean buildworld1 buildkernel1 \
121 buildiso srcs customizeiso mkiso mkimg
123 quickrel: check clean buildworld2 buildkernel2 \
124 buildiso srcs customizeiso mkiso mkimg
126 realquickrel: check clean \
127 buildiso srcs customizeiso mkiso mkimg
129 restartpkgs: check customizeiso mkiso mkimg
133 realquick: realquickrel
135 #########################################################################
136 # CORE SUPPORT TARGETS #
137 #########################################################################
140 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
142 @echo "Your machine does not have cdrtools installed. You can install it with:"
143 @echo " pkg install cdrtools"
145 @if [ ! -d ${DPORTS_PATH} ]; then \
146 echo "${DPORTS_PATH} does not exist."; \
148 echo "Please set DPORTS_PATH to the dports tree that shall be used for"; \
149 echo "package building. The default is /usr/dports. See the Makefile in"; \
150 echo "/usr if you are unfamiliar with dports."; \
153 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
156 @echo "Using ${DPORTS_PATH} as the dports tree."
158 buildworld1 buildworld2:
160 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
161 make -j ${MAKE_JOBS} -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
163 buildkernel1 buildkernel2:
165 for kernconf in ${KERNCONF}; do \
166 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
167 make -j ${MAKE_JOBS} ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
168 KERNCONF=$${kernconf}; \
171 # Note that we do not want to mess with any /usr/obj directories not related
172 # to buildworld, buildkernel, or nrelease, so we must supply the proper
173 # MAKEOBJDIRPREFIX for targets that are not run through the buildworld and
174 # buildkernel mechanism.
176 # Unconditionally clean out ${ISOROOT} so a previous img build
177 # does not blow up a future quick iso build
179 # We install with INSTALLSTRIPPEDMODULES to make things fit into the ISO.
180 # We leave the kernel's debug variables intact.
183 -chflags -R noschg ${ISOROOT}
186 if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
187 ( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
188 ( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
189 make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
190 cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
191 ( cd ${.CURDIR}/..; \
192 for kernconf in ${KERNCONF}; do \
193 make DESTDIR=${ISOROOT} reinstallkernel KERNCONF=$${kernconf}; \
195 rm -rf ${ISOROOT}/boot/kernel.old
196 ln -sf kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
197 mtree ${MTREE_FSCHG} -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist \
199 dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
201 # The GUI build includes the ports tree (~1G+) while the nominal release
204 # The GUI build includes full sources while the nominal release build
205 # only includes kernel sources (~27MB).
208 .if !defined(WITHOUT_SRCS)
210 rm -f ${ISOROOT}/usr/src-sys.tgz
211 rm -f ${ISOROOT}/usr/src-sys.tar.bz2
212 .if !empty(DPORTS_PACKAGES)
213 cd ${ISOROOT}/usr && make dports-create GITURL_DPORTS=${GITURL_DPORTS}
214 # NOTE: Adding the git gc --aggressive helps by significantly
215 # reducing the disk space required.
217 cd ${ISOROOT}/usr/dports && git gc --aggressive
219 cd ${ISOROOT}/usr && make src-create GITURL_SRC=${GITURL_SRC}
220 # XXX: git gc --aggressive
222 rm -f ${ISOROOT}/usr/src-sys.tgz
223 rm -f ${ISOROOT}/usr/src-sys.tar.bz2
224 cd ${.CURDIR}/.. && tar --exclude .git -s '/^\./src/' \
225 -cf - ./Makefile ./Makefile.inc1 ./sys | \
226 bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2
230 # Customize the ISO by copying rootskels in reverse priority order,
231 # building packages, and doing other post-install tasks.
234 # Copy the rootskels. Allow sources to be owned by someone other
235 # than root (as is common when checked out via git).
237 .for ROOTSKEL in ${ROOTSKELS}
238 cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
239 @test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
240 @test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
242 pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
243 .for UPGRADE_ITEM in Makefile \
244 etc.${MACHINE_ARCH} \
247 periodic/daily/Makefile \
248 periodic/security/Makefile \
249 periodic/weekly/Makefile \
250 periodic/monthly/Makefile
251 cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
254 # Setup some things & mount dports tree. Use defensive umounts and
255 # rm -rf's to allow restarts. Allow /usr/dports to be read-only.
257 -@umount ${ISOROOT}/dev
258 mount_null /dev ${ISOROOT}/dev
259 .if !empty(DPORTS_PACKAGES)
260 cp /etc/resolv.conf ${ISOROOT}/etc
261 ${CHROOT_CMD} "ldconfig -elf /lib /usr/lib /usr/lib/gcc*"
262 -@umount ${ISOROOT}/usr/distfiles
263 -@umount ${ISOROOT}/usr/dports
264 rm -rf ${ISOROOT}/usr/obj/dports
266 # Mount /usr/dports, make sure /usr/distfiles is writable.
267 # Make /usr/dports read-only for safety, else a failed umount and
268 # our rm -rf will do bad things.
270 mkdir -p ${ISOROOT}/usr/dports
271 mkdir -p ${ISOROOT}/usr/distfiles
272 mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
273 cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
274 || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
276 # Build and install packages, skip packages already installed
278 .for PKG in ${DPORTS_PACKAGES}
279 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} install"
281 .for PKG in ${DPORTS_PACKAGES}
282 ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
285 # Remove packages which nothing depends on, add a whatis database
286 # for dports manual pages, create an initial locate database and
289 ${CHROOT_CMD} "yes | pkg autoremove"
290 ${CHROOT_CMD} "makewhatis /usr/local/man"
291 -umount ${ISOROOT}/usr/distfiles
292 umount ${ISOROOT}/usr/dports
293 rm -rf ${ISOROOT}/usr/dports
294 rm -rf ${ISOROOT}/usr/obj/dports
295 rm -rf ${ISOROOT}/usr/distfiles
296 rm -f ${ISOROOT}/etc/resolv.conf
299 # Finally, update the locate(8) database, allow ISODIR
300 # to be on tmpfs (fails to create locate database then)
302 -${CHROOT_CMD} /etc/periodic/weekly/310.locate
303 umount ${ISOROOT}/dev
305 # Recopy files that dports may have updated in /etc into /etc.hdd
307 cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
308 cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
311 if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
312 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
313 vnconfig -u `cat ${ISODIR}/vn.which`; fi
314 newfs_msdos -C 400k -F 12 -L EFI -m 0xf8 ${ISOROOT}/boot/efiboot.img
315 vnconfig -l | grep "not in use" | head -n 1 | \
316 cut -f 1 -d: > ${ISODIR}/vn.which
317 vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${ISOROOT}/boot/efiboot.img
318 mount_msdos /dev/`cat ${ISODIR}/vn.which` ${IMGMNT}
319 mkdir -p ${IMGMNT}/EFI/BOOT
320 cp ${ISOROOT}/boot/loader.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
322 ( cd ${ISOROOT}; mkisofs -R -J -o ${ISOFILE} \
323 -b boot/cdboot -no-emul-boot \
324 -eltorito-alt-boot -eltorito-platform efi \
325 -eltorito-boot boot/efiboot.img -no-emul-boot \
326 -V ${LABEL:C/(^.{32}).*/\1/} . ) # cut label to <= 32 characters
327 rm -f ${ISOROOT}/boot/efiboot.img
330 if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
331 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
332 vnconfig -u `cat ${ISODIR}/vn.which`; fi
334 @echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
336 sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
338 @echo "STEP: Determine required image size in 1GB steps"
339 @echo " Leave ~600MB of unused space"
340 sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`; \
341 sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
343 sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`; \
345 truncate -s $${sz}M ${IMGFILE};
347 @echo "STEP: determine free vn device"
348 vnconfig -l | grep "not in use" | head -n 1 | \
349 cut -f 1 -d: > ${ISODIR}/vn.which
350 vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
351 @echo "STEP: set up legacy MBR"
352 fdisk -b ${ISOROOT}/boot/mbr -IB `cat ${ISODIR}/vn.which`
353 fdisk -s `cat ${ISODIR}/vn.which` >${ISODIR}/fdisk.dat
354 awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
355 ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
356 echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
357 awk '($$1=="1:"){printf("p 2 165 258048 %lu\n", $$3 - 258528);}' \
358 ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
359 echo "a 2" >>${ISODIR}/fdisk.conf
360 fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
361 rm ${ISODIR}/fdisk.conf ${ISODIR}/fdisk.dat
362 newfs_msdos -F 32 -c 2 -L EFI -m 0xf8 `cat ${ISODIR}/vn.which`s1
363 mount_msdos /dev/`cat ${ISODIR}/vn.which`s1 ${IMGMNT}
364 mkdir -p ${IMGMNT}/EFI/BOOT
365 cp ${ISOROOT}/boot/boot1.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
367 @echo "STEP: write standard disklabel"
368 disklabel -w -r `cat ${ISODIR}/vn.which`s2 auto
369 @echo "STEP: read disklabel back"
370 disklabel -r `cat ${ISODIR}/vn.which`s2 > ${IMGFILE}.label
371 @echo "STEP: set disklabel name"
372 echo "label: ${LABEL}" >> ${IMGFILE}.label
373 @echo "STEP: add slice parition"
374 echo "a: * * 4.2BSD" >> ${IMGFILE}.label;
375 @echo "STEP: write modified disklabel back"
376 disklabel -R -r `cat ${ISODIR}/vn.which`s2 ${IMGFILE}.label
378 disklabel -B -b ${ISOROOT}/boot/boot1_64 -s ${ISOROOT}/boot/boot2_64 \
379 `cat ${ISODIR}/vn.which`s2
380 newfs /dev/`cat ${ISODIR}/vn.which`s2a
381 mount /dev/`cat ${ISODIR}/vn.which`s2a ${IMGMNT}
382 cpdup ${ISOROOT} ${IMGMNT}
383 @echo "STEP: fixup ${IMGMNT}/etc/fstab"
384 echo "/dev/part-by-label/${LABEL}.a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
385 echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
386 echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
387 echo "dummy /var/run tmpfs rw,-C 0 0" >> ${IMGMNT}/etc/fstab
388 echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
389 echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
390 @echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
391 -fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
392 echo 'vfs.root.mountfrom="ufs:part-by-label/${LABEL}.a"' >> ${IMGMNT}/boot/loader.conf.new
393 mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
394 @echo "STEP: cleanup"
399 vnconfig -u `cat ${ISODIR}/vn.which`
400 rm -f ${ISODIR}/vn.which
402 @echo "STEP: done, image files are in ${ISODIR}"
407 -umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
408 -umount ${ISOROOT}/usr/dports > /dev/null 2>&1
409 -umount ${ISOROOT}/dev > /dev/null 2>&1
410 -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT}; \
411 vnconfig -u `cat ${ISODIR}/vn.which`; fi
412 if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
414 rm -rf ${NRLOBJDIR}/nrelease
415 rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
418 rm -rf ${OBJSYS}/${KERNCONF}
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"
428 @echo "NOTE: Add the optional 'gui' target to do a GUI release"
431 @echo " DPORTS_EXTRA_PACKAGES: add additional packages"
432 @echo " GITURL_SRC: override the Git URL to source repository"
433 @echo " GITURL_DPORTS: override the Git URL to dports repository"
434 @echo " IMGSIZE: override the size of .img (in 512-byte sectors)"
435 @echo " MAKE_JOBS: override the default value (sysctl hw.ncpu)"
437 .PHONY: release quickrel realquickrel
439 .PHONY: quick realquick
440 .PHONY: check buildworld1 buildworld2
441 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
442 .PHONY: clean realclean help all srcs
444 .include <bsd.prog.mk>