ia64/xen-unstable

view stubdom/Makefile @ 18420:05c7efee10a1

cross-install: Only apply in tools directory, and automatically wrap $INSTALL.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Sat Aug 30 08:36:02 2008 +0100 (2008-08-30)
parents 48b33c4275f1
children 31e06b3ccf53
line source
1 XEN_ROOT = ..
2 MINI_OS = $(XEN_ROOT)/extras/mini-os
4 export XEN_OS=MiniOS
6 export stubdom=y
7 export debug=y
8 include $(XEN_ROOT)/Config.mk
10 override CONFIG_QEMU=ioemu
12 IOEMU_OPTIONS=--disable-sdl --disable-opengl --disable-vnc-tls --disable-brlapi --disable-kqemu
13 ZLIB_URL?=http://www.zlib.net
14 ZLIB_VERSION=1.2.3
15 LIBPCI_URL?=http://www.kernel.org/pub/software/utils/pciutils
16 LIBPCI_VERSION=2.2.9
17 NEWLIB_URL?=ftp://sources.redhat.com/pub/newlib
18 NEWLIB_VERSION=1.16.0
19 LWIP_URL?=http://download.savannah.gnu.org/releases/lwip
20 LWIP_VERSION=1.3.0
21 GRUB_URL?=http://alpha.gnu.org/gnu/grub
22 GRUB_VERSION=0.97
24 WGET=wget -c
26 GNU_TARGET_ARCH:=$(XEN_TARGET_ARCH)
27 ifeq ($(XEN_TARGET_ARCH),x86_32)
28 GNU_TARGET_ARCH:=i686
29 endif
31 ifeq ($(GNU_TARGET_ARCH), i686)
32 TARGET_CFLAGS=
33 NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
34 STUBDOM_SUPPORTED=1
35 endif
36 ifeq ($(GNU_TARGET_ARCH), x86_64)
37 TARGET_CFLAGS=-mno-red-zone
38 NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
39 STUBDOM_SUPPORTED=1
40 endif
41 ifeq ($(GNU_TARGET_ARCH), ia64)
42 TARGET_CFLAGS=-mconstant-gp
43 endif
45 CROSS_ROOT=cross-root-$(GNU_TARGET_ARCH)
46 CROSS_PREFIX=$(CURDIR)/$(CROSS_ROOT)
48 # Disable PIE/SSP if GCC supports them. They can break us.
49 TARGET_CFLAGS += $(CFLAGS)
50 TARGET_CPPFLAGS += $(CPPFLAGS)
51 TARGET_CFLAGS += $(call cc-option,$(CC),-nopie,)
52 TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
53 TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
55 # Do not use host headers and libs
56 GCC_INSTALL = $(shell LANG=C gcc -print-search-dirs | sed -n -e 's/install: \(.*\)/\1/p')
57 TARGET_CPPFLAGS += -U __linux__ -U __FreeBSD__ -U __sun__
58 TARGET_CPPFLAGS += -nostdinc
59 TARGET_CPPFLAGS += -isystem $(CURDIR)/$(MINI_OS)/include/posix
60 TARGET_CPPFLAGS += -isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include
61 TARGET_CPPFLAGS += -isystem $(GCC_INSTALL)include
62 TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip/src/include
63 TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip/src/include/ipv4
64 TARGET_CPPFLAGS += -I$(CURDIR)/include
66 TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
68 TARGETS=ioemu c caml grub
70 .PHONY: all
71 all: build
72 ifeq ($(STUBDOM_SUPPORTED),1)
73 build: ioemu-stubdom c-stubdom pv-grub
74 else
75 build:
76 endif
78 ##############
79 # Cross-newlib
80 ##############
82 newlib-$(NEWLIB_VERSION).tar.gz:
83 $(WGET) $(NEWLIB_URL)/$@
85 newlib-$(NEWLIB_VERSION): newlib-$(NEWLIB_VERSION).tar.gz
86 tar xzf $<
87 patch -d $@ -p0 < newlib.patch
88 touch $@
90 NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
91 .PHONY: cross-newlib
92 cross-newlib: $(NEWLIB_STAMPFILE)
93 $(NEWLIB_STAMPFILE): mk-headers-$(XEN_TARGET_ARCH) newlib-$(NEWLIB_VERSION)
94 mkdir -p newlib-$(XEN_TARGET_ARCH)
95 ( cd newlib-$(XEN_TARGET_ARCH) && \
96 CC_FOR_TARGET="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(NEWLIB_CFLAGS)" AR_FOR_TARGET=$(AR) LD_FOR_TARGET=$(LD) RANLIB_FOR_TARGET=$(RANLIB) ../newlib-$(NEWLIB_VERSION)/configure --prefix=$(CROSS_PREFIX) --verbose --target=$(GNU_TARGET_ARCH)-xen-elf --enable-newlib-io-long-long --disable-multilib && \
97 $(MAKE) && \
98 DESTDIR= $(MAKE) install )
100 ############
101 # Cross-zlib
102 ############
104 zlib-$(ZLIB_VERSION).tar.gz:
105 $(WGET) $(ZLIB_URL)/$@
107 zlib-$(XEN_TARGET_ARCH): zlib-$(ZLIB_VERSION).tar.gz
108 tar xzf $<
109 mv zlib-$(ZLIB_VERSION) $@
111 ZLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libz.a
112 .PHONY: cross-zlib
113 cross-zlib: $(ZLIB_STAMPFILE)
114 $(ZLIB_STAMPFILE): zlib-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
115 ( cd $< && \
116 CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" CC=$(CC) ./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
117 $(MAKE) libz.a && \
118 $(MAKE) install )
120 ##############
121 # Cross-libpci
122 ##############
124 pciutils-$(LIBPCI_VERSION).tar.bz2:
125 $(WGET) $(LIBPCI_URL)/$@
127 pciutils-$(XEN_TARGET_ARCH): pciutils-$(LIBPCI_VERSION).tar.bz2
128 tar xjf $<
129 mv pciutils-$(LIBPCI_VERSION) $@
130 patch -d $@ -p1 < pciutils.patch
131 touch $@
133 LIBPCI_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpci.a
134 .PHONY: cross-libpci
135 cross-libpci: $(LIBPCI_STAMPFILE)
136 $(LIBPCI_STAMPFILE): pciutils-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) $(ZLIB_STAMPFILE)
137 ( cd $< && \
138 cp ../libpci.config.h lib/config.h && \
139 echo '#define PCILIB_VERSION "$(LIBPCI_VERSION)"' >> lib/config.h && \
140 cp ../libpci.config.mak lib/config.mk && \
141 $(MAKE) CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(realpath $(MINI_OS)/include)" lib/libpci.a && \
142 $(INSTALL_DATA) lib/libpci.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ && \
143 $(INSTALL_DIR) $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci && \
144 $(INSTALL_DATA) lib/config.h lib/header.h lib/pci.h lib/types.h $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci/ \
145 )
147 ######
148 # lwIP
149 ######
151 lwip-$(LWIP_VERSION).tar.gz:
152 $(WGET) $(LWIP_URL)/$@
154 lwip-$(XEN_TARGET_ARCH): lwip-$(LWIP_VERSION).tar.gz
155 tar xzf $<
156 mv lwip $@
157 patch -d $@ -p0 < lwip.patch-cvs
158 touch $@
160 #######
161 # Links
162 #######
164 .PHONY: $(CROSS_ROOT)
165 $(CROSS_ROOT): cross-newlib cross-zlib cross-libpci
167 mk-headers-$(XEN_TARGET_ARCH):
168 mkdir -p include/xen && \
169 ln -sf $(addprefix ../../,$(wildcard $(XEN_ROOT)/xen/include/public/*.h)) include/xen && \
170 ln -sf $(addprefix ../../$(XEN_ROOT)/xen/include/public/,arch-ia64 arch-x86 hvm io xsm) include/xen && \
171 ( [ -h include/xen/sys ] || ln -sf ../../$(XEN_ROOT)/tools/include/xen-sys/MiniOS include/xen/sys ) && \
172 mkdir -p include/xen-foreign && \
173 ln -sf $(addprefix ../../,$(wildcard $(XEN_ROOT)/tools/include/xen-foreign/*)) include/xen-foreign/ && \
174 $(MAKE) -C include/xen-foreign/ && \
175 ( [ -h include/xen/foreign ] || ln -sf ../xen-foreign include/xen/foreign )
176 mkdir -p libxc-$(XEN_TARGET_ARCH)
177 [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
178 ln -sf ../$(XEN_ROOT)/tools/libxc/*.h . && \
179 ln -sf ../$(XEN_ROOT)/tools/libxc/*.c . && \
180 ln -sf ../$(XEN_ROOT)/tools/libxc/Makefile . )
181 mkdir -p libxc-$(XEN_TARGET_ARCH)/$(XEN_TARGET_ARCH)
182 [ -h libxc-$(XEN_TARGET_ARCH)/$(XEN_TARGET_ARCH) ] || ( cd libxc-$(XEN_TARGET_ARCH)/$(XEN_TARGET_ARCH) && \
183 ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.c . && \
184 ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.h . && \
185 ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/Makefile . )
186 mkdir -p ioemu
187 ifeq ($(CONFIG_QEMU),ioemu)
188 [ -h ioemu/Makefile ] || ( cd ioemu && \
189 ln -sf ../$(XEN_ROOT)/tools/ioemu/* .)
190 else
191 [ -h ioemu/Makefile ] || ( cd ioemu && \
192 ln -sf $(CONFIG_QEMU)/* . && \
193 rm -fr i386-dm && \
194 rm -fr i386-stubdom && \
195 mkdir i386-dm && \
196 mkdir i386-stubdom && \
197 ln -sf $(CONFIG_QEMU)/i386-dm/* i386-dm/ && \
198 ln -sf $(CONFIG_QEMU)/i386-stubdom/* i386-stubdom/ )
199 endif
200 [ ! -h ioemu/config-host.h ] || rm -f ioemu/config-host.h
201 [ ! -h ioemu/config-host.mak ] || rm -f ioemu/config-host.mak
202 $(MAKE) -C $(MINI_OS) links
203 touch mk-headers-$(XEN_TARGET_ARCH)
205 TARGETS_MINIOS=$(addprefix mini-os-$(XEN_TARGET_ARCH)-,$(TARGETS))
206 $(TARGETS_MINIOS): mini-os-%:
207 [ -d $@ ] || \
208 for i in $$(cd $(MINI_OS) ; find . -type d) ; do \
209 mkdir -p $@/$$i ; \
210 done
212 #######
213 # libxc
214 #######
216 .PHONY: libxc
217 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
218 libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a:: cross-zlib
219 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C libxc-$(XEN_TARGET_ARCH)
221 #######
222 # ioemu
223 #######
225 .PHONY: ioemu
226 ioemu: cross-zlib cross-libpci libxc
227 ifeq ($(CONFIG_QEMU),ioemu)
228 [ -f ioemu/config-host.mak ] || \
229 ( cd ioemu ; \
230 XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) CFLAGS="$(TARGET_CFLAGS)" sh configure --prefix=/usr --enable-stubdom $(IOEMU_OPTIONS))
231 CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C ioemu LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) TOOLS=
232 else
233 [ -f ioemu/config-host.mak ] || \
234 ( cd ioemu ; \
235 CONFIG_STUBDOM=yes XEN_ROOT=$(abspath $(XEN_ROOT)) XEN_TARGET_ARCH=$(XEN_TARGET_ARCH) CFLAGS="$(TARGET_CFLAGS)" sh ./xen-setup --cc=$(CC) --disable-gcc-check $(IOEMU_OPTIONS))
236 CPPFLAGS= TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" $(MAKE) -C ioemu LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) TOOLS= CONFIG_STUBDOM=yes
237 endif
239 ######
240 # caml
241 ######
243 .PHONY: caml
244 caml: $(CROSS_ROOT)
245 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH)
247 ###
248 # C
249 ###
251 .PHONY: c
252 c: $(CROSS_ROOT)
253 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH)
255 ######
256 # Grub
257 ######
259 grub-$(GRUB_VERSION).tar.gz:
260 $(WGET) $(GRUB_URL)/$@
262 grub-upstream: grub-$(GRUB_VERSION).tar.gz
263 tar xzf $<
264 mv grub-$(GRUB_VERSION) $@
265 for i in grub.patches/* ; do \
266 patch -d $@ -p1 < $$i ; \
267 done
269 .PHONY: grub
270 grub: grub-upstream $(CROSS_ROOT)
271 mkdir -p grub-$(XEN_TARGET_ARCH)
272 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ OBJ_DIR=$(CURDIR)/grub-$(XEN_TARGET_ARCH)
274 ########
275 # minios
276 ########
278 .PHONY: ioemu-stubdom
279 ifeq ($(CONFIG_QEMU),ioemu)
280 ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-dm-stubdom/qemu.a $(CURDIR)/ioemu/i386-dm-stubdom/libqemu.a
281 else
282 ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a $(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
283 endif
284 ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxc ioemu
285 DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_QEMU $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(APP_OBJS)"
287 CAMLLIB = $(shell ocamlc -where)
288 .PHONY: caml-stubdom
289 caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxc caml
290 DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_CAML $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(CURDIR)/caml/main-caml.o $(CURDIR)/caml/caml.o $(CAMLLIB)/libasmrun.a"
292 .PHONY: c-stubdom
293 c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
294 DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_C $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/c/main.a
296 .PHONY: pv-grub
297 pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
298 DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="-DCONFIG_GRUB $(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
300 #########
301 # install
302 #########
304 ifeq ($(STUBDOM_SUPPORTED),1)
305 install: install-readme install-ioemu install-grub
306 else
307 install:
308 endif
310 install-readme:
311 $(INSTALL_DIR) $(DESTDIR)$(DOCDIR)
312 $(INSTALL_DATA) README $(DESTDIR)$(DOCDIR)/README.stubdom
314 install-ioemu: ioemu-stubdom
315 $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/bin"
316 $(INSTALL_PROG) stubdom-dm "$(DESTDIR)/usr/lib/xen/bin"
317 $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/boot"
318 $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-ioemu/mini-os.gz "$(DESTDIR)/usr/lib/xen/boot/ioemu-stubdom.gz"
320 install-grub: pv-grub
321 $(INSTALL_DIR) "$(DESTDIR)/usr/lib/xen/boot"
322 $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)/usr/lib/xen/boot/pv-grub-$(XEN_TARGET_ARCH).gz"
324 #######
325 # clean
326 #######
328 # Only clean the libxc/ioemu/mini-os part
329 .PHONY: clean
330 clean:
331 rm -fr mini-os-$(XEN_TARGET_ARCH)-ioemu
332 rm -fr mini-os-$(XEN_TARGET_ARCH)-c
333 rm -fr mini-os-$(XEN_TARGET_ARCH)-caml
334 rm -fr mini-os-$(XEN_TARGET_ARCH)-grub
335 $(MAKE) -C caml clean
336 $(MAKE) -C c clean
337 rm -fr grub-$(XEN_TARGET_ARCH)
338 [ ! -d libxc-$(XEN_TARGET_ARCH) ] || $(MAKE) -C libxc-$(XEN_TARGET_ARCH) clean
339 [ ! -d ioemu ] || $(MAKE) -C ioemu clean
341 # clean the cross-compilation result
342 .PHONY: crossclean
343 crossclean: clean
344 rm -fr $(CROSS_ROOT)
345 rm -fr newlib-$(XEN_TARGET_ARCH)
346 rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
347 rm -fr libxc-$(XEN_TARGET_ARCH) ioemu
348 rm -f mk-headers-$(XEN_TARGET_ARCH)
350 # clean patched sources
351 .PHONY: patchclean
352 patchclean: crossclean
353 rm -fr newlib-$(NEWLIB_VERSION)
354 rm -fr lwip-$(XEN_TARGET_ARCH)
355 rm -fr grub-upstream
357 # clean downloads
358 .PHONY: downloadclean
359 downloadclean: patchclean
360 rm -f newlib-$(NEWLIB_VERSION).tar.gz
361 rm -f zlib-$(ZLIB_VERSION).tar.gz
362 rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
363 rm -f grub-$(GRUB_VERSION).tar.gz
364 rm -f lwip-$(LWIP_VERSION).tar.gz
366 .PHONY: distclean
367 distclean: downloadclean