tools: generate most contents of library make variables
PATCH 6/6 tools: generate most contents of library make variables
Library related make variables (CFLAGS_lib*, SHDEPS_lib*, LDLIBS_lib* and SHLIB_lib*) mostly have a common pattern for their values. Generate most of this content automatically by adding a new per-library variable defining on which other libraries a lib is depending.
This in turn makes it possible to drop the USELIB variable from each library Makefile.
The LIBNAME variable can be dropped, too, as it can be derived from the directory name the library is residing in.
--- tools/Rules.mk | 74 +++++++++++-------------------- tools/libs/call/Makefile | 2 - tools/libs/devicemodel/Makefile | 2 - tools/libs/evtchn/Makefile | 2 - tools/libs/foreignmemory/Makefile | 2 - tools/libs/gnttab/Makefile | 2 - tools/libs/hypfs/Makefile | 2 - tools/libs/libs.mk | 8 ++-- tools/libs/toolcore/Makefile | 1 - tools/libs/toollog/Makefile | 1 - 10 files changed, 31 insertions(+), 65 deletions(-)
tools/Rules.mk +27 -47
@@ -12,14 +12,24 @@ INSTALL = $(XEN_ROOT)/tools/cross-install LDFLAGS += $(PREPEND_LDFLAGS_XEN_TOOLS) XEN_INCLUDE = $(XEN_ROOT)/tools/include -XEN_libxentoolcore = $(XEN_ROOT)/tools/libs/toolcore -XEN_libxentoollog = $(XEN_ROOT)/tools/libs/toollog -XEN_libxenevtchn = $(XEN_ROOT)/tools/libs/evtchn -XEN_libxengnttab = $(XEN_ROOT)/tools/libs/gnttab -XEN_libxencall = $(XEN_ROOT)/tools/libs/call -XEN_libxenforeignmemory = $(XEN_ROOT)/tools/libs/foreignmemory -XEN_libxendevicemodel = $(XEN_ROOT)/tools/libs/devicemodel -XEN_libxenhypfs = $(XEN_ROOT)/tools/libs/hypfs + +LIBS_LIBS += toolcore +USELIBS_toolcore := +LIBS_LIBS += toollog +USELIBS_toollog := +LIBS_LIBS += evtchn +USELIBS_evtchn := toollog toolcore +LIBS_LIBS += gnttab +USELIBS_gnttab := toollog toolcore +LIBS_LIBS += call +USELIBS_call := toollog toolcore +LIBS_LIBS += foreignmemory +USELIBS_foreignmemory := toollog toolcore +LIBS_LIBS += devicemodel +USELIBS_devicemodel := toollog toolcore call +LIBS_LIBS += hypfs +USELIBS_hypfs := toollog toolcore call + XEN_libxenctrl = $(XEN_ROOT)/tools/libxc # Currently libxenguest lives in the same directory as libxenctrl XEN_libxenguest = $(XEN_libxenctrl)
@@ -99,45 +109,15 @@ endif # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or # $(SHLIB_libfoo) -CFLAGS_libxentoollog = -I$(XEN_libxentoollog)/include $(CFLAGS_xeninclude) -SHDEPS_libxentoollog = -LDLIBS_libxentoollog = $(SHDEPS_libxentoollog) $(XEN_libxentoollog)/libxentoollog$(libextension) -SHLIB_libxentoollog = $(SHDEPS_libxentoollog) -Wl,-rpath-link=$(XEN_libxentoollog) - -CFLAGS_libxentoolcore = -I$(XEN_libxentoolcore)/include $(CFLAGS_xeninclude) -SHDEPS_libxentoolcore = -LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) $(XEN_libxentoolcore)/libxentoolcore$(libextension) -SHLIB_libxentoolcore = $(SHDEPS_libxentoolcore) -Wl,-rpath-link=$(XEN_libxentoolcore) - -CFLAGS_libxenevtchn = -I$(XEN_libxenevtchn)/include $(CFLAGS_xeninclude) -SHDEPS_libxenevtchn = $(SHLIB_libxentoolcore) -LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) $(XEN_libxenevtchn)/libxenevtchn$(libextension) -SHLIB_libxenevtchn = $(SHDEPS_libxenevtchn) -Wl,-rpath-link=$(XEN_libxenevtchn) - -CFLAGS_libxengnttab = -I$(XEN_libxengnttab)/include $(CFLAGS_xeninclude) -SHDEPS_libxengnttab = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) -LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) $(XEN_libxengnttab)/libxengnttab$(libextension) -SHLIB_libxengnttab = $(SHDEPS_libxengnttab) -Wl,-rpath-link=$(XEN_libxengnttab) - -CFLAGS_libxencall = -I$(XEN_libxencall)/include $(CFLAGS_xeninclude) -SHDEPS_libxencall = $(SHLIB_libxentoolcore) -LDLIBS_libxencall = $(SHDEPS_libxencall) $(XEN_libxencall)/libxencall$(libextension) -SHLIB_libxencall = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_libxencall) - -CFLAGS_libxenforeignmemory = -I$(XEN_libxenforeignmemory)/include $(CFLAGS_xeninclude) -SHDEPS_libxenforeignmemory = $(SHLIB_libxentoolcore) -LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) $(XEN_libxenforeignmemory)/libxenforeignmemory$(libextension) -SHLIB_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) -Wl,-rpath-link=$(XEN_libxenforeignmemory) - -CFLAGS_libxendevicemodel = -I$(XEN_libxendevicemodel)/include $(CFLAGS_xeninclude) -SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall) -LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_libxendevicemodel)/libxendevicemodel$(libextension) -SHLIB_libxendevicemodel = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_libxendevicemodel) - -CFLAGS_libxenhypfs = -I$(XEN_libxenhypfs)/include $(CFLAGS_xeninclude) -SHDEPS_libxenhypfs = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall) -LDLIBS_libxenhypfs = $(SHDEPS_libxenhypfs) $(XEN_libxenhypfs)/libxenhypfs$(libextension) -SHLIB_libxenhypfs = $(SHDEPS_libxenhypfs) -Wl,-rpath-link=$(XEN_libxenhypfs) +define LIB_defs = + XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1) + CFLAGS_libxen$(1) = -I$$(XEN_libxen$(1))/include $$(CFLAGS_xeninclude) + SHDEPS_libxen$(1) = $$(foreach use,$$(USELIBS_$(1)),$$(SHLIB_libxen$$(use))) + LDLIBS_libxen$(1) = $$(SHDEPS_libxen$(1)) $$(XEN_libxen$(1))/libxen$(1)$$(libextension) + SHLIB_libxen$(1) = $$(SHDEPS_libxen$(1)) -Wl,-rpath-link=$$(XEN_libxen$(1)) +endef + +$(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib)))) # code which compiles against libxenctrl get __XEN_TOOLS__ and # therefore sees the unstable hypercall interfaces.
tools/libs/call/Makefile +0 -2
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 2 -LIBNAME := call -USELIBS := toollog toolcore SRCS-y += core.c buffer.c SRCS-$(CONFIG_Linux) += linux.c
tools/libs/devicemodel/Makefile +0 -2
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 3 -LIBNAME := devicemodel -USELIBS := toollog toolcore call SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.c
tools/libs/evtchn/Makefile +0 -2
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 1 -LIBNAME := evtchn -USELIBS := toollog toolcore SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.c
tools/libs/foreignmemory/Makefile +0 -2
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 3 -LIBNAME := foreignmemory -USELIBS := toollog toolcore SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.c
tools/libs/gnttab/Makefile +0 -2
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 2 -LIBNAME := gnttab -USELIBS := toollog toolcore SRCS-GNTTAB += gnttab_core.c SRCS-GNTSHR += gntshr_core.c
tools/libs/hypfs/Makefile +0 -2
@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 0 -LIBNAME := hypfs -USELIBS := toollog toolcore call APPEND_LDFLAGS += -lz
tools/libs/libs.mk +4 -4
@@ -1,18 +1,18 @@ # Common Makefile for building a lib. # # Variables taken as input: -# LIBNAME: name of lib to build, will be prepended with "libxen" # MAJOR: major version of lib # MINOR: minor version of lib -# USELIBS: xen libs to use (e.g. "toolcore toollog") + +LIBNAME := $(notdir $(CURDIR)) SHLIB_LDFLAGS += -Wl,--version-script=libxen$(LIBNAME).map CFLAGS += -Werror -Wmissing-prototypes CFLAGS += -I./include $(CFLAGS_xeninclude) -CFLAGS += $(foreach lib, $(USELIBS), $(CFLAGS_libxen$(lib))) +CFLAGS += $(foreach lib, $(USELIBS_$(LIBNAME)), $(CFLAGS_libxen$(lib))) -LDUSELIBS = $(foreach lib, $(USELIBS), $(LDLIBS_libxen$(lib))) +LDUSELIBS = $(foreach lib, $(USELIBS_$(LIBNAME)), $(LDLIBS_libxen$(lib))) LIB_OBJS := $(SRCS-y:.c=.o) PIC_OBJS := $(SRCS-y:.c=.opic)
tools/libs/toolcore/Makefile +0 -1
@@ -3,7 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 0 -LIBNAME := toolcore AUTOINCS := include/_xentoolcore_list.h SRCS-y += handlereg.c
tools/libs/toollog/Makefile +0 -1
@@ -3,7 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 0 -LIBNAME := toollog SRCS-y += xtl_core.c SRCS-y += xtl_logger_stdio.c
Signature · 1 line
2.26.2
Quoted 5 lines · Juergen Gross
Library related make variables (CFLAGS_lib*, SHDEPS_lib*, LDLIBS_lib* and SHLIB_lib*) mostly have a common pattern for their values. Generate most of this content automatically by adding a new per-library variable defining on which other libraries a lib is depending.
Quoted 7 lines
This in turn makes it possible to drop the USELIB variable from each library
Makefile.The LIBNAME variable can be dropped, too, as it can be derived from the directory name the library is residing in.
Signed-off-by Juergen Gross <[email protected]>
Hmm, after Samuel's reply to patch II 1/17 I'm inclined to put the USELIBS_* variables into a new tools/libs/uselibs.mk file in order to be able to include it from stubdom/Makefile.
Juergen
Quoted 235 lines
--- tools/Rules.mk | 74 +++++++++++-------------------- tools/libs/call/Makefile | 2 - tools/libs/devicemodel/Makefile | 2 - tools/libs/evtchn/Makefile | 2 - tools/libs/foreignmemory/Makefile | 2 - tools/libs/gnttab/Makefile | 2 - tools/libs/hypfs/Makefile | 2 - tools/libs/libs.mk | 8 ++-- tools/libs/toolcore/Makefile | 1 - tools/libs/toollog/Makefile | 1 - 10 files changed, 31 insertions(+), 65 deletions(-)tools/Rules.mk +27
-47@@ -12,14 +12,24 @@ INSTALL = $(XEN_ROOT)/tools/cross-install LDFLAGS += $(PREPEND_LDFLAGS_XEN_TOOLS) XEN_INCLUDE = $(XEN_ROOT)/tools/include -XEN_libxentoolcore = $(XEN_ROOT)/tools/libs/toolcore -XEN_libxentoollog = $(XEN_ROOT)/tools/libs/toollog -XEN_libxenevtchn = $(XEN_ROOT)/tools/libs/evtchn -XEN_libxengnttab = $(XEN_ROOT)/tools/libs/gnttab -XEN_libxencall = $(XEN_ROOT)/tools/libs/call -XEN_libxenforeignmemory = $(XEN_ROOT)/tools/libs/foreignmemory -XEN_libxendevicemodel = $(XEN_ROOT)/tools/libs/devicemodel -XEN_libxenhypfs = $(XEN_ROOT)/tools/libs/hypfs + +LIBS_LIBS += toolcore +USELIBS_toolcore := +LIBS_LIBS += toollog +USELIBS_toollog := +LIBS_LIBS += evtchn +USELIBS_evtchn := toollog toolcore +LIBS_LIBS += gnttab +USELIBS_gnttab := toollog toolcore +LIBS_LIBS += call +USELIBS_call := toollog toolcore +LIBS_LIBS += foreignmemory +USELIBS_foreignmemory := toollog toolcore +LIBS_LIBS += devicemodel +USELIBS_devicemodel := toollog toolcore call +LIBS_LIBS += hypfs +USELIBS_hypfs := toollog toolcore call + XEN_libxenctrl = $(XEN_ROOT)/tools/libxc # Currently libxenguest lives in the same directory as libxenctrl XEN_libxenguest = $(XEN_libxenctrl)@@ -99,45 +109,15 @@ endif # Consumers of libfoo should not directly use $(SHDEPS_libfoo) or # $(SHLIB_libfoo) -CFLAGS_libxentoollog = -I$(XEN_libxentoollog)/include $(CFLAGS_xeninclude) -SHDEPS_libxentoollog = -LDLIBS_libxentoollog = $(SHDEPS_libxentoollog) $(XEN_libxentoollog)/libxentoollog$(libextension) -SHLIB_libxentoollog = $(SHDEPS_libxentoollog) -Wl,-rpath-link=$(XEN_libxentoollog) - -CFLAGS_libxentoolcore = -I$(XEN_libxentoolcore)/include $(CFLAGS_xeninclude) -SHDEPS_libxentoolcore = -LDLIBS_libxentoolcore = $(SHDEPS_libxentoolcore) $(XEN_libxentoolcore)/libxentoolcore$(libextension) -SHLIB_libxentoolcore = $(SHDEPS_libxentoolcore) -Wl,-rpath-link=$(XEN_libxentoolcore) - -CFLAGS_libxenevtchn = -I$(XEN_libxenevtchn)/include $(CFLAGS_xeninclude) -SHDEPS_libxenevtchn = $(SHLIB_libxentoolcore) -LDLIBS_libxenevtchn = $(SHDEPS_libxenevtchn) $(XEN_libxenevtchn)/libxenevtchn$(libextension) -SHLIB_libxenevtchn = $(SHDEPS_libxenevtchn) -Wl,-rpath-link=$(XEN_libxenevtchn) - -CFLAGS_libxengnttab = -I$(XEN_libxengnttab)/include $(CFLAGS_xeninclude) -SHDEPS_libxengnttab = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) -LDLIBS_libxengnttab = $(SHDEPS_libxengnttab) $(XEN_libxengnttab)/libxengnttab$(libextension) -SHLIB_libxengnttab = $(SHDEPS_libxengnttab) -Wl,-rpath-link=$(XEN_libxengnttab) - -CFLAGS_libxencall = -I$(XEN_libxencall)/include $(CFLAGS_xeninclude) -SHDEPS_libxencall = $(SHLIB_libxentoolcore) -LDLIBS_libxencall = $(SHDEPS_libxencall) $(XEN_libxencall)/libxencall$(libextension) -SHLIB_libxencall = $(SHDEPS_libxencall) -Wl,-rpath-link=$(XEN_libxencall) - -CFLAGS_libxenforeignmemory = -I$(XEN_libxenforeignmemory)/include $(CFLAGS_xeninclude) -SHDEPS_libxenforeignmemory = $(SHLIB_libxentoolcore) -LDLIBS_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) $(XEN_libxenforeignmemory)/libxenforeignmemory$(libextension) -SHLIB_libxenforeignmemory = $(SHDEPS_libxenforeignmemory) -Wl,-rpath-link=$(XEN_libxenforeignmemory) - -CFLAGS_libxendevicemodel = -I$(XEN_libxendevicemodel)/include $(CFLAGS_xeninclude) -SHDEPS_libxendevicemodel = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall) -LDLIBS_libxendevicemodel = $(SHDEPS_libxendevicemodel) $(XEN_libxendevicemodel)/libxendevicemodel$(libextension) -SHLIB_libxendevicemodel = $(SHDEPS_libxendevicemodel) -Wl,-rpath-link=$(XEN_libxendevicemodel) - -CFLAGS_libxenhypfs = -I$(XEN_libxenhypfs)/include $(CFLAGS_xeninclude) -SHDEPS_libxenhypfs = $(SHLIB_libxentoollog) $(SHLIB_libxentoolcore) $(SHLIB_libxencall) -LDLIBS_libxenhypfs = $(SHDEPS_libxenhypfs) $(XEN_libxenhypfs)/libxenhypfs$(libextension) -SHLIB_libxenhypfs = $(SHDEPS_libxenhypfs) -Wl,-rpath-link=$(XEN_libxenhypfs) +define LIB_defs = + XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1) + CFLAGS_libxen$(1) = -I$$(XEN_libxen$(1))/include $$(CFLAGS_xeninclude) + SHDEPS_libxen$(1) = $$(foreach use,$$(USELIBS_$(1)),$$(SHLIB_libxen$$(use))) + LDLIBS_libxen$(1) = $$(SHDEPS_libxen$(1)) $$(XEN_libxen$(1))/libxen$(1)$$(libextension) + SHLIB_libxen$(1) = $$(SHDEPS_libxen$(1)) -Wl,-rpath-link=$$(XEN_libxen$(1)) +endef + +$(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib)))) # code which compiles against libxenctrl get __XEN_TOOLS__ and # therefore sees the unstable hypercall interfaces.tools/libs/call/Makefile +0
-2@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 2 -LIBNAME := call -USELIBS := toollog toolcore SRCS-y += core.c buffer.c SRCS-$(CONFIG_Linux) += linux.ctools/libs/devicemodel/Makefile +0
-2@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 3 -LIBNAME := devicemodel -USELIBS := toollog toolcore call SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.ctools/libs/evtchn/Makefile +0
-2@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 1 -LIBNAME := evtchn -USELIBS := toollog toolcore SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.ctools/libs/foreignmemory/Makefile +0
-2@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 3 -LIBNAME := foreignmemory -USELIBS := toollog toolcore SRCS-y += core.c SRCS-$(CONFIG_Linux) += linux.ctools/libs/gnttab/Makefile +0
-2@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 2 -LIBNAME := gnttab -USELIBS := toollog toolcore SRCS-GNTTAB += gnttab_core.c SRCS-GNTSHR += gntshr_core.ctools/libs/hypfs/Makefile +0
-2@@ -3,8 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 0 -LIBNAME := hypfs -USELIBS := toollog toolcore call APPEND_LDFLAGS += -lztools/libs/libs.mk +4
-4@@ -1,18 +1,18 @@ # Common Makefile for building a lib. # # Variables taken as input: -# LIBNAME: name of lib to build, will be prepended with "libxen" # MAJOR: major version of lib # MINOR: minor version of lib -# USELIBS: xen libs to use (e.g. "toolcore toollog") + +LIBNAME := $(notdir $(CURDIR)) SHLIB_LDFLAGS += -Wl,--version-script=libxen$(LIBNAME).map CFLAGS += -Werror -Wmissing-prototypes CFLAGS += -I./include $(CFLAGS_xeninclude) -CFLAGS += $(foreach lib, $(USELIBS), $(CFLAGS_libxen$(lib))) +CFLAGS += $(foreach lib, $(USELIBS_$(LIBNAME)), $(CFLAGS_libxen$(lib))) -LDUSELIBS = $(foreach lib, $(USELIBS), $(LDLIBS_libxen$(lib))) +LDUSELIBS = $(foreach lib, $(USELIBS_$(LIBNAME)), $(LDLIBS_libxen$(lib))) LIB_OBJS := $(SRCS-y:.c=.o) PIC_OBJS := $(SRCS-y:.c=.opic)tools/libs/toolcore/Makefile +0
-1@@ -3,7 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 0 -LIBNAME := toolcore AUTOINCS := include/_xentoolcore_list.h SRCS-y += handlereg.ctools/libs/toollog/Makefile +0
-1@@ -3,7 +3,6 @@ include $(XEN_ROOT)/tools/Rules.mk MAJOR = 1 MINOR = 0 -LIBNAME := toollog SRCS-y += xtl_core.c SRCS-y += xtl_logger_stdio.c