Merge branch 'vendor/MDOCML'
[dragonfly.git] / nrelease / Makefile
1 #########################################################################
2 #                               ENHANCEMENTS                            #
3 #########################################################################
4
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.
8 #
9 # img is now the default (produces both the .iso and .img)
10 #
11 gui installer img nopkgs:
12
13 #########################################################################
14 #                               SETUP                                   #
15 #########################################################################
16
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)
24
25 # XXX makeshift fix to build the right kernel for the (target) architecture
26 # We should configure this in the platform files somehow
27 .if ${MACHINE_ARCH} == "x86_64"
28 KERNCONF?=      X86_64_GENERIC
29 .endif
30
31 GITREV!=        sh ${.CURDIR}/../tools/gitrev.sh
32
33 # The label/name of the disklabel64(5) slice in the ".img" file.  This is
34 # used to identify the USB device with DragonFly installation image, avoiding
35 # hardcoding the USB device name (e.g., "da8").
36 #
37 # This label is also used as the volume ID of the ".iso" file.
38 #
39 LABEL?=         DragonFly_${GITREV}
40
41 CHROOT_CMD?=    /usr/sbin/chroot ${ISOROOT} sh -c
42
43 ISOFILE?=       ${ISODIR}/dfly.iso
44 IMGFILE?=       ${ISODIR}/dfly.img
45 IMGMNT?=        ${ISODIR}/mnt
46
47 # NOTE: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
48 # the additional '/nrelease' manually, as a safety measure.
49 #
50 NRLOBJDIR?=     /usr/obj
51
52 .if !make(nopkgs)
53 # User may specify extra packages in addition to the defaults
54 #
55 DPORTS_EXTRA_PACKAGES?=
56
57 # dports packages to be built and installed on the release ISO
58 #
59 DPORTS_PACKAGES?=       security/ca_root_nss \
60                         devel/git-lite \
61                         dns/bind-tools \
62                         net/isc-dhcp44-server \
63                         sysutils/cdrtools \
64                         security/wpa_supplicant \
65                         ${DPORTS_EXTRA_PACKAGES}
66
67 # dports options to use when building packages
68 #
69 DPORTS_OPTIONS+=        -DBATCH
70 DPORTS_OPTIONS+=        dns_bind-tools_UNSET=PYTHON
71 .endif
72
73 # Specify which root skeletons are required, and let the user include
74 # their own.  They are copied into ISODIR during the `customizeiso'
75 # target; each overwrites the last.
76 #
77 REQ_ROOTSKELS=  ${.CURDIR}/root
78 ROOTSKELS?=     ${REQ_ROOTSKELS}
79
80 .if make(gui)
81 ISOFILE?=               ${ISODIR}/dfly-gui.iso
82 IMGFILE?=               ${ISODIR}/dfly-gui.img
83
84 .if !make(nopkgs)
85 # NOTE: order important, do not sort package list
86 #
87 DPORTS_PACKAGES+=       x11/xorg \
88                         x11-wm/fluxbox \
89                         x11-wm/fvwm \
90                         www/firefox \
91                         graphics/xpdf \
92                         shells/zsh \
93                         editors/emacs \
94                         editors/vim \
95                         irc/irssi \
96                         lang/perl5 \
97                         editors/nano \
98                         shells/bash \
99                         devel/ctags \
100                         archivers/zip \
101                         security/sudo \
102                         www/links \
103                         ftp/wget \
104                         x11-fonts/terminus-font \
105                         net/rsync \
106                         x11-clocks/asclock \
107                         sysutils/screen
108 .endif
109
110 ROOTSKELS+=             ${.CURDIR}/gui
111 .endif
112
113 #########################################################################
114 #                               BASE ISO TARGETS                        #
115 #########################################################################
116
117 release:        check clean buildworld1 buildkernel1 \
118                 buildiso srcs customizeiso mkiso mkimg
119
120 quickrel:       check clean buildworld2 buildkernel2 \
121                 buildiso srcs customizeiso mkiso mkimg
122
123 realquickrel:   check clean \
124                 buildiso srcs customizeiso mkiso mkimg
125
126 restartpkgs:    check customizeiso mkiso mkimg
127
128 quick:          quickrel
129
130 realquick:      realquickrel
131
132 #########################################################################
133 #                       CORE SUPPORT TARGETS                            #
134 #########################################################################
135
136 check:
137 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
138         @echo
139         @echo "Your machine does not have cdrtools installed.  You can install it with:"
140         @echo "    pkg install cdrtools"
141 .endif
142         @if [ ! -d ${DPORTS_PATH} ]; then \
143                 echo "${DPORTS_PATH} does not exist."; \
144                 echo ""; \
145                 echo "Please set DPORTS_PATH to the dports tree that shall be used for"; \
146                 echo "package building. The default is /usr/dports. See the Makefile in"; \
147                 echo "/usr if you are unfamiliar with dports."; \
148                 /usr/bin/false; \
149         fi
150 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
151         @/usr/bin/false
152 .endif
153         @echo "Using ${DPORTS_PATH} as the dports tree."
154
155 buildworld1 buildworld2:
156         cd ${.CURDIR}/..; \
157         ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
158                 make -j ${MAKE_JOBS} -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
159
160 buildkernel1 buildkernel2:
161         cd ${.CURDIR}/..; \
162         for kernconf in ${KERNCONF}; do \
163                 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
164                         make -j ${MAKE_JOBS} ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
165                         KERNCONF=$${kernconf}; \
166         done
167
168 # Note that we do not want to mess with any /usr/obj directories not related
169 # to buildworld, buildkernel, or nrelease, so we must supply the proper
170 # MAKEOBJDIRPREFIX for targets that are not run through the buildworld and
171 # buildkernel mechanism.
172 #
173 # Unconditionally clean out ${ISOROOT} so a previous img build
174 # does not blow up a future quick iso build
175 #
176 # We install with INSTALLSTRIPPEDMODULES to make things fit into the ISO.
177 # We leave the kernel's debug variables intact.
178 #
179 buildiso:
180         -chflags -R noschg ${ISOROOT}
181         rm -rf ${ISOROOT}
182         mkdir -p ${ISOROOT}
183         if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
184         ( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
185         ( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
186                 make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
187         cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
188         ( cd ${.CURDIR}/..; \
189                 for kernconf in ${KERNCONF}; do \
190                         make DESTDIR=${ISOROOT} reinstallkernel KERNCONF=$${kernconf}; \
191                 done )
192         rm -rf ${ISOROOT}/boot/kernel.old
193         ln -sf kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
194         mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist -p ${ISOROOT}/var
195         dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
196
197 # The GUI build includes the ports tree (~1G+) while the nominal release
198 # build does not.
199 #
200 # The GUI build includes full sources while the nominal release build
201 # only includes kernel sources (~27MB).
202 #
203 srcs:
204 .if !defined(WITHOUT_SRCS)
205 .if make(gui)
206         rm -f ${ISOROOT}/usr/src-sys.tgz
207         rm -f ${ISOROOT}/usr/src-sys.tar.bz2
208 .if !empty(DPORTS_PACKAGES)
209         cd ${ISOROOT}/usr && make dports-create GITURL_DPORTS=${GITURL_DPORTS}
210         # NOTE: Adding the git gc --aggressive helps by significantly
211         #       reducing the disk space required.
212         #
213         cd ${ISOROOT}/usr/dports && git gc --aggressive
214 .endif
215         cd ${ISOROOT}/usr && make src-create GITURL_SRC=${GITURL_SRC}
216         # XXX: git gc --aggressive
217 .else
218         rm -f ${ISOROOT}/usr/src-sys.tgz
219         rm -f ${ISOROOT}/usr/src-sys.tar.bz2
220         cd ${.CURDIR}/.. && tar --exclude .git -s '/^\./src/' \
221                 -cf - ./Makefile ./Makefile.inc1 \
222                 ./crypto/libressl/include ./sys | \
223                 bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2
224 .endif
225 .endif
226
227 # Customize the ISO by copying rootskels in reverse priority order,
228 # building packages, and doing other post-install tasks.
229 #
230 customizeiso:
231         # Copy the rootskels.  Allow sources to be owned by someone other
232         # than root (as is common when checked out via git).
233         #
234 .for ROOTSKEL in ${ROOTSKELS}
235         cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
236         @test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
237         @test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
238 .endfor
239         pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
240 .for UPGRADE_ITEM in Makefile                   \
241                      etc.${MACHINE_ARCH}        \
242                      rc.d/Makefile              \
243                      periodic/Makefile          \
244                      periodic/daily/Makefile    \
245                      periodic/security/Makefile \
246                      periodic/weekly/Makefile   \
247                      periodic/monthly/Makefile
248         cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
249 .endfor
250         #
251         # Setup some things & mount dports tree.  Use defensive umounts and
252         # rm -rf's to allow restarts.  Allow /usr/dports to be read-only.
253         #
254         -@umount ${ISOROOT}/dev
255         mount_null /dev ${ISOROOT}/dev
256 .if !empty(DPORTS_PACKAGES)
257         cp /etc/resolv.conf ${ISOROOT}/etc
258         ${CHROOT_CMD} "ldconfig -elf /lib /usr/lib /usr/lib/gcc*"
259         -@umount ${ISOROOT}/usr/distfiles
260         -@umount ${ISOROOT}/usr/dports
261         rm -rf ${ISOROOT}/usr/obj/dports
262         #
263         # Mount /usr/dports, make sure /usr/distfiles is writable.
264         # Make /usr/dports read-only for safety, else a failed umount and
265         # our rm -rf will do bad things.
266         #
267         mkdir -p ${ISOROOT}/usr/dports
268         mkdir -p ${ISOROOT}/usr/distfiles
269         mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
270         cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
271             || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
272         #
273         # Build and install packages, skip packages already installed
274         #
275 .for PKG in ${DPORTS_PACKAGES}
276         ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} install"
277 .endfor
278 .for PKG in ${DPORTS_PACKAGES}
279         ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
280 .endfor
281         #
282         # Remove packages which nothing depends on, add a whatis database
283         # for dports manual pages, create an initial locate database and
284         # clean up
285         #
286         ${CHROOT_CMD} "yes | pkg autoremove"
287         ${CHROOT_CMD} "makewhatis /usr/local/man"
288         -umount ${ISOROOT}/usr/distfiles
289         umount ${ISOROOT}/usr/dports
290         rm -rf ${ISOROOT}/usr/dports
291         rm -rf ${ISOROOT}/usr/obj/dports
292         rm -rf ${ISOROOT}/usr/distfiles
293         rm -f ${ISOROOT}/etc/resolv.conf
294 .endif
295         #
296         # Finally, update the locate(8) database, allow ISODIR
297         # to be on tmpfs (fails to create locate database then)
298         #
299         -${CHROOT_CMD} /etc/periodic/weekly/310.locate
300         umount ${ISOROOT}/dev
301         #
302         # Recopy files that dports may have updated in /etc into /etc.hdd
303         #
304         cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
305         cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
306
307 mkiso:
308         if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
309         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
310             vnconfig -u `cat ${ISODIR}/vn.which`; fi
311         newfs_msdos -C 400k -F 12 -L EFI -m 0xf8 ${ISOROOT}/boot/efiboot.img
312         vnconfig -l | grep "not in use" | head -n 1 |                   \
313             cut -f 1 -d: > ${ISODIR}/vn.which
314         vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${ISOROOT}/boot/efiboot.img
315         mount_msdos /dev/`cat ${ISODIR}/vn.which` ${IMGMNT}
316         mkdir -p ${IMGMNT}/EFI/BOOT
317         cp ${ISOROOT}/boot/loader.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
318         umount ${IMGMNT}
319         ( cd ${ISOROOT}; mkisofs -R -J -o ${ISOFILE} \
320             -b boot/cdboot -no-emul-boot \
321             -eltorito-alt-boot -eltorito-platform efi \
322             -eltorito-boot boot/efiboot.img -no-emul-boot \
323             -V ${LABEL:C/(^.{32}).*/\1/} . )  # cut label to <= 32 characters
324         rm -f ${ISOROOT}/boot/efiboot.img
325
326 mkimg:
327         if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
328         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
329             vnconfig -u `cat ${ISODIR}/vn.which`; fi
330 .ifdef IMGSIZE
331         @echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
332         rm -f ${IMGFILE}
333         sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
334 .else
335         @echo "STEP: Determine required image size in 1GB steps"
336         @echo "      Leave ~600MB of unused space"
337         sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;                  \
338             sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
339             cut -f1 -d.`;                                               \
340             sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`;         \
341             rm -f ${IMGFILE};                                           \
342             truncate -s $${sz}M ${IMGFILE};
343 .endif
344         @echo "STEP: determine free vn device"
345         vnconfig -l | grep "not in use" | head -n 1 |                   \
346             cut -f 1 -d: > ${ISODIR}/vn.which
347         vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
348         @echo "STEP: set up legacy MBR"
349         fdisk -b ${ISOROOT}/boot/mbr -IB `cat ${ISODIR}/vn.which`
350         fdisk -s `cat ${ISODIR}/vn.which` >${ISODIR}/fdisk.dat
351         awk '(NR==1){printf("g c%s h%s s%s\n", $$2, $$4, $$6);}' \
352             ${ISODIR}/fdisk.dat >${ISODIR}/fdisk.conf
353         echo "p 1 239 63 257985" >>${ISODIR}/fdisk.conf
354         awk '($$1=="1:"){printf("p 2 165 258048 %lu\n", $$3 - 258528);}' \
355             ${ISODIR}/fdisk.dat >>${ISODIR}/fdisk.conf
356         echo "a 2" >>${ISODIR}/fdisk.conf
357         fdisk -iv -f ${ISODIR}/fdisk.conf `cat ${ISODIR}/vn.which`
358         rm ${ISODIR}/fdisk.conf ${ISODIR}/fdisk.dat
359         newfs_msdos -F 32 -c 2 -L EFI -m 0xf8 `cat ${ISODIR}/vn.which`s1
360         mount_msdos /dev/`cat ${ISODIR}/vn.which`s1 ${IMGMNT}
361         mkdir -p ${IMGMNT}/EFI/BOOT
362         cp ${ISOROOT}/boot/boot1.efi ${IMGMNT}/EFI/BOOT/BOOTX64.EFI
363         umount ${IMGMNT}
364         @echo "STEP: write standard disklabel"
365         disklabel -w -r `cat ${ISODIR}/vn.which`s2 auto
366         @echo "STEP: read disklabel back"
367         disklabel -r `cat ${ISODIR}/vn.which`s2 > ${IMGFILE}.label
368         @echo "STEP: set disklabel name"
369         echo "label: ${LABEL}" >> ${IMGFILE}.label
370         @echo "STEP: add slice parition"
371         echo "a: * * 4.2BSD" >> ${IMGFILE}.label;
372         @echo "STEP: write modified disklabel back"
373         disklabel -R -r `cat ${ISODIR}/vn.which`s2 ${IMGFILE}.label
374         rm ${IMGFILE}.label
375         disklabel -B -b ${ISOROOT}/boot/boot1_64 -s ${ISOROOT}/boot/boot2_64 \
376             `cat ${ISODIR}/vn.which`s2
377         newfs /dev/`cat ${ISODIR}/vn.which`s2a
378         mount /dev/`cat ${ISODIR}/vn.which`s2a ${IMGMNT}
379         cpdup ${ISOROOT} ${IMGMNT}
380         @echo "STEP: fixup ${IMGMNT}/etc/fstab"
381         echo "/dev/part-by-label/${LABEL}.a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
382         echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
383         echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
384         echo "dummy /var/run tmpfs rw,-C 0 0" >> ${IMGMNT}/etc/fstab
385         echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
386         echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
387         @echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
388         -fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
389         echo 'vfs.root.mountfrom="ufs:part-by-label/${LABEL}.a"' >> ${IMGMNT}/boot/loader.conf.new
390         mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
391         @echo "STEP: cleanup"
392         df ${IMGMNT}
393         sync
394         sleep 1
395         umount ${IMGMNT}
396         vnconfig -u `cat ${ISODIR}/vn.which`
397         rm -f ${ISODIR}/vn.which
398         rmdir ${IMGMNT}
399         @echo "STEP: done"
400
401 clean:
402         sync
403         sleep 1
404         -umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
405         -umount ${ISOROOT}/usr/dports > /dev/null 2>&1
406         -umount ${ISOROOT}/dev > /dev/null 2>&1
407         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
408             vnconfig -u `cat ${ISODIR}/vn.which`; fi
409         if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
410         rm -rf ${ISOROOT}
411         rm -rf ${NRLOBJDIR}/nrelease
412         rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
413
414 realclean:      clean
415         rm -rf ${OBJSYS}/${KERNCONF}
416         rm -rf ${ISODIR}/packages
417         rm -rf ${ISODIR}/distfiles
418
419 help all:
420         @echo "Targets:"
421         @echo "  release     - full build from scratch"
422         @echo "  quick       - attempt to do an incremental rebuild"
423         @echo "  realquick   - attempt to restart after world & kernel"
424         @echo "  restartpkgs - attempt to restart at the pkg building stage"
425         @echo "NOTE: Add the optional 'gui' target to do a GUI release"
426         @echo ""
427         @echo "Variables:"
428         @echo "  DPORTS_EXTRA_PACKAGES: add additional packages"
429         @echo "  GITURL_SRC: override the Git URL to source repository"
430         @echo "  GITURL_DPORTS: override the Git URL to dports repository"
431         @echo "  IMGSIZE: override the size of .img (in 512-byte sectors)"
432         @echo "  MAKE_JOBS: override the default value (sysctl hw.ncpu)"
433
434 .PHONY: release quickrel realquickrel
435 .PHONY: installer
436 .PHONY: quick realquick
437 .PHONY: check buildworld1 buildworld2
438 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
439 .PHONY: clean realclean help all srcs
440
441 .include <bsd.prog.mk>