Makefile_upgrade.inc: Remove /usr/share/libg++
[dragonfly.git] / test / vkernel / Makefile
1 # Makefile - set up a vkernel environment for testing the vkernel
2 #
3
4 # require it to be specified
5 SRCDIR ?= ${.CURDIR}/../..
6 PHYSMEM ?= 256m
7 NCPUS ?= 2
8 FSTYPE ?=
9 EXTRAOPTS ?=
10
11 all: help
12
13 .if ${MACHINE_ARCH} == "i386"
14 USEKERNEL=VKERNEL
15 .else
16 USEKERNEL=VKERNEL64
17 .endif
18
19 scratch: world kernel root install
20         @echo "Run the environment with:"
21         @echo "make VKDIR=${VKDIR} run"
22
23 quickw: quickworld quickkernel reinstall reinstallkernel
24         @echo "Run the environment with:"
25         @echo "make VKDIR=${VKDIR} run"
26
27 quick: quickkernel reinstallkernel
28         @echo "Run the environment with:"
29         @echo "make VKDIR=${VKDIR} run"
30
31 help:
32         @echo "Setup Instructions:"
33         @echo ""
34         @echo "    setenv ROOTSIZE size (optional)"
35         @echo "    setenv VKDIR target_dir"
36         @echo "    setenv FSTYPE fstype (optional. values:hammer, 4.2BSD)"
37         @echo ""
38         @echo "Meta target components:"
39         @echo ""
40         @echo "    help     - this help"
41         @echo "    clean    - clean up"
42         @echo "    scratch  - build and install everything from scratch"
43         @echo "               (this is absolutely everything)"
44         @echo "    quick    - incremental kernel build & reinstall"
45         @echo "    quickw   - incremental world & kernel build & reinstall"
46         @echo "    run      - run vkernel with VKDIR/root.img"
47         @echo "    mount    - mount VKDIR/root.img at VKDIR/root"
48         @echo "    umount   - unmount"
49         @echo "    fsck     - fsck VKDIR/root.img"
50         @echo ""
51         @echo "Individual target components:"
52         @echo ""
53         @echo "    world             - build the world from scratch"
54         @echo "    root              - create a new, empty root.img"
55         @echo "    install           - install a world & kernel"
56         @echo "                        into root.img"
57         @echo "    leaf              - additional customization"
58         @echo "    kernel            - build vkernel"
59         @echo "    quickworld        - incremental rebuild world"
60         @echo "    quickkernel       - incremental rebuild kernel"
61         @echo "    reinstall         - reinstall world into root.img"
62         @echo "                        (just the installworld piece)"
63         @echo "    reinstallkernel   - reinstall kernel into root.img"
64         @echo ""
65
66 # Unmount everything, de-configured VN, and clean up.
67 # (check handles umounting/deconfiguring)
68 #
69 clean: check
70         rm -rf ${VKDIR}/root.img ${VKDIR}/root
71
72 # Build the world and kernel
73 #
74 #
75 world: checkq
76         cd ${SRCDIR} && make -j 4 buildworld
77
78 kernel: checkq
79         cd ${SRCDIR} && make -j 4 KERNCONF=${USEKERNEL} buildkernel
80
81 nativekernel: checkq
82         cd ${SRCDIR} && make -j 4 KERNCONF=${USEKERNEL} nativekernel
83
84 # Quick build - just rebuild the kernel quickly
85 #
86 #
87 quickworld: checkq
88         cd ${SRCDIR} && make -j 4 quickworld
89
90 quickkernel: checkq
91         cd ${SRCDIR} && make -j 4 KERNCONF=${USEKERNEL} quickkernel
92
93 # Build and mount an empty filesystem for the emulated root disk
94 #
95 # NOTE: root must umount when done because a later dependency may
96 #       have a dependency on mount.
97 #
98 root:   check
99         vnconfig -c -T -S ${ROOTSIZE} -s labels \
100             `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
101         dd if=/dev/zero of=/dev/`cat ${VKDIR}/vn.which` bs=32k count=4
102         fdisk -IB `cat ${VKDIR}/vn.which`
103         disklabel -r -w `cat ${VKDIR}/vn.which`s1 auto
104         disklabel `cat ${VKDIR}/vn.which`s1 > ${VKDIR}/label.tmp
105         echo 'a: * 0 ${FSTYPE}' >> ${VKDIR}/label.tmp
106         disklabel -R `cat ${VKDIR}/vn.which`s1 ${VKDIR}/label.tmp
107         disklabel -B `cat ${VKDIR}/vn.which`s1
108         ${NEWFS_CMD} ${NEWFS_ARGS} /dev/`cat ${VKDIR}/vn.which`s1a
109         mkdir -p ${VKDIR}/root
110         vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
111
112 mount: check
113         vnconfig -c -s labels `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
114 .       if ${FSTYPE} == "4.2BSD"
115                 fsck -p /dev/`cat ${VKDIR}/vn.which`s1a
116 .       endif
117         ${MOUNT_CMD} /dev/`cat ${VKDIR}/vn.which`s1a ${VKDIR}/root
118         @echo "Mounted ${VKDIR}/root"
119
120 umount: check
121
122 fsck: check
123         vnconfig -c -s labels `cat ${VKDIR}/vn.which` ${VKDIR}/root.img
124         fsck -y /dev/`cat ${VKDIR}/vn.which`s1a
125         make umount
126
127 # Install a fresh world & distribution, and kernel
128 #
129 install: mount
130         cd ${SRCDIR} && \
131             make -j 4 DESTDIR=${VKDIR}/root NO_BACKUP=TRUE installworld
132         cd ${SRCDIR}/etc && \
133             make -j 4 DESTDIR=${VKDIR}/root distribution
134         echo '/dev/vkd0s1a      /       ufs     rw      1 1' > ${VKDIR}/root/etc/fstab
135         echo 'proc              /proc   procfs  rw      0 0' >> ${VKDIR}/root/etc/fstab
136         echo 'vfs.root.mountfrom="ufs:vkd0s1a"' > ${VKDIR}/root/boot/loader.conf
137         #(egrep -v '^console' ${VKDIR}/root/etc/ttys; echo 'console "/usr/libexec/getty Pc"     cons25  on      secure') > ${VKDIR}/root/etc/ttys.new
138         #mv -f ${VKDIR}/root/etc/ttys.new ${VKDIR}/root/etc/ttys
139         cd ${SRCDIR} && \
140             make -j 4 \
141                  DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
142                  installkernel
143         cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
144
145 leaf: mount
146         echo 'ifconfig_vke0="up"' > ${VKDIR}/root/etc/rc.conf
147         echo 'defaultrouter="10.26.0.1"' >> ${VKDIR}/root/etc/rc.conf
148         echo 'search dragonflybsd.org backplane.com' > ${VKDIR}/root/etc/resolv.conf
149         echo 'nameserver 10.0.0.25' >> ${VKDIR}/root/etc/resolv.conf
150         echo 'nameserver 10.0.0.2' >> ${VKDIR}/root/etc/resolv.conf
151         echo 'nameserver 8.8.8.8' >> ${VKDIR}/root/etc/resolv.conf
152         make umount
153         chmod 644 /build/vkernel/root.img
154
155 # Quick reinstall - just install a new kernel on top of an existing image
156 #
157 #
158 reinstall: mount
159         cd ${SRCDIR} && \
160             make -j 4 DESTDIR=${VKDIR}/root NO_BACKUP=TRUE installworld
161
162 reinstallkernel: mount
163         cd ${SRCDIR} && \
164             make -j 4 DESTDIR=${VKDIR}/root KERNCONF=${USEKERNEL} \
165                  installkernel
166         cp ${VKDIR}/root/boot/kernel/kernel ${VKDIR}/vkernel
167
168 sysloader: mount
169         cp /boot/loader ${VKDIR}/root/boot/loader
170         sync
171
172 # Run the vkernel on our image.  Make sure we are unmounted so
173 # we do not compete against the emulated kernel when writing to root.img.
174 # (check does this for us)
175 #
176 run: check
177         mkdir -p /var/vkernel
178         sysctl vm.vkernel_enable=1
179         cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} \
180                         -r root.img -U -v \
181                         -I /var/run/vknet ${EXTRAOPTS}
182
183 # When running w/ a NFS root
184 #
185 NFS_IP?= 10.0.0.53
186 NFS_NETMASK?= 255.255.255.0
187 NFS_ROOT_IP?= 10.0.0.1
188 NFS_ROOT_PATH?= /netboot2
189
190 run_nfsroot: check
191         cd ${VKDIR} && ./vkernel -m ${PHYSMEM} -n ${NCPUS} -U -v \
192                         -I /var/run/vknet \
193                         -e 'boot.netif.ip=${NFS_IP}:boot.netif.netmask=${NFS_NETMASK}:boot.netif.name=vke0:boot.nfsroot.server=${NFS_ROOT_IP}:boot.nfsroot.path=${NFS_ROOT_PATH}'
194
195 # Make sure we are not mounted and the VN device is unconfigured,
196 #
197 # Find an unused VN device but do not do anything with it yet.
198 #
199 checkq:
200 .if !defined(VKDIR)
201         @(echo "must specify VKDIR=target or as an environment variable"; /usr/bin/false)
202 .endif
203
204 .if exists(${VKDIR})
205         @echo "${VKDIR} found"
206 .else
207         mkdir -p ${VKDIR}
208 .endif
209
210 .if ${FSTYPE} == "hammer"
211 NEWFS_CMD = newfs_${FSTYPE}
212 NEWFS_ARGS = -L VKROOT -f
213 MOUNT_CMD = mount_${FSTYPE}
214 ROOTSIZE ?= 5G
215 .else
216 FSTYPE = 4.2BSD
217 NEWFS_CMD = newfs
218 NEWFS_ARGS =
219 MOUNT_CMD = mount
220 ROOTSIZE ?= 2G
221 .endif
222
223
224 check: checkq
225 .if exists(${VKDIR}/vn.which)
226         -umount ${VKDIR}/root > /dev/null 2>&1
227         -vnconfig -u `cat ${VKDIR}/vn.which` > /dev/null 2>&1
228         rm -f ${VKDIR}/vn.which
229 .endif
230         (vnconfig -l | fgrep "not in use" > /dev/null) || \
231             (echo "Cannot find unused VN"; /usr/bin/false)
232         vnconfig -l | fgrep "not in use" | \
233             cut -f 1 -d : | head -1 > ${VKDIR}/vn.which
234         egrep '^vn' ${VKDIR}/vn.which > /dev/null || \
235             (echo "VN device selection is bad"; /usr/bin/false)