1XEN_ROOT = $(CURDIR)/..
2MINI_OS = $(XEN_ROOT)/extras/mini-os
3
4export XEN_ROOT
5export XEN_OS=MiniOS
6export PKG_CONFIG_DIR = $(CURDIR)/pkg-config
7
8# Remove flags which are meant for tools, e.g. "-m64"
9export EXTRA_CFLAGS_XEN_TOOLS=
10export EXTRA_CFLAGS_QEMU_TRADITIONAL=
11
12export stubdom=y
13export debug=y
14# Moved from config/StdGNU.mk
15CFLAGS += -O1 -fno-omit-frame-pointer
16
17ifeq (,$(findstring clean,$(MAKECMDGOALS)))
18  ifeq ($(wildcard $(MINI_OS)/Config.mk),)
19    $(error Please run `make mini-os-dir' in top-level directory)
20  endif
21  include $(XEN_ROOT)/Config.mk
22endif
23
24-include $(XEN_ROOT)/config/Stubdom.mk
25
26GNU_TARGET_ARCH:=$(XEN_TARGET_ARCH)
27ifeq ($(XEN_TARGET_ARCH),x86_32)
28GNU_TARGET_ARCH:=i686
29endif
30
31ifeq ($(GNU_TARGET_ARCH), i686)
32TARGET_CFLAGS=
33NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
34STUBDOM_SUPPORTED=1
35endif
36ifeq ($(GNU_TARGET_ARCH), x86_64)
37TARGET_CFLAGS=-mno-red-zone
38NEWLIB_CFLAGS+=-D_I386MACH_ALLOW_HW_INTERRUPTS
39STUBDOM_SUPPORTED=1
40endif
41
42CROSS_ROOT=cross-root-$(GNU_TARGET_ARCH)
43CROSS_PREFIX=$(CURDIR)/$(CROSS_ROOT)
44
45# Disable PIE/SSP if GCC supports them. They can break us.
46TARGET_CFLAGS += $(CFLAGS)
47TARGET_CPPFLAGS += $(CPPFLAGS)
48$(call cc-options-add,TARGET_CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
49
50# Do not use host headers and libs
51GCC_INSTALL = $(shell LANG=C gcc -print-search-dirs | sed -n -e 's/install: \(.*\)/\1/p')
52TARGET_CPPFLAGS += -U __linux__ -U __FreeBSD__ -U __sun__
53TARGET_CPPFLAGS += -nostdinc
54TARGET_CPPFLAGS += -isystem $(MINI_OS)/include/posix
55TARGET_CPPFLAGS += -isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include
56TARGET_CPPFLAGS += -isystem $(GCC_INSTALL)include
57TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include
58TARGET_CPPFLAGS += -isystem $(CURDIR)/lwip-$(XEN_TARGET_ARCH)/src/include/ipv4
59TARGET_CPPFLAGS += -I$(CURDIR)/include
60TARGET_CPPFLAGS += -I$(XEN_ROOT)/xen/include
61
62TARGET_LDFLAGS += -nostdlib -L$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib
63
64TARGETS=$(STUBDOM_TARGETS)
65
66STUBDOMPATH="stubdompath.sh"
67genpath-target = $(call buildmakevars2file,$(STUBDOMPATH))
68$(eval $(genpath-target))
69
70.PHONY: all
71all: build
72ifeq ($(STUBDOM_SUPPORTED),1)
73build: $(STUBDOMPATH) $(STUBDOM_BUILD)
74else
75build: $(STUBDOMPATH)
76endif
77
78##############
79# Cross-newlib
80##############
81
82newlib-$(NEWLIB_VERSION).tar.gz:
83	$(FETCHER) $@ $(NEWLIB_URL)/$@
84
85newlib-$(NEWLIB_VERSION): newlib-$(NEWLIB_VERSION).tar.gz
86	tar xzf $<
87	patch -d $@ -p0 < newlib.patch
88	patch -d $@ -p0 < newlib-chk.patch
89	patch -d $@ -p1 < newlib-stdint-size_max-fix-from-1.17.0.patch
90	find $@ -type f | xargs perl -i.bak \
91		-pe 's/\b_(tzname|daylight|timezone)\b/$$1/g'
92	touch $@
93
94NEWLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libc.a
95.PHONY: cross-newlib
96cross-newlib: $(NEWLIB_STAMPFILE)
97$(NEWLIB_STAMPFILE): mk-headers-$(XEN_TARGET_ARCH) newlib-$(NEWLIB_VERSION)
98	mkdir -p newlib-$(XEN_TARGET_ARCH)
99	( cd newlib-$(XEN_TARGET_ARCH) && \
100	  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 && \
101	  $(MAKE) DESTDIR= && \
102	  $(MAKE) DESTDIR= install )
103
104############
105# Cross-zlib
106############
107
108zlib-$(ZLIB_VERSION).tar.gz:
109	$(FETCHER) $@ $(ZLIB_URL)/$@
110
111zlib-$(XEN_TARGET_ARCH): zlib-$(ZLIB_VERSION).tar.gz
112	tar xzf $<
113	mv zlib-$(ZLIB_VERSION) $@
114
115ZLIB_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libz.a
116.PHONY: cross-zlib
117cross-zlib: $(ZLIB_STAMPFILE)
118$(ZLIB_STAMPFILE): zlib-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
119	( cd $< && \
120	  CFLAGS="$(TARGET_CPPFLAGS) $(TARGET_CFLAGS)" CC=$(CC) ./configure --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf && \
121	  $(MAKE) DESTDIR= libz.a && \
122	  $(MAKE) DESTDIR= install )
123
124##############
125# Cross-libpci
126##############
127
128pciutils-$(LIBPCI_VERSION).tar.bz2:
129	$(FETCHER) $@ $(LIBPCI_URL)/$@
130
131pciutils-$(XEN_TARGET_ARCH): pciutils-$(LIBPCI_VERSION).tar.bz2
132	tar xjf $<
133	mv pciutils-$(LIBPCI_VERSION) $@
134	patch -d $@ -p1 < pciutils.patch
135	touch $@
136
137LIBPCI_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpci.a
138.PHONY: cross-libpci
139cross-libpci: $(LIBPCI_STAMPFILE)
140$(LIBPCI_STAMPFILE): pciutils-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) $(ZLIB_STAMPFILE)
141	( cd $< && \
142	  cp ../libpci.config.h lib/config.h && \
143	  chmod u+w lib/config.h && \
144	  echo '#define PCILIB_VERSION "$(LIBPCI_VERSION)"' >> lib/config.h && \
145	  ln -sf ../../libpci.config.mak lib/config.mk && \
146	  $(MAKE) DESTDIR= CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I$(call realpath,$(MINI_OS)/include)" lib/libpci.a && \
147	  $(INSTALL_DATA) lib/libpci.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ && \
148	  $(INSTALL_DIR) $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci && \
149	  $(INSTALL_DATA) lib/config.h lib/header.h lib/pci.h lib/types.h $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include/pci/ \
150	)
151
152######
153# lwIP
154######
155
156lwip-$(LWIP_VERSION).tar.gz:
157	$(FETCHER) $@ $(LWIP_URL)/$@
158
159lwip-$(XEN_TARGET_ARCH): lwip-$(LWIP_VERSION).tar.gz
160	tar xzf $<
161	mv lwip $@
162	patch -d $@ -p0 < lwip.patch-cvs
163	patch -d $@ -p0 < lwip.dhcp_create_request-hwaddr_len.patch
164	touch $@
165
166#############
167# cross-gmp
168#############
169gmp-$(GMP_VERSION).tar.bz2:
170	$(FETCHER) $@ $(GMP_URL)/$@
171
172.PHONY: cross-gmp
173ifeq ($(XEN_TARGET_ARCH), x86_32)
174   GMPEXT=ABI=32
175endif
176gmp-$(XEN_TARGET_ARCH): gmp-$(GMP_VERSION).tar.bz2 $(NEWLIB_STAMPFILE)
177	tar xjf $<
178	rm $@ -rf || :
179	mv gmp-$(GMP_VERSION) $@
180	#patch -d $@ -p0 < gmp.patch
181	cd $@; CPPFLAGS="-isystem $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include $(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" CC=$(CC) $(GMPEXT) ./configure --disable-shared --enable-static --disable-fft --without-readline --prefix=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf --libdir=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib --build=`gcc -dumpmachine` --host=$(GNU_TARGET_ARCH)-xen-elf
182	sed -i 's/#define HAVE_OBSTACK_VPRINTF 1/\/\/#define HAVE_OBSTACK_VPRINTF 1/' $@/config.h
183	touch $@
184
185GMP_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libgmp.a
186cross-gmp: $(GMP_STAMPFILE)
187$(GMP_STAMPFILE): gmp-$(XEN_TARGET_ARCH)
188	( cd $< && \
189	  $(MAKE) && \
190	  $(MAKE) DESTDIR= install )
191
192#############
193# cross-polarssl
194#############
195polarssl-$(POLARSSL_VERSION)-gpl.tgz:
196	$(FETCHER) $@ $(POLARSSL_URL)/$@
197
198polarssl-$(XEN_TARGET_ARCH): polarssl-$(POLARSSL_VERSION)-gpl.tgz
199	tar xzf $<
200	mv polarssl-$(POLARSSL_VERSION) $@
201	patch -d $@ -p1 < polarssl.patch
202	touch $@
203
204POLARSSL_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libpolarssl.a
205cross-polarssl: $(POLARSSL_STAMPFILE)
206$(POLARSSL_STAMPFILE): polarssl-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE) lwip-$(XEN_TARGET_ARCH)
207	 ( cd $</library && \
208	   make CC="$(CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -I $(realpath $(MINI_OS)/include)" && \
209	   mkdir -p $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include && \
210	   cp -r ../include/* $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/include && \
211	   mkdir -p $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib && \
212	   $(INSTALL_DATA) libpolarssl.a $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ )
213
214#############
215# cross-tpmemu
216#############
217tpm_emulator-$(TPMEMU_VERSION).tar.gz:
218	$(FETCHER) $@ $(TPMEMU_URL)/$@
219
220tpm_emulator-$(XEN_TARGET_ARCH): tpm_emulator-$(TPMEMU_VERSION).tar.gz
221	@if [ ! -f "$(CMAKE)" ]; then echo "cmake not installed! Install it and then rerun ./configure!"; false; fi
222	tar xzf $<
223	mv tpm_emulator-$(TPMEMU_VERSION) $@
224	patch -d $@ -p1 < tpmemu-$(TPMEMU_VERSION).patch;
225	patch -d $@ -p1 < vtpm-bufsize.patch
226	patch -d $@ -p1 < vtpm-locality.patch
227	patch -d $@ -p1 < vtpm-parent-sign-ek.patch
228	patch -d $@ -p1 < vtpm-deepquote.patch
229	patch -d $@ -p1 < vtpm-deepquote-anyloc.patch
230	patch -d $@ -p1 < vtpm-cmake-Wextra.patch
231	patch -d $@ -p1 < vtpm-implicit-fallthrough.patch
232	mkdir $@/build
233	cd $@/build; CC=${CC} $(CMAKE) .. -DCMAKE_C_FLAGS:STRING="-std=c99 -DTPM_NO_EXTERN $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) -Wno-declaration-after-statement"
234	touch $@
235
236TPMEMU_STAMPFILE=$(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libtpm.a
237$(TPMEMU_STAMPFILE): tpm_emulator-$(XEN_TARGET_ARCH) $(GMP_STAMPFILE)
238	( cd $</build && make VERBOSE=1 tpm_crypto tpm  )
239	cp $</build/crypto/libtpm_crypto.a $(CROSS_ROOT)/$(GNU_TARGET_ARCH)-xen-elf/lib/libtpm_crypto.a
240	cp $</build/tpm/libtpm.a $(TPMEMU_STAMPFILE)
241
242.PHONY: cross-tpmemu
243cross-tpmemu: $(TPMEMU_STAMPFILE)
244
245#############
246# Cross-ocaml
247#############
248
249CAMLLIB = $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/lib/ocaml
250OCAML_STAMPFILE=$(CAMLLIB)/.dirstamp
251
252ocaml-$(OCAML_VERSION).tar.gz:
253	$(FETCHER) $@ $(OCAML_URL)/$@
254
255ocaml-$(XEN_TARGET_ARCH)/.dirstamp: ocaml-$(OCAML_VERSION).tar.gz ocaml.patch
256	tar xzf $<
257	cd ocaml-$(OCAML_VERSION) && patch -p0 < ../ocaml.patch
258	rm -rf ocaml-$(XEN_TARGET_ARCH)
259	mv ocaml-$(OCAML_VERSION) ocaml-$(XEN_TARGET_ARCH)
260	touch $@
261
262MINIOS_HASNOT=IPV6 INET_ATON
263
264.PHONY: cross-ocaml
265cross-ocaml: $(OCAML_STAMPFILE)
266$(OCAML_STAMPFILE): ocaml-$(XEN_TARGET_ARCH)/.dirstamp
267	cd ocaml-$(XEN_TARGET_ARCH) &&  ./configure -prefix $(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf \
268		-no-pthread -no-shared-libs -no-tk -no-curses \
269		-cc "$(CC) -U_FORTIFY_SOURCE -fno-stack-protector -mno-red-zone"
270	$(foreach i,$(MINIOS_HASNOT),sed -i 's,^\(#define HAS_$(i)\),//\1,' ocaml-$(XEN_TARGET_ARCH)/config/s.h ; )
271	$(MAKE) DESTDIR= -C ocaml-$(XEN_TARGET_ARCH) world
272	$(MAKE) DESTDIR= -C ocaml-$(XEN_TARGET_ARCH) opt
273	$(MAKE) -C ocaml-$(XEN_TARGET_ARCH) install
274	touch $@
275
276#######
277# Links
278#######
279
280.PHONY: $(CROSS_ROOT)
281$(CROSS_ROOT): cross-newlib cross-zlib cross-libpci
282
283QEMU_ROOT := $(shell if [ -d "$(QEMU_TRADITIONAL_LOC)" ]; then echo "$(QEMU_TRADITIONAL_LOC)"; else echo .; fi)
284
285ifneq ($(filter ioemu,$(STUBDOM_TARGETS)),)
286IOEMU_LINKFARM_TARGET := ioemu/linkfarm.stamp
287endif
288
289ifeq ($(QEMU_ROOT),.)
290$(XEN_ROOT)/tools/qemu-xen-traditional-dir:
291	$(MAKE) DESTDIR= -C $(XEN_ROOT)/tools qemu-xen-traditional-dir-find
292
293ioemu/linkfarm.stamp: $(XEN_ROOT)/tools/qemu-xen-traditional-dir
294	mkdir -p ioemu
295	set -e;									\
296	$(buildmakevars2shellvars);						\
297	cd ioemu;								\
298	src="$$XEN_ROOT/tools/qemu-xen-traditional-dir"; export src;		\
299	(cd $$src && find * -type d						\
300		$(addprefix ! -path , '*-softmmu*' '*-linux-user*') -print)	\
301		| xargs mkdir -p;						\
302	(cd $$src && find *	! -type l  -type f  $(addprefix ! -path ,	\
303			'*.[oda1]' 'config-*' config.mak qemu-dm qemu-img-xen	\
304			'*.html' '*.pod' '*-softmmu*' '*-linux-user*'		\
305			)) >linkfarm.stamp.tmp;				\
306	cmp -s linkfarm.stamp.tmp linkfarm.stamp &&			\
307		rm linkfarm.stamp.tmp || {				\
308		mv linkfarm.stamp.tmp linkfarm.stamp;			\
309		cat linkfarm.stamp | while read f;			\
310			do rm -f "$$f"; ln -s "$$src/$$f" "$$f"; done;	\
311	}
312else
313export QEMU_ROOT
314
315ioemu/linkfarm.stamp:
316	mkdir -p ioemu
317	touch ioemu/linkfarm.stamp
318endif
319
320define do_links
321  mkdir -p $(dir $@)include
322  cd $(dir $@); \
323  ln -sf $(dir $<)include/*.h include/; \
324  ln -sf $(dir $<)*.[ch] .; \
325  ln -sf $(dir $<)*.pc.in .; \
326  ln -sf $(dir $<)Makefile .
327  touch $@
328endef
329
330libs-$(XEN_TARGET_ARCH)/toolcore/stamp: $(XEN_ROOT)/tools/libs/toolcore/Makefile
331	$(do_links)
332
333libs-$(XEN_TARGET_ARCH)/toollog/stamp: $(XEN_ROOT)/tools/libs/toollog/Makefile
334	$(do_links)
335
336libs-$(XEN_TARGET_ARCH)/evtchn/stamp: $(XEN_ROOT)/tools/libs/evtchn/Makefile
337	$(do_links)
338
339libs-$(XEN_TARGET_ARCH)/gnttab/stamp: $(XEN_ROOT)/tools/libs/gnttab/Makefile
340	$(do_links)
341
342libs-$(XEN_TARGET_ARCH)/call/stamp: $(XEN_ROOT)/tools/libs/call/Makefile
343	$(do_links)
344
345libs-$(XEN_TARGET_ARCH)/foreignmemory/stamp: $(XEN_ROOT)/tools/libs/foreignmemory/Makefile
346	$(do_links)
347
348libs-$(XEN_TARGET_ARCH)/devicemodel/stamp: $(XEN_ROOT)/tools/libs/devicemodel/Makefile
349	$(do_links)
350
351libxc-$(XEN_TARGET_ARCH)/stamp: $(XEN_ROOT)/tools/libxc/Makefile
352	$(do_links)
353
354xenstore/stamp: $(XEN_ROOT)/tools/xenstore/Makefile
355	$(do_links)
356
357LINK_LIBS_DIRS := toolcore toollog evtchn gnttab call foreignmemory devicemodel
358LINK_DIRS := libxc-$(XEN_TARGET_ARCH) xenstore $(foreach dir,$(LINK_LIBS_DIRS),libs-$(XEN_TARGET_ARCH)/$(dir))
359LINK_STAMPS := $(foreach dir,$(LINK_DIRS),$(dir)/stamp)
360
361mk-headers-$(XEN_TARGET_ARCH): $(IOEMU_LINKFARM_TARGET) $(LINK_STAMPS)
362	mkdir -p include/xen && \
363          ln -sf $(wildcard $(XEN_ROOT)/xen/include/public/*.h) include/xen && \
364          ln -sf $(addprefix $(XEN_ROOT)/xen/include/public/,arch-x86 hvm io xsm) include/xen && \
365          ( [ -h include/xen/sys ] || ln -sf $(XEN_ROOT)/tools/include/xen-sys/MiniOS include/xen/sys ) && \
366          ( [ -h include/xen/libelf ] || ln -sf $(XEN_ROOT)/tools/include/xen/libelf include/xen/libelf ) && \
367	  mkdir -p include/xen-foreign && \
368	  ln -sf $(wildcard $(XEN_ROOT)/tools/include/xen-foreign/*) include/xen-foreign/ && \
369	  $(MAKE) DESTDIR= -C include/xen-foreign/ && \
370	  ( [ -h include/xen/foreign ] || ln -sf ../xen-foreign include/xen/foreign )
371	$(MAKE) DESTDIR= -C $(MINI_OS) links
372	touch mk-headers-$(XEN_TARGET_ARCH)
373
374TARGETS_MINIOS=$(addprefix mini-os-$(XEN_TARGET_ARCH)-,$(TARGETS))
375$(TARGETS_MINIOS): mini-os-%:
376	[ -d $@ ] || \
377	for i in $$(cd $(MINI_OS) ; find . -type d) ; do \
378                mkdir -p $@/$$i ; \
379	done
380
381#######
382# libxentoolcore
383#######
384
385.PHONY: libxentoolcore
386libxentoolcore: libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a
387libs-$(XEN_TARGET_ARCH)/toolcore/libxentoolcore.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
388	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toolcore
389
390#######
391# libxentoollog
392#######
393
394.PHONY: libxentoollog
395libxentoollog: libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a
396libs-$(XEN_TARGET_ARCH)/toollog/libxentoollog.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
397	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog
398
399#######
400# libxenevtchn
401#######
402
403.PHONY: libxenevtchn
404libxenevtchn: libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a
405libs-$(XEN_TARGET_ARCH)/evtchn/libxenevtchn.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
406	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn
407
408#######
409# libxengnttab
410#######
411
412.PHONY: libxengnttab
413libxengnttab: libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a
414libs-$(XEN_TARGET_ARCH)/gnttab/libxengnttab.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
415	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab
416
417#######
418# libxencall
419#######
420
421.PHONY: libxencall
422libxencall: libs-$(XEN_TARGET_ARCH)/call/libxencall.a
423libs-$(XEN_TARGET_ARCH)/call/libxencall.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
424	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call
425
426#######
427# libxenforeignmemory
428#######
429
430.PHONY: libxenforeignmemory
431libxenforeignmemory: libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a
432libs-$(XEN_TARGET_ARCH)/foreignmemory/libxenforeignmemory.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
433	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory
434
435#######
436# libxendevicemodel
437#######
438
439.PHONY: libxendevicemodel
440libxendevicemodel: libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a
441libs-$(XEN_TARGET_ARCH)/devicemodel/libxendevicemodel.a: mk-headers-$(XEN_TARGET_ARCH) $(NEWLIB_STAMPFILE)
442	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/devicemodel
443
444#######
445# libxc
446#######
447
448.PHONY: libxc
449libxc: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a libxc-$(XEN_TARGET_ARCH)/libxenguest.a
450libxc-$(XEN_TARGET_ARCH)/libxenctrl.a: mk-headers-$(XEN_TARGET_ARCH) libxentoolcore libxentoollog libxenevtchn libxengnttab libxencall libxenforeignmemory libxendevicemodel cross-zlib
451	CPPFLAGS="$(TARGET_CPPFLAGS)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= CONFIG_LIBXC_MINIOS=y -C libxc-$(XEN_TARGET_ARCH)
452
453 libxc-$(XEN_TARGET_ARCH)/libxenguest.a: libxc-$(XEN_TARGET_ARCH)/libxenctrl.a
454
455#######
456# ioemu
457#######
458
459ioemu-minios-config.mk: $(CURDIR)/ioemu-minios.cfg
460	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
461
462.PHONY: ioemu
463ioemu: cross-zlib cross-libpci libxc ioemu-minios-config.mk
464	[ -f ioemu/config-host.mak ] || \
465	  ( $(buildmakevars2shellvars); \
466	    cd ioemu ; \
467	    LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) \
468	    TARGET_CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat ioemu-minios-config.mk)" \
469	    TARGET_CFLAGS="$(TARGET_CFLAGS)" \
470	    TARGET_LDFLAGS="$(TARGET_LDFLAGS)" \
471	    $(QEMU_ROOT)/xen-setup-stubdom )
472	$(MAKE) DESTDIR= -C ioemu -f $(QEMU_ROOT)/Makefile
473
474######
475# caml
476######
477
478caml-minios-config.mk: $(CURDIR)/caml/minios.cfg
479	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
480
481.PHONY: caml
482caml: $(CROSS_ROOT)
483	CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat caml-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) OCAMLC_CROSS_PREFIX=$(CROSS_PREFIX)/$(GNU_TARGET_ARCH)-xen-elf/bin/
484
485###
486# C
487###
488
489c-minios-config.mk: $(CURDIR)/c/minios.cfg
490	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
491
492.PHONY: c
493c: $(CROSS_ROOT) c-minios-config.mk
494	CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat c-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH)
495
496######
497# VTPM
498######
499
500vtpm-minios-config.mk: $(CURDIR)/vtpm/minios.cfg
501	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
502
503.PHONY: vtpm
504vtpm: cross-polarssl cross-tpmemu vtpm-minios-config.mk
505	XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat vtpm-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
506
507######
508# VTPMMGR
509######
510
511vtpmmgr-minios-config.mk: $(CURDIR)/vtpmmgr/minios.cfg
512	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
513
514.PHONY: vtpmmgr
515vtpmmgr: cross-polarssl vtpmmgr-minios-config.mk
516	XEN_TARGET_ARCH="$(XEN_TARGET_ARCH)" CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat vtpmmgr-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) -C $@
517
518######
519# Grub
520######
521
522grub-$(GRUB_VERSION).tar.gz:
523	$(FETCHER) $@ $(GRUB_URL)/$@
524
525grub-upstream: grub-$(GRUB_VERSION).tar.gz
526	tar xzf $<
527	mv grub-$(GRUB_VERSION) $@
528	for i in grub.patches/* ; do \
529		patch -d $@ -p1 < $$i || exit 1; \
530	done
531
532grub-$(XEN_TARGET_ARCH)-minios-config.mk: $(CURDIR)/grub/minios.cfg
533	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
534
535.PHONY: grub
536grub: cross-polarssl grub-upstream $(CROSS_ROOT) grub-$(XEN_TARGET_ARCH)-minios-config.mk
537	mkdir -p grub-$(XEN_TARGET_ARCH)
538	CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat grub-$(XEN_TARGET_ARCH)-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ OBJ_DIR=$(CURDIR)/grub-$(XEN_TARGET_ARCH)
539
540##########
541# xenstore
542##########
543
544xenstore-minios-config.mk: $(CURDIR)/xenstore-minios.cfg
545	MINIOS_CONFIG="$<" CONFIG_FILE="$(CURDIR)/$@" $(MAKE) DESTDIR= -C $(MINI_OS) config
546
547.PHONY: xenstore
548xenstore: $(CROSS_ROOT) xenstore-minios-config.mk
549	CPPFLAGS="$(TARGET_CPPFLAGS) $(shell cat xenstore-minios-config.mk)" CFLAGS="$(TARGET_CFLAGS)" $(MAKE) DESTDIR= -C $@ xenstored.a CONFIG_STUBDOM=y
550
551########
552# minios
553########
554
555.PHONY: ioemu-stubdom
556ioemu-stubdom: APP_OBJS=$(CURDIR)/ioemu/i386-stubdom/qemu.a $(CURDIR)/ioemu/i386-stubdom/libqemu.a $(CURDIR)/ioemu/libqemu_common.a
557ioemu-stubdom: mini-os-$(XEN_TARGET_ARCH)-ioemu lwip-$(XEN_TARGET_ARCH) libxc ioemu
558	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/ioemu-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS="$(APP_OBJS)"
559
560.PHONY: caml-stubdom
561caml-stubdom: mini-os-$(XEN_TARGET_ARCH)-caml lwip-$(XEN_TARGET_ARCH) libxc cross-ocaml caml
562	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/caml/minios.cfg" $(MAKE) DESTDIR= -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"
563
564.PHONY: c-stubdom
565c-stubdom: mini-os-$(XEN_TARGET_ARCH)-c lwip-$(XEN_TARGET_ARCH) libxc c
566	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/c/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< LWIPDIR=$(CURDIR)/lwip-$(XEN_TARGET_ARCH) APP_OBJS=$(CURDIR)/c/main.a
567
568.PHONY: vtpm-stubdom
569vtpm-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpm vtpm
570	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/vtpm/minios.cfg" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS="$(CURDIR)/vtpm/vtpm.a" APP_LDLIBS="-ltpm -ltpm_crypto -lgmp -lpolarssl"
571
572.PHONY: vtpmmgr-stubdom
573vtpmmgr-stubdom: mini-os-$(XEN_TARGET_ARCH)-vtpmmgr vtpmmgr
574	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/vtpmmgr/minios.cfg" $(MAKE) -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS="$(CURDIR)/vtpmmgr/vtpmmgr.a" APP_LDLIBS="-lm -lpolarssl"
575
576.PHONY: pv-grub
577pv-grub: mini-os-$(XEN_TARGET_ARCH)-grub libxc grub
578	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/grub/minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/grub-$(XEN_TARGET_ARCH)/main.a
579
580.PHONY: xenstore-stubdom
581xenstore-stubdom: mini-os-$(XEN_TARGET_ARCH)-xenstore libxc xenstore
582	DEF_CPPFLAGS="$(TARGET_CPPFLAGS)" DEF_CFLAGS="$(TARGET_CFLAGS)" DEF_LDFLAGS="$(TARGET_LDFLAGS)" MINIOS_CONFIG="$(CURDIR)/xenstore-minios.cfg" $(MAKE) DESTDIR= -C $(MINI_OS) OBJ_DIR=$(CURDIR)/$< APP_OBJS=$(CURDIR)/xenstore/xenstored.a
583
584#########
585# install
586#########
587
588ifeq ($(STUBDOM_SUPPORTED),1)
589install: $(STUBDOMPATH) $(STUBDOM_INSTALL)
590else
591install: $(STUBDOMPATH)
592endif
593
594install-ioemu: ioemu-stubdom
595	$(INSTALL_DIR) "$(DESTDIR)$(LIBEXEC_BIN)"
596	$(INSTALL_PROG) stubdom-dm "$(DESTDIR)$(LIBEXEC_BIN)"
597	$(INSTALL_DATA) stubdompath.sh "$(DESTDIR)$(LIBEXEC_BIN)"
598	$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
599	$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-ioemu/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/ioemu-stubdom.gz"
600
601install-grub: pv-grub
602	$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
603	$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-grub/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz"
604
605install-c: c-stubdom
606
607install-caml: caml-stubdom
608
609install-xenstore: xenstore-stubdom
610	$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
611	$(INSTALL_DATA) mini-os-$(XEN_TARGET_ARCH)-xenstore/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/xenstore-stubdom.gz"
612
613install-vtpm: vtpm-stubdom
614	$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
615	$(INSTALL_PROG) mini-os-$(XEN_TARGET_ARCH)-vtpm/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/vtpm-stubdom.gz"
616
617install-vtpmmgr: vtpmmgr-stubdom
618	$(INSTALL_DIR) "$(DESTDIR)$(XENFIRMWAREDIR)"
619	$(INSTALL_PROG) mini-os-$(XEN_TARGET_ARCH)-vtpmmgr/mini-os.gz "$(DESTDIR)$(XENFIRMWAREDIR)/vtpmmgr-stubdom.gz"
620
621###########
622# uninstall
623###########
624
625ifeq (x$(STUBDOM_UNINSTALL),x)
626STUBDOM_UNINSTALL=$(patsubst install-%,uninstall-%,$(STUBDOM_INSTALL))
627endif
628
629ifeq ($(STUBDOM_SUPPORTED),1)
630uninstall: $(STUBDOM_UNINSTALL)
631else
632uninstall:
633endif
634
635uninstall-ioemu:
636	rm -f $(DESTDIR)$(LIBEXEC_BIN)/stubdom-dm
637	rm -f $(DESTDIR)$(LIBEXEC_BIN)/stubdompath.sh
638	rm -f $(DESTDIR)$(XENFIRMWAREDIR)/ioemu-stubdom.gz
639
640uninstall-grub:
641	rm -f $(DESTDIR)$(XENFIRMWAREDIR)/pv-grub-$(XEN_TARGET_ARCH).gz
642
643uninstall-xenstore:
644	rm -f $(DESTDIR)$(XENFIRMWAREDIR)/xenstore-stubdom.gz
645
646uninstall-vtpm:
647	rm -f $(DESTDIR)$(XENFIRMWAREDIR)/vtpm-stubdom.gz
648
649uninstall-vtpmmgr:
650	rm -f $(DESTDIR)$(XENFIRMWAREDIR)/vtpmmgr-stubdom.gz
651
652#######
653# clean
654#######
655
656# Only clean the libxc/ioemu/mini-os part
657.PHONY: clean
658clean:
659	rm -fr mini-os-$(XEN_TARGET_ARCH)-ioemu
660	rm -fr mini-os-$(XEN_TARGET_ARCH)-c
661	rm -fr mini-os-$(XEN_TARGET_ARCH)-caml
662	rm -fr mini-os-$(XEN_TARGET_ARCH)-grub
663	rm -fr mini-os-$(XEN_TARGET_ARCH)-xenstore
664	rm -fr mini-os-$(XEN_TARGET_ARCH)-vtpm
665	rm -fr mini-os-$(XEN_TARGET_ARCH)-vtpmmgr
666	$(MAKE) DESTDIR= -C caml clean
667	$(MAKE) DESTDIR= -C c clean
668	$(MAKE) -C vtpm clean
669	$(MAKE) -C vtpmmgr clean
670	rm -fr grub-$(XEN_TARGET_ARCH)
671	rm -f $(STUBDOMPATH)
672	rm -f *-minios-config.mk
673	rm -fr pkg-config
674	[ ! -e libs-$(XEN_TARGET_ARCH)/toolcore/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toolcore clean
675	[ ! -e libs-$(XEN_TARGET_ARCH)/toollog/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/toollog clean
676	[ ! -e libs-$(XEN_TARGET_ARCH)/evtchn/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/evtchn clean
677	[ ! -e libs-$(XEN_TARGET_ARCH)/gnttab/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/gnttab clean
678	[ ! -e libs-$(XEN_TARGET_ARCH)/call/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/call clean
679	[ ! -e libs-$(XEN_TARGET_ARCH)/foreignmemory/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/foreignmemory clean
680	[ ! -e libs-$(XEN_TARGET_ARCH)/devicemodel/Makefile ] || $(MAKE) DESTDIR= -C libs-$(XEN_TARGET_ARCH)/devicemodel clean
681	[ ! -e libxc-$(XEN_TARGET_ARCH)/Makefile ] || $(MAKE) DESTDIR= -C libxc-$(XEN_TARGET_ARCH) clean
682	-[ ! -d ioemu ] || $(MAKE) DESTDIR= -C ioemu clean
683	-[ ! -d xenstore ] || $(MAKE) DESTDIR= -C xenstore clean
684
685# clean the cross-compilation result
686.PHONY: crossclean
687crossclean: clean
688	rm -fr $(CROSS_ROOT)
689	rm -fr newlib-$(XEN_TARGET_ARCH)
690	rm -fr zlib-$(XEN_TARGET_ARCH) pciutils-$(XEN_TARGET_ARCH)
691	rm -fr libs-$(XEN_TARGET_ARCH)
692	rm -fr libxc-$(XEN_TARGET_ARCH) ioemu xenstore
693	rm -fr gmp-$(XEN_TARGET_ARCH)
694	rm -fr polarssl-$(XEN_TARGET_ARCH)
695	rm -fr openssl-$(XEN_TARGET_ARCH)
696	rm -fr tpm_emulator-$(XEN_TARGET_ARCH)
697	rm -f mk-headers-$(XEN_TARGET_ARCH)
698	rm -fr ocaml-$(XEN_TARGET_ARCH)
699	rm -fr include
700
701# clean patched sources
702.PHONY: patchclean
703patchclean: crossclean
704	rm -fr newlib-$(NEWLIB_VERSION)
705	rm -fr gmp-$(XEN_TARGET_ARCH)
706	rm -fr polarssl-$(XEN_TARGET_ARCH)
707	rm -fr openssl-$(XEN_TARGET_ARCH)
708	rm -fr tpm_emulator-$(XEN_TARGET_ARCH)
709	rm -fr lwip-$(XEN_TARGET_ARCH)
710	rm -fr grub-upstream
711
712# clean downloads
713.PHONY: downloadclean
714downloadclean: patchclean
715	rm -f newlib-$(NEWLIB_VERSION).tar.gz
716	rm -f zlib-$(ZLIB_VERSION).tar.gz
717	rm -f gmp-$(GMP_VERSION).tar.bz2
718	rm -f tpm_emulator-$(TPMEMU_VERSION).tar.gz
719	rm -f pciutils-$(LIBPCI_VERSION).tar.bz2
720	rm -f grub-$(GRUB_VERSION).tar.gz
721	rm -f lwip-$(LWIP_VERSION).tar.gz
722	rm -f ocaml-$(OCAML_VERSION).tar.gz
723	rm -f polarssl-$(POLARSSL_VERSION)-gpl.tgz
724	rm -f openssl-$(POLARSSL_VERSION)-gpl.tgz
725
726.PHONY: distclean
727distclean: downloadclean
728	rm -rf config.log config.status config.cache autom4te.cache ../config/Stubdom.mk
729
730ifeq (,$(findstring clean,$(MAKECMDGOALS)))
731$(XEN_ROOT)/config/Stubdom.mk:
732	$(error You have to run ./configure before building or installing stubdom)
733endif
734