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