f308f2f80e316639160bf55ffd27a1acf949a650
[dragonfly.git] / nrelease / Makefile
1 # $DragonFly: src/nrelease/Makefile,v 1.90 2008/09/01 21:20:30 swildner Exp $
2 #
3
4 #########################################################################
5 #                               ENHANCEMENTS                            #
6 #########################################################################
7
8 # These targets are now obsolete and should not be used 
9 #
10 installer_release: warning release
11 installer_quickrel: warning quickrel
12 installer_realquickrel: warning realquickrel
13 installer_fetch: warning fetch
14
15 # New method e.g. 'make gui release'.  A series of enhancement
16 # targes may be specified which set make variables which enhance
17 # the build in various ways.
18 #
19 gui installer img:
20
21 warning:
22         @echo "WARNING: The installer_* targets are now obsolete, please"
23         @echo "use 'make blah' instead of 'make installer_blah'"
24         @echo ""
25         @echo "will continue in 10 seconds"
26         @sleep 10
27
28 #########################################################################
29 #                                SETUP                                  #
30 #########################################################################
31
32 ISODIR ?= /usr/release
33 ISOROOT ?= ${ISODIR}/root
34 OBJSYS= ${.OBJDIR}/../sys
35
36 .if make(gui)
37 KERNCONF ?= DFLYLIVE VKERNEL DFLYLIVE-SMP DFLYLIVE-SMP-NOAPIC
38 .else
39 KERNCONF ?= GENERIC VKERNEL
40 .endif
41
42 PKGSRC_PREFIX?=         /usr/pkg
43 PKGBIN_PKG_ADD?=        ${PKGSRC_PREFIX}/sbin/pkg_add
44 PKGBIN_PKG_DELETE?=     ${PKGSRC_PREFIX}/sbin/pkg_delete
45 PKGBIN_PKG_ADMIN?=      ${PKGSRC_PREFIX}/sbin/pkg_admin
46 PKGBIN_MKISOFS?=        ${PKGSRC_PREFIX}/bin/mkisofs
47 PKGSRC_PKG_PATH?=       ${ISODIR}/packages
48 PKGSRC_DB?=             /var/db/pkg
49 PKGSRC_BOOTSTRAP_URL?=  http://pkgbox.dragonflybsd.org/DragonFly-pkgsrc-packages/i386/1.12.0-RELEASE-BUILD
50 CVSUP_BOOTSTRAP_KIT?=   cvsup-bootstrap-20070716
51
52 # We use env -i in the chroot, so that environment variables won't
53 # disturb any (pkgsrc) build.  This has happened for TARGET_ARCH,
54 # which is used by gmake in completely different context.
55 CHROOT_CMD?=            env -i CCVER=${CCVER:Q} /usr/sbin/chroot ${ISOROOT} sh -c
56
57 # User may specify extra packages in addition to the defaults
58 #
59 PKGSRC_EXTRA_PACKAGES?=
60
61 # Pkgsrc packages to be built and installed on the release ISO
62 #
63 PKGSRC_PACKAGES?=       pkgtools/pkg_leaves \
64                         pkgtools/pkg_tarup \
65                         devel/scmgit \
66                         net/isc-dhcp4 \
67                         net/isc-dhcpd4 \
68                         sysutils/cdrtools \
69                         ${PKGSRC_EXTRA_PACKAGES}
70
71 # pkgsrc options to use when building packages
72 #
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 `pkgcustomizeiso'
101 # target; each overwrites the last.
102 #
103 REQ_ROOTSKELS=  ${.CURDIR}/root \
104                 ${.CURDIR}/installer
105 ROOTSKELS?=     ${REQ_ROOTSKELS}
106
107 .if make(gui)
108 ISOFILE?=               ${ISODIR}/dfly-gui.iso
109 IMGFILE?=               ${ISODIR}/dfly-gui.img
110 PKGSRC_PACKAGES+=       meta/modular-xorg-apps \
111                         meta/modular-xorg-drivers \
112                         meta/modular-xorg-fonts \
113                         meta/modular-xorg-libs \
114                         wm/fluxbox \
115                         www/firefox3 \
116                         print/xpdf \
117                         shells/zsh \
118                         editors/emacs \
119                         editors/vim \
120                         chat/pidgin \
121                         chat/irssi \
122                         chat/xchat \
123                         x11/rxvt-unicode \
124                         x11/eterm \
125                         lang/perl5 \
126                         editors/nano \
127                         shells/bash \
128                         devel/exctags \
129                         archivers/zip \
130                         security/sudo \
131                         www/links-gui \
132                         net/nmap \
133                         net/wget \
134                         fonts/terminus-font \
135                         net/rsync \
136                         sysutils/idesk \
137                         misc/screen
138 ROOTSKELS+=             ${.CURDIR}/gui
139 .endif
140
141 ISOFILE ?= ${ISODIR}/dfly.iso
142 IMGFILE ?= ${ISODIR}/dfly.img
143
144 IMGMNT ?= ${ISODIR}/mnt
145 IMGUSBDEV ?= /dev/da0
146
147 # note: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
148 # the additional '/nrelease' manually, as a safety measure.
149 #
150 NRLOBJDIR?= /usr/obj
151
152 #########################################################################
153 #                               BASE ISO TARGETS                        #
154 #########################################################################
155
156 release:        check clean buildworld1 buildkernel1 \
157                 buildiso syssrcs customizeiso mklocatedb mkiso mkimg
158
159 quickrel:       check clean buildworld2 buildkernel2 \
160                 buildiso syssrcs customizeiso mklocatedb mkiso mkimg
161
162 realquickrel:   check clean buildiso syssrcs customizeiso mklocatedb mkiso \
163                 mkimg
164
165 quick:          quickrel
166
167 realquick:      realquickrel
168
169 #########################################################################
170 #                          CORE SUPPORT TARGETS                         #
171 #########################################################################
172
173 check:
174 .if !exists(${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}.tgz)
175         @echo "The cvsup bootstrap kit is not installed.  You can install it with:"
176         @echo "    make fetch"
177         @exit 1
178 .endif
179 .if !defined(PKGSRC_PATH)
180         @echo "Please set PKGSRC_PATH to the pkgsrc tree that shall be used for"
181         @echo "package building."
182         @exit 1
183 .endif
184
185 buildworld1 buildworld2:
186         cd ${.CURDIR}/..; ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} make -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
187
188 buildkernel1 buildkernel2:
189 .if make(gui)
190         cd ${.CURDIR}/..; \
191         for kernconf in ${KERNCONF}; do \
192                 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
193                 make ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
194                         KERNCONF=$${kernconf} KERNCONFDIR=${.CURDIR}/gui/root; \
195         done
196 .else
197         cd ${.CURDIR}/..; \
198         first=; \
199         for kernconf in ${KERNCONF}; do \
200                 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
201                 make ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
202                         KERNCONF=$${kernconf} \
203                         $${first:+-DNO_MODULES}; \
204                 first=done; \
205         done
206 .endif
207
208 # note that we do not want to mess with any /usr/obj directories not related
209 # to buildworld, buildkernel, or nrelease, so we must supply the proper
210 # MAKEOBJDIRPREFIX for targets that are not run through the buildworld and 
211 # buildkernel mechanism.
212 #
213 buildiso:
214         if [ ! -d ${ISOROOT} ]; then mkdir -p ${ISOROOT}; fi
215         if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
216         ( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
217         ( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
218                 make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
219         cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
220 .if make(gui)
221         if [ ! -d ${ISOROOT}/kernel.smp/boot ]; then mkdir -p ${ISOROOT}/kernel.smp/boot; fi
222         cd ${.CURDIR}/..; \
223         make installkernel DESTDIR=${ISOROOT} \
224         KERNCONF=DFLYLIVE DESTKERNNAME=kernel KERNCONFDIR=${.CURDIR}/gui/root; \
225         cd ${.CURDIR}/..; \
226         make installkernel DESTDIR=${ISOROOT} \
227         KERNCONF=VKERNEL DESTKERNNAME=kernel.VKERNEL -DNO_MODULES KERNCONFDIR=${.CURDIR}/gui/root; \
228         cd ${.CURDIR}/..; \
229         make installkernel DESTDIR=${ISOROOT}/kernel.smp \
230         KERNCONF=DFLYLIVE-SMP DESTKERNNAME=kernel KERNCONFDIR=${.CURDIR}/gui/root; \
231         cd ${.CURDIR}/..; \
232         make installkernel DESTDIR=${ISOROOT}/kernel.smp \
233         KERNCONF=DFLYLIVE-SMP-NOAPIC DESTKERNNAME=kernel.noapic \
234                 KERNCONFDIR=${.CURDIR}/gui/root -DNO_MODULES;
235 .else
236         cd ${.CURDIR}/..; \
237         first=; \
238         for kernconf in ${KERNCONF}; do \
239                 make DESTDIR=${ISOROOT} \
240                         installkernel KERNCONF=$${kernconf} \
241                         $${first:+DESTKERNNAME=kernel.$${kernconf}} \
242                         $${first:+-DNO_MODULES}; \
243                 first=done; \
244         done
245 .endif
246         ln -s kernel ${ISOROOT}/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 # Include kernel sources on the release CD (~14MB)
252 #
253 syssrcs:
254 .if !defined(WITHOUT_SRCS)
255         ( cd ${.CURDIR}/../..; tar -cf - src/Makefile src/Makefile.inc1 src/sys | bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2 )
256 .endif
257
258 customizeiso:
259 .for ROOTSKEL in ${ROOTSKELS}
260         cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
261 .endfor
262         (cd ${PKGSRC_PKG_PATH}; tar xzpf ${CVSUP_BOOTSTRAP_KIT}.tgz)
263         cp -p ${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}/usr/local/bin/cvsup ${ISOROOT}/usr/local/bin/cvsup
264         cp -p ${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}/usr/local/man/man1/cvsup.1 ${ISOROOT}/usr/local/man/man1/cvsup.1
265         pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
266 .for UPGRADE_ITEM in Makefile                   \
267                      etc.${MACHINE_ARCH}        \
268                      isdn/Makefile              \
269                      rc.d/Makefile              \
270                      periodic/Makefile          \
271                      periodic/daily/Makefile    \
272                      periodic/security/Makefile \
273                      periodic/weekly/Makefile   \
274                      periodic/monthly/Makefile
275         cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
276 .endfor
277         #
278         # Setup some things & mount pkgsrc tree.  Use defensive umounts and
279         # rm -rf's to allow restarts.  Allow /usr/pkgsrc to be read-only.
280         #
281         # If we did not get past the bootstrap we clean out the entire
282         # /usr/pkg infrastructure.  Otherwise we attempt to pick up where
283         # we left off.
284         #
285         cp -p /etc/resolv.conf ${ISOROOT}/etc
286         ${CHROOT_CMD} "ldconfig -elf /usr/lib /usr/lib/gcc* /usr/lib/compat"
287         -@umount ${ISOROOT}/usr/pkgsrc/distfiles
288         -@umount ${ISOROOT}/usr/pkgsrc
289         mkdir -p ${ISODIR}/distfiles
290         rm -rf ${ISOROOT}/usr/pkgobj
291         test -e ${ISODIR}/.didbootstrap ||          \
292             rm -rf ${ISOROOT}/usr/pkg ${ISOROOT}/var/db/pkg \
293                     ${ISOROOT}/var/db/pkg.refcount
294         #
295         # Mount /usr/pkgsrc, make sure /usr/pkgsrc/distfiles is writable
296         #
297         mkdir -p ${ISOROOT}/usr/pkgobj
298         mkdir -p ${ISOROOT}/usr/pkgobj/bootstrap/work
299         mkdir -p ${ISOROOT}/usr/pkgsrc
300         mount_null ${PKGSRC_PATH} ${ISOROOT}/usr/pkgsrc
301         cp /etc/shells ${ISOROOT}/usr/pkgsrc/distfiles/.test || \
302                 mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/pkgsrc/distfiles
303         #
304         # Bootstrap, if not already installed
305         #
306         test -e ${ISODIR}/.didbootstrap ||      \
307             ${CHROOT_CMD} "cd /usr/pkgsrc/bootstrap;    \
308                 ./bootstrap --workdir /usr/pkgobj/bootstrap/work"
309         sync
310         touch ${ISODIR}/.didbootstrap
311         #
312         # Build and install packages, skip packages already installed
313         #
314 .for PKG in ${PKGSRC_PACKAGES}
315         ${CHROOT_CMD} "cd /usr/pkgsrc/${PKG} && \
316             (bmake WRKOBJDIR=/usr/pkgobj check > /dev/null 2>&1 || \
317             bmake WRKOBJDIR=/usr/pkgobj ${PKGSRC_OPTIONS} clean build install)"
318 .endfor
319         #
320         # Remove packages which nothing depends on and clean up
321         #
322         ${CHROOT_CMD} "pkg_leaves | xargs pkg_delete -R"
323         -umount ${ISOROOT}/usr/pkgsrc/distfiles
324         umount ${ISOROOT}/usr/pkgsrc
325         rmdir ${ISOROOT}/usr/pkgsrc
326         rm -rf ${ISOROOT}/usr/pkgobj
327         rm -f ${ISOROOT}/etc/resolv.conf
328         makewhatis ${ISOROOT}/usr/local/man
329         makewhatis ${ISOROOT}/usr/pkg/man
330
331 mklocatedb:
332         ( find -s ${ISOROOT} -path ${ISOROOT}/tmp -or \
333                 -path ${ISOROOT}/usr/tmp -or -path ${ISOROOT}/var/tmp \
334                 -prune -o -print | sed -e 's#^${ISOROOT}##g' | \
335                 /usr/libexec/locate.mklocatedb \
336                 -presort >${ISOROOT}/var/db/locate.database )
337
338 mkiso:
339         ( cd ${ISOROOT}; ${PKGBIN_MKISOFS} -b boot/cdboot -no-emul-boot \
340                 -R -J -o ${ISOFILE} \
341                 -V DragonFly-`${.CURDIR}/../tools/gitrev.sh | cut -c -22` . )
342
343
344 mkimg:
345 .if make(img)
346         if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
347
348         echo "determine required image size" > /dev/null;               \
349         sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;                  \
350         echo "add 15% more space as required" > /dev/null;              \
351         sz=`bc -e "(($${sz}) / 1024) * 1.15" -equit | cut -f1 -d.`;     \
352         dd if=/dev/zero of=${IMGFILE} bs=1m count=$${sz};               \
353         fdisk -IB -p ${IMGFILE};                                        \
354         echo "determine free vn device" > /dev/null;                    \
355         vn=`vnconfig -l | grep "not in use" | head -n 1 | cut -f 1 -d:`; \
356         vnconfig -e -s labels $${vn} ${IMGFILE};                        \
357         echo "write standard disklabel" > /dev/null;                    \
358         disklabel -w -r $${vn}s1 auto;                                  \
359         echo "read disklabel back" > /dev/null;                         \
360         disklabel -r $${vn}s1 > ${IMGFILE}.label;                       \
361         echo "determine number of sectors of whole disk" > /dev/null;   \
362         secs=`tail -n 1 ${IMGFILE}.label | cut -f 3 -w`;                \
363         echo "and add a: partition" > /dev/null;                        \
364         echo "  a:  $${secs} 0 4.2BSD" >> ${IMGFILE}.label;             \
365         echo "write modified disklabel back" > /dev/null;               \
366         disklabel -R -r $${vn}s1 ${IMGFILE}.label;                      \
367         rm ${IMGFILE}.label;                                            \
368         echo "write bootsector" >  /dev/null;                           \
369         disklabel -B $${vn}s1;                                          \
370         newfs /dev/$${vn}s1a;                                           \
371         mount /dev/$${vn}s1a ${IMGMNT};                                 \
372         cpdup -vvv ${ISOROOT} ${IMGMNT};                                \
373         echo "fix /etc/fstab" > /dev/null;                              \
374         echo "${IMGUSBDEV}s1a / ufs rw 0 0" > ${IMGMNT}/etc/fstab;      \
375         echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab;         \
376         df ${IMGMNT};                                                   \
377         umount ${IMGMNT};                                               \
378         vnconfig -u $${vn};                                             \
379         rmdir ${IMGMNT}
380 .endif
381
382 clean:
383         -umount ${ISOROOT}/usr/pkgsrc/distfiles
384         -umount ${ISOROOT}/usr/pkgsrc
385         if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
386         if [ -d ${ISOROOT} ]; then rm -rf ${ISOROOT}/*; fi
387         if [ -d ${NRLOBJDIR}/nrelease ]; then rm -rf ${NRLOBJDIR}/nrelease; fi
388         rm -f ${ISODIR}/.didbootstrap
389
390 realclean:      clean
391         rm -rf ${OBJSYS}/${KERNCONF}
392         #
393         # do not use PKGSRC_PKG_PATH here, we do not want to destroy an
394         # override location.
395         #
396         if [ -d ${ISODIR}/packages ]; then rm -rf ${ISODIR}/packages; fi
397
398 fetch:
399         @if [ ! -d ${PKGSRC_PKG_PATH} ]; then mkdir -p ${PKGSRC_PKG_PATH}; fi
400 .if !exists(${PKGSRC_PKG_PATH}/${CVSUP_BOOTSTRAP_KIT}.tgz)
401         (cd ${PKGSRC_PKG_PATH}; fetch ${PKGSRC_BOOTSTRAP_URL}/${CVSUP_BOOTSTRAP_KIT}.tgz)
402 .endif
403
404 pkgsrc_bootstrap:
405         mkdir -p ${PKGSRC_PKG_PATH}
406 .if !exists(${PKGSRC_PKG_PATH}/${PKGSRC_BOOTSTRAP_KIT}.tgz)
407         (cd ${PKGSRC_PKG_PATH}; fetch ${PKGSRC_BOOTSTRAP_URL}/${PKGSRC_BOOTSTRAP_KIT}.tgz)
408 .endif
409         (cd ${PKGSRC_PKG_PATH}; tar xzpf ${PKGSRC_BOOTSTRAP_KIT}.tgz)
410         (cd ${PKGSRC_PKG_PATH}/${PKGSRC_BOOTSTRAP_KIT}/bootstrap; ./bootstrap)
411
412 pkgsrc_cdrecord:
413 .if !exists (${PKGBIN_MKISOFS})
414         ${PKGBIN_PKG_ADD} ${PKGSRC_PKG_PATH}/cdrtools*
415 .endif
416
417 help:
418         @echo "make release   - complete build from scratch"
419         @echo "make quick     - attempt to do an incremental rebuild"
420         @echo "make realquic  - attempt to restart after world & kernel"
421         @echo ""
422         @echo "If the main build works but customizeiso fails you can restart"
423         @echo "at the customize iso step with:"
424         @echo ""
425         @echo "make customizeiso mklocatedb mkiso mkimg"
426         @echo ""
427         @echo "Extra packages may be specified with PKGSRC_EXTRA_PACKAGES"
428
429 .PHONY: all release installer_release quickrel installer_quickrel realquickrel
430 .PHONY: installer_fetch installer
431 .PHONY: quick realquick
432 .PHONY: installer_realquickrel check buildworld1 buildworld2
433 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mklocatedb mkiso mkimg
434 .PHONY: clean realclean fetch help
435
436 .include <bsd.prog.mk>