1XEN_ROOT = $(CURDIR)/..
2
3export PKG_CONFIG_DIR = $(CURDIR)/pkg-config
4
5include $(XEN_ROOT)/tools/Rules.mk
6
7SUBDIRS-y :=
8SUBDIRS-y += libs
9SUBDIRS-y += libxc
10SUBDIRS-y += flask
11SUBDIRS-y += fuzz
12SUBDIRS-y += xenstore
13SUBDIRS-y += misc
14SUBDIRS-y += examples
15SUBDIRS-y += hotplug
16SUBDIRS-y += xentrace
17SUBDIRS-$(CONFIG_XCUTILS) += xcutils
18SUBDIRS-$(CONFIG_X86) += firmware
19SUBDIRS-y += console
20SUBDIRS-y += xenmon
21SUBDIRS-y += xenstat
22SUBDIRS-$(CONFIG_NetBSD) += xenbackendd
23SUBDIRS-y += libfsimage
24SUBDIRS-$(CONFIG_Linux) += libvchan
25
26# do not recurse in to a dir we are about to delete
27ifneq "$(MAKECMDGOALS)" "distclean"
28SUBDIRS-$(CONFIG_QEMU_TRAD) += qemu-xen-traditional-dir
29SUBDIRS-$(CONFIG_QEMU_XEN) += qemu-xen-dir
30endif
31
32SUBDIRS-y += xenpmd
33SUBDIRS-y += libxl
34SUBDIRS-$(CONFIG_GOLANG) += golang
35SUBDIRS-y += xl
36SUBDIRS-y += helpers
37SUBDIRS-$(CONFIG_X86) += xenpaging
38SUBDIRS-$(CONFIG_X86) += debugger/gdbsx
39SUBDIRS-$(CONFIG_X86) += debugger/kdd
40SUBDIRS-$(CONFIG_TESTS) += tests
41
42# These don't cross-compile
43ifeq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
44SUBDIRS-y += python
45SUBDIRS-y += pygrub
46SUBDIRS-$(OCAML_TOOLS) += ocaml
47endif
48
49ifeq ($(CONFIG_RUMP),y)
50SUBDIRS-y := libs libxc xenstore
51endif
52
53# For the sake of linking, set the sys-root
54ifneq ($(CROSS_COMPILE),)
55CROSS_BIN_PATH ?= /usr/$(CROSS_COMPILE:-=)/bin
56CROSS_SYS_ROOT ?= /usr/$(CROSS_COMPILE:-=)/sys-root
57export CROSS_SYS_ROOT # exported for check/funcs.sh
58export CROSS_BIN_PATH # exported for cross-install.sh
59endif
60
61.PHONY: build all
62build all: subdirs-all
63
64.PHONY: install
65install:
66	$(INSTALL_DIR) -m 700 $(DESTDIR)$(XEN_DUMP_DIR)
67	$(INSTALL_DIR) $(DESTDIR)$(XEN_LOG_DIR)
68	$(INSTALL_DIR) $(DESTDIR)$(XEN_RUN_DIR)
69	$(INSTALL_DIR) $(DESTDIR)$(XEN_LIB_DIR)
70	$(INSTALL_DIR) $(DESTDIR)$(XEN_RUN_STORED)
71	$(INSTALL_DIR) $(DESTDIR)$(PKG_INSTALLDIR)
72	$(MAKE) subdirs-install
73
74.PHONY: uninstall
75uninstall: D=$(DESTDIR)
76uninstall:
77	[ -d $(D)$(XEN_CONFIG_DIR) ] && mv -f $(D)$(XEN_CONFIG_DIR) $(D)$(XEN_CONFIG_DIR).old-`date +%s` || true
78	rm -rf $(D)$(libdir)/xen
79	rm -rf $(D)$(SHAREDIR)/xen
80	rm -rf $(D)$(SHAREDIR)/qemu-xen
81	$(MAKE) subdirs-uninstall
82
83.PHONY: clean
84clean: subdirs-clean
85	rm -rf pkg-config
86
87.PHONY: distclean
88distclean: subdirs-distclean clean
89	rm -rf qemu-xen-traditional-dir qemu-xen-traditional-dir-remote
90	rm -rf qemu-xen-dir qemu-xen-dir-remote qemu-xen-build
91	rm -rf ../config/Tools.mk config.h config.log config.status \
92		config.cache autom4te.cache
93
94ifneq ($(XEN_COMPILE_ARCH),$(XEN_TARGET_ARCH))
95IOEMU_CONFIGURE_CROSS ?= --cross-prefix=$(CROSS_COMPILE) \
96			 --interp-prefix=$(CROSS_SYS_ROOT)
97endif
98
99ifeq ($(XEN_TOOLS_RPATH),y)
100QEMU_UPSTREAM_RPATH := -Wl,-rpath,$(LIBEXEC_LIB):$(libdir)
101IOEMU_EXTRA_LDFLAGS := --extra-ldflags="-Wl,-rpath,$(libdir)"
102else
103QEMU_UPSTREAM_RPATH := -Wl,-rpath,$(LIBEXEC_LIB)
104IOEMU_EXTRA_LDFLAGS :=
105endif
106
107QEMU_ROOT := $(shell if [ -d "$(QEMU_TRADITIONAL_LOC)" ]; then echo "$(QEMU_TRADITIONAL_LOC)"; else echo .; fi)
108ifneq ($(QEMU_ROOT),.)
109export QEMU_ROOT
110endif
111
112# Targets for external trees:
113#  ${target}-dir-find
114#    See if the directory exists and check it out if not.
115#  ${target}-dir-force-update
116#    Pull to the most recent update (as if you had checked it out for the
117#    first time)
118#  subdir-all-${target}-dir
119#    Do "make all" for ${target}, including all prerequisites (such as
120#    configure)
121#  subdir-install-${target}-dir
122#    Do "make install" for $TARGET
123#  subdir-clean-${target}-dir
124#    Do "make clean" for $TARGET
125#
126# Directories for external trees:
127#  ${target}-dir
128#    Used for local builds.  Usually a link to ${target}-dir-remote
129#  ${target}-dir-remote
130#    Where remote repositories are cloned
131#  ${target}
132#    Where a copy of the source files are put when building a source
133#    tarball for release
134#
135# Expected variables:
136#   ${TARGET}_URL
137#     A url from which to clone a git repo
138#   ${TARGET}_REVISION
139#     The target revision to check out when doing "find" or "force-update"
140#   ${TARGET}_INTREE
141#     The directory where the subtree can be found (usually used when building
142#     a source tarball)
143#   ${TARGET}_LOC
144#     The ultimate location of the source (either a local dir or remote URL)
145
146# External target: qemu-xen-traditional
147qemu-xen-traditional-dir-find:
148	set -ex; \
149	if test -d $(QEMU_TRADITIONAL_LOC); then \
150		mkdir -p qemu-xen-traditional-dir; \
151	else \
152		export GIT=$(GIT); \
153		$(XEN_ROOT)/scripts/git-checkout.sh $(QEMU_TRADITIONAL_LOC) $(QEMU_TRADITIONAL_REVISION) qemu-xen-traditional-dir; \
154	fi
155
156.PHONY: qemu-xen-traditional-dir-force-update
157qemu-xen-traditional-dir-force-update: qemu-xen-traditional-dir-find
158	set -ex; \
159	if [ "$(QEMU_TRADITIONAL_REVISION)" ]; then \
160		cd qemu-xen-traditional-dir-remote; \
161		$(GIT) fetch origin; \
162		$(GIT) reset --hard $(QEMU_TRADITIONAL_REVISION); \
163	fi
164
165qemu-traditional-recurse = \
166	set -e; \
167		$(buildmakevars2shellvars); \
168		export CONFIG_BLKTAP1=n; \
169		cd qemu-xen-traditional-dir; \
170		$(1)
171
172subdir-all-qemu-xen-traditional-dir: qemu-xen-traditional-dir-find
173	$(call qemu-traditional-recurse,\
174		$(QEMU_ROOT)/xen-setup \
175		--extra-cflags="-D__XEN_TOOLS__ $(EXTRA_CFLAGS_QEMU_TRADITIONAL)" \
176		$(IOEMU_EXTRA_LDFLAGS) \
177		--cpu=$(IOEMU_CPU_ARCH) \
178		$(IOEMU_CONFIGURE_CROSS); \
179		$(MAKE) all \
180	)
181
182subdir-install-qemu-xen-traditional-dir: subdir-all-qemu-xen-traditional-dir
183	$(call qemu-traditional-recurse,$(MAKE) install)
184
185subdir-clean-qemu-xen-traditional-dir:
186	set -e; if test -d qemu-xen-traditional-dir/.; then \
187		$(MAKE) -C qemu-xen-traditional-dir clean; \
188	fi
189subdir-uninstall-qemu-xen-traditional-dir:
190	rm -f $(D)$(bindir)/qemu-nbd*
191	rm -f $(D)$(bindir)/qemu-img*
192
193# External target: qemu-xen
194qemu-xen-dir-find:
195	if test -d $(QEMU_UPSTREAM_LOC) ; then \
196		mkdir -p qemu-xen-dir; \
197	else \
198		export GIT=$(GIT); \
199		$(XEN_ROOT)/scripts/git-checkout.sh $(QEMU_UPSTREAM_LOC) $(QEMU_UPSTREAM_REVISION) qemu-xen-dir ; \
200	fi
201
202.PHONY: qemu-xen-dir-force-update
203qemu-xen-dir-force-update: qemu-xen-dir-find
204	set -ex; \
205	if [ "$(QEMU_UPSTREAM_REVISION)" ]; then \
206		cd qemu-xen-dir-remote; \
207		$(GIT) fetch origin; \
208		$(GIT) reset --hard $(QEMU_UPSTREAM_REVISION); \
209	fi
210
211ifeq ($(debug),y)
212QEMU_XEN_ENABLE_DEBUG := --enable-debug
213else
214QEMU_XEN_ENABLE_DEBUG :=
215endif
216
217subdir-all-qemu-xen-dir: qemu-xen-dir-find
218	unset MAKELEVEL; \
219	if test -d $(QEMU_UPSTREAM_LOC) ; then \
220		source=$(QEMU_UPSTREAM_LOC); \
221	else \
222		source=$(XEN_ROOT)/tools/qemu-xen-dir; \
223	fi; \
224	mkdir -p qemu-xen-build; \
225	cd qemu-xen-build; \
226	if $$source/scripts/tracetool.py --check-backend --backend log ; then \
227		enable_trace_backend='--enable-trace-backend=log'; \
228	elif $$source/scripts/tracetool.py --check-backend --backend stderr ; then \
229		enable_trace_backend='--enable-trace-backend=stderr'; \
230	else \
231		enable_trace_backend='' ; \
232	fi ; \
233	if [ "$(CONFIG_9PFS)" = "y" ]; then \
234		virtfs='--enable-virtfs' ; \
235	elif [ "$(CONFIG_9PFS)" = "n" ]; then \
236		virtfs='--disable-virtfs' ; \
237	else \
238		virtfs='' ; \
239	fi ; \
240	PKG_CONFIG_PATH=$(XEN_ROOT)/tools/pkg-config$${PKG_CONFIG_PATH:+:$${PKG_CONFIG_PATH}} \
241	$$source/configure --enable-xen --target-list=i386-softmmu \
242		$(QEMU_XEN_ENABLE_DEBUG) \
243		$$enable_trace_backend \
244		--prefix=$(LIBEXEC) \
245		--libdir=$(LIBEXEC_LIB) \
246		--includedir=$(LIBEXEC_INC) \
247		--extra-cflags="-DXC_WANT_COMPAT_EVTCHN_API=1 \
248		-DXC_WANT_COMPAT_GNTTAB_API=1 \
249		-DXC_WANT_COMPAT_MAP_FOREIGN_API=1 \
250		-DXC_WANT_COMPAT_DEVICEMODEL_API=1 \
251		-I$(XEN_ROOT)/tools/include \
252		-I$(XEN_ROOT)/tools/libs/toolcore/include \
253		-I$(XEN_ROOT)/tools/libs/toollog/include \
254		-I$(XEN_ROOT)/tools/libs/evtchn/include \
255		-I$(XEN_ROOT)/tools/libs/gnttab/include \
256		-I$(XEN_ROOT)/tools/libs/foreignmemory/include \
257		-I$(XEN_ROOT)/tools/libs/devicemodel/include \
258		-I$(XEN_ROOT)/tools/libxc/include \
259		-I$(XEN_ROOT)/tools/xenstore/include \
260		-I$(XEN_ROOT)/tools/xenstore/compat/include \
261		$(EXTRA_CFLAGS_QEMU_XEN)" \
262		--extra-ldflags="-L$(XEN_ROOT)/tools/libxc \
263		-L$(XEN_ROOT)/tools/xenstore \
264		-L$(XEN_ROOT)/tools/libs/toolcore \
265		-L$(XEN_ROOT)/tools/libs/evtchn \
266		-L$(XEN_ROOT)/tools/libs/gnttab \
267		-L$(XEN_ROOT)/tools/libs/foreignmemory \
268		-L$(XEN_ROOT)/tools/libs/devicemodel \
269		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toolcore \
270		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/toollog \
271		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/evtchn \
272		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/gnttab \
273		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/call \
274		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/foreignmemory \
275		-Wl,-rpath-link=$(XEN_ROOT)/tools/libs/devicemodel \
276		$(QEMU_UPSTREAM_RPATH)" \
277		--bindir=$(LIBEXEC_BIN) \
278		--datadir=$(SHAREDIR)/qemu-xen \
279		--localstatedir=$(localstatedir) \
280		--disable-kvm \
281		--disable-docs \
282		--disable-guest-agent \
283		--python=$(PYTHON) \
284		$(CONFIG_QEMUU_EXTRA_ARGS) \
285		--cpu=$(IOEMU_CPU_ARCH) \
286		$(IOEMU_CONFIGURE_CROSS) \
287		$$virtfs; \
288	$(MAKE) all
289
290subdir-install-qemu-xen-dir: subdir-all-qemu-xen-dir
291	cd qemu-xen-build; \
292	$(MAKE) install
293
294subdir-clean-qemu-xen-dir:
295	set -e; if test -d qemu-xen-build/.; then \
296		$(MAKE) -C qemu-xen-build clean; \
297	fi
298
299subdir-uninstall-qemu-xen-dir: ;
300
301subdir-clean-debugger/gdbsx subdir-distclean-debugger/gdbsx: .phony
302	$(MAKE) -C debugger/gdbsx clean
303
304subdir-install-debugger/gdbsx: .phony
305	$(MAKE) -C debugger/gdbsx install
306
307subdir-all-debugger/gdbsx: .phony
308	$(MAKE) -C debugger/gdbsx all
309
310subdir-uninstall-debugger/gdbsx: .phony
311	$(MAKE) -C debugger/gdbsx uninstall
312
313subdir-clean-debugger/kdd subdir-distclean-debugger/kdd: .phony
314	$(MAKE) -C debugger/kdd clean
315
316subdir-install-debugger/kdd: .phony
317	$(MAKE) -C debugger/kdd install
318
319subdir-uninstall-debugger/kdd: .phony
320	$(MAKE) -C debugger/kdd uninstall
321
322subdir-all-debugger/kdd: .phony
323	$(MAKE) -C debugger/kdd all
324
325subdir-distclean-firmware: .phony
326	$(MAKE) -C firmware distclean
327
328subtree-force-update:
329ifeq ($(CONFIG_QEMU_XEN),y)
330	$(MAKE) qemu-xen-dir-force-update
331endif
332ifeq ($(CONFIG_QEMU_TRAD),y)
333	$(MAKE) qemu-xen-traditional-dir-force-update
334endif
335ifeq ($(CONFIG_X86),y)
336	$(MAKE) -C firmware subtree-force-update
337endif
338
339subtree-force-update-all:
340	$(MAKE) qemu-xen-dir-force-update
341	$(MAKE) qemu-xen-traditional-dir-force-update
342	$(MAKE) -C firmware subtree-force-update-all
343