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