BIND: add pkgsrc/bind96 to nrelease
[dragonfly.git] / nrelease / Makefile
1 #########################################################################
2 #                               ENHANCEMENTS                            #
3 #########################################################################
4
5 # New method e.g. 'make gui release'.  A series of enhancement
6 # targes may be specified which set make variables which enhance
7 # the build in various ways.
8 #
9 gui installer img:
10
11 #########################################################################
12 #                                SETUP                                  #
13 #########################################################################
14
15 ISODIR?=        /usr/release
16 ISOROOT?=       ${ISODIR}/root
17 OBJSYS=         ${.OBJDIR}/../sys
18
19 MAKE_JOBS?=     $$(sysctl -n hw.ncpu)
20
21 # temporary until everybody has converted to x86_64
22 .if ${MACHINE_ARCH} == "amd64"
23 MACHINE_ARCH=   x86_64
24 .makeenv MACHINE_ARCH
25 .endif
26
27 # XXX makeshift fix to build the right kernel for the (target) architecture
28 # We should configure this in the platform files somehow
29 .if ${MACHINE_ARCH} == "i386"
30 KERNCONF ?= GENERIC VKERNEL
31 .else
32 KERNCONF ?= X86_64_GENERIC VKERNEL64
33 .endif
34
35 PKGSRC_PREFIX?=         /usr/pkg
36 PKGBIN_PKG_ADD?=        ${PKGSRC_PREFIX}/sbin/pkg_add
37 PKGBIN_PKG_DELETE?=     ${PKGSRC_PREFIX}/sbin/pkg_delete
38 PKGBIN_PKG_ADMIN?=      ${PKGSRC_PREFIX}/sbin/pkg_admin
39 PKGBIN_MKISOFS?=        ${PKGSRC_PREFIX}/bin/mkisofs
40 PKGSRC_PKG_PATH?=       ${ISODIR}/packages
41
42 # We use env -i in the chroot, so that environment variables won't
43 # disturb any (pkgsrc) build.  This has happened for TARGET_ARCH,
44 # which is used by gmake in completely different context.
45 #
46 CHROOT_CMD?=            env -i CCVER=${CCVER:Q} /usr/sbin/chroot ${ISOROOT} sh -c
47
48 # User may specify extra packages in addition to the defaults
49 #
50 PKGSRC_EXTRA_PACKAGES?=
51
52 # Pkgsrc packages to be built and installed on the release ISO
53 #
54 PKGSRC_PACKAGES?=       pkgtools/pkg_leaves \
55                         pkgtools/pkg_tarup \
56                         pkgtools/pkgin \
57                         devel/scmgit \
58                         net/bind96 \
59                         net/isc-dhcp4 \
60                         net/isc-dhcpd4 \
61                         sysutils/cdrtools \
62                         net/csup \
63                         ${PKGSRC_EXTRA_PACKAGES}
64
65 # pkgsrc options to use when building packages
66 #
67 PKGSRC_OPTIONS+=        MAKE_JOBS=${MAKE_JOBS}
68 PKGSRC_OPTIONS+=        WRKOBJDIR=/usr/pkgobj
69 PKGSRC_OPTIONS+=        PKG_DEFAULT_OPTIONS='dri inet6'
70 .if !make(gui)
71 PKGSRC_OPTIONS+=        PKG_OPTIONS.scmgit=-scmgit-gui
72 .endif
73
74 # Even though buildiso wipes the packages, our check target has to run
75 # first and old packages (listed as they appear in pkg_info) must be
76 # cleaned out in order for the pkg_add -n test we use in the check target
77 # to operate properly.
78 #
79 OLD_PKGSRC_PACKAGES?=   cdrtools-2.01.01.27nb1 \
80                         cdrecord-2.00.3nb2 \
81                         bootstrap-kit-20070205 \
82                         dfuibe_installer-1.1.6 \
83                         gettext-lib-0.14.5 \
84                         dfuibe_installer-1.1.7nb1 \
85                         dfuife_curses-1.5 \
86                         gettext-lib-0.14.6 \
87                         gettext-tools-0.14.6nb1 \
88                         libaura-3.1 \
89                         libdfui-4.2 \
90                         libinstaller-5.1 \
91                         bootstrap-kit-20080211 \
92                         cdrtools-ossdvd-2.01.1.36nb2 \
93                         isc-dhcp-base-4.0.0 \
94                         isc-dhcp-server-4.0.0
95
96 # Specify which root skeletons are required, and let the user include
97 # their own.  They are copied into ISODIR during the `customizeiso'
98 # target; each overwrites the last.
99 #
100 REQ_ROOTSKELS=  ${.CURDIR}/root
101 ROOTSKELS?=     ${REQ_ROOTSKELS}
102
103 .if make(gui)
104 ISOFILE?=               ${ISODIR}/dfly-gui.iso
105 IMGFILE?=               ${ISODIR}/dfly-gui.img
106 PKGSRC_PACKAGES+=       meta-pkgs/modular-xorg-apps \
107                         meta-pkgs/modular-xorg-drivers \
108                         meta-pkgs/modular-xorg-fonts \
109                         meta-pkgs/modular-xorg-libs \
110                         wm/fluxbox \
111                         wm/fvwm \
112                         www/firefox \
113                         print/xpdf \
114                         shells/zsh \
115                         editors/emacs \
116                         editors/vim \
117                         chat/pidgin \
118                         chat/irssi \
119                         chat/xchat \
120                         x11/modular-xorg-server \
121                         x11/rxvt-unicode \
122                         x11/eterm \
123                         lang/perl5 \
124                         editors/nano \
125                         shells/bash \
126                         devel/exctags \
127                         archivers/zip \
128                         security/sudo \
129                         www/links-gui \
130                         net/nmap \
131                         net/wget \
132                         fonts/terminus-font \
133                         net/rsync \
134                         sysutils/idesk \
135                         time/asclock \
136                         misc/screen
137 ROOTSKELS+=             ${.CURDIR}/gui
138 .endif
139
140 ISOFILE ?= ${ISODIR}/dfly.iso
141 IMGFILE ?= ${ISODIR}/dfly.img
142
143 IMGMNT ?= ${ISODIR}/mnt
144
145 # USB umass now probes starting at da8, so the usb stick is
146 # probably sitting on da8.
147 #
148 IMGUSBDEV ?= da8
149
150 # note: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
151 # the additional '/nrelease' manually, as a safety measure.
152 #
153 NRLOBJDIR?= /usr/obj
154
155 #########################################################################
156 #                               BASE ISO TARGETS                        #
157 #########################################################################
158
159 release:        check clean buildworld1 buildkernel1 \
160                 buildiso srcs customizeiso mklocatedb \
161                 mkiso mkimg
162
163 quickrel:       check clean buildworld2 buildkernel2 \
164                 buildiso srcs customizeiso mklocatedb \
165                 mkiso mkimg
166
167 realquickrel:   check clean \
168                 buildiso srcs customizeiso mklocatedb \
169                 mkiso mkimg
170
171 restartpkgs:    check customizeiso mklocatedb mkiso mkimg
172
173 quick:          quickrel
174
175 realquick:      realquickrel
176
177
178 #########################################################################
179 #                          CORE SUPPORT TARGETS                         #
180 #########################################################################
181
182 check:
183 .if !exists(${PKGBIN_PKG_ADMIN})
184         @echo "You never bootstrapped pkgsrc on your machine.  You can install it with:"
185         @echo "    make pkgsrc_bootstrap"
186 .endif
187 .if !exists (${PKGBIN_MKISOFS})
188         @echo
189         @echo "Your machine does not have cdrtools installed.  You can install it with:"
190         @echo "    make pkgsrc_cdrecord"
191 .endif
192 .if !defined(PKGSRC_PATH)
193         @echo "Please set PKGSRC_PATH to the pkgsrc tree that shall be used for"
194         @echo "package building.  For example /usr/pkgsrc.  See the Makefile"
195         @echo "in /usr if you are unfamiliar with pkgsrc."
196 .endif
197 .if !exists (${PKGBIN_MKISOFS})
198         @exit 1
199 .endif
200 .if !defined(PKGSRC_PATH)
201         @exit 1
202 .endif
203
204 buildworld1 buildworld2:
205         cd ${.CURDIR}/..; \
206         ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
207                 make -j ${MAKE_JOBS} -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
208
209 buildkernel1 buildkernel2:
210         cd ${.CURDIR}/..; \
211         first=; \
212         for kernconf in ${KERNCONF}; do \
213                 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
214                         make -j ${MAKE_JOBS} ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
215                         KERNCONF=$${kernconf} \
216                         $${first:+-DNO_MODULES}; \
217                 first=done; \
218         done
219
220 # note that we do not want to mess with any /usr/obj directories not related
221 # to buildworld, buildkernel, or nrelease, so we must supply the proper
222 # MAKEOBJDIRPREFIX for targets that are not run through the buildworld and 
223 # buildkernel mechanism.
224 #
225 # Unconditionally clean out /usr/release/root so a previous img build
226 # does not blow up a future quick iso build
227 #
228 buildiso:
229         -rm -rf ${ISOROOT}
230         -chflags -R noschg ${ISOROOT}
231         rm -rf ${ISOROOT}
232         mkdir -p ${ISOROOT}
233         if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
234         ( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
235         ( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
236                 make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
237         cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
238         cd ${.CURDIR}/..; \
239         first=; \
240         for kernconf in ${KERNCONF}; do \
241                 make DESTDIR=${ISOROOT} \
242                         installkernel KERNCONF=$${kernconf} \
243                         $${first:+DESTKERNNAME=kernel.$${kernconf}} \
244                         $${first:+-DNO_MODULES}; \
245                 first=done; \
246         done
247         ln -s kernel ${ISOROOT}/boot/kernel.BOOTP
248         mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.local.dist -p ${ISOROOT}/usr/local/
249         mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist -p ${ISOROOT}/var
250         dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
251
252 # Release CD: Kernel sources (~16M) and the full pkgsrc tree (~27M)
253 # Release DVD: Full sources (~90M) and the full pkgsrc tree (~27M)
254 #
255 srcs:
256 .if !defined(WITHOUT_SRCS)
257         rm -f ${ISOROOT}/usr/pkgsrc-git.tgz
258         rm -f ${ISOROOT}/usr/pkgsrc
259         mkdir -p ${ISOROOT}/usr/pkgsrc
260         cd ${ISOROOT}/usr/pkgsrc && git init
261         cd ${ISOROOT}/usr/pkgsrc && \
262                 git remote add origin git://git.dragonflybsd.org/pkgsrc.git
263         cd ${ISOROOT}/usr/pkgsrc && git fetch origin
264         cd ${ISOROOT}/usr/pkgsrc && git branch vendor origin/vendor
265         cd ${ISOROOT}/usr/pkgsrc && git gc
266 .if make(gui)
267         rm -f ${ISOROOT}/usr/src-git.tgz
268         rm -rf ${ISOROOT}/usr/src
269         mkdir -p ${ISOROOT}/usr/src
270         cd ${ISOROOT}/usr/src && git init
271         cd ${ISOROOT}/usr/src && \
272                 git remote add origin git://git.dragonflybsd.org/dragonfly.git
273         cd ${ISOROOT}/usr/src && git fetch origin
274         cd ${ISOROOT}/usr/src && git branch master origin/master
275         cd ${ISOROOT}/usr/src && git gc
276 .else
277         rm -f ${ISOROOT}/usr/src-sys.tgz
278         cd ${.CURDIR}/.. && tar --exclude .git --exclude CVS -s '/^\./src/' \
279                 -czf ${ISOROOT}/usr/src-sys.tgz ./Makefile ./Makefile.inc1 ./sys
280 .endif
281 .endif
282
283 # Customize the ISO by copying rootskels in reverse priority order,
284 # building packages, and doing other post-install tasks.
285 #
286 customizeiso:
287         # Copy the rootskels.  Allow sources to be owned by someone other
288         # then root (as is common when checked out via git).
289         #
290 .for ROOTSKEL in ${ROOTSKELS}
291         cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
292         @test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
293         @test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
294 .endfor
295         pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
296 .for UPGRADE_ITEM in Makefile                   \
297                      etc.${MACHINE_ARCH}        \
298                      isdn/Makefile              \
299                      rc.d/Makefile              \
300                      periodic/Makefile          \
301                      periodic/daily/Makefile    \
302                      periodic/security/Makefile \
303                      periodic/weekly/Makefile   \
304                      periodic/monthly/Makefile
305         cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
306 .endfor
307         #
308         # Setup some things & mount pkgsrc tree.  Use defensive umounts and
309         # rm -rf's to allow restarts.  Allow /usr/pkgsrc to be read-only.
310         #
311         # If we did not get past the bootstrap we clean out the entire
312         # /usr/pkg infrastructure.  Otherwise we attempt to pick up where
313         # we left off.
314         #
315         cp -p /etc/resolv.conf ${ISOROOT}/etc
316         ${CHROOT_CMD} "ldconfig -elf /usr/lib /usr/lib/gcc* /usr/lib/compat"
317         -@umount ${ISOROOT}/usr/pkgsrc/distfiles
318         -@umount ${ISOROOT}/usr/pkgsrc
319         -@umount ${ISOROOT}/dev
320         mkdir -p ${ISODIR}/distfiles
321         rm -rf ${ISOROOT}/usr/pkgobj
322         #
323         # Mount /usr/pkgsrc, make sure /usr/pkgsrc/distfiles is writable.
324         # Make /usr/pkgsrc read-only for safety, else a failed umount and
325         # our rm -rf will do bad things.
326         #
327         mkdir -p ${ISOROOT}/usr/pkgobj
328         mkdir -p ${ISOROOT}/usr/pkgobj/bootstrap
329         mkdir -p ${ISOROOT}/usr/pkgsrc
330         mount_null -o ro ${PKGSRC_PATH} ${ISOROOT}/usr/pkgsrc
331         mount_null /dev ${ISOROOT}/dev
332         cp /etc/shells ${ISOROOT}/usr/pkgsrc/distfiles/.test > /dev/null 2>&1 \
333             || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/pkgsrc/distfiles
334         #
335         # Bootstrap, if not already installed, and add licenses needed
336         # for the gui release
337         #
338         test -e ${ISODIR}/.didbootstrap || \
339             rm -rf ${ISOROOT}/usr/pkg ${ISOROOT}/var/db/pkg \
340                     ${ISOROOT}/var/db/pkg.refcount
341         test -e ${ISODIR}/.didbootstrap || \
342             ${CHROOT_CMD} "cd /usr/pkgsrc/bootstrap;    \
343                 export share_dir=/usr/pkgobj/bootstrap/work/share; \
344                 ./bootstrap --workdir /usr/pkgobj/bootstrap/work"
345 .if make(gui)
346         test -e ${ISODIR}/.didbootstrap || \
347             echo ".ifdef BSD_PKG_MK     # added by nrelease" \
348                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
349         test -e ${ISODIR}/.didbootstrap || \
350             echo "ACCEPTABLE_LICENSES+=openmotif-license" \
351                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
352         test -e ${ISODIR}/.didbootstrap || \
353             echo "ACCEPTABLE_LICENSES+=vim-license" \
354                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
355         test -e ${ISODIR}/.didbootstrap || \
356             echo ".endif                        # added by nrelease" \
357                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
358 .endif
359         test -e ${ISODIR}/.didbootstrap || sync
360         test -e ${ISODIR}/.didbootstrap || touch ${ISODIR}/.didbootstrap
361         #
362         # Build and install packages, skip packages already installed
363         #
364 .for PKG in ${PKGSRC_PACKAGES}
365         ${CHROOT_CMD} "cd /usr/pkgsrc/${PKG} && \
366             (bmake check > /dev/null 2>&1 || \
367             bmake ${PKGSRC_OPTIONS} clean build install)"
368 .endfor
369         #
370         # Remove packages which nothing depends on and clean up
371         #
372         ${CHROOT_CMD} "pkg_leaves | xargs pkg_delete -R"
373         -umount ${ISOROOT}/usr/pkgsrc/distfiles
374         umount ${ISOROOT}/dev
375         umount ${ISOROOT}/usr/pkgsrc
376         rm -rf ${ISOROOT}/usr/pkgobj
377         rm -f ${ISOROOT}/etc/resolv.conf
378         makewhatis ${ISOROOT}/usr/pkg/man
379
380 # So locate works
381 #
382 mklocatedb:
383         ( find -s ${ISOROOT} -path ${ISOROOT}/tmp -or \
384                 -path ${ISOROOT}/usr/tmp -or -path ${ISOROOT}/var/tmp \
385                 -prune -o -print | sed -e 's#^${ISOROOT}##g' | \
386                 /usr/libexec/locate.mklocatedb \
387                 -presort >${ISOROOT}/var/db/locate.database )
388
389 mkiso:
390         ( cd ${ISOROOT}; ${PKGBIN_MKISOFS} -b boot/cdboot -no-emul-boot \
391                 -R -J -o ${ISOFILE} \
392                 -V "DragonFly `${.CURDIR}/../tools/gitrev.sh | cut -c -22`" . )
393
394
395 mkimg:
396 .if make(img)
397         if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
398         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
399             vnconfig -u `cat ${ISODIR}/vn.which`; fi
400         @echo "STEP: determine required image size"
401         sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;                  \
402             sz=`bc -e "(($${sz}) / 1024) * 1.15" -equit | cut -f1 -d.`; \
403             dd if=/dev/zero of=${IMGFILE} bs=1m count=$${sz};
404         fdisk -IB -p ${IMGFILE}
405         @echo "STEP: determine free vn device"
406         vnconfig -l | grep "not in use" | head -n 1 |                   \
407             cut -f 1 -d: > ${ISODIR}/vn.which
408         vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
409         @echo "STEP: write standard disklabel"
410         disklabel -w -r `cat ${ISODIR}/vn.which`s1 auto
411         @echo "STEP: read disklabel back"
412         disklabel -r `cat ${ISODIR}/vn.which`s1 > ${IMGFILE}.label
413         @echo "STEP: determine number of sectors of whole disk"
414         secs=`tail -n 1 ${IMGFILE}.label | cut -f 3 -w`;                \
415             echo "  a:  $${secs} 0 4.2BSD" >> ${IMGFILE}.label;
416         @echo "STEP: write modified disklabel back"
417         disklabel -R -r `cat ${ISODIR}/vn.which`s1 ${IMGFILE}.label
418         rm ${IMGFILE}.label
419         @echo "STEP: write bootsector"
420         disklabel -B `cat ${ISODIR}/vn.which`s1
421         boot0cfg -B -o noupdate `cat ${ISODIR}/vn.which`
422         newfs /dev/`cat ${ISODIR}/vn.which`s1a
423         mount /dev/`cat ${ISODIR}/vn.which`s1a ${IMGMNT}
424         cpdup ${ISOROOT} ${IMGMNT}
425         @echo "STEP: fixup ${IMGMNT}/etc/fstab"
426         echo "/dev/${IMGUSBDEV}s1a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
427         echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
428         @echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
429         -fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
430         echo 'vfs.root.mountfrom="ufs:${IMGUSBDEV}s1a"' >> ${IMGMNT}/boot/loader.conf.new
431         mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
432         @echo "STEP: cleanup"
433         df ${IMGMNT}
434         umount ${IMGMNT}
435         vnconfig -u `cat ${ISODIR}/vn.which`
436         rm -f ${ISODIR}/vn.which
437         rmdir ${IMGMNT}
438         @echo "STEP: done"
439 .endif
440
441 clean:
442         -umount ${ISOROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
443         -umount ${ISOROOT}/usr/pkgsrc > /dev/null 2>&1
444         -umount ${ISOROOT}/dev > /dev/null 2>&1
445         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
446             vnconfig -u `cat ${ISODIR}/vn.which`; fi
447         if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
448         rm -rf ${ISOROOT}
449         rm -rf ${NRLOBJDIR}/nrelease
450         rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
451
452 realclean:      clean
453         rm -rf ${OBJSYS}/${KERNCONF}
454         #
455         # do not use PKGSRC_PKG_PATH here, we do not want to destroy an
456         # override location.
457         #
458         rm -rf ${ISODIR}/packages
459         rm -rf ${ISODIR}/distfiles
460
461 pkgsrc_bootstrap:
462         mkdir -p /usr/release/bootstrap
463         (cd ${PKGSRC_PATH}/bootstrap; \
464             export share_dir=/usr/release/bootstrap/share; \
465             ./bootstrap --workdir /usr/release/bootstrap)
466
467 pkgsrc_cdrecord:
468 .if !exists (${PKGBIN_MKISOFS})
469         (cd ${PKGSRC_PATH}/sysutils/cdrtools; bmake clean build install)
470 .endif
471
472 help all:
473         @echo "make [gui] release   - complete build from scratch"
474         @echo "make [gui] quick     - attempt to do an incremental rebuild"
475         @echo "make [gui] realquick - attempt to restart after world & kernel"
476         @echo "make [gui] restartpkgs - attempt to restart at the pkg building stage"
477         @echo ""
478         @echo "Extra packages may be specified with PKGSRC_EXTRA_PACKAGES"
479
480 .PHONY: release quickrel realquickrel
481 .PHONY: installer
482 .PHONY: quick realquick
483 .PHONY: check buildworld1 buildworld2
484 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mklocatedb mkiso mkimg
485 .PHONY: clean realclean help all srcs
486
487 .include <bsd.prog.mk>