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