nrelease - Set dports default, add dports defaults
[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 nopkgs:
12
13 #########################################################################
14 #                                SETUP                                  #
15 #########################################################################
16
17 DPORTS_PATH?=   /usr/dports
18 ISODIR?=        /usr/release
19 ISOROOT?=       ${ISODIR}/root
20 OBJSYS=         ${.OBJDIR}/../sys
21 GITHOST?=       git.dragonflybsd.org
22
23 MAKE_JOBS?=     $$(sysctl -n hw.ncpu)
24
25 # temporary until everybody has converted to x86_64
26 .if ${MACHINE_ARCH} == "amd64"
27 MACHINE_ARCH=   x86_64
28 .if defined(.PARSEDIR)
29 .export MACHINE_ARCH
30 .else
31 # LEGACY MAKE - REMOVE FOR DFLY 3.6
32 .makeenv MACHINE_ARCH
33 .endif
34 .endif
35
36 # XXX makeshift fix to build the right kernel for the (target) architecture
37 # We should configure this in the platform files somehow
38 .if ${MACHINE_ARCH} == "i386"
39 KERNCONF ?= GENERIC
40 .else
41 KERNCONF ?= X86_64_GENERIC
42 .endif
43
44 CHROOT_CMD?=            /usr/sbin/chroot ${ISOROOT} sh -c
45
46 # User may specify extra packages in addition to the defaults
47 #
48 DPORTS_EXTRA_PACKAGES?=
49
50 # dports packages to be built and installed on the release ISO
51 #
52 # MISSING: csup
53 #
54 DPORTS_PACKAGES?=       devel/git \
55                         dns/bind98 \
56                         net/isc-dhcp42-client \
57                         net/isc-dhcp42-server \
58                         sysutils/cdrtools \
59                         ${PKGSRC_EXTRA_PACKAGES}
60
61 # dports options to use when building packages
62 #
63 DPORTS_OPTIONS+=                -DBATCH
64 .if !make(gui)
65 DPORTS_OPTIONS.devel_git+=      -DWITHOUT_CONTRIB -DWITHOUT_PERL
66 .endif
67
68 # Specify which root skeletons are required, and let the user include
69 # their own.  They are copied into ISODIR during the `customizeiso'
70 # target; each overwrites the last.
71 #
72 REQ_ROOTSKELS=  ${.CURDIR}/root
73 ROOTSKELS?=     ${REQ_ROOTSKELS}
74
75 .if make(notyet)
76 # LIST OF PACKAGES NOT INCLUDED DUE TO BUILD ISSUES:
77 #       chat/pidgin             textproc/enchant dependency is broken
78 #       x11/rxvt-unicode        broken configure
79 #       net/nmap                tries to access openssl/md2.h which does not
80 #                               exist.
81 #       sysutils/idesk          dying on link __sync_fetch_and_add_4
82 #
83 ISOFILE?=               ${ISODIR}/dfly-gui.iso
84 IMGFILE?=               ${ISODIR}/dfly-gui.img
85
86 # NOTE: order important, do not sort package list
87 #
88 # Apps we want in the gui build but which have problems building:
89 #       chat/xchat      link error on x86-64, something about ___progname
90 #
91 #
92 .if !make(nopkgs)
93 PKGSRC_PACKAGES+=       meta-pkgs/modular-xorg-libs \
94                         meta-pkgs/modular-xorg-fonts \
95                         meta-pkgs/modular-xorg-apps \
96                         meta-pkgs/modular-xorg-drivers \
97                         x11/libXinerama \
98                         wm/fluxbox \
99                         wm/fvwm \
100                         www/firefox \
101                         print/xpdf \
102                         shells/zsh \
103                         editors/emacs \
104                         editors/vim \
105                         chat/irssi \
106                         x11/modular-xorg-server \
107                         x11/eterm \
108                         lang/perl5 \
109                         editors/nano \
110                         shells/bash \
111                         devel/exctags \
112                         archivers/zip \
113                         security/sudo \
114                         www/links-gui \
115                         net/wget \
116                         fonts/terminus-font \
117                         net/rsync \
118                         time/asclock \
119                         misc/screen \
120                         devel/scmgit-gitk
121 .endif
122
123 ROOTSKELS+=             ${.CURDIR}/gui
124 .endif
125
126 ISOFILE ?= ${ISODIR}/dfly.iso
127 IMGFILE ?= ${ISODIR}/dfly.img
128
129 IMGMNT ?= ${ISODIR}/mnt
130
131 # USB umass now probes starting at da8, so the usb stick is
132 # probably sitting on da8.
133 #
134 IMGUSBDEV ?= da8
135
136 # note: we use the '${NRLOBJDIR}/nrelease' construct, that is we add
137 # the additional '/nrelease' manually, as a safety measure.
138 #
139 NRLOBJDIR?= /usr/obj
140
141 #########################################################################
142 #                               BASE ISO TARGETS                        #
143 #########################################################################
144
145 release:        check clean buildworld1 buildkernel1 \
146                 buildiso srcs customizeiso mkiso mkimg
147
148 quickrel:       check clean buildworld2 buildkernel2 \
149                 buildiso srcs customizeiso mkiso mkimg
150
151 realquickrel:   check clean \
152                 buildiso srcs customizeiso mkiso mkimg
153
154 restartpkgs:    check customizeiso mkiso mkimg
155
156 quick:          quickrel
157
158 realquick:      realquickrel
159
160
161 #########################################################################
162 #                          CORE SUPPORT TARGETS                         #
163 #########################################################################
164
165 check:
166 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
167         @echo
168         @echo "Your machine does not have cdrtools installed.  You can install it with:"
169         @echo "    pkg install cdrecord"
170 .endif
171 .if !defined(DPORTS_PATH)
172         @echo "Please set DPORTS_PATH to the dports tree that shall be used for"
173         @echo "package building.  For example /usr/dports.  See the Makefile"
174         @echo "in /usr if you are unfamiliar with dports."
175 .endif
176 .if !exists(/usr/local/bin/mkisofs) && !exists(/usr/pkg/bin/mkisofs)
177         @/usr/bin/false
178 .endif
179 .if !defined(DPORTS_PATH)
180         @/usr/bin/false
181 .endif
182
183 buildworld1 buildworld2:
184         cd ${.CURDIR}/..; \
185         ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
186                 make -j ${MAKE_JOBS} -DWANT_INSTALLER ${.TARGET:C/build(.*)2/quick\1/:C/1//}
187
188 buildkernel1 buildkernel2:
189         cd ${.CURDIR}/..; \
190         for kernconf in ${KERNCONF}; do \
191                 ${WORLD_CCVER:C/^..*$/WORLD_CCVER=/}${WORLD_CCVER} \
192                         make -j ${MAKE_JOBS} ${.TARGET:C/build(.*)2/quick\1/:C/1//} \
193                         KERNCONF=$${kernconf}; \
194         done
195
196 # note that we do not want to mess with any /usr/obj directories not related
197 # to buildworld, buildkernel, or nrelease, so we must supply the proper
198 # MAKEOBJDIRPREFIX for targets that are not run through the buildworld and 
199 # buildkernel mechanism.
200 #
201 # Unconditionally clean out ${ISOROOT} so a previous img build
202 # does not blow up a future quick iso build
203 #
204 # We install with INSTALLSTRIPPEDMODULES to make things fit into the ISO.
205 # We leave the kernel's debug variables intact.
206 #
207 buildiso:
208         -rm -rf ${ISOROOT}
209         -chflags -R noschg ${ISOROOT}
210         rm -rf ${ISOROOT}
211         mkdir -p ${ISOROOT}
212         if [ ! -d ${NRLOBJDIR}/nrelease ]; then mkdir -p ${NRLOBJDIR}/nrelease; fi
213         ( cd ${.CURDIR}/..; make -DWANT_INSTALLER DESTDIR=${ISOROOT} installworld )
214         ( cd ${.CURDIR}/../etc; MAKEOBJDIRPREFIX=${NRLOBJDIR}/nrelease \
215                 make -m ${.CURDIR}/../share/mk DESTDIR=${ISOROOT} distribution )
216         cpdup ${ISOROOT}/etc ${ISOROOT}/etc.hdd
217         cd ${.CURDIR}/..; \
218         for kernconf in ${KERNCONF}; do \
219                 make DESTDIR=${ISOROOT} installkernel KERNCONF=$${kernconf}; \
220         done
221         rm -rf ${ISOROOT}/boot/kernel.old
222         ln -s kernel ${ISOROOT}/boot/kernel/kernel.BOOTP
223         mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.local.dist -p ${ISOROOT}/usr/local/
224         mtree -deU -f ${.CURDIR}/../etc/mtree/BSD.var.dist -p ${ISOROOT}/var
225         dev_mkdb -f ${ISOROOT}/var/run/dev.db ${ISOROOT}/dev
226
227 # The GUI build includes the pkgsrc tree (~1G+) while the nominal release
228 # build does not.
229 #
230 # The GUI build includes full sources while the nominal release build
231 # only includes kernel sources (~27MB).
232 #
233 srcs:
234 .if !defined(WITHOUT_SRCS)
235 .if make(notyet)
236         rm -f ${ISOROOT}/usr/src-sys.tgz
237         rm -f ${ISOROOT}/usr/src-sys.tar.bz2
238         cd ${ISOROOT}/usr && make pkgsrc-create-repo GITHOST=${GITHOST}
239         # NOTE: Adding the git gc --aggressive helps by significantly
240         #       reducing the disk space required.
241         #
242         cd ${ISOROOT}/usr/pkgsrc && git gc --aggressive
243         cd ${ISOROOT}/usr && make src-create-repo GITHOST=${GITHOST}
244 .else
245         rm -f ${ISOROOT}/usr/src-sys.tgz
246         rm -f ${ISOROOT}/usr/src-sys.tar.bz2
247         cd ${.CURDIR}/.. && tar --exclude .git -s '/^\./src/' \
248                 -cf - ./Makefile ./Makefile.inc1 ./sys | \
249                 bzip2 -9 > ${ISOROOT}/usr/src-sys.tar.bz2
250 .endif
251 .endif
252
253 # Customize the ISO by copying rootskels in reverse priority order,
254 # building packages, and doing other post-install tasks.
255 #
256 customizeiso:
257         # Copy the rootskels.  Allow sources to be owned by someone other
258         # than root (as is common when checked out via git).
259         #
260 .for ROOTSKEL in ${ROOTSKELS}
261         cpdup -X cpignore -o ${ROOTSKEL} ${ISOROOT}
262         @test -O ${.CURDIR} || echo "chowning copied files to root:wheel"
263         @test -O ${.CURDIR} || ((cd ${ROOTSKEL} && find .) | fgrep -v cpignore | (cd ${ISOROOT} && xargs chown root:wheel))
264 .endfor
265         pwd_mkdb -p -d ${ISOROOT}/etc ${ISOROOT}/etc/master.passwd
266 .for UPGRADE_ITEM in Makefile                   \
267                      etc.${MACHINE_ARCH}        \
268                      rc.d/Makefile              \
269                      periodic/Makefile          \
270                      periodic/daily/Makefile    \
271                      periodic/security/Makefile \
272                      periodic/weekly/Makefile   \
273                      periodic/monthly/Makefile
274         cp -R ${.CURDIR}/../etc/${UPGRADE_ITEM} ${ISOROOT}/etc/${UPGRADE_ITEM}
275 .endfor
276         #
277         # Setup some things & mount dports tree.  Use defensive umounts and
278         # rm -rf's to allow restarts.  Allow /usr/dports to be read-only.
279         #
280         cp -p /etc/resolv.conf ${ISOROOT}/etc
281         ${CHROOT_CMD} "ldconfig -elf /usr/lib /usr/lib/gcc* /usr/lib/compat"
282         -@umount ${ISOROOT}/usr/distfiles
283         -@umount ${ISOROOT}/usr/dports
284         -@umount ${ISOROOT}/dev
285         rm -rf ${ISOROOT}/usr/obj/dports
286         #
287         # Mount /usr/dports, make sure /usr/distfiles is writable.
288         # Make /usr/dports read-only for safety, else a failed umount and
289         # our rm -rf will do bad things.
290         #
291         mkdir -p ${ISOROOT}/usr/dports
292         mkdir -p ${ISOROOT}/usr/distfiles
293         mount_null -o ro ${DPORTS_PATH} ${ISOROOT}/usr/dports
294         mount_null /dev ${ISOROOT}/dev
295         cp /etc/shells ${ISOROOT}/usr/distfiles/.test > /dev/null 2>&1 \
296             || mount_null ${ISODIR}/distfiles ${ISOROOT}/usr/distfiles
297         #
298         # Build and install packages, skip packages already installed
299         #
300 .for PKG in ${DPORTS_PACKAGES}
301         ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} ${DPORTS_OPTIONS.${PKG:S/\//_/g}} install"
302 .endfor
303 .for PKG in ${DPORTS_PACKAGES}
304         ${CHROOT_CMD} "cd /usr/dports/${PKG} && make ${DPORTS_OPTIONS} clean"
305 .endfor
306         #
307         # Remove packages which nothing depends on, add a whatis database
308         # for dports manual pages, create an initial locate database and
309         # clean up
310         #
311         ${CHROOT_CMD} "yes | pkg autoremove"
312         ${CHROOT_CMD} "makewhatis /usr/local/man"
313         -umount ${ISOROOT}/usr/distfiles
314         umount ${ISOROOT}/usr/dports
315         rm -rf ${ISOROOT}/usr/dports
316         rm -rf ${ISOROOT}/usr/obj/dports
317         rm -rf ${ISOROOT}/usr/distfiles
318         rm -f ${ISOROOT}/etc/resolv.conf
319         #
320         # Add a pkg.conf
321         #
322         ${CHROOT_CMD} "echo PACKAGESITE: http://avalon.dragonflybsd.org/dports/$$\\{ABI\\}/RELEASE >/usr/local/etc/pkg.conf"
323         #
324         # Finally, update the locate(8) database
325         #
326         ${CHROOT_CMD} /etc/periodic/weekly/310.locate
327         umount ${ISOROOT}/dev
328         #
329         # Recopy files that pkgsrc may have updated in /etc into /etc.hdd
330         #
331         cpdup ${ISOROOT}/etc/shells ${ISOROOT}/etc.hdd/shells
332         cpdup ${ISOROOT}/etc/group ${ISOROOT}/etc.hdd/group
333
334 mkiso:
335         ( cd ${ISOROOT}; mkisofs -b boot/cdboot -no-emul-boot \
336                 -R -J -o ${ISOFILE} \
337                 -V "DragonFly `${.CURDIR}/../tools/gitrev.sh | cut -c -22`" . )
338
339 mkimg:
340         if [ ! -d ${IMGMNT} ]; then mkdir -p ${IMGMNT}; fi
341         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
342             vnconfig -u `cat ${ISODIR}/vn.which`; fi
343 .ifdef IMGSIZE
344         @echo "STEP: use an image size of ${IMGSIZE} 512-byte sectors"
345         rm -f ${IMGFILE}
346         sz=`bc -e "((${IMGSIZE}) * 512)" -equit`; truncate -s $${sz} ${IMGFILE}
347 .else
348         @echo "STEP: Determine required image size in 1GB steps"
349         @echo "      Leave ~600MB of unused space"
350         sz=`du -ck ${ISOROOT} | tail -n 1 | cut -f 1`;                  \
351             sz=`bc -e "(($${sz}) * 1.15 + 999999 + 600000) / 1000000" -equit | \
352             cut -f1 -d.`;                                               \
353             sz=`bc -e "(($${sz}) * 953)" -equit | cut -f1 -d.`;         \
354             rm -f ${IMGFILE};                                           \
355             truncate -s $${sz}M ${IMGFILE};
356 .endif
357         fdisk -IB -p ${IMGFILE}
358         @echo "STEP: determine free vn device"
359         vnconfig -l | grep "not in use" | head -n 1 |                   \
360             cut -f 1 -d: > ${ISODIR}/vn.which
361         vnconfig -e -s labels `cat ${ISODIR}/vn.which` ${IMGFILE}
362         @echo "STEP: write standard disklabel"
363         disklabel -w -r `cat ${ISODIR}/vn.which`s1 auto
364         @echo "STEP: read disklabel back"
365         disklabel -r `cat ${ISODIR}/vn.which`s1 > ${IMGFILE}.label
366         @echo "STEP: determine number of sectors of whole disk"
367         secs=`tail -n 1 ${IMGFILE}.label | cut -f 3 -w`;                \
368             echo "  a:  $${secs} 0 4.2BSD" >> ${IMGFILE}.label;
369         @echo "STEP: write modified disklabel back"
370         disklabel -R -r `cat ${ISODIR}/vn.which`s1 ${IMGFILE}.label
371         rm ${IMGFILE}.label
372         @echo "STEP: write bootsector"
373         disklabel -B `cat ${ISODIR}/vn.which`s1
374         boot0cfg -B -o noupdate `cat ${ISODIR}/vn.which`
375         newfs /dev/`cat ${ISODIR}/vn.which`s1a
376         mount /dev/`cat ${ISODIR}/vn.which`s1a ${IMGMNT}
377         cpdup ${ISOROOT} ${IMGMNT}
378         @echo "STEP: fixup ${IMGMNT}/etc/fstab"
379         echo "/dev/${IMGUSBDEV}s1a / ufs rw,noatime 0 1" > ${IMGMNT}/etc/fstab
380         echo "dummy /tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
381         echo "dummy /var/tmp tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
382         echo "dummy /var/run tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
383         echo "dummy /usr/obj tmpfs rw 0 0" >> ${IMGMNT}/etc/fstab
384         echo "proc /proc procfs rw 0 0" >> ${IMGMNT}/etc/fstab
385         @echo "STEP: fixup ${IMGMNT}/boot/loader.conf"
386         -fgrep -v kernel_options ${IMGMNT}/boot/loader.conf > ${IMGMNT}/boot/loader.conf.new
387         echo 'vfs.root.mountfrom="ufs:${IMGUSBDEV}s1a"' >> ${IMGMNT}/boot/loader.conf.new
388         mv ${IMGMNT}/boot/loader.conf.new ${IMGMNT}/boot/loader.conf
389         @echo "STEP: cleanup"
390         df ${IMGMNT}
391         umount ${IMGMNT}
392         vnconfig -u `cat ${ISODIR}/vn.which`
393         rm -f ${ISODIR}/vn.which
394         rmdir ${IMGMNT}
395         @echo "STEP: done"
396
397 clean:
398         -umount ${ISOROOT}/usr/distfiles > /dev/null 2>&1
399         -umount ${ISOROOT}/usr/dports > /dev/null 2>&1
400         -umount ${ISOROOT}/dev > /dev/null 2>&1
401         -if [ -f ${ISODIR}/vn.which ]; then umount ${IMGMNT};           \
402             vnconfig -u `cat ${ISODIR}/vn.which`; fi
403         if [ -d ${ISOROOT} ]; then chflags -R noschg ${ISOROOT}; fi
404         rm -rf ${ISOROOT}
405         rm -rf ${NRLOBJDIR}/nrelease
406         rm -f ${ISODIR}/.didbootstrap ${ISODIR}/vn.which
407
408 realclean:      clean
409         rm -rf ${OBJSYS}/${KERNCONF}
410         rm -rf ${ISODIR}/packages
411         rm -rf ${ISODIR}/distfiles
412
413 help all:
414         @echo "make [gui] release   - complete build from scratch"
415         @echo "make [gui] quick     - attempt to do an incremental rebuild"
416         @echo "make [gui] realquick - attempt to restart after world & kernel"
417         @echo "make [gui] restartpkgs - attempt to restart at the pkg building stage"
418         @echo ""
419         @echo "DPORTS_EXTRA_PACKAGES may be used to add additional pkgs"
420         @echo "GITHOST may be used to override git.dragonflybsd.org"
421         @echo "IMGSIZE may be used to override the .img (in 512-byte sectors)"
422
423 .PHONY: release quickrel realquickrel
424 .PHONY: installer
425 .PHONY: quick realquick
426 .PHONY: check buildworld1 buildworld2
427 .PHONY: buildkernel1 buildkernel2 buildiso customizeiso mkiso mkimg
428 .PHONY: clean realclean help all srcs
429
430 .include <bsd.prog.mk>