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