1# Common Makefile for building a lib.
2#
3# Variables taken as input:
4#   LIBNAME: name of lib to build, will be prepended with "libxen"
5#   MAJOR:   major version of lib
6#   MINOR:   minor version of lib
7#   USELIBS: xen libs to use (e.g. "toolcore toollog")
8
9SHLIB_LDFLAGS += -Wl,--version-script=libxen$(LIBNAME).map
10
11CFLAGS   += -Werror -Wmissing-prototypes
12CFLAGS   += -I./include $(CFLAGS_xeninclude)
13CFLAGS   += $(foreach lib, $(USELIBS), $(CFLAGS_libxen$(lib)))
14
15LDUSELIBS = $(foreach lib, $(USELIBS), $(LDLIBS_libxen$(lib)))
16
17LIB_OBJS := $(SRCS-y:.c=.o)
18PIC_OBJS := $(SRCS-y:.c=.opic)
19
20LIB := libxen$(LIBNAME).a
21ifneq ($(nosharedlibs),y)
22LIB += libxen$(LIBNAME).so
23endif
24
25PKG_CONFIG := xen$(LIBNAME).pc
26PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
27
28ifneq ($(CONFIG_LIBXC_MINIOS),y)
29PKG_CONFIG_INST := $(PKG_CONFIG)
30$(PKG_CONFIG_INST): PKG_CONFIG_PREFIX = $(prefix)
31$(PKG_CONFIG_INST): PKG_CONFIG_INCDIR = $(includedir)
32$(PKG_CONFIG_INST): PKG_CONFIG_LIBDIR = $(libdir)
33endif
34
35PKG_CONFIG_LOCAL := $(foreach pc,$(PKG_CONFIG),$(PKG_CONFIG_DIR)/$(pc))
36
37$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
38$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
39
40.PHONY: all
41all: build
42
43.PHONY: build
44build:
45	$(MAKE) libs
46
47.PHONY: libs
48libs: headers.chk $(LIB) $(PKG_CONFIG_INST) $(PKG_CONFIG_LOCAL)
49
50headers.chk: $(wildcard include/*.h) $(AUTOINCS)
51
52libxen$(LIBNAME).a: $(LIB_OBJS)
53	$(AR) rc $@ $^
54
55libxen$(LIBNAME).so: libxen$(LIBNAME).so.$(MAJOR)
56	$(SYMLINK_SHLIB) $< $@
57libxen$(LIBNAME).so.$(MAJOR): libxen$(LIBNAME).so.$(MAJOR).$(MINOR)
58	$(SYMLINK_SHLIB) $< $@
59
60libxen$(LIBNAME).so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxen$(LIBNAME).map
61	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxen$(LIBNAME).so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDUSELIBS) $(APPEND_LDFLAGS)
62
63.PHONY: install
64install: build
65	$(INSTALL_DIR) $(DESTDIR)$(libdir)
66	$(INSTALL_DIR) $(DESTDIR)$(includedir)
67	$(INSTALL_SHLIB) libxen$(LIBNAME).so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
68	$(INSTALL_DATA) libxen$(LIBNAME).a $(DESTDIR)$(libdir)
69	$(SYMLINK_SHLIB) libxen$(LIBNAME).so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/libxen$(LIBNAME).so.$(MAJOR)
70	$(SYMLINK_SHLIB) libxen$(LIBNAME).so.$(MAJOR) $(DESTDIR)$(libdir)/libxen$(LIBNAME).so
71	$(INSTALL_DATA) include/xen$(LIBNAME).h $(DESTDIR)$(includedir)
72	$(INSTALL_DATA) xen$(LIBNAME).pc $(DESTDIR)$(PKG_INSTALLDIR)
73
74.PHONY: uninstall
75uninstall:
76	rm -f $(DESTDIR)$(PKG_INSTALLDIR)/xen$(LIBNAME).pc
77	rm -f $(DESTDIR)$(includedir)/xen$(LIBNAME).h
78	rm -f $(DESTDIR)$(libdir)/libxen$(LIBNAME).so
79	rm -f $(DESTDIR)$(libdir)/libxen$(LIBNAME).so.$(MAJOR)
80	rm -f $(DESTDIR)$(libdir)/libxen$(LIBNAME).so.$(MAJOR).$(MINOR)
81	rm -f $(DESTDIR)$(libdir)/libxen$(LIBNAME).a
82
83.PHONY: TAGS
84TAGS:
85	etags -t *.c *.h
86
87.PHONY: clean
88clean:
89	rm -rf *.rpm $(LIB) *~ $(DEPS_RM) $(LIB_OBJS) $(PIC_OBJS)
90	rm -f libxen$(LIBNAME).so.$(MAJOR).$(MINOR) libxen$(LIBNAME).so.$(MAJOR)
91	rm -f headers.chk
92	rm -f xen$(LIBNAME).pc
93
94.PHONY: distclean
95distclean: clean
96