summaryrefslogtreecommitdiff
path: root/tools/Rules.mk
blob: a5229bb5acb409e493d8d4b978080809cf971632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#  -*- mode: Makefile; -*-

# `all' is the default target
all:

-include $(XEN_ROOT)/config/Tools.mk
include $(XEN_ROOT)/Config.mk

XEN_FULLVERSION=$(shell env \
    XEN_EXTRAVERSION=$(XEN_EXTRAVERSION) \
    XEN_VENDORVERSION=$(XEN_VENDORVERSION) \
    $(SHELL) $(XEN_ROOT)/version.sh --full $(XEN_ROOT)/xen/Makefile)

export _INSTALL := $(INSTALL)
INSTALL = $(XEN_ROOT)/tools/cross-install

LDFLAGS += $(PREPEND_LDFLAGS_XEN_TOOLS)

XEN_INCLUDE        = $(XEN_ROOT)/tools/include

include $(XEN_ROOT)/tools/libs/uselibs.mk

CFLAGS_xeninclude = -I$(XEN_INCLUDE)

XENSTORE_XENSTORED ?= y

# A debug build of tools?
debug ?= n
debug_symbols ?= $(debug)

XEN_GOCODE_URL    = golang.xenproject.org

ifeq ($(debug_symbols),y)
CFLAGS += -g3
endif

ifneq ($(nosharedlibs),y)
INSTALL_SHLIB = $(INSTALL_PROG)
SYMLINK_SHLIB = ln -sf
libextension = .so
else
libextension = .a
XENSTORE_STATIC_CLIENTS=y
# If something tries to use these it is a mistake.  Provide references
# to nonexistent programs to produce a sane error message.
INSTALL_SHLIB = : install-shlib-unsupported-fail
SYMLINK_SHLIB = : symlink-shlib-unsupported-fail
endif

# Compiling and linking against in tree libraries.
#
# In order to compile and link against an in-tree library various
# cpp/compiler/linker options are required.
#
# For example consider a library "libfoo" which itself uses two other
# libraries:
#  libbar - whose use is entirely internal to libfoo and not exposed
#           to users of libfoo at all.
#  libbaz - whose use is entirely internal to libfoo but libfoo's
#           public headers include one or more of libbaz's
#           public headers. Users of libfoo are therefore transitively
#           using libbaz's header but not linking against libbaz.
#
# SHLIB_libfoo: Flags for recursively linking against libfoo. Must
#               contains $(call xenlibs-rpath,foo) and:
#                   -Wl,-rpath-link=<directory containing libfoo.so>
#
# CFLAGS_libfoo: Flags for compiling against libfoo. Must add the
#                directories containing libfoo's headers to the
#                include path. Must recursively include
#                $(CFLAGS_libbaz), to satisfy the transitive inclusion
#                of the headers but not $(CFLAGS_libbar) since none of
#                libbar's headers are required to build against
#                libfoo.
#
# LDLIBS_libfoo: Flags for linking against libfoo. Must contain
#                $(call xenlibs-rpath,foo) and the path to libfoo.so
#
# Consumers of libfoo should include $(CFLAGS_libfoo) and
# $(LDLIBS_libfoo) in their appropriate directories. They should not
# include any CFLAGS or LDLIBS relating to libbar or libbaz unless
# they use those libraries directly (not via libfoo) too.

# Give the list of Xen library that the libraries in $(1) are linked against,
# directly or indirectly.
define xenlibs-dependencies
    $(sort $(foreach lib,$(1), \
        $(USELIBS_$(lib)) $(call xenlibs-dependencies,$(USELIBS_$(lib)))))
endef

# Flags for linking recursive dependencies of Xen libraries in $(1)
define xenlibs-rpath
    $(addprefix -Wl$(comma)-rpath-link=$(XEN_ROOT)/tools/libs/,$(call xenlibs-dependencies,$(1)))
endef

# Provide a path for each library in $(1)
define xenlibs-libs
    $(foreach lib,$(1), \
        $(XEN_ROOT)/tools/libs/$(lib)/lib$(FILENAME_$(lib))$(libextension))
endef

# Flags for linking against all Xen libraries listed in $(1)
define xenlibs-ldlibs
    $(call xenlibs-rpath,$(1)) $(call xenlibs-libs,$(1)) \
    $(foreach lib,$(1),$(xenlibs-ldlibs-$(lib)))
endef

# Provide needed flags for linking an in-tree Xen library by an external
# project (or when it is necessary to link with "-lxen$(1)" instead of using
# the full path to the library).
define xenlibs-ldflags
    $(call xenlibs-rpath,$(1)) \
    $(foreach lib,$(1),-L$(XEN_ROOT)/tools/libs/$(lib))
endef

# Flags for linking against all Xen libraries listed in $(1) but by making use
# of -L and -l instead of providing a path to the shared library.
define xenlibs-ldflags-ldlibs
    $(call xenlibs-ldflags,$(1)) \
    $(foreach lib,$(1), -l$(FILENAME_$(lib))) \
    $(foreach lib,$(1),$(xenlibs-ldlibs-$(lib)))
endef

define LIB_defs
 FILENAME_$(1) ?= xen$(1)
 XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1)
 CFLAGS_libxen$(1) = $$(CFLAGS_xeninclude)
 SHLIB_libxen$(1) = $$(call xenlibs-rpath,$(1)) -Wl,-rpath-link=$$(XEN_libxen$(1))
 LDLIBS_libxen$(1) = $$(call xenlibs-ldlibs,$(1))
endef

$(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))

# code which compiles against libxenctrl get __XEN_TOOLS__ and
# therefore sees the unstable hypercall interfaces.
CFLAGS_libxenctrl += -D__XEN_TOOLS__

