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