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