1# 2# tools/libxl/Makefile 3# 4 5XEN_ROOT = $(CURDIR)/../.. 6include $(XEN_ROOT)/tools/Rules.mk 7 8MAJOR = 4.14 9MINOR = 0 10 11XLUMAJOR = 4.14 12XLUMINOR = 0 13 14CFLAGS += -Werror -Wno-format-zero-length -Wmissing-declarations \ 15 -Wno-declaration-after-statement -Wformat-nonliteral 16CFLAGS += -I. -fPIC 17 18ifeq ($(CONFIG_Linux),y) 19LIBUUID_LIBS += -luuid 20endif 21 22LIBXL_LIBS = 23LIBXL_LIBS = $(LDLIBS_libxentoollog) $(LDLIBS_libxenevtchn) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxenhypfs) $(LDLIBS_libxenstore) $(LDLIBS_libxentoolcore) $(PTYFUNCS_LIBS) $(LIBUUID_LIBS) 24ifeq ($(CONFIG_LIBNL),y) 25LIBXL_LIBS += $(LIBNL3_LIBS) 26endif 27ifeq ($(CONFIG_Linux),y) 28LIBXL_LIBS += -lrt 29endif 30 31CFLAGS_LIBXL += $(CFLAGS_libxentoollog) 32CFLAGS_LIBXL += $(CFLAGS_libxentoolcore) 33CFLAGS_LIBXL += $(CFLAGS_libxenevtchn) 34CFLAGS_LIBXL += $(CFLAGS_libxenctrl) 35CFLAGS_LIBXL += $(CFLAGS_libxenguest) 36CFLAGS_LIBXL += $(CFLAGS_libxenhypfs) 37CFLAGS_LIBXL += $(CFLAGS_libxenstore) 38ifeq ($(CONFIG_LIBNL),y) 39CFLAGS_LIBXL += $(LIBNL3_CFLAGS) 40endif 41CFLAGS_LIBXL += -Wshadow 42ifeq ($(debug),y) 43CFLAGS_LIBXL += -DCONFIG_DEBUG 44endif 45 46LIBXL_LIBS-$(CONFIG_ARM) += -lfdt 47 48CFLAGS += $(PTHREAD_CFLAGS) 49LDFLAGS += $(PTHREAD_LDFLAGS) 50LIBXL_LIBS += $(PTHREAD_LIBS) 51LIBXL_LIBS += $(LIBXL_LIBS-y) 52 53LIBXLU_LIBS = $(LDLIBS_libxenlight) 54 55LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o flexarray.o 56 57ifeq ($(CONFIG_LIBNL),y) 58LIBXL_OBJS-y += libxl_netbuffer.o 59else 60LIBXL_OBJS-y += libxl_nonetbuffer.o 61endif 62 63ifeq ($(CONFIG_X86),y) 64LIBXL_OBJS-y += libxl_convert_callout.o 65else 66LIBXL_OBJS-y += libxl_no_convert_callout.o 67endif 68 69LIBXL_OBJS-y += libxl_remus.o libxl_checkpoint_device.o libxl_remus_disk_drbd.o 70 71ifeq ($(CONFIG_LIBNL),y) 72LIBXL_OBJS-y += libxl_colo_restore.o libxl_colo_save.o 73LIBXL_OBJS-y += libxl_colo_qdisk.o 74LIBXL_OBJS-y += libxl_colo_proxy.o 75LIBXL_OBJS-y += libxl_colo_nic.o 76else 77LIBXL_OBJS-y += libxl_no_colo.o 78endif 79 80ACPI_PATH = $(XEN_ROOT)/tools/libacpi 81DSDT_FILES-$(CONFIG_X86) = dsdt_pvh.c 82ACPI_OBJS = $(patsubst %.c,%.o,$(DSDT_FILES-y)) build.o static_tables.o 83$(DSDT_FILES-y): acpi 84$(ACPI_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/libxl_x86_acpi.h\" 85vpath build.c $(ACPI_PATH)/ 86vpath static_tables.c $(ACPI_PATH)/ 87LIBXL_OBJS-$(CONFIG_X86) += $(ACPI_OBJS) 88 89.PHONY: acpi 90acpi: 91 $(MAKE) -C $(ACPI_PATH) ACPI_BUILD_DIR=$(CURDIR) DSDT_FILES="$(DSDT_FILES-y)" 92 93LIBXL_OBJS-$(CONFIG_X86) += libxl_cpuid.o libxl_x86.o libxl_psr.o libxl_x86_acpi.o 94LIBXL_OBJS-$(CONFIG_ARM) += libxl_nocpuid.o libxl_arm.o libxl_libfdt_compat.o 95ifeq ($(CONFIG_ARM_64),y) 96DSDT_FILES-y = dsdt_anycpu_arm.c 97LIBXL_OBJS-y += libxl_arm_acpi.o $(patsubst %.c,%.o,$(DSDT_FILES-y)) 98dsdt_anycpu_arm.c: 99 $(MAKE) -C $(ACPI_PATH) ACPI_BUILD_DIR=$(CURDIR) DSDT_FILES="$(DSDT_FILES-y)" 100else 101LIBXL_OBJS-$(CONFIG_ARM) += libxl_arm_no_acpi.o 102endif 103 104ifeq ($(CONFIG_NetBSD),y) 105LIBXL_OBJS-y += libxl_netbsd.o 106else 107ifeq ($(CONFIG_Linux),y) 108LIBXL_OBJS-y += libxl_linux.o 109else 110ifeq ($(CONFIG_FreeBSD),y) 111LIBXL_OBJS-y += libxl_freebsd.o 112else 113$(error Your Operating System is not supported by libxenlight, \ 114please check libxl_linux.c and libxl_netbsd.c to see how to get it ported) 115endif 116endif 117endif 118 119ifeq ($(FLEX),) 120%.c %.h:: %.l 121 $(warning Flex is needed to rebuild some libxl parsers and \ 122 scanners, please install it and rerun configure) 123endif 124 125ifeq ($(BISON),) 126%.c %.h:: %.y 127 $(warning Bison is needed to rebuild some libxl parsers and \ 128 scanners, please install it an rerun configure) 129endif 130 131LIBXL_LIBS += -lyajl 132 133LIBXL_OBJS = flexarray.o libxl.o libxl_create.o libxl_dm.o libxl_pci.o \ 134 libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o \ 135 libxl_internal.o libxl_utils.o libxl_uuid.o \ 136 libxl_json.o libxl_aoutils.o libxl_numa.o libxl_vnuma.o \ 137 libxl_stream_read.o libxl_stream_write.o \ 138 libxl_save_callout.o _libxl_save_msgs_callout.o \ 139 libxl_qmp.o libxl_event.o libxl_fork.o \ 140 libxl_dom_suspend.o libxl_dom_save.o libxl_usb.o \ 141 libxl_vtpm.o libxl_nic.o libxl_disk.o libxl_console.o \ 142 libxl_cpupool.o libxl_mem.o libxl_sched.o libxl_tmem.o \ 143 libxl_9pfs.o libxl_domain.o libxl_vdispl.o \ 144 libxl_pvcalls.o libxl_vsnd.o libxl_vkb.o $(LIBXL_OBJS-y) 145LIBXL_OBJS += libxl_genid.o 146LIBXL_OBJS += _libxl_types.o libxl_flask.o _libxl_types_internal.o 147 148LIBXL_TESTS += timedereg 149LIBXL_TESTS_PROGS = $(LIBXL_TESTS) fdderegrace 150LIBXL_TESTS_INSIDE = $(LIBXL_TESTS) fdevent 151 152# Each entry FOO in LIBXL_TESTS has two main .c files: 153# libxl_test_FOO.c "inside libxl" code to support the test case 154# test_FOO.c "outside libxl" code to exercise the test case 155# Conventionally there will also be: 156# libxl_test_FOO.h interface between the "inside" and "outside" parts 157# The "inside libxl" file is compiled exactly like a piece of libxl, and the 158# "outside libxl" file is compiled exactly like a piece of application 159# code. They must share information via explicit libxl entrypoints. 160# Unlike proper parts of libxl, it is permissible for libxl_test_FOO.c 161# to use private global variables for its state. Note that all the 162# "inside" parts are compiled into a single test library, so their 163# symbol names must be unique. 164# 165# To run these tests, either use LD_PRELOAD to get libxenlight_test.so 166# loaded, or rename it to libxenlight.so so it is the target of the 167# appropriate symlinks. 168 169LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS_INSIDE),libxl_test_$t.o) 170TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t.o) test_common.o 171TEST_PROGS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t) 172 173$(LIBXL_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h 174 175AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h _libxl_list.h _paths.h \ 176 libxlu_disk_l.h _libxl_save_msgs_callout.h _libxl_save_msgs_helper.h 177AUTOSRCS= libxlu_cfg_y.c libxlu_cfg_l.c 178AUTOSRCS += _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c 179LIBXLU_OBJS = libxlu_cfg_y.o libxlu_cfg_l.o libxlu_cfg.o \ 180 libxlu_disk_l.o libxlu_disk.o libxlu_vif.o libxlu_pci.o 181$(LIBXLU_OBJS): CFLAGS += $(CFLAGS_libxenctrl) # For xentoollog.h 182 183$(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore) 184 185CLIENTS = testidl libxl-save-helper 186 187libxl_dom.o: CFLAGS += -I$(XEN_ROOT)/tools # include libacpi/x86.h 188libxl_x86_acpi.o: CFLAGS += -I$(XEN_ROOT)/tools 189 190SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o 191$(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) 192 193PKG_CONFIG = xenlight.pc xlutil.pc 194PKG_CONFIG_VERSION := $(MAJOR).$(MINOR) 195 196ifneq ($(CONFIG_LIBXC_MINIOS),y) 197PKG_CONFIG_INST := $(PKG_CONFIG) 198xenlight.pc: PKG_CONFIG_VERSION = $(MAJOR).$(MINOR) 199xlutil.pc: PKG_CONFIG_VERSION = $(XLUMAJOR).$(XLUMINOR) 200$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix) 201$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir) 202$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir) 203endif 204 205PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc)) 206 207$(PKG_CONFIG_DIR)/xenlight.pc: PKG_CONFIG_VERSION = $(MAJOR).$(MINOR) 208$(PKG_CONFIG_DIR)/xlutil.pc: PKG_CONFIG_VERSION = $(XLUMAJOR).$(XLUMINOR) 209$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT) 210$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(CURDIR) 211$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR) 212$(PKG_CONFIG_LOCAL): PKG_CONFIG_CFLAGS_LOCAL = $(CFLAGS_xeninclude) 213 214testidl.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight) 215testidl.c: libxl_types.idl gentest.py libxl.h $(AUTOINCS) 216 $(PYTHON) gentest.py libxl_types.idl testidl.c.new 217 mv testidl.c.new testidl.c 218 219.PHONY: all 220all: $(CLIENTS) $(TEST_PROGS) $(PKG_CONFIG) $(PKG_CONFIG_LOCAL) \ 221 libxenlight.so libxenlight.a libxlutil.so libxlutil.a \ 222 $(AUTOSRCS) $(AUTOINCS) idl-external 223 224$(LIBXL_OBJS) $(LIBXLU_OBJS) $(SAVE_HELPER_OBJS) \ 225 $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): \ 226 $(AUTOINCS) libxl.api-ok 227 228%.c %.h:: %.y 229 @rm -f $*.[ch] 230 $(BISON) --output=$*.c $< 231 232%.c %.h:: %.l 233 @rm -f $*.[ch] 234 $(FLEX) --header-file=$*.h --outfile=$*.c $< 235 236genpath-target = $(call buildmakevars2header,_paths.h) 237$(eval $(genpath-target)) 238 239libxl.api-ok: check-libxl-api-rules _libxl.api-for-check 240 $(PERL) $^ 241 touch $@ 242 243_%.api-for-check: %.h $(AUTOINCS) 244 $(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_$*.o) -c -E $< $(APPEND_CFLAGS) \ 245 -DLIBXL_EXTERNAL_CALLERS_ONLY=LIBXL_EXTERNAL_CALLERS_ONLY \ 246 >$@.new 247 mv -f $@.new $@ 248 249_libxl_list.h: $(XEN_INCLUDE)/xen-external/bsd-sys-queue-h-seddery $(XEN_INCLUDE)/xen-external/bsd-sys-queue.h 250 $(PERL) $^ --prefix=libxl >$@.new 251 $(call move-if-changed,$@.new,$@) 252 253_libxl_save_msgs_helper.c _libxl_save_msgs_callout.c \ 254_libxl_save_msgs_helper.h _libxl_save_msgs_callout.h: \ 255 libxl_save_msgs_gen.pl 256 $(PERL) -w $< $@ >$@.new 257 $(call move-if-changed,$@.new,$@) 258 259libxl.h: _libxl_types.h _libxl_list.h 260libxl_json.h: _libxl_types_json.h 261libxl_internal.h: _libxl_types_internal.h _libxl_types_private.h _libxl_types_internal_private.h _paths.h 262libxl_internal_json.h: _libxl_types_internal_json.h 263xl.h: _paths.h 264 265$(LIBXL_OBJS) $(LIBXL_TEST_OBJS) $(LIBXLU_OBJS) \ 266 $(TEST_PROG_OBJS) $(SAVE_HELPER_OBJS): libxl.h 267$(LIBXL_OBJS) $(LIBXL_TEST_OBJS): libxl_internal.h 268 269_libxl_type%.h _libxl_type%_json.h _libxl_type%_private.h _libxl_type%.c: libxl_type%.idl gentypes.py idl.py 270 $(eval stem = $(notdir $*)) 271 $(PYTHON) gentypes.py libxl_type$(stem).idl __libxl_type$(stem).h __libxl_type$(stem)_private.h \ 272 __libxl_type$(stem)_json.h __libxl_type$(stem).c 273 $(call move-if-changed,__libxl_type$(stem).h,_libxl_type$(stem).h) 274 $(call move-if-changed,__libxl_type$(stem)_private.h,_libxl_type$(stem)_private.h) 275 $(call move-if-changed,__libxl_type$(stem)_json.h,_libxl_type$(stem)_json.h) 276 $(call move-if-changed,__libxl_type$(stem).c,_libxl_type$(stem).c) 277 278# NOTE: This is safe to do at the moment because idl-external and 279# idl-gen are only called from libxl/Makefile:all, which must return 280# before golang/Makefile is callid. idl-external and idl-gen must 281# never be called from another part of the make system without careful thought 282# about races with tools/golang/xenlight/Makefile:all 283.PHONY: idl-external 284idl-external: 285 $(MAKE) -C $(XEN_ROOT)/tools/golang/xenlight idl-gen 286 287LIBXL_IDLGEN_FILES = _libxl_types.h _libxl_types_json.h _libxl_types_private.h _libxl_types.c \ 288 _libxl_types_internal.h _libxl_types_internal_json.h _libxl_types_internal_private.h _libxl_types_internal.c 289 290 291idl-gen: $(LIBXL_GEN_FILES) idl-external 292 293libxenlight.so: libxenlight.so.$(MAJOR) 294 $(SYMLINK_SHLIB) $< $@ 295 296libxenlight.so.$(MAJOR): libxenlight.so.$(MAJOR).$(MINOR) 297 $(SYMLINK_SHLIB) $< $@ 298 299libxenlight.so.$(MAJOR).$(MINOR): $(LIBXL_OBJS) 300 $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LIBXL_LIBS) $(APPEND_LDFLAGS) 301 302libxenlight_test.so: $(LIBXL_OBJS) $(LIBXL_TEST_OBJS) 303 $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LIBXL_LIBS) $(APPEND_LDFLAGS) 304 305libxenlight.a: $(LIBXL_OBJS) 306 $(AR) rcs libxenlight.a $^ 307 308libxlutil.so: libxlutil.so.$(XLUMAJOR) 309 $(SYMLINK_SHLIB) $< $@ 310 311libxlutil.so.$(XLUMAJOR): libxlutil.so.$(XLUMAJOR).$(XLUMINOR) 312 $(SYMLINK_SHLIB) $< $@ 313 314libxlutil.so.$(XLUMAJOR).$(XLUMINOR): $(LIBXLU_OBJS) libxenlight.so 315 $(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxlutil.so.$(XLUMAJOR) $(SHLIB_LDFLAGS) -o $@ $(LIBXLU_OBJS) $(LIBXLU_LIBS) $(APPEND_LDFLAGS) 316 317libxlutil.a: $(LIBXLU_OBJS) 318 $(AR) rcs libxlutil.a $^ 319 320test_%: test_%.o test_common.o libxlutil.so libxenlight_test.so 321 $(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS) 322 323libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so 324 $(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS) 325 326testidl: testidl.o libxlutil.so libxenlight.so 327 $(CC) $(LDFLAGS) -o $@ testidl.o libxlutil.so $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS) 328 329.PHONY: install 330install: all 331 $(INSTALL_DIR) $(DESTDIR)$(libdir) 332 $(INSTALL_DIR) $(DESTDIR)$(includedir) 333 $(INSTALL_DIR) $(DESTDIR)$(LIBEXEC_BIN) 334 $(INSTALL_PROG) libxl-save-helper $(DESTDIR)$(LIBEXEC_BIN) 335 $(INSTALL_SHLIB) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir) 336 $(SYMLINK_SHLIB) libxenlight.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenlight.so.$(MAJOR) 337 $(SYMLINK_SHLIB) libxenlight.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenlight.so 338 $(INSTALL_DATA) libxenlight.a $(DESTDIR)$(libdir) 339 $(INSTALL_SHLIB) libxlutil.so.$(XLUMAJOR).$(XLUMINOR) $(DESTDIR)$(libdir) 340 $(SYMLINK_SHLIB) libxlutil.so.$(XLUMAJOR).$(XLUMINOR) $(DESTDIR)$(libdir)/libxlutil.so.$(XLUMAJOR) 341 $(SYMLINK_SHLIB) libxlutil.so.$(XLUMAJOR) $(DESTDIR)$(libdir)/libxlutil.so 342 $(INSTALL_DATA) libxlutil.a $(DESTDIR)$(libdir) 343 $(INSTALL_DATA) libxl.h libxl_event.h libxl_json.h _libxl_types.h _libxl_types_json.h _libxl_list.h libxl_utils.h libxl_uuid.h libxlutil.h $(DESTDIR)$(includedir) 344 $(INSTALL_DATA) xenlight.pc $(DESTDIR)$(PKG_INSTALLDIR) 345 $(INSTALL_DATA) xlutil.pc $(DESTDIR)$(PKG_INSTALLDIR) 346 347.PHONY: uninstall 348uninstall: 349 rm -f $(addprefix $(DESTDIR)$(PKG_INSTALLDIR)/,xlutil.pc xenlight.pc) 350 rm -f $(addprefix $(DESTDIR)$(includedir)/,libxl.h libxl_event.h libxl_json.h _libxl_types.h _libxl_types_json.h _libxl_list.h libxl_utils.h libxl_uuid.h libxlutil.h) 351 rm -f $(DESTDIR)$(libdir)/libxlutil.a 352 rm -f $(DESTDIR)$(libdir)/libxlutil.so 353 rm -f $(DESTDIR)$(libdir)/libxlutil.so.$(XLUMAJOR) 354 rm -f $(DESTDIR)$(libdir)/libxlutil.so.$(XLUMAJOR).$(XLUMINOR) 355 rm -f $(DESTDIR)$(libdir)/libxenlight.a 356 rm -f $(DESTDIR)$(libdir)/libxenlight.so 357 rm -f $(DESTDIR)$(libdir)/libxenlight.so.$(MAJOR) 358 rm -f $(DESTDIR)$(libdir)/libxenlight.so.$(MAJOR).$(MINOR) 359 rm -f $(DESTDIR)$(LIBEXEC_BIN)/libxl-save-helper 360 361.PHONY: clean 362clean: 363 $(RM) -f _*.h *.o *.so* *.a $(CLIENTS) $(DEPS_RM) 364 $(RM) -f _*.c *.pyc _paths.*.tmp _*.api-for-check 365 $(RM) -f testidl.c.new testidl.c *.api-ok 366 $(RM) -f xenlight.pc 367 $(RM) -f xlutil.pc 368 $(MAKE) -C $(ACPI_PATH) ACPI_BUILD_DIR=$(CURDIR) clean 369 370distclean: clean 371 372realclean: distclean 373 $(RM) -f $(AUTOSRCS) $(AUTOINCS) 374 375-include $(DEPS_INCLUDE) 376