1# libxenstat: statistics-collection library for Xen
2# Copyright (C) International Business Machines Corp., 2005
3# Author: Josh Triplett <josh@kernel.org>
4#
5# This library is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9#
10# This library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13# Lesser General Public License for more details.
14
15XEN_ROOT=$(CURDIR)/../../..
16include $(XEN_ROOT)/tools/Rules.mk
17
18LDCONFIG=ldconfig
19MAKE_LINK=ln -sf
20
21MAJOR=0
22MINOR=0
23
24LIB=src/libxenstat.a
25SHLIB=src/libxenstat.so.$(MAJOR).$(MINOR)
26SHLIB_LINKS=src/libxenstat.so.$(MAJOR) src/libxenstat.so
27OBJECTS-y=src/xenstat.o src/xenstat_qmp.o
28OBJECTS-$(CONFIG_Linux) += src/xenstat_linux.o
29OBJECTS-$(CONFIG_SunOS) += src/xenstat_solaris.o
30OBJECTS-$(CONFIG_NetBSD) += src/xenstat_netbsd.o
31OBJECTS-$(CONFIG_FreeBSD) += src/xenstat_freebsd.o
32SONAME_FLAGS=-Wl,$(SONAME_LDFLAG) -Wl,libxenstat.so.$(MAJOR)
33
34CFLAGS+=-fPIC
35CFLAGS+=-Isrc $(CFLAGS_libxenctrl) $(CFLAGS_libxenstore) $(CFLAGS_xeninclude) -include $(XEN_ROOT)/tools/config.h
36
37LDLIBS-y = $(LDLIBS_libxenstore) $(LDLIBS_libxenctrl) -lyajl
38LDLIBS-$(CONFIG_SunOS) += -lkstat
39
40PKG_CONFIG := xenstat.pc
41PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
42
43ifneq ($(CONFIG_LIBXC_MINIOS),y)
44PKG_CONFIG_INST := $(PKG_CONFIG)
45$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
46$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
47$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
48endif
49
50PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
51
52$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
53$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_LIBXENSTAT)
54$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
55
56.PHONY: all
57all: $(LIB) $(SHLIB) $(SHLIB_LINKS) $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
58
59$(OBJECTS-y): src/_paths.h
60
61$(LIB): $(OBJECTS-y)
62	$(AR) rc $@ $^
63	$(RANLIB) $@
64
65$(SHLIB): $(OBJECTS-y)
66	$(CC) $(LDFLAGS) $(SONAME_FLAGS) $(SHLIB_LDFLAGS) -o $@ \
67	    $(OBJECTS-y) $(LDLIBS-y) $(APPEND_LDFLAGS)
68
69src/libxenstat.so.$(MAJOR): $(SHLIB)
70	$(MAKE_LINK) $(<F) $@
71
72src/libxenstat.so: src/libxenstat.so.$(MAJOR)
73	$(MAKE_LINK) $(<F) $@
74
75.PHONY: install
76install: all
77	$(INSTALL_DATA) src/xenstat.h $(DESTDIR)$(includedir)
78	$(INSTALL_DATA) $(LIB) $(DESTDIR)$(libdir)/libxenstat.a
79	$(INSTALL_PROG) src/libxenstat.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
80	ln -sf libxenstat.so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxenstat.so.$(MAJOR)
81	ln -sf libxenstat.so.$(MAJOR) $(DESTDIR)$(libdir)/libxenstat.so
82	$(INSTALL_DATA) xenstat.pc $(DESTDIR)$(PKG_INSTALLDIR)
83
84.PHONY: uninstall
85uninstall:
86	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xenstat.pc
87	rm -f $(DESTDIR)$(libdir)/libxenstat.so
88	rm -f $(DESTDIR)$(libdir)/libxenstat.so.$(MAJOR)
89	rm -f $(DESTDIR)$(libdir)/libxenstat.so.$(MAJOR).$(MINOR)
90	rm -f $(DESTDIR)$(libdir)/libxenstat.a
91	rm -f $(DESTDIR)$(includedir)/xenstat.h
92
93PYLIB=bindings/swig/python/_xenstat.so
94PYMOD=bindings/swig/python/xenstat.py
95PYSRC=bindings/swig/python/_xenstat.c
96PERLLIB=bindings/swig/perl/xenstat.so
97PERLMOD=bindings/swig/perl/xenstat.pm
98PERLSRC=bindings/swig/perl/xenstat.c
99BINDINGS=$(PYLIB) $(PYMOD) $(PERLLIB) $(PERLMOD)
100BINDINGSRC=$(PYSRC) $(PERLSRC)
101
102# The all-bindings target builds all the language bindings
103.PHONY: all-bindings
104all-bindings: perl-bindings python-bindings
105
106# The install-bindings target installs all the language bindings
107install-bindings: install-perl-bindings install-python-bindings
108
109.PHONY: uninstall-bindings
110uninstall-bindings: uninstall-perl-bindings uninstall-python-bindings
111
112$(BINDINGS): $(SHLIB) $(SHLIB_LINKS) src/xenstat.h
113
114SWIG_FLAGS=-module xenstat -Isrc
115
116# Python bindings
117PYTHON_VERSION=$(PYTHON:python%=%)
118PYTHON_FLAGS=-I/usr/include/python$(PYTHON_VERSION) -lpython$(PYTHON_VERSION)
119$(PYMOD): $(PYSRC)
120$(PYSRC): bindings/swig/xenstat.i
121	swig -python $(SWIG_FLAGS) -outdir $(@D) -o $(PYSRC) $<
122
123$(PYLIB): $(PYSRC)
124	$(CC) $(CFLAGS) $(LDFLAGS) $(PYTHON_FLAGS) $(SHLIB_LDFLAGS) -lxenstat -o $@ $< $(APPEND_LDFLAGS)
125
126python-bindings: $(PYLIB) $(PYMOD)
127
128pythonlibdir=$(prefix)/lib/python$(PYTHON_VERSION)/site-packages
129install-python-bindings: $(PYLIB) $(PYMOD)
130	$(INSTALL_PROG) $(PYLIB) $(DESTDIR)$(pythonlibdir)/_xenstat.so
131	$(INSTALL_PROG) $(PYMOD) $(DESTDIR)$(pythonlibdir)/xenstat.py
132
133.PHONY: uninstall-python-bindings
134uninstall-python-bindings:
135	rm -f $(DESTDIR)$(pythonlibdir)/_xenstat.so
136	rm -f $(DESTDIR)$(pythonlibdir)/xenstat.py
137
138ifeq ($(XENSTAT_PYTHON_BINDINGS),y)
139.PHONY: all
140all: python-bindings
141install: install-python-bindings
142uninstall: uninstall-python-bindings
143endif
144
145# Perl bindings
146PERL_FLAGS=`perl -MConfig -e 'print "$$Config{ccflags} -I$$Config{archlib}/CORE";'`
147$(PERLMOD): $(PERLSRC)
148$(PERLSRC): bindings/swig/xenstat.i
149	swig -perl $(SWIG_FLAGS) -outdir $(@D) -o $(PERLSRC) $<
150
151$(PERLLIB): $(PERLSRC)
152	$(CC) $(CFLAGS) $(LDFLAGS) $(PERL_FLAGS) $(SHLIB_LDFLAGS) -lxenstat -o $@ $< $(APPEND_LDFLAGS)
153
154.PHONY: perl-bindings
155perl-bindings: $(PERLLIB) $(PERLMOD)
156
157.PHONY: install-perl-bindings
158perllibdir=$(prefix)/lib/perl5
159perlmoddir=$(prefix)/share/perl5
160install-perl-bindings: $(PERLLIB) $(PERLMOD)
161	$(INSTALL_PROG) $(PERLLIB) $(DESTDIR)$(perllibdir)/xenstat.so
162	$(INSTALL_PROG) $(PERLMOD) $(DESTDIR)$(perlmoddir)/xenstat.pm
163
164.PHONY: uninstall-perl-bindings
165uninstall-perl-bindings:
166	rm -f $(DESTDIR)$(perllibdir)/xenstat.so
167	rm -f $(DESTDIR)$(perlmoddir)/xenstat.pm
168
169ifeq ($(XENSTAT_PERL_BINDINGS),y)
170.PHONY: all
171all: perl-bindings
172
173.PHONY: install
174install: install-perl-bindings
175uninstall: uninstall-perl-bindings
176endif
177
178.PHONY: clean
179clean:
180	rm -f $(LIB) $(SHLIB) $(SHLIB_LINKS) $(OBJECTS-y) \
181	      $(BINDINGS) $(BINDINGSRC) $(DEPS_RM) src/_paths.h
182	rm -f xenstat.pc
183
184.PHONY: distclean
185distclean: clean
186
187-include $(DEPS_INCLUDE)
188
189genpath-target = $(call buildmakevars2header,src/_paths.h)
190$(eval $(genpath-target))
191