test/amd64: build and install modules
[dragonfly.git] / test / amd64 / Makefile
CommitLineData
edbdff6b
MD
1# Makefile - manage a qemu system for testing 64 bit DragonFly builds
2#
3# This Makefile will patch and build qemu, do all necessary world and
4# kernel builds, and create a 64 bit root.img disk.
5#
6
4166d988 7# require it to be specified
f50a0df7 8SRCDIR ?= ${.CURDIR}/../..
671df0de 9QEMU ?= qemu-0.10.6
7470b4a3 10ROOTSIZE ?= 2048M
edbdff6b 11
11526d93
MD
12.if defined(WITHSDL)
13QEMU_SDL_OPT ?= --extra-cflags=-I/usr/pkg/include \
14 --extra-ldflags=-L/usr/pkg/lib
15.else
16QEMU_SDL_OPT ?= --disable-sdl
17.endif
18
edbdff6b
MD
19all: help
20
d8ab33fe 21scratch: qemu world32 world64 kernel64 root64 install64 sysloader
edbdff6b 22 @echo "Run the environment with:"
0d9f5ab9 23 @echo "make QEMUDIR=${QEMUDIR} run"
edbdff6b 24
d8ab33fe 25quickw: quickworld64 quickkernel64 reinstall64 reinstallkernel64 sysloader
edbdff6b 26 @echo "Run the environment with:"
0d9f5ab9 27 @echo "make QEMUDIR=${QEMUDIR} run"
edbdff6b 28
0d9f5ab9
MD
29quick: quickkernel64 reinstallkernel64
30 @echo "Run the environment with:"
31 @echo "make QEMUDIR=${QEMUDIR} run"
edbdff6b
MD
32
33help:
d8ab33fe
MD
34 @echo "Setup Instructions:"
35 @echo ""
36 @echo " setenv QEMUDIR target_dir"
37 @echo ""
38 @echo "Meta target components:"
39 @echo ""
0d9f5ab9
MD
40 @echo " help - this help"
41 @echo " clean - clean up"
d8ab33fe
MD
42 @echo " scratch - build and install everything from scratch"
43 @echo " (this is absolutely everything, except gdb64)"
44 @echo " quick - incremental kernel build & reinstall"
45 @echo " quickw - incremental world & kernel build & reinstall"
11526d93
MD
46 @echo " run - run qemu with QEMUDIR/root.img - curses mode"
47 @echo " xrun - run qemu with QEMUDIR/root.img - X Window mode"
d8ab33fe 48 @echo " mount - mount QEMUDIR/root.img at QEMUDIR/root"
0d9f5ab9
MD
49 @echo " umount - unmount"
50 @echo " gdb64 - create /usr/loca/bin/gdb64 - debug 64 bit bins"
d8ab33fe
MD
51 @echo ""
52 @echo "Individual target components:"
53 @echo ""
54 @echo " qemu - fetch, patch, and build qemu"
11526d93 55 @echo " Specify WITHSDL=yes to build X support"
d8ab33fe
MD
56 @echo " world32 - build the 32 bit world from scratch"
57 @echo " world64 - build the 64 bit world from scratch"
58 @echo " kernel64 - build the 64 bit kernel from scratch"
59 @echo " root64 - create a new, empty root.img"
60 @echo " install64 - install a 64 bit world & kernel"
61 @echo " into root.img"
62 @echo " quickworld64 - incremental rebuild world64"
63 @echo " quickkernel64 - incremental rebuild kernel64"
64 @echo " reinstall64 - reinstall world64 into root.img"
65 @echo " (just the installworld piece)"
66 @echo " reinstallkernel64 - reinstall kernel64 into root.img"
67 @echo " sysloader - reinstall 32-bit system loader"
68 @echo " (in case the 64 bit loader fails,"
69 @echo " the 32 bit loader can be used)"
70 @echo ""
edbdff6b
MD
71
72# Unmount everything, de-configured VN, and clean up.
73# (check handles umounting/deconfiguring)
74#
75clean: check
76 rm -rf ${QEMUDIR}/${QEMU}.tar.gz ${QEMUDIR}/${QEMU} \
edbdff6b
MD
77 ${QEMUDIR}/root.img ${QEMUDIR}/root
78
79# Build qemu for Intel 32 and 64 bit environments
80#
81# If configuring with sdl support from pkgsrc add the following
82# options to the configure command:
83#
84# --extra-cflags=-I/usr/pkg/include
85# --extra-ldflags=-L/usr/pkg/lib
86#
11526d93 87qemu: checkq sdl
edbdff6b
MD
88.if !exists(${QEMUDIR}/${QEMU}.tar.gz)
89 cd ${QEMUDIR} && \
90 fetch http://download.savannah.gnu.org/releases/qemu/${QEMU}.tar.gz
91.endif
edbdff6b
MD
92 rm -rf ${QEMUDIR}/${QEMU}
93 cd ${QEMUDIR} && tar xvzpf ${QEMU}.tar.gz
671df0de 94 cd ${QEMUDIR}/${QEMU} && patch -p1 < ${.CURDIR}/qemu.patch
edbdff6b 95 cd ${QEMUDIR}/${QEMU} && \
11526d93
MD
96 ./configure --disable-gfx-check \
97 ${QEMU_SDL_OPT} \
edbdff6b
MD
98 --disable-kqemu \
99 --enable-system \
100 --disable-aio \
101 --disable-kvm \
102 --target-list=i386-softmmu,x86_64-softmmu
671df0de
SS
103 cd ${QEMUDIR}/${QEMU} && gmake
104 cd ${QEMUDIR}/${QEMU} && gmake install
edbdff6b 105
11526d93
MD
106# SDL dependancies
107#
108sdl:
109.if defined(WITHSDL)
110 @echo "SDL enabled"
111 pkg_info libX11 > /dev/null 2>&1 || pkg_radd libX11
112 pkg_info SDL > /dev/null 2>&1 || pkg_radd SDL
113.else
114 @echo "SDL not enabled"
115.endif
116
edbdff6b
MD
117# Build the 32 and 64 bit worlds and the 64 bit kernel
118#
119#
4166d988 120world32: checkq
edbdff6b
MD
121 cd ${SRCDIR} && make -j 4 buildworld
122
4166d988 123world64: checkq
edbdff6b 124 cd ${SRCDIR} && \
d8280c36
MD
125 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 NO_GCC44=1 \
126 buildworld
edbdff6b 127
4166d988 128kernel64: checkq
edbdff6b
MD
129 cd ${SRCDIR} && \
130 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
131 buildkernel
132
133# Quick build - just rebuild the kernel quickly
134#
135#
4166d988 136quickworld64: checkq
0d9f5ab9 137 cd ${SRCDIR} && \
d8280c36
MD
138 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 NO_GCC44=1 \
139 quickworld
0d9f5ab9 140
4166d988 141quickkernel64: checkq
edbdff6b
MD
142 cd ${SRCDIR} && \
143 make TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 KERNCONF=JG64 \
144 quickkernel
145
146# Build and mount an empty filesystem for the emulated root disk
147#
0d210a64
MD
148# NOTE: root64 must umount when done because a later dependency may
149# have a dependency on mount.
edbdff6b
MD
150#
151root64: check
152 vnconfig -c -T -S ${ROOTSIZE} -s labels \
153 `cat ${QEMUDIR}/vn.which` ${QEMUDIR}/root.img
154 dd if=/dev/zero of=/dev/`cat ${QEMUDIR}/vn.which` bs=32k count=4
155 fdisk -IB `cat ${QEMUDIR}/vn.which`
156 disklabel -r -w `cat ${QEMUDIR}/vn.which`s1 auto
157 disklabel `cat ${QEMUDIR}/vn.which`s1 > ${QEMUDIR}/label.tmp
158 echo 'a: * 0 4.2BSD' >> ${QEMUDIR}/label.tmp
159 disklabel -R `cat ${QEMUDIR}/vn.which`s1 ${QEMUDIR}/label.tmp
160 disklabel -B `cat ${QEMUDIR}/vn.which`s1
161 newfs /dev/`cat ${QEMUDIR}/vn.which`s1a
162 mkdir -p ${QEMUDIR}/root
0d210a64 163 vnconfig -u `cat ${QEMUDIR}/vn.which` > /dev/null 2>&1
edbdff6b
MD
164
165mount: check
166 vnconfig -c -s labels `cat ${QEMUDIR}/vn.which` ${QEMUDIR}/root.img
0d9f5ab9 167 fsck -p /dev/`cat ${QEMUDIR}/vn.which`s1a
edbdff6b
MD
168 mount /dev/`cat ${QEMUDIR}/vn.which`s1a ${QEMUDIR}/root
169 @echo "Mounted ${QEMUDIR}/root"
170
171umount: check
172
173# Install a fresh 64 bit world & distribution, and kernel
174#
175#
176install64: mount
177 cd ${SRCDIR} && \
178 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
6e9ae5ae 179 DESTDIR=${QEMUDIR}/root NO_GCC44=1 installworld
edbdff6b
MD
180 cd ${SRCDIR}/etc && \
181 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
182 DESTDIR=${QEMUDIR}/root distribution
0c00c411 183 echo '/dev/ad0s1a / ufs rw 1 1' > ${QEMUDIR}/root/etc/fstab
edbdff6b 184 echo 'proc /proc procfs rw 0 0' >> ${QEMUDIR}/root/etc/fstab
0c00c411 185 echo 'vfs.root.mountfrom="ufs:ad0s1a"' > ${QEMUDIR}/root/boot/loader.conf
edbdff6b
MD
186 (egrep -v '^console' ${QEMUDIR}/root/etc/ttys; echo 'console "/usr/libexec/getty Pc" cons25 on secure') > ${QEMUDIR}/root/etc/ttys.new
187 mv -f ${QEMUDIR}/root/etc/ttys.new ${QEMUDIR}/root/etc/ttys
188 cd ${SRCDIR} && \
189 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
190 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
edbdff6b 191 installkernel
d8ab33fe
MD
192 @echo "WARNING: 64 bit loader installed, if it doesn't work"
193 @echo " then use 'sysloader' to install the 32 bit one"
edbdff6b
MD
194
195# Quick reinstall - just install a new kernel on top of an existing image
196#
197#
198reinstall64: mount
d8ab33fe
MD
199 @echo "NOTE: Installing native 32 bit loader into root.img."
200 @echo " This loader should still be able to boot the"
201 @echo " 64 bit kernel"
edbdff6b
MD
202 cd ${SRCDIR} && \
203 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
340f8695 204 DESTDIR=${QEMUDIR}/root NO_GCC44=1 installworld
0d9f5ab9
MD
205
206reinstallkernel64: mount
207 cd ${SRCDIR} && \
208 make -j 4 TARGET_ARCH=amd64 TARGET_PLATFORM=pc64 \
edbdff6b 209 DESTDIR=${QEMUDIR}/root KERNCONF=JG64 \
edbdff6b
MD
210 installkernel
211
d8ab33fe
MD
212sysloader: mount
213 cp /boot/loader ${QEMUDIR}/root/boot/loader
214 sync
215
edbdff6b
MD
216# Run qemu on our image in 64 bit mode. Make sure we are unmounted so
217# we do not compete against the emulated kernel when writing to root.img.
218# (check does this for us)
219#
220run: check
b0fc2716
MD
221 cd ${QEMUDIR} && qemu-system-x86_64 -curses -hda ${QEMUDIR}/root.img \
222 -m 128 -no-fd-bootchk
edbdff6b 223
11526d93
MD
224xrun:
225.if !defined(DISPLAY)
226 @(echo "Variable DISPLAY not set. Is X running?"; exit 1)
227.endif
228 cd ${QEMUDIR} && qemu-system-x86_64 -hda ${QEMUDIR}/root.img \
229 -m 128 -no-fd-bootchk
230
edbdff6b 231rungdb: check
b0fc2716 232 @echo "RUN WITH: run -curses -hda root.img"
edbdff6b
MD
233 cd ${QEMUDIR} && gdb qemu-system-x86_64
234
0d9f5ab9
MD
235# build a gdb capable of debugging 64 bit binaries
236#
237gdb64:
238 cd /usr/src/gnu/usr.bin/gdb && (make clean; make TARGET_ARCH=amd64)
239 cp /usr/obj/usr/src/gnu/usr.bin/gdb/gdb/gdb /usr/local/bin/gdb64
240 cd /usr/src/gnu/usr.bin/gdb && make clean
edbdff6b
MD
241
242# Make sure we are not mounted and the VN device is unconfigured,
243#
244# Find an unused VN device but do not do anything with it yet.
245#
246checkq:
247.if !defined(QEMUDIR)
4166d988
MD
248 @(echo "must specify QEMUDIR=target or as an environment variable"; exit 1)
249.endif
edbdff6b
MD
250.if exists(${QEMUDIR})
251 @echo "${QEMUDIR} found"
252.else
253 mkdir -p ${QEMUDIR}
254.endif
255
256check: checkq
257.if exists(${QEMUDIR}/vn.which)
258 -umount ${QEMUDIR}/root > /dev/null 2>&1
259 -vnconfig -u `cat ${QEMUDIR}/vn.which` > /dev/null 2>&1
260 rm -f ${QEMUDIR}/vn.which
261.endif
262 (vnconfig -l | fgrep "not in use" > /dev/null) || \
263 (echo "Cannot find unused VN"; exit 1)
264 vnconfig -l | fgrep "not in use" | \
265 cut -f 1 -d : | head -1 > ${QEMUDIR}/vn.which
266 egrep '^vn' ${QEMUDIR}/vn.which > /dev/null || \
267 (echo "VN device selection is bad"; exit 1)