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