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