Files
xen/tools/libs/libs.mk
T
Anthony PERARD 98d95437ed libs: Fix auto-generation of version-script for unstable libs
When there isn't a version-script for a shared library (like for
unstable libs), we create one based on the current Xen version. But
that version-script became out-of-date as soon as Xen's version
changes and make as no way to regenerate the version-script on
rebuild.

For unstable libs, we only needs the symver to be different from a
previous release of Xen. There's an option "--default-symver" which
allow to use the soname as symver and as the soname have the Xen
release version, it will be different for every release. With
--default-symver we don't need to generate a version-script.

But we also need to know if there's already an existing version script
, for that we introduce $(version-script) to be used to point to the
path of the existing script. (Guessing if a version script exist for a
stable library with for example $(wildcard) won't work as a file will
exist when building the library without this patch.)

We don't need the version-script unless we are making the shared
library so it is removed from the "all" target.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
2023-02-07 15:17:53 +01:00

131 lines
4.3 KiB
Makefile

# Common Makefile for building a lib.
#
# Variables taken as input:
# PKG_CONFIG: name of pkg-config file (xen$(LIBNAME).pc if empty)
# MAJOR: major version of lib (Xen version if empty)
# MINOR: minor version of lib (0 if empty)
# version-script: Specify the name of a version script to the linker.
LIBNAME := $(notdir $(CURDIR))
ifeq ($(origin MAJOR), undefined)
MAJOR := $(shell $(XEN_ROOT)/version.sh $(XEN_ROOT)/xen/Makefile)
endif
MINOR ?= 0
CFLAGS += -Wmissing-prototypes
CFLAGS += $(CFLAGS_xeninclude)
CFLAGS += $(foreach lib, $(USELIBS_$(LIBNAME)), $(CFLAGS_libxen$(lib)))
LDLIBS += $(call xenlibs-ldlibs,$(USELIBS_$(LIBNAME)))
PIC_OBJS := $(OBJS-y:.o=.opic)
LIB_FILE_NAME = $(FILENAME_$(LIBNAME))
TARGETS := lib$(LIB_FILE_NAME).a
ifneq ($(nosharedlibs),y)
TARGETS += lib$(LIB_FILE_NAME).so
endif
PKG_CONFIG ?= $(LIB_FILE_NAME).pc
PKG_CONFIG_NAME ?= Xen$(LIBNAME)
PKG_CONFIG_DESC ?= The $(PKG_CONFIG_NAME) library for Xen hypervisor
PKG_CONFIG_VERSION := $(MAJOR).$(MINOR)
PKG_CONFIG_USELIBS := $(SHLIB_libxen$(LIBNAME))
PKG_CONFIG_LIB := $(LIB_FILE_NAME)
PKG_CONFIG_REQPRIV := $(subst $(space),$(comma),$(strip $(foreach lib,$(patsubst ctrl,control,$(USELIBS_$(LIBNAME))),xen$(lib))))
ifneq ($(CONFIG_LIBXC_MINIOS),y)
TARGETS += $(PKG_CONFIG)
$(PKG_CONFIG): PKG_CONFIG_PREFIX = $(prefix)
$(PKG_CONFIG): PKG_CONFIG_INCDIR = $(includedir)
$(PKG_CONFIG): PKG_CONFIG_LIBDIR = $(libdir)
endif
PKG_CONFIG_LOCAL := $(PKG_CONFIG_DIR)/$(PKG_CONFIG)
LIBHEADER ?= $(LIB_FILE_NAME).h
LIBHEADERS = $(foreach h, $(LIBHEADER), $(XEN_INCLUDE)/$(h))
PKG_ABI := lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR)-$(XEN_TARGET_ARCH)-abi.dump
$(PKG_CONFIG_LOCAL): PKG_CONFIG_PREFIX = $(XEN_ROOT)
$(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_INCLUDE)
$(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
.PHONY: all
all: $(TARGETS) $(PKG_CONFIG_LOCAL) $(LIBHEADERS)
ifneq ($(NO_HEADERS_CHK),y)
all: headers.chk
headers.chk: $(LIBHEADERS) $(AUTOINCS)
for i in $(filter %.h,$^); do \
$(CC) -x c -ansi -Wall -Werror $(CFLAGS_xeninclude) \
-S -o /dev/null $$i || exit 1; \
echo $$i; \
done >$@.new
mv $@.new $@
endif
headers.lst: FORCE
@{ set -e; $(foreach h,$(LIBHEADERS),echo $(h);) } > $@.tmp
@$(call move-if-changed,$@.tmp,$@)
lib$(LIB_FILE_NAME).a: $(OBJS-y)
$(AR) rc $@ $^
lib$(LIB_FILE_NAME).so: lib$(LIB_FILE_NAME).so.$(MAJOR)
$(SYMLINK_SHLIB) $< $@
lib$(LIB_FILE_NAME).so.$(MAJOR): lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR)
$(SYMLINK_SHLIB) $< $@
lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR): $(PIC_OBJS) $(version-script)
$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,lib$(LIB_FILE_NAME).so.$(MAJOR) -Wl,$(if $(version-script),--version-script=$(version-script),--default-symver) $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS) $(APPEND_LDFLAGS)
# If abi-dumper is available, write out the ABI analysis
ifneq ($(ABI_DUMPER),)
ifneq ($(nosharedlibs),y)
all: $(PKG_ABI)
$(PKG_ABI): lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) headers.lst
$(ABI_DUMPER) $< -o $@ -public-headers headers.lst -lver $(MAJOR).$(MINOR)
endif
endif
.PHONY: install
install:: all
$(INSTALL_DIR) $(DESTDIR)$(libdir)
$(INSTALL_DIR) $(DESTDIR)$(includedir)
$(INSTALL_SHLIB) lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)
$(INSTALL_DATA) lib$(LIB_FILE_NAME).a $(DESTDIR)$(libdir)
$(SYMLINK_SHLIB) lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) $(DESTDIR)$(libdir)/lib$(LIB_FILE_NAME).so.$(MAJOR)
$(SYMLINK_SHLIB) lib$(LIB_FILE_NAME).so.$(MAJOR) $(DESTDIR)$(libdir)/lib$(LIB_FILE_NAME).so
for i in $(LIBHEADERS); do $(INSTALL_DATA) $$i $(DESTDIR)$(includedir); done
$(INSTALL_DATA) $(PKG_CONFIG) $(DESTDIR)$(PKG_INSTALLDIR)
.PHONY: uninstall
uninstall::
rm -f $(DESTDIR)$(PKG_INSTALLDIR)/$(LIB_FILE_NAME).pc
for i in $(LIBHEADER); do rm -f $(DESTDIR)$(includedir)/$$i; done
rm -f $(DESTDIR)$(libdir)/lib$(LIB_FILE_NAME).so
rm -f $(DESTDIR)$(libdir)/lib$(LIB_FILE_NAME).so.$(MAJOR)
rm -f $(DESTDIR)$(libdir)/lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR)
rm -f $(DESTDIR)$(libdir)/lib$(LIB_FILE_NAME).a
.PHONY: TAGS
TAGS:
etags -t *.c *.h
.PHONY: clean
clean::
rm -rf $(TARGETS) *~ $(DEPS_RM) $(OBJS-y) $(PIC_OBJS)
rm -f lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR) lib$(LIB_FILE_NAME).so.$(MAJOR)
rm -f headers.chk headers.lst
.PHONY: distclean
distclean: clean
ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
-include $(DEPS_INCLUDE)
endif