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