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