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