ifeq ($(CONFIG_Linux),y)
xenlibs-ldlibs-store := -ldl
endif

CFLAGS_libxenlight += $(CFLAGS_libxenctrl)

# Don't add -Werror if we are used by qemu-trad build system.
ifndef BUILDING_QEMU_TRAD
ifeq ($(CONFIG_WERROR),y)
CFLAGS += -Werror
endif
endif

ifeq ($(debug),y)
# Use -Og if available, -O0 otherwise
dbg_opt_level := $(call cc-option,$(CC),-Og,-O0)
CFLAGS += $(dbg_opt_level) -fno-omit-frame-pointer
# But allow an override to -O0 in case Python enforces -D_FORTIFY_SOURCE=<n>.
PY_CFLAGS += $(PY_NOOPT_CFLAGS)
else
CFLAGS += -O2 -fomit-frame-pointer
endif

CFLAGS += -D__XEN_INTERFACE_VERSION__=__XEN_LATEST_INTERFACE_VERSION__

# Get gcc to generate the dependencies for us.
CFLAGS += -MMD -MP -MF .$(if $(filter-out .,$(@D)),$(subst /,@,$(@D))@)$(@F).d
DEPS = .*.d

ifneq ($(FILE_OFFSET_BITS),)
CFLAGS  += -D_FILE_OFFSET_BITS=$(FILE_OFFSET_BITS)
endif
ifneq ($(XEN_OS),NetBSD)
# Enable implicit LFS support *and* explicit LFS names.
CFLAGS  += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
endif

# 32-bit x86 does not perform well with -ve segment accesses on Xen.
CFLAGS-$(CONFIG_X86_32) += $(call cc-option,$(CC),-mno-tls-direct-seg-refs)
CFLAGS += $(CFLAGS-y)

CFLAGS += $(EXTRA_CFLAGS_XEN_TOOLS)

INSTALL_PYTHON_PROG = \
	$(XEN_ROOT)/tools/python/install-wrap "$(PYTHON_PATH)" $(INSTALL_PROG)

%.opic: %.c
	$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) $(CFLAGS_$*.opic) -fPIC -c -o $@ $< $(APPEND_CFLAGS)

%.o: %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) -c -o $@ $< $(APPEND_CFLAGS)

%.o: %.cc
	$(CC) $(CPPFLAGS) $(CXXFLAGS) $(CXXFLAGS_$*.o) -c -o $@ $< $(APPEND_CFLAGS)

%.o: %.S
	$(CC) $(CFLAGS) $(CFLAGS_$*.o) -c $< -o $@ $(APPEND_CFLAGS)
%.opic: %.S
	$(CC) $(CPPFLAGS) -DPIC $(CFLAGS) -fPIC -c -o $@ $< $(APPEND_CFLAGS)

subdirs-all subdirs-clean subdirs-install subdirs-distclean subdirs-uninstall: .phony
	@set -e; for subdir in $(SUBDIRS) $(SUBDIRS-y); do \
		$(MAKE) subdir-$(patsubst subdirs-%,%,$@)-$$subdir; \
	done

subdir-all-% subdir-clean-% subdir-install-% subdir-uninstall-%: .phony
	$(MAKE) -C $* $(patsubst subdir-%-$*,%,$@)

subdir-distclean-%: .phony
	$(MAKE) -C $* distclean

no-configure-targets := distclean subdir-distclean% clean subdir-clean% subtree-force-update-all %-dir-force-update
ifeq (,$(filter $(no-configure-targets),$(MAKECMDGOALS)))
$(XEN_ROOT)/config/Tools.mk:
	$(error You have to run ./configure before building or installing the tools)
endif

PKG_CONFIG_DIR ?= $(XEN_ROOT)/tools/pkg-config

$(PKG_CONFIG_DIR):
	mkdir -p $(PKG_CONFIG_DIR)

$(PKG_CONFIG_DIR)/%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk $(PKG_CONFIG_DIR)
	{ \
	echo "prefix=$(PKG_CONFIG_PREFIX)"; \
	echo "includedir=$(PKG_CONFIG_INCDIR)"; \
	echo "libdir=$(PKG_CONFIG_LIBDIR)"; \
	echo ""; \
	echo "Name: $(PKG_CONFIG_NAME)"; \
	echo "Description: $(PKG_CONFIG_DESC)"; \
	echo "Version: $(PKG_CONFIG_VERSION)"; \
	echo "Cflags: -I\$${includedir}"; \
	echo "Libs: -L\$${libdir} $(PKG_CONFIG_USELIBS) -l$(PKG_CONFIG_LIB)"; \
	echo "Libs.private: $(PKG_CONFIG_LIBSPRIV)"; \
	echo "Requires.private: $(PKG_CONFIG_REQPRIV)"; \
	} > $@

%.pc: Makefile $(XEN_ROOT)/tools/Rules.mk
	{ \
	echo "prefix=$(PKG_CONFIG_PREFIX)"; \
	echo "includedir=$(PKG_CONFIG_INCDIR)"; \
	echo "libdir=$(PKG_CONFIG_LIBDIR)"; \
	echo ""; \
	echo "Name: $(PKG_CONFIG_NAME)"; \
	echo "Description: $(PKG_CONFIG_DESC)"; \
	echo "Version: $(PKG_CONFIG_VERSION)"; \
	echo "Cflags: -I\$${includedir}"; \
	echo "Libs: -L\$${libdir} -l$(PKG_CONFIG_LIB)"; \
	echo "Libs.private: $(PKG_CONFIG_LIBSPRIV)"; \
	echo "Requires.private: $(PKG_CONFIG_REQPRIV)"; \
	} > $@

.PHONY: FORCE
FORCE: