ia64/xen-unstable

view stubdom/Makefile @ 19404:633e08774dab

build system cleanup - get rid of some hardcoded paths

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 19 14:01:56 2009 +0000 (2009-03-19)
parents 2039e8271051
children 6ad2b1ded12f
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 #ZLIB_URL?=http://www.zlib.net
11 ZLIB_URL=$(XEN_EXTFILES_URL)
12 ZLIB_VERSION=1.2.3
14 #LIBPCI_URL?=http://www.kernel.org/pub/software/utils/pciutils
15 LIBPCI_URL?=$(XEN_EXTFILES_URL)
16 LIBPCI_VERSION=2.2.9
18 #NEWLIB_URL?=ftp://sources.redhat.com/pub/newlib
19 NEWLIB_URL?=$(XEN_EXTFILES_URL)
20 NEWLIB_VERSION=1.16.0
22 #LWIP_URL?=http://download.savannah.gnu.org/releases/lwip
23 LWIP_URL?=$(XEN_EXTFILES_URL)
24 LWIP_VERSION=1.3.0
26 #GRUB_URL?=http://alpha.gnu.org/gnu/grub
27 GRUB_URL?=$(XEN_EXTFILES_URL)
28 GRUB_VERSION=0.97
30 WGET=wget -c
32 GNU_TARGET_ARCH:=$(XEN_TARGET_ARCH)
33 ifeq ($(XEN_TARGET_ARCH),x86_32)
34 GNU_TARGET_ARCH:=i686
35 endif
37 ifeq ($(GNU_TARGET_ARCH), i686)
38 TARGET_CFLAGS=
39 NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
40 STUBDOM_SUPPORTED=1
41 endif
42 ifeq ($(GNU_TARGET_ARCH), x86_64)
43 TARGET_CFLAGS=-mno-red-zone
44 NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
45 STUBDOM_SUPPORTED=1
46 endif
47 ifeq ($(GNU_TARGET_ARCH), ia64)
48 TARGET_CFLAGS=-mconstant-gp
49 endif
51 CROSS_ROOT=cross-root-$(GNU_TARGET_ARCH)
52 CROSS_PREFIX=$(CURDIR)/$(CROSS_ROOT)
54 # Disable PIE/SSP if GCC supports them. They can break us.
55 TARGET_CFLAGS += $(CFLAGS)
56 TARGET_CPPFLAGS += $(CPPFLAGS)
57 TARGET_CFLAGS += $(call cc-option,$(CC),-nopie,)
58 TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector,)
59 TARGET_CFLAGS += $(call cc-option,$(CC),-fno-stack-protector-all,)
61 # Do not use host headers and libs
62 GCC_INSTALL = $(shell LANG=C gcc -print-search-dirs | sed -n -e 's/install: \(.*\)/\1/p')
63 TARGET_CPPFLAGS += -U __linux__ -U __FreeBSD__ -U __sun__
64 TARGET_CPPFLAGS += -nostdinc
65 TARGET_CPPFLAGS += -isystem $(CURDIR)/$(MINI_OS)/include/posix
66 TARGET_CPPFLAGS += -isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include
67 TARGET_CPPFLAGS += -isystem $(GCC_INSTALL)include
68 TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include
69 TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include/ipv4
70 TARGET_CPPFLAGS += -I$(CURDIR)/include
72 TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
74 TARGETS=ioemu c caml grub
76 .PHONY: all
77 all: build
78 ifeq ($(STUBDOM_SUPPORTED),1)
79 build: ioemu-stubdom c-stubdom pv-grub
80 else
81 build:
82 endif
84 ##############
85 # Cross-newlib
86 ##############
88 newlib-$(NEWLIB_VERSION).tar.gz:
89 $(WGET) $(NEWLIB_URL)/$@
91 newlib-$(NEWLIB_VERSION): newlib-$(NEWLIB_VERSION).tar.gz
92 tar xzf $<
93 patch -d $@ -p0 < newlib.patch
94 touch $@
96 NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
97 .PHONY: cross-newlib
98 cross-newlib: $(NEWLIB_STAMPFILE)
99 $(NEWLIB_STAMPFILE): mk-headers-$(XEN_TARGET_ARCH) newlib-$(NEWLIB_VERSION)
100 mkdir -p newlib-$(XEN_TARGET_ARCH)
101 ( cd newlib-$(XEN_TARGET_ARCH) && \
102 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 && \
103 $(MAKE) && \
104 DESTDIR= $(MAKE) install )
106 ############
107 # Cross-zlib
108 ############
110 zlib-$(ZLIB_VERSION).tar.gz:
111 $(WGET) $(ZLIB_URL)/$@
113 zlib-$(XEN_TARGET_ARCH): zlib-$(ZLIB_VERSION).tar.gz
114 tar xzf $<
115 mv zlib-$(ZLIB_VERSION) $@
117 ZLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libz.a
118 .PHONY: cross-zlib
119 cross-zlib: $(ZLIB_STAMPFILE)
120 $(ZLIB_STAMPFILE): zlib-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
121 ( cd $< && \
122 CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" CC=$(CC) ./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
123 $(MAKE) libz.a && \
124 $(MAKE) install )
126 ##############
127 # Cross-libpci
128 ##############
130 pciutils-$(LIBPCI_VERSION).tar.bz2:
131 $(WGET) $(LIBPCI_URL)/$@
133 pciutils-$(XEN_TARGET_ARCH): pciutils-$(LIBPCI_VERSION).tar.bz2
134 tar xjf $<
135 mv pciutils-$(LIBPCI_VERSION) $@
136 patch -d $@ -p1 < pciutils.patch
137 touch $@
139 LIBPCI_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpci.a
140 .PHONY: cross-libpci
141 cross-libpci: $(LIBPCI_STAMPFILE)
142 $(LIBPCI_STAMPFILE): pciutils-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) $(ZLIB_STAMPFILE)
143 ( cd $< && \
144 cp ../libpci.config.h lib/config.h && \
145 echo '#define PCILIB_VERSION "$(LIBPCI_VERSION)"' >> lib/config.h && \
146 cp ../libpci.config.mak lib/config.mk && \
147 $(MAKE) CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(realpath $(MINI_OS)/include)" lib/libpci.a && \
148 $(INSTALL_DATA) lib/libpci.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ && \
149 $(INSTALL_DIR) $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci && \
150 $(INSTALL_DATA) lib/config.h lib/header.h lib/pci.h lib/types.h $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci/ \
151 )
153 ######
154 # lwIP
155 ######
157 lwip-$(LWIP_VERSION).tar.gz:
158 $(WGET) $(LWIP_URL)/$@
160 lwip-$(XEN_TARGET_ARCH): lwip-$(LWIP_VERSION).tar.gz
161 tar xzf $<
162 mv lwip $@
163 patch -d $@ -p0 < lwip.patch-cvs
164 touch $@
166 #######
167 # Links
168 #######
170 .PHONY: $(CROSS_ROOT)
171 $(CROSS_ROOT): cross-newlib cross-zlib cross-libpci
173 $(XEN_ROOT)/tools/ioemu-dir:
174 make -C $(XEN_ROOT)/tools ioemu-dir-find
176 ioemu/linkfarm.stamp: $(XEN_ROOT)/tools/ioemu-dir
177 mkdir -p ioemu
178 set -e; \
179 $(absolutify_xen_root); \
180 cd ioemu; \
181 src="$$XEN_ROOT/tools/ioemu-dir"; export src; \
182 (cd $$src && find * -type d -print) | xargs mkdir -p; \
183 (cd $$src && find * ! -type l -type f $(addprefix ! -name , \
184 '*.[oda1]' 'config-*' config.mak qemu-dm qemu-img-xen \
185 '*.html' '*.pod' \
186 )) | \
187 while read f; do rm -f "$$f"; ln -s "$$src/$$f" "$$f"; done
188 touch ioemu/linkfarm.stamp
190 mk-headers-$(XEN_TARGET_ARCH): ioemu/linkfarm.stamp
191 mkdir -p include/xen && \
192 ln -sf $(addprefix ../../,$(wildcard $(XEN_ROOT)/xen/include/public/*.h)) include/xen && \
193 ln -sf $(addprefix ../../$(XEN_ROOT)/xen/include/public/,arch-ia64 arch-x86 hvm io xsm) include/xen && \
194 ( [ -h include/xen/sys ] || ln -sf ../../$(XEN_ROOT)/tools/include/xen-sys/MiniOS include/xen/sys ) && \
195 ( [ -h include/xen/libelf ] || ln -sf ../../$(XEN_ROOT)/tools/include/xen/libelf include/xen/libelf ) && \
196 mkdir -p include/xen-foreign && \
197 ln -sf $(addprefix ../../,$(wildcard $(XEN_ROOT)/tools/include/xen-foreign/*)) include/xen-foreign/ && \
198 $(MAKE) -C include/xen-foreign/ && \
199 ( [ -h include/xen/foreign ] || ln -sf ../xen-foreign include/xen/foreign )
200 mkdir -p libxc-$(XEN_TARGET_ARCH)
201 [ -h libxc-$(XEN_TARGET_ARCH)/Makefile ] || ( cd libxc-$(XEN_TARGET_ARCH) && \
202 ln -sf ../$(XEN_ROOT)/tools/libxc/*.h . && \
203 ln -sf ../$(XEN_ROOT)/tools/libxc/*.c . && \
204 ln -sf ../$(XEN_ROOT)/tools/libxc/Makefile . )
205 mkdir -p libxc-$(XEN_TARGET_ARCH)/$(XEN_TARGET_ARCH)
206 [ -h libxc-$(XEN_TARGET_ARCH)/$(XEN_TARGET_ARCH) ] || ( cd libxc-$(XEN_TARGET_ARCH)/$(XEN_TARGET_ARCH) && \
207 ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.c . && \
208 ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/*.h . && \
209 ln -sf ../$(XEN_ROOT)/tools/libxc/$(XEN_TARGET_ARCH)/Makefile . )
210 $(MAKE) -C $(MINI_OS) links
211 touch mk-headers-$(XEN_TARGET_ARCH)
213 TARGETS_MINIOS=$(addprefix mini-os-$(XEN_TARGET_ARCH)-,$(TARGETS))
214 $(TARGETS_MINIOS): mini-os-%:
215 [ -d $@ ] || \
216 for i in $$(cd $(MINI_OS) ; find . -type d) ; do \
217 mkdir -p $@/$$i ; \
218 done
220 #######
221 # libxc
222 #######
224 .PHONY: libxc
225 libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
226 libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a:: cross-zlib
227 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C libxc-$(XEN_TARGET_ARCH)
229 #######
230 # ioemu
231 #######
233 .PHONY: ioemu
234 ioemu: cross-zlib cross-libpci libxc
235 [ -f ioemu/config-host.mak ] || \
236 ( $(absolutify_xen_root); \
237 cd ioemu ; \
238 LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) \
239 TARGET_CPPFLAGS="$(TARGET_CPPFLAGS)" \
240 TARGET_CFLAGS="$(TARGET_CFLAGS)" \
241 TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
242 ./xen-setup-stubdom )
243 $(MAKE) -C ioemu
245 ######
246 # caml
247 ######
249 .PHONY: caml
250 caml: $(CROSS_ROOT)
251 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH)
253 ###
254 # C
255 ###
257 .PHONY: c
258 c: $(CROSS_ROOT)
259 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH)
261 ######
262 # Grub
263 ######
265 grub-$(GRUB_VERSION).tar.gz:
266 $(WGET) $(GRUB_URL)/$@
268 grub-upstream: grub-$(GRUB_VERSION).tar.gz
269 tar xzf $<
270 mv grub-$(GRUB_VERSION) $@
271 for i in grub.patches/* ; do \
272 patch -d $@ -p1 < $$i ; \
273 done
275 .PHONY: grub
276 grub: grub-upstream $(CROSS_ROOT)
277 mkdir -p grub-$(XEN_TARGET_ARCH)
278 CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@ OBJ_DIR=$(CURDIR)/grub-$(XEN_TARGET_ARCH)
280 ########
281 # minios
282 ########
284 .PHONY: ioemu-stubdom
285 ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a $(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
286 ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxc ioemu
287 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)"
289 CAMLLIB = $(shell ocamlc -where)
290 .PHONY: caml-stubdom
291 caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxc caml
292 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"
294 .PHONY: c-stubdom
295 c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
296 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
298 .PHONY: pv-grub
299 pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
300 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
302 #########
303 # install
304 #########
306 ifeq ($(STUBDOM_SUPPORTED),1)
307 install: install-readme install-ioemu install-grub
308 else
309 install:
310 endif
312 install-readme:
313 $(INSTALL_DIR) $(DESTDIR)$(DOCDIR)
314 $(INSTALL_DATA) README $(DESTDIR)$(DOCDIR)/README.stubdom
316 install-ioemu: ioemu-stubdom
317 $(INSTALL_DIR) "$(DESTDIR)$(LIBEXEC)"
318 $(INSTALL_PROG) stubdom-dm "$(DESTDIR)$(LIBEXEC)"
319 $(INSTALL_DIR) "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot"
320 $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-ioemu/mini-os.gz "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot/ioemu-stubdom.gz"
322 install-grub: pv-grub
323 $(INSTALL_DIR) "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot"
324 $(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)$(LIBDIR_x86_32)/xen/boot/pv-grub-$(XEN_TARGET_ARCH).gz"
326 #######
327 # clean
328 #######
330 # Only clean the libxc/ioemu/mini-os part
331 .PHONY: clean
332 clean:
333 rm -fr mini-os-$(XEN_TARGET_ARCH)-ioemu
334 rm -fr mini-os-$(XEN_TARGET_ARCH)-c
335 rm -fr mini-os-$(XEN_TARGET_ARCH)-caml
336 rm -fr mini-os-$(XEN_TARGET_ARCH)-grub
337 $(MAKE) -C caml clean
338 $(MAKE) -C c clean
339 rm -fr grub-$(XEN_TARGET_ARCH)
340 [ ! -d libxc-$(XEN_TARGET_ARCH) ] || $(MAKE) -C libxc-$(XEN_TARGET_ARCH) clean
341 -[ ! -d ioemu ] || $(MAKE) -C ioemu clean
343 # clean the cross-compilation result
344 .PHONY: crossclean
345 crossclean: clean
346 rm -fr $(CROSS_ROOT)
347 rm -fr newlib-$(XEN_TARGET_ARCH)
348 rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
349 rm -fr libxc-$(XEN_TARGET_ARCH) ioemu
350 rm -f mk-headers-$(XEN_TARGET_ARCH)
352 # clean patched sources
353 .PHONY: patchclean
354 patchclean: crossclean
355 rm -fr newlib-$(NEWLIB_VERSION)
356 rm -fr lwip-$(XEN_TARGET_ARCH)
357 rm -fr grub-upstream
359 # clean downloads
360 .PHONY: downloadclean
361 downloadclean: patchclean
362 rm -f newlib-$(NEWLIB_VERSION).tar.gz
363 rm -f zlib-$(ZLIB_VERSION).tar.gz
364 rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
365 rm -f grub-$(GRUB_VERSION).tar.gz
366 rm -f lwip-$(LWIP_VERSION).tar.gz
368 .PHONY: distclean
369 distclean: downloadclean