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