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