Merge remote branch 'crater/master' into net80211-update
[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                 ./bootstrap --workdir /usr/pkgobj/bootstrap/work"
343 .if make(gui)
344         test -e ${ISODIR}/.didbootstrap || \
345             echo ".ifdef BSD_PKG_MK     # added by nrelease" \
346                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
347         test -e ${ISODIR}/.didbootstrap || \
348             echo "ACCEPTABLE_LICENSES+=openmotif-license" \
349                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
350         test -e ${ISODIR}/.didbootstrap || \
351             echo "ACCEPTABLE_LICENSES+=vim-license" \
352                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
353         test -e ${ISODIR}/.didbootstrap || \
354             echo ".endif                        # added by nrelease" \
355                 >> ${ISOROOT}/usr/pkg/etc/mk.conf
356 .endif
357         test -e ${ISODIR}/.didbootstrap || sync
358         test -e ${ISODIR}/.didbootstrap || touch ${ISODIR}/.didbootstrap
359         #
360         # Build and install packages, skip packages already installed
361         #
362 .for PKG in ${PKGSRC_PACKAGES}
363         ${CHROOT_CMD} "cd /usr/pkgsrc/${PKG} && \
364             (bmake check > /dev/null 2>&1 || \
365             bmake ${PKGSRC_OPTIONS} clean build install)"
366 .endfor
367         #
368         # Remove packages which nothing depends on and clean up
369         #
370         ${CHROOT_CMD} "pkg_leaves | xargs pkg_delete -R"
371         -umount ${ISOROOT}/usr/pkgsrc/distfiles
372         umount ${ISOROOT}/dev
373         umount ${ISOROOT}/usr/pkgsrc
374         rm -rf ${ISOROOT}/usr/pkgobj
375         rm -f ${ISOROOT}/etc/resolv.conf
376         makewhatis ${ISOROOT}/usr/pkg/man
377
378 # So locate works
379 #
380 mklocatedb:
381         ( find -s ${ISOROOT} -path ${ISOROOT}/tmp -or \
382                 -path ${ISOROOT}/usr/tmp -or -path ${ISOROOT}/var/tmp \
383                 -prune -o -print | sed -e 's#^${ISOROOT}##g' | \
384                 /usr/libexec/locate.mklocatedb \
385                 -presort >${ISOROOT}/var/db/locate.database )
386
387 mkiso:
388         ( cd ${ISOROOT}; ${PKGBIN_MKISOFS} -b boot/cdboot -no-emul-boot \
389                 -R -J -o ${ISOFILE} \
390                 -V "DragonFly `${.CURDIR}/../tools/gitrev.sh | cut -c -22`" . )
391
392
393 mkimg:
394 .if make(img)
395         if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
396         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
397             vnconfig -u `cat ${ISODIR}/vn.which`; fi
398         @echo "STEP: determine required image size"
399         sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;                  \
400             sz=`bc -e "(($${sz}) / 1024) * 1.15" -equit | cut -f1 -d.`; \
401             dd if=/dev/zero of=${IMGFILE} bs=1m count=$${sz};
402         fdisk -IB -p ${IMGFILE}
403         @echo "STEP: determine free vn device"
404         vnconfig -l | grep "not in use" | head -n 1 |                   \
405             cut -f 1 -d: > ${ISODIR}/vn.which
406         vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
407         @echo "STEP: write standard disklabel"
408         disklabel -w -r `cat ${ISODIR}/vn.which`s1 auto
409         @echo "STEP: read disklabel back"
410         disklabel -r `cat ${ISODIR}/vn.which`s1 > ${IMGFILE}.label
411         @echo "STEP: determine number of sectors of whole disk"
412         secs=`tail -n 1 ${IMGFILE}.label | cut -f 3 -w`;                \
413             echo "  a:  $${secs} 0 4.2BSD" >> ${IMGFILE}.label;
414         @echo "STEP: write modified disklabel back"
415         disklabel -R -r `cat ${ISODIR}/vn.which`s1 ${IMGFILE}.label
416         rm ${IMGFILE}.label
417         @echo "STEP: write bootsector"
418         disklabel -B `cat ${ISODIR}/vn.which`s1
419         boot0cfg -B -o noupdate `cat ${ISODIR}/vn.which`
420         newfs /dev/`cat ${ISODIR}/vn.which`s1a
421         mount /dev/`cat ${ISODIR}/vn.which`s1a ${IMGMNT}
422         cpdup ${ISOROOT} ${IMGMNT}
423         @echo "STEP: fixup ${IMGMNT}/etc/fstab"
424         echo "/dev/${IMGUSBDEV}s1a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
425         echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
426         @echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
427         -fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
428         echo 'vfs.root.mountfrom="ufs:${IMGUSBDEV}s1a"' >> ${IMGMNT}/boot/loader.conf.new
429         mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
430         @echo "STEP: cleanup"
431         df ${IMGMNT}
432         umount ${IMGMNT}
433         vnconfig -u `cat ${ISODIR}/vn.which`
434         rm -f ${ISODIR}/vn.which
435         rmdir ${IMGMNT}
436         @echo "STEP: done"
437 .endif
438
439 clean:
440         -umount ${ISOROOT}/usr/pkgsrc/distfiles > /dev/null 2>&1
441         -umount ${ISOROOT}/usr/pkgsrc > /dev/null 2>&1
442         -umount ${ISOROOT}/dev > /dev/null 2>&1
443         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
444             vnconfig -u `cat ${ISODIR}/vn.which`; fi
445         if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
446         rm -rf ${ISOROOT}
447         rm -rf ${NRLOBJDIR}/nrelease
448         rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
449
450 realclean:      clean
451         rm -rf ${OBJSYS}/${KERNCONF}
452         #
453         # do not use PKGSRC_PKG_PATH here, we do not want to destroy an
454         # override location.
455         #
456         rm -rf ${ISODIR}/packages
457         rm -rf ${ISODIR}/distfiles
458
459 pkgsrc_bootstrap:
460         mkdir -p /usr/release/bootstrap
461         (cd ${PKGSRC_PATH}/bootstrap; ./bootstrap --workdir /usr/release/bootstrap)
462
463 pkgsrc_cdrecord:
464 .if !exists (${PKGBIN_MKISOFS})
465         (cd ${PKGSRC_PATH}/sysutils/cdrtools; bmake clean build install)
466 .endif
467
468 help all:
469         @echo "make [gui] release   - complete build from scratch"
470         @echo "make [gui] quick     - attempt to do an incremental rebuild"
471         @echo "make [gui] realquick - attempt to restart after world & kernel"
472         @echo "make [gui] restartpkgs - attempt to restart at the pkg building stage"
473         @echo ""
474         @echo "Extra packages may be specified with PKGSRC_EXTRA_PACKAGES"
475
476 .PHONY: release quickrel realquickrel
477 .PHONY: installer
478 .PHONY: quick realquick
479 .PHONY: check buildworld1 buildworld2
480 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mklocatedb mkiso mkimg
481 .PHONY: clean realclean help all srcs
482
483 .include <bsd.prog.mk>