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