1#  -*- mode: Makefile; -*-
2
3# `all' is the default target
4all:
5
6-include $(XEN_ROOT)/config/Tools.mk
7include $(XEN_ROOT)/Config.mk
8
9export _INSTALL := $(INSTALL)
10INSTALL = $(XEN_ROOT)/tools/cross-install
11
12XEN_INCLUDE        = $(XEN_ROOT)/tools/include
13XEN_LIBXENTOOLCORE  = $(XEN_ROOT)/tools/libs/toolcore
14XEN_LIBXENTOOLLOG  = $(XEN_ROOT)/tools/libs/toollog
15XEN_LIBXENEVTCHN   = $(XEN_ROOT)/tools/libs/evtchn
16XEN_LIBXENGNTTAB   = $(XEN_ROOT)/tools/libs/gnttab
17XEN_LIBXENCALL     = $(XEN_ROOT)/tools/libs/call
18XEN_LIBXENFOREIGNMEMORY = $(XEN_ROOT)/tools/libs/foreignmemory
19XEN_LIBXENDEVICEMODEL = $(XEN_ROOT)/tools/libs/devicemodel
20XEN_LIBXC          = $(XEN_ROOT)/tools/libxc
21XEN_XENLIGHT       = $(XEN_ROOT)/tools/libxl
22# Currently libxlutil lives in the same directory as libxenlight
23XEN_XLUTIL         = $(XEN_XENLIGHT)
24XEN_XENSTORE       = $(XEN_ROOT)/tools/xenstore
25XEN_LIBXENSTAT     = $(XEN_ROOT)/tools/xenstat/libxenstat/src
26XEN_BLKTAP2        = $(XEN_ROOT)/tools/blktap2
27XEN_LIBVCHAN       = $(XEN_ROOT)/tools/libvchan
28
29CFLAGS_xeninclude = -I$(XEN_INCLUDE)
30
31XENSTORE_XENSTORED ?= y
32
33# A debug build of tools?
34debug ?= n
35debug_symbols ?= $(debug)
36
37# Set CONFIG_GOLANG=y in .config (or in make) to build golang
38CONFIG_GOLANG ?= n
39XEN_GOPATH        = $(XEN_ROOT)/tools/golang
40XEN_GOCODE_URL    = golang.xenproject.org
41
42ifeq ($(debug_symbols),y)
43CFLAGS += -g3
44endif
45
46ifneq ($(nosharedlibs),y)
47INSTALL_SHLIB = $(INSTALL_PROG)
48SYMLINK_SHLIB = ln -sf
49libextension = .so
50else
51libextension = .a
52XENSTORE_STATIC_CLIENTS=y
53# If something tries to use these it is a mistake.  Provide references
54# to nonexistent programs to produce a sane error message.
55INSTALL_SHLIB = : install-shlib-unsupported-fail
56SYMLINK_SHLIB = : symlink-shlib-unsupported-fail
57endif
58
59# Compiling and linking against in tree libraries.
60#
61# In order to compile and link against an in-tree library various
62# cpp/compiler/linker options are required.
63#
64# For example consider a library "libfoo" which itself uses two other
65# libraries:
66#  libbar - whose use is entirely internal to libfoo and not exposed
67#           to users of libfoo at all.
68#  libbaz - whose use is entirely internal to libfoo but libfoo's
69#           public headers include one or more of libbaz's
70#           public headers. Users of libfoo are therefore transitively
71#           using libbaz's header but not linking against libbaz.
72#
73# SHDEPS_libfoo: Flags for linking recursive dependencies of
74#                libfoo. Must contain SHLIB for every library which
75#                libfoo links against. So must contain both
76#                $(SHLIB_libbar) and $(SHLIB_libbaz).
77#
78# SHLIB_libfoo: Flags for recursively linking against libfoo. Must
79#               contains SHDEPS_libfoo and:
80#                   -Wl,-rpath-link=<directory containing libfoo.so>
81#
82# CFLAGS_libfoo: Flags for compiling against libfoo. Must add the
83#                directories containing libfoo's headers to the
84#                include path. Must recursively include
85#                $(CFLAGS_libbaz), to satisfy the transitive inclusion
86#                of the headers but not $(CFLAGS_libbar) since none of
87#                libbar's headers are required to build against
88#                libfoo.
89#
90# LDLIBS_libfoo: Flags for linking against libfoo. Must contain
91#                $(SHDEPS_libfoo) and the path to libfoo.so
92#
93# Consumers of libfoo should include $(CFLAGS_libfoo) and
94# $(LDLIBS_libfoo) in their appropriate directories. They should not
95# include any CFLAGS or LDLIBS relating to libbar or libbaz unless
96# they use those libraries directly (not via libfoo) too.
97#
98# Consumers of libfoo should not directly use $(SHDEPS_libfoo) or
99# $(SHLIB_libfoo)
100
101CFLAGS_libxentoollog = -I$(XEN_LIBXENTOOLLOG)/include $(CFLAGS_xeninclude)
102SHDEPS_libxentoollog =
103LDLIBS_libxentoollog = $(SHDEPS_libxentoollog) $(XEN_LIBXENTOOLLOG)/libxentoollog$(libextension)
104SHLIB_libxentoollog  = $(SHDEPS_libxentoollog) -Wl,-rpath-link=$(XEN_LIBXENTOOLLOG)
105
106CFLAGS_libxentoolcore = -I$(XEN_LIBXENTOOLCORE)/include $(CFLAGS_xeninclude)
107SHDEPS_libxentoolcore =
108LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) $(XEN_LIBXENTOOLCORE)/libxentoolcore$(libextension)
109SHLIB_libxentoolcore  = $(SHDEPS_libxentoolcore) -Wl,-rpath-link=$(XEN_LIBXENTOOLCORE)
110
111CFLAGS_libxenevtchn = -I$(XEN_LIBXENEVTCHN)/include $(CFLAGS_xeninclude)
112SHDEPS_libxenevtchn = $(SHLIB_libxentoolcore)
113LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) $(XEN_LIBXENEVTCHN)/libxenevtchn$(libextension)
114SHLIB_libxenevtchn  = $(SHDEPS_libxenevtchn) -Wl,-rpath-link=$(XEN_LIBXENEVTCHN)
115
116CFLAGS_libxengnttab = -I$(XEN_LIBXENGNTTAB)/include $(CFLAGS_xeninclude)
117SHDEPS_libxengnttab = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore)
118LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) $(XEN_LIBXENGNTTAB)/libxengnttab$(libextension)
119SHLIB_libxengnttab  = $(SHDEPS_libxengnttab) -Wl,-rpath-link=$(XEN_LIBXENGNTTAB)
120
121CFLAGS_libxencall = -I$(XEN_LIBXENCALL)/include $(CFLAGS_xeninclude)
122SHDEPS_libxencall = $(SHLIB_libxentoolcore)
123LDLIBS_libxencall = $(SHDEPS_libxencall) $(XEN_LIBXENCALL)/libxencall$(libextension)
124SHLIB_libxencall  = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_LIBXENCALL)
125
126CFLAGS_libxenforeignmemory = -I$(XEN_LIBXENFOREIGNMEMORY)/include $(CFLAGS_xeninclude)
127SHDEPS_libxenforeignmemory = $(SHLIB_libxentoolcore)
128LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) $(XEN_LIBXENFOREIGNMEMORY)/libxenforeignmemory$(libextension)
129SHLIB_libxenforeignmemory  = $(SHDEPS_libxenforeignmemory) -Wl,-rpath-link=$(XEN_LIBXENFOREIGNMEMORY)
130
131CFLAGS_libxendevicemodel = -I$(XEN_LIBXENDEVICEMODEL)/include $(CFLAGS_xeninclude)
132SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_xencall)
133LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_LIBXENDEVICEMODEL)/libxendevicemodel$(libextension)
134SHLIB_libxendevicemodel  = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_LIBXENDEVICEMODEL)
135
136# code which compiles against libxenctrl get __XEN_TOOLS__ and
137# therefore sees the unstable hypercall interfaces.
138CFLAGS_libxenctrl = -I$(XEN_LIBXC)/include $(CFLAGS_libxentoollog) $(CFLAGS_libxenforeignmemory) $(CFLAGS_libxendevicemodel) $(CFLAGS_xeninclude) -D__XEN_TOOLS__
139SHDEPS_libxenctrl = $(SHLIB_libxentoollog) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab) $(SHLIB_libxencall) $(SHLIB_libxenforeignmemory) $(SHLIB_libxendevicemodel)
140LDLIBS_libxenctrl = $(SHDEPS_libxenctrl) $(XEN_LIBXC)/libxenctrl$(libextension)
141SHLIB_libxenctrl  = $(SHDEPS_libxenctrl) -Wl,-rpath-link=$(XEN_LIBXC)
142
143CFLAGS_libxenguest = -I$(XEN_LIBXC)/include $(CFLAGS_libxenevtchn) $(CFLAGS_libxenforeignmemory) $(CFLAGS_xeninclude)
144SHDEPS_libxenguest = $(SHLIB_libxenevtchn)
145LDLIBS_libxenguest = $(SHDEPS_libxenguest) $(XEN_LIBXC)/libxenguest$(libextension)
146SHLIB_libxenguest  = $(SHDEPS_libxenguest) -Wl,-rpath-link=$(XEN_LIBXC)
147
148CFLAGS_libxenstore = -I$(XEN_XENSTORE)/include $(CFLAGS_xeninclude)
149SHDEPS_libxenstore = $(SHLIB_libxentoolcore)
150LDLIBS_libxenstore = $(SHDEPS_libxenstore) $(XEN_XENSTORE)/libxenstore$(libextension)
151SHLIB_libxenstore  = $(SHDEPS_libxenstore) -Wl,-rpath-link=$(XEN_XENSTORE)
152
153CFLAGS_libxenstat  = -I$(XEN_LIBXENSTAT)
154SHDEPS_libxenstat  = $(SHLIB_libxenctrl) $(SHLIB_libxenstore)
155LDLIBS_libxenstat  = $(SHDEPS_libxenstat) $(XEN_LIBXENSTAT)/libxenstat$(libextension)
156SHLIB_libxenstat   = $(SHDEPS_libxenstat) -Wl,-rpath-link=$(XEN_LIBXENSTAT)
157
158CFLAGS_libxenvchan = -I$(XEN_LIBVCHAN)
159SHDEPS_libxenvchan = $(SHLIB_libxentoollog) $(SHLIB_libxenstore) $(SHLIB_libxenevtchn) $(SHLIB_libxengnttab)
160LDLIBS_libxenvchan = $(SHDEPS_libxenvchan) $(XEN_LIBVCHAN)/libxenvchan$(libextension)
161SHLIB_libxenvchan  = $(SHDEPS_libxenvchan) -Wl,-rpath-link=$(XEN_LIBVCHAN)
162
163ifeq ($(debug),y)
164# Disable optimizations
165CFLAGS += -O0 -fno-omit-frame-pointer
166# But allow an override to -O0 in case Python enforces -D_FORTIFY_SOURCE=<n>.
167PY_CFLAGS += $(PY_NOOPT_CFLAGS)
168else
169CFLAGS += -O2 -fomit-frame-pointer
170endif
171
172ifeq ($(CONFIG_BLKTAP2),y)
173CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_xeninclude)
174SHDEPS_libblktapctl =
175LDLIBS_libblktapctl = $(SHDEPS_libblktapctl) $(XEN_BLKTAP2)/control/libblktapctl$(libextension)
176SHLIB_libblktapctl  = $(SHDEPS_libblktapctl) -Wl,-rpath-link=$(XEN_BLKTAP2)/control
177else
178CFLAGS_libblktapctl =
179SHDEPS_libblktapctl =
180LDLIBS_libblktapctl =
181SHLIB_libblktapctl  =
182PKG_CONFIG_REMOVE += xenblktapctl
183endif
184
185CFLAGS_libxenlight = -I$(XEN_XENLIGHT) $(CFLAGS_libxenctrl) $(CFLAGS_xeninclude)
186SHDEPS_libxenlight = $(SHLIB_libxenctrl) $(SHLIB_libxenstore) $(SHLIB_libblktapctl)
187LDLIBS_libxenlight = $(SHDEPS_libxenlight) $(XEN_XENLIGHT)/libxenlight$(libextension)
188SHLIB_libxenlight  = $(SHDEPS_libxenlight) -Wl,-rpath-link=$(XEN_XENLIGHT)
189
190CFLAGS_libxlutil = -I$(XEN_XLUTIL)
191SHDEPS_libxlutil = $(SHLIB_libxenlight)
192LDLIBS_libxlutil = $(SHDEPS_libxlutil) $(XEN_XLUTIL)/libxlutil$(libextension)
193SHLIB_libxlutil  = $(SHDEPS_libxlutil) -Wl,-rpath-link=$(XEN_XLUTIL)
194
195CFLAGS += -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__
196
197# Get gcc to generate the dependencies for us.
198CFLAGS += -MMD -MF .$(if $(filter-out .,$(@D)),$(subst /,@,$(@D))@)$(@F).d
199DEPS = .*.d
200
201ifneq ($(FILE_OFFSET_BITS),)
202CFLAGS  += -D_FILE_OFFSET_BITS=$(FILE_OFFSET_BITS)
203endif
204ifneq ($(XEN_OS),NetBSD)
205# Enable implicit LFS support *and* explicit LFS names.
206CFLAGS  += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
207endif
208
209# 32-bit x86 does not perform well with -ve segment accesses on Xen.
210CFLAGS-$(CONFIG_X86_32) += $(call cc-option,$(CC),-mno-tls-direct-seg-refs)
211CFLAGS += $(CFLAGS-y)
212
213CFLAGS += $(EXTRA_CFLAGS_XEN_TOOLS)
214
215INSTALL_PYTHON_PROG = \
216	$(XEN_ROOT)/tools/python/install-wrap "$(PYTHON_PATH)" $(INSTALL_PROG)
217
218%.opic: %.c
219	$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) $(CFLAGS_$*.opic) -fPIC -c -o $@ $< $(APPEND_CFLAGS)
220
221%.o: %.c
222	$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) -c -o $@ $< $(APPEND_CFLAGS)
223
224%.o: %.cc
225	$(CC) $(CPPFLAGS) $(CXXFLAGS) $(CXXFLAGS_$*.o) -c -o $@ $< $(APPEND_CFLAGS)
226
227%.o: %.S
228	$(CC) $(CFLAGS) $(CFLAGS_$*.o) -c $< -o $@ $(APPEND_CFLAGS)
229%.opic: %.S
230	$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) $(CFLAGS.opic) -fPIC -c -o $@ $< $(APPEND_CFLAGS)
231
232headers.chk:
233	for i in $(filter %.h,$^); do \
234	    $(CC) -x c -ansi -Wall -Werror $(CFLAGS_xeninclude) \
235	          -S -o /dev/null $$i || exit 1; \
236	    echo $$i; \
237	done >$@.new
238	mv $@.new $@
239
240subdirs-all subdirs-clean subdirs-install subdirs-distclean subdirs-uninstall: .phony
241	@set -e; for subdir in $(SUBDIRS) $(SUBDIRS-y); do \
242		$(MAKE) subdir-$(patsubst subdirs-%,%,$@)-$$subdir; \
243	done
244
245subdir-all-% subdir-clean-% subdir-install-% subdir-uninstall-%: .phony
246	$(MAKE) -C $* $(patsubst subdir-%-$*,%,$@)
247
248subdir-distclean-%: .phony
249	$(MAKE) -C $* distclean
250
251ifeq (,$(findstring clean,$(MAKECMDGOALS)))
252$(XEN_ROOT)/config/Tools.mk:
253	$(error You have to run ./configure before building or installing the tools)
254endif
255
256PKG_CONFIG_DIR ?= $(XEN_ROOT)/tools/pkg-config
257
258PKG_CONFIG_FILTER = $(foreach l,$(PKG_CONFIG_REMOVE),-e 's!\([ ,]\)$(l),!\1!g' -e 's![ ,]$(l)$$!!g')
259
260$(PKG_CONFIG_DIR)/%.pc: %.pc.in Makefile
261	mkdir -p $(PKG_CONFIG_DIR)
262	@sed -e 's!@@version@@!$(PKG_CONFIG_VERSION)!g' \
263	     -e 's!@@prefix@@!$(PKG_CONFIG_PREFIX)!g' \
264	     -e 's!@@incdir@@!$(PKG_CONFIG_INCDIR)!g' \
265	     -e 's!@@libdir@@!$(PKG_CONFIG_LIBDIR)!g' \
266	     -e 's!@@firmwaredir@@!$(XENFIRMWAREDIR)!g' \
267	     -e 's!@@libexecbin@@!$(LIBEXEC_BIN)!g' \
268	     -e 's!@@cflagslocal@@!$(PKG_CONFIG_CFLAGS_LOCAL)!g' \
269	     -e 's!@@libsflag@@!-Wl,-rpath-link=!g' \
270	     $(PKG_CONFIG_FILTER) < $< > $@
271
272%.pc: %.pc.in Makefile
273	@sed -e 's!@@version@@!$(PKG_CONFIG_VERSION)!g' \
274	     -e 's!@@prefix@@!$(PKG_CONFIG_PREFIX)!g' \
275	     -e 's!@@incdir@@!$(PKG_CONFIG_INCDIR)!g' \
276	     -e 's!@@libdir@@!$(PKG_CONFIG_LIBDIR)!g' \
277	     -e 's!@@firmwaredir@@!$(XENFIRMWAREDIR)!g' \
278	     -e 's!@@libexecbin@@!$(LIBEXEC_BIN)!g' \
279	     -e 's!@@cflagslocal@@!!g' \
280	     -e 's!@@libsflag@@!-L!g' \
281	     $(PKG_CONFIG_FILTER) < $< > $@
282