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