Skip to contentSkip to conversation

Toolstack build system improvement, toward non-recursive makefiles

PATCH In review Anthony PERARD 3 participants 16 messages Jan 20, 2023 – Feb 8, 2023

lore
Share & tools
lore
#0 lore raw

v6 cover Toolstack build system improvement, toward non-recursive makefiles

Patch series available in this git branch:
https://xenbits.xen.org/git-http/people/aperard/xen-unstable.git br.toolstack-build-system-v6

Changes in v6:
- For unstable libs, use --default-symver instead of a generated version-script.
- Two new patches to deal with $(xenlibs-*,) macros.
- Second patch description reworded.

Changes in v5:
- rebased on staging
- added "tools: Rework linking options for ocaml binding libraries"

Changes in v4:
- several new patches
- some changes to other patches listed in their changelogs

Changes in v3:
- rebased
- several new patches, starting with 13/25 "tools/libs/util: cleanup Makefile"
- introducing macros to deal with linking with in-tree xen libraries
- Add -Werror to CFLAGS for all builds in tools/

Changes in v2:
- one new patch
- other changes described in patch notes

Hi everyone,

I've been looking at reworking the build system we have for the "tools/", and transforming it to something that suit it better. There are a lot of dependencies between different sub-directories so it would be nice if GNU make could actually handle them. This is possible with "non-recursive makefiles".

With non-recursive makefiles, make will have to load/include all the makefiles and thus will have complete overview of all the dependencies. This will allow make to build the necessary targets in other directory, and we won't need to build sub-directories one by one.

To help with this transformation, I've chosen to go with a recent project called "subdirmk". It help to deal with the fact that all makefiles will share the same namespace, it is hooked into autoconf, we can easily run make from any subdirectory. Together "autoconf" and "subdirmk" will also help to get closer to be able to do out-of-tree build of the tools, but I'm mainly looking to have non-recursive makefile.

Link to the project:
https://www.chiark.greenend.org.uk/ucgi/~ian/git/subdirmk.git/

But before getting to the main course, I've got quite a few cleanup and some changes to the makefiles. I start the patch series with patches that remove old left over stuff, then start reworking makefiles. They are some common changes like removing the "build" targets in many places as "all" would be the more common way to spell it and "all" is the default target anyway. They are other changes related to the conversion to "subdirmk", I start to use the variable $(TARGETS) in several makefiles, this variable will have a special meaning in subdirmk which will build those target by default.

As for the conversion to non-recursive makefile, with subdirmk, I have this WIP branch, it contains some changes that I'm trying out, some notes, and the conversion, one Makefile per commit. Cleanup are still needed, some makefile not converted yet, but it's otherwise mostly done.

https://xenbits.xen.org/git-http/people/aperard/xen-unstable.git br.toolstack-build-system-v1-wip-extra

With that branch, you could tried something like:
./configure; cd tools/xl; make
and xl should be built as well as all the xen library needed. Also, things like make clean or rebuild should be faster in the all tools/ directory.

Cheers,

Anthony PERARD (5):
libs: Fix auto-generation of version-script for unstable libs libs/light: Rework targets prerequisites
libs/light: Makefile cleanup
tools: Introduce macro $(xenlibs-cflags,) and introduce $(USELIBS) in
subdirs
tools: Rework $(xenlibs-ldlibs, ) to provide library flags only.

 tools/console/client/Makefile     |  8 ++++--
 tools/console/daemon/Makefile     | 11 ++++----
 tools/helpers/Makefile            | 29 ++++++++-----------
 tools/libs/call/Makefile          |  1 +
 tools/libs/ctrl/Makefile          |  3 --
 tools/libs/devicemodel/Makefile   |  1 +
 tools/libs/evtchn/Makefile        |  1 +
 tools/libs/foreignmemory/Makefile |  1 +
 tools/libs/gnttab/Makefile        |  1 +
 tools/libs/guest/Makefile         |  3 --
 tools/libs/hypfs/Makefile         |  1 +
 tools/libs/light/Makefile         | 47 ++++++++++++++++---------------
 tools/libs/stat/Makefile          |  2 +-
 tools/libs/store/Makefile         |  1 +
 tools/libs/toolcore/Makefile      |  1 +
 tools/libs/toollog/Makefile       |  1 +
 tools/libs/util/Makefile          |  3 --
 tools/libs/vchan/Makefile         |  3 --
 tools/Rules.mk                    | 22 +++++++++------
 tools/libs/libs.mk                | 11 ++++----
 tools/libs/light/libxl_x86_acpi.c |  2 +-
 .gitignore                        |  6 ----
 22 files changed, 75 insertions(+), 84 deletions(-)
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH v6 1/5 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.

---

Notes:
v6:
- use --default-symver instead of generating a version-script. (option was available in binutils 2.16, according to the doc, so that should work.)

v4:
- new patch

CC Andrew Cooper <[email protected]>
 tools/libs/call/Makefile          |  1 +
 tools/libs/ctrl/Makefile          |  3 ---
 tools/libs/devicemodel/Makefile   |  1 +
 tools/libs/evtchn/Makefile        |  1 +
 tools/libs/foreignmemory/Makefile |  1 +
 tools/libs/gnttab/Makefile        |  1 +
 tools/libs/guest/Makefile         |  3 ---
 tools/libs/hypfs/Makefile         |  1 +
 tools/libs/light/Makefile         |  1 -
 tools/libs/stat/Makefile          |  2 +-
 tools/libs/store/Makefile         |  1 +
 tools/libs/toolcore/Makefile      |  1 +
 tools/libs/toollog/Makefile       |  1 +
 tools/libs/util/Makefile          |  3 ---
 tools/libs/vchan/Makefile         |  3 ---
 tools/libs/libs.mk                | 10 ++++------
 .gitignore                        |  6 ------
 17 files changed, 14 insertions(+), 26 deletions(-)
tools/libs/call/Makefile +1 -0
index 103f5ad360..56a964b517 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 3
+version-script := libxencall.map
 
 include Makefile.common
 
tools/libs/ctrl/Makefile +0 -3
index 93442ab389..094e84b8d8 100644
@@ -10,6 +10,3 @@ PKG_CONFIG_NAME := Xencontrol
 NO_HEADERS_CHK := y
 
 include $(XEN_ROOT)/tools/libs/libs.mk
-
-clean::
-	rm -f libxenctrl.map
tools/libs/devicemodel/Makefile +1 -0
index b70dd774e4..20d1d112e7 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 4
+version-script := libxendevicemodel.map
 
 include Makefile.common
 
tools/libs/evtchn/Makefile +1 -0
index 3dad3840c6..18cdaab89e 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 2
+version-script := libxenevtchn.map
 
 include Makefile.common
 
tools/libs/foreignmemory/Makefile +1 -0
index b70dd774e4..81398e88b1 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 4
+version-script := libxenforeignmemory.map
 
 include Makefile.common
 
tools/libs/gnttab/Makefile +1 -0
index 3dad3840c6..4528830bdc 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 2
+version-script := libxengnttab.map
 
 include Makefile.common
 
tools/libs/guest/Makefile +0 -3
index 19d3ff2fdb..93338a9301 100644
@@ -14,6 +14,3 @@ NO_HEADERS_CHK := y
 include $(XEN_ROOT)/tools/libs/libs.mk
 
 libxenguest.so.$(MAJOR).$(MINOR): LDLIBS += $(ZLIB_LIBS) -lz
-
-clean::
-	rm -f libxenguest.map
tools/libs/hypfs/Makefile +1 -0
index 630e1e6f3e..7fae5c750d 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR    = 1
 MINOR    = 0
+version-script := libxenhypfs.map
 
 LDLIBS += -lz
 
tools/libs/light/Makefile +0 -1
index 4fddcc6f51..cd3fa855e1 100644
@@ -262,6 +262,5 @@ clean::
 	$(RM) testidl.c.new testidl.c *.api-ok
 	$(RM) $(TEST_PROGS) libxenlight_test.so libxl_test_*.opic
 	$(RM) -r __pycache__
-	$(RM) libxenlight.map
 	$(RM) $(AUTOSRCS) $(AUTOINCS)
 	$(MAKE) -C $(ACPI_PATH) ACPI_BUILD_DIR=$(CURDIR) clean
tools/libs/stat/Makefile +1 -1
index 7eaf50e91e..ee5c42bf7b 100644
@@ -134,4 +134,4 @@ uninstall:: uninstall-perl-bindings
 endif
 
 clean::
-	$(RM) libxenstat.map $(BINDINGS) $(BINDINGSRC)
+	$(RM) $(BINDINGS) $(BINDINGSRC)
tools/libs/store/Makefile +1 -0
index 3557a8c76d..daed9d148f 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR = 4
 MINOR = 0
+version-script := libxenstore.map
 
 ifeq ($(CONFIG_Linux),y)
 LDLIBS += -ldl
tools/libs/toolcore/Makefile +1 -0
index 0d92b68b3b..20671dadd0 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR	= 1
 MINOR	= 0
+version-script := libxentoolcore.map
 
 LIBHEADER := xentoolcore.h
 
tools/libs/toollog/Makefile +1 -0
index 2361b8cbf1..d612227c85 100644
@@ -3,6 +3,7 @@ include $(XEN_ROOT)/tools/Rules.mk
 
 MAJOR	= 1
 MINOR	= 0
+version-script := libxentoollog.map
 
 include Makefile.common
 
tools/libs/util/Makefile +0 -3
index 493d2e00be..e016baf888 100644
@@ -47,6 +47,3 @@ $(OBJS-y) $(PIC_OBJS): $(AUTOINCS)
 %.c %.h:: %.l
 	@rm -f $*.[ch]
 	$(FLEX) --header-file=$*.h --outfile=$*.c $<
-
-clean::
-	$(RM) libxenutil.map
tools/libs/vchan/Makefile +0 -3
index ac2bff66f5..a1ef60ac8e 100644
@@ -11,6 +11,3 @@ OBJS-y += io.o
 NO_HEADERS_CHK := y
 
 include $(XEN_ROOT)/tools/libs/libs.mk
-
-clean::
-	rm -f libxenvchan.map
tools/libs/libs.mk +4 -6
index 3eb91fc8f3..0e4b5e0bd0 100644
@@ -4,6 +4,7 @@
 #   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))
 
@@ -53,7 +54,7 @@ $(PKG_CONFIG_LOCAL): PKG_CONFIG_INCDIR = $(XEN_INCLUDE)
 $(PKG_CONFIG_LOCAL): PKG_CONFIG_LIBDIR = $(CURDIR)
 
 .PHONY: all
-all: $(TARGETS) $(PKG_CONFIG_LOCAL) libxen$(LIBNAME).map $(LIBHEADERS)
+all: $(TARGETS) $(PKG_CONFIG_LOCAL) $(LIBHEADERS)
 
 ifneq ($(NO_HEADERS_CHK),y)
 all: headers.chk
@@ -71,9 +72,6 @@ headers.lst: FORCE
 	@{ set -e; $(foreach h,$(LIBHEADERS),echo $(h);) } > [email protected]
 	@$(call move-if-changed,[email protected],$@)
 
-libxen$(LIBNAME).map:
-	echo 'VERS_$(MAJOR).$(MINOR) { global: *; };' >$@
-
 lib$(LIB_FILE_NAME).a: $(OBJS-y)
 	$(AR) rc $@ $^
 
@@ -82,8 +80,8 @@ lib$(LIB_FILE_NAME).so: lib$(LIB_FILE_NAME).so.$(MAJOR)
 lib$(LIB_FILE_NAME).so.$(MAJOR): lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR)
 	$(SYMLINK_SHLIB) $< $@
 
-lib$(LIB_FILE_NAME).so.$(MAJOR).$(MINOR): $(PIC_OBJS) libxen$(LIBNAME).map
-	$(CC) $(LDFLAGS) $(PTHREAD_LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,lib$(LIB_FILE_NAME).so.$(MAJOR) -Wl,--version-script=libxen$(LIBNAME).map $(SHLIB_LDFLAGS) -o $@ $(PIC_OBJS) $(LDLIBS) $(APPEND_LDFLAGS)
+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),)
.gitignore +0 -6
index 880ba88c55..d9c906670d 100644
@@ -110,8 +110,6 @@ tools/config.cache
 config/Tools.mk
 config/Stubdom.mk
 config/Docs.mk
-tools/libs/ctrl/libxenctrl.map
-tools/libs/guest/libxenguest.map
 tools/libs/guest/xc_bitops.h
 tools/libs/guest/xc_core.h
 tools/libs/guest/xc_core_arm.h
@@ -121,7 +119,6 @@ tools/libs/light/_*.[ch]
 tools/libs/light/*.pyc
 tools/libs/light/_libxl.api-for-check
 tools/libs/light/*.api-ok
-tools/libs/light/libxenlight.map
 tools/libs/light/libxl-save-helper
 tools/libs/light/dsdt*
 tools/libs/light/mk_dsdt
@@ -131,13 +128,10 @@ tools/libs/light/testidl.c
 tools/libs/light/test_timedereg
 tools/libs/light/test_fdderegrace
 tools/libs/light/tmp.*
-tools/libs/stat/libxenstat.map
 tools/libs/store/list.h
 tools/libs/store/utils.h
 tools/libs/store/xs_lib.c
 tools/libs/util/libxlu_cfg_y.output
-tools/libs/util/libxenutil.map
-tools/libs/vchan/libxenvchan.map
 tools/debugger/gdb/gdb-6.2.1-linux-i386-xen/*
 tools/debugger/gdb/gdb-6.2.1/*
 tools/debugger/gdb/gdb-6.2.1.tar.bz2
Signature · 1 line
Anthony PERARD
Acked-by on v6 1/5
#2 lore raw

Re: [XEN PATCH for-4.17 v6 1/5] libs: Fix auto-generation of version-script for unstable libs

Quoted 18 lines · Anthony PERARD

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.)

Quoted 4 lines

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

#3 lore raw

PATCH v6 2/5 libs/light: Rework targets prerequisites

In reply to Anthony PERARD

No need for $(AUTOSRCS), GNU make can generate them as needed when trying to build them as needed when trying to build the object. Also, those two AUTOSRCS don't need to be a prerequisite of "all". As for the "clean" target, those two files are already removed via "_*.c".

We don't need $(AUTOINCS) either:
- As for both _libxl_save_msgs*.h headers, we are adding more selective dependencies so the headers will still be generated as needed.
- "clean" rule already delete the _*.h files, so AUTOINCS aren't needed there.

"libxl_internal_json.h" doesn't seems to have ever existed, so the dependency is removed.

Rework objects prerequisites, to have them dependents on either "libxl.h" or "libxl_internal.h". "libxl.h" is not normally included directly in the source code as "libxl_internal.h" is used instead, but we have "libxl.h" as prerequisite of "libxl_internal.h", so generated headers will still be generated as needed.

Make doesn't need "libxl.h" to generate "testidl.c", "libxl.h" is only needed later when building "testidl.o". This avoid the need to regenerate "testidl.c" when only "libxl.h" changed. Also use automatic variables $< and $@.

---

Notes:
v6:
- rebased, part of the patch commited as 4ff0811
- reword commit message

v4:
- new patch

 tools/libs/light/Makefile | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
tools/libs/light/Makefile +16 -12
index cd3fa855e1..b28447a2ae 100644
@@ -148,9 +148,6 @@ LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS_INSIDE),libxl_test_$t.opic)
 TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t.o) test_common.o
 TEST_PROGS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t)
 
-AUTOINCS = _libxl_save_msgs_callout.h _libxl_save_msgs_helper.h
-AUTOSRCS = _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c
-
 CLIENTS = testidl libxl-save-helper
 
 SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o
@@ -178,13 +175,13 @@ libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS += -I$(XEN_ROOT)/tools
 $(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenguest)
 
 testidl.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight)
-testidl.c: libxl_types.idl gentest.py $(XEN_INCLUDE)/libxl.h $(AUTOINCS)
-	$(PYTHON) gentest.py libxl_types.idl testidl.c.new
-	mv testidl.c.new testidl.c
+testidl.c: libxl_types.idl gentest.py
+	$(PYTHON) gentest.py $< [email protected]
+	mv -f [email protected] $@
 
-all: $(CLIENTS) $(TEST_PROGS) $(AUTOSRCS) $(AUTOINCS)
+all: $(CLIENTS) $(TEST_PROGS)
 
-$(OBJS-y) $(PIC_OBJS) $(SAVE_HELPER_OBJS) $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): $(AUTOINCS) libxl.api-ok
+$(OBJS-y) $(PIC_OBJS) $(SAVE_HELPER_OBJS) $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): libxl.api-ok
 
 $(DSDT_FILES-y): acpi
 
@@ -196,7 +193,7 @@ libxl.api-ok: check-libxl-api-rules _libxl.api-for-check
 	$(PERL) $^
 	touch $@
 
-_libxl.api-for-check: $(XEN_INCLUDE)/libxl.h $(AUTOINCS)
+_libxl.api-for-check: $(XEN_INCLUDE)/libxl.h
 	$(CC) $(CPPFLAGS) $(CFLAGS) -c -E $< $(APPEND_CFLAGS) \
 		-DLIBXL_EXTERNAL_CALLERS_ONLY=LIBXL_EXTERNAL_CALLERS_ONLY \
 		>[email protected]
@@ -208,14 +205,22 @@ _libxl_save_msgs_helper.h _libxl_save_msgs_callout.h: \
 	$(PERL) -w $< $@ >[email protected]
 	$(call move-if-changed,[email protected],$@)
 
+#
+# headers dependencies on generated headers
+#
 $(XEN_INCLUDE)/libxl.h: $(XEN_INCLUDE)/_libxl_types.h
 $(XEN_INCLUDE)/libxl_json.h: $(XEN_INCLUDE)/_libxl_types_json.h
 libxl_internal.h: $(XEN_INCLUDE)/libxl.h $(XEN_INCLUDE)/libxl_json.h
 libxl_internal.h: _libxl_types_internal.h _libxl_types_private.h _libxl_types_internal_private.h
-libxl_internal_json.h: _libxl_types_internal_json.h
+libxl_internal.h: _libxl_save_msgs_callout.h
 
-$(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS) $(SAVE_HELPER_OBJS): $(XEN_INCLUDE)/libxl.h
+#
+# objects dependencies on headers that depends on generated headers
+#
+$(TEST_PROG_OBJS): $(XEN_INCLUDE)/libxl.h
 $(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS): libxl_internal.h
+$(SAVE_HELPER_OBJS): $(XEN_INCLUDE)/libxl.h _libxl_save_msgs_helper.h
+testidl.o: $(XEN_INCLUDE)/libxl.h
 
 # This exploits the 'multi-target pattern rule' trick.
 # gentypes.py should be executed only once to make all the targets.
@@ -262,5 +267,4 @@ clean::
 	$(RM) testidl.c.new testidl.c *.api-ok
 	$(RM) $(TEST_PROGS) libxenlight_test.so libxl_test_*.opic
 	$(RM) -r __pycache__
-	$(RM) $(AUTOSRCS) $(AUTOINCS)
 	$(MAKE) -C $(ACPI_PATH) ACPI_BUILD_DIR=$(CURDIR) clean
Signature · 1 line
Anthony PERARD
#4 lore raw

Re: [XEN PATCH for-4.17 v6 2/5] libs/light: Rework targets prerequisites

Quoted 55 lines · Anthony PERARD

No need for $(AUTOSRCS), GNU make can generate them as needed when trying to build them as needed when trying to build the object. Also, those two AUTOSRCS don't need to be a prerequisite of "all". As for the "clean" target, those two files are already removed via "_*.c".

We don't need $(AUTOINCS) either:
- As for both _libxl_save_msgs*.h headers, we are adding more selective dependencies so the headers will still be generated as needed.
- "clean" rule already delete the _*.h files, so AUTOINCS aren't needed there.

"libxl_internal_json.h" doesn't seems to have ever existed, so the dependency is removed.

Rework objects prerequisites, to have them dependents on either "libxl.h" or "libxl_internal.h". "libxl.h" is not normally included directly in the source code as "libxl_internal.h" is used instead, but we have "libxl.h" as prerequisite of "libxl_internal.h", so generated headers will still be generated as needed.

Make doesn't need "libxl.h" to generate "testidl.c", "libxl.h" is only needed later when building "testidl.o". This avoid the need to regenerate "testidl.c" when only "libxl.h" changed. Also use automatic variables $< and $@.

---

Notes:
v6:
- rebased, part of the patch commited as 4ff0811
- reword commit message

v4:
- new patch

 tools/libs/light/Makefile | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)
tools/libs/light/Makefile +0 -3
index cd3fa855e1..b28447a2ae 100644
@@ -148,9 +148,6 @@ LIBXL_TEST_OBJS += $(foreach t, $(LIBXL_TESTS_INSIDE),libxl_test_$t.opic)
 TEST_PROG_OBJS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t.o) test_common.o
 TEST_PROGS += $(foreach t, $(LIBXL_TESTS_PROGS),test_$t)
 
-AUTOINCS = _libxl_save_msgs_callout.h _libxl_save_msgs_helper.h
-AUTOSRCS = _libxl_save_msgs_callout.c _libxl_save_msgs_helper.c
-
 CLIENTS = testidl libxl-save-helper
 
 SAVE_HELPER_OBJS = libxl_save_helper.o _libxl_save_msgs_helper.o

tools/libs/light/Makefile libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS += -I$(XEN_ROOT)/tools · line 180

Quoted 9 lines
tools/libs/light/Makefile +3 -3
@@ -178,13 +175,13 @@ libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS += -I$(XEN_ROOT)/tools
 $(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenguest)
 
 testidl.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight)
-testidl.c: libxl_types.idl gentest.py $(XEN_INCLUDE)/libxl.h $(AUTOINCS)
-	$(PYTHON) gentest.py libxl_types.idl testidl.c.new
-	mv testidl.c.new testidl.c
+testidl.c: libxl_types.idl gentest.py
+	$(PYTHON) gentest.py $< [email protected]
+	mv -f [email protected] $@

Doesn't this want to be a mov-if-changed?

We don't need to force a rebuild if testidl.c hasn't changed, I don't think.

Quoted 30 lines
tools/libs/light/Makefile +6 -4
-all: $(CLIENTS) $(TEST_PROGS) $(AUTOSRCS) $(AUTOINCS)
+all: $(CLIENTS) $(TEST_PROGS)
 
-$(OBJS-y) $(PIC_OBJS) $(SAVE_HELPER_OBJS) $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): $(AUTOINCS) libxl.api-ok
+$(OBJS-y) $(PIC_OBJS) $(SAVE_HELPER_OBJS) $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS): libxl.api-ok
 
 $(DSDT_FILES-y): acpi
 
@@ -196,7 +193,7 @@ libxl.api-ok: check-libxl-api-rules _libxl.api-for-check
 	$(PERL) $^
 	touch $@
 
-_libxl.api-for-check: $(XEN_INCLUDE)/libxl.h $(AUTOINCS)
+_libxl.api-for-check: $(XEN_INCLUDE)/libxl.h
 	$(CC) $(CPPFLAGS) $(CFLAGS) -c -E $< $(APPEND_CFLAGS) \
 		-DLIBXL_EXTERNAL_CALLERS_ONLY=LIBXL_EXTERNAL_CALLERS_ONLY \
 		>[email protected]
@@ -208,14 +205,22 @@ _libxl_save_msgs_helper.h _libxl_save_msgs_callout.h: \
 	$(PERL) -w $< $@ >[email protected]
 	$(call move-if-changed,[email protected],$@)
 
+#
+# headers dependencies on generated headers
+#
 $(XEN_INCLUDE)/libxl.h: $(XEN_INCLUDE)/_libxl_types.h
 $(XEN_INCLUDE)/libxl_json.h: $(XEN_INCLUDE)/_libxl_types_json.h
 libxl_internal.h: $(XEN_INCLUDE)/libxl.h $(XEN_INCLUDE)/libxl_json.h
 libxl_internal.h: _libxl_types_internal.h _libxl_types_private.h _libxl_types_internal_private.h
-libxl_internal_json.h: _libxl_types_internal_json.h

tools/libs/light/Makefile _libxl_save_msgs_helper.h _libxl_save_msgs_callout.h: \ · line 223

Quoted 10 lines
tools/libs/light/Makefile +7 -1
+libxl_internal.h: _libxl_save_msgs_callout.h
 
-$(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS) $(SAVE_HELPER_OBJS): $(XEN_INCLUDE)/libxl.h
+#
+# objects dependencies on headers that depends on generated headers
+#
+$(TEST_PROG_OBJS): $(XEN_INCLUDE)/libxl.h
 $(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS): libxl_internal.h
+$(SAVE_HELPER_OBJS): $(XEN_INCLUDE)/libxl.h _libxl_save_msgs_helper.h
+testidl.o: $(XEN_INCLUDE)/libxl.h

I know you're just rearranging existing the existing logic, but why doesn't #include <libxl.h> not generate suitable dependences ?

~Andrew

#5 lore raw

Re: [XEN PATCH for-4.17 v6 2/5] libs/light: Rework targets prerequisites

Quoted 18 lines · Andrew Cooper
Quoted 5 lines · Anthony PERARD
tools/libs/light/Makefile +0 -0
index cd3fa855e1..b28447a2ae 100644

tools/libs/light/Makefile libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS += -I$(XEN_ROOT)/tools · line 180

Quoted 9 lines
tools/libs/light/Makefile +3 -3
@@ -178,13 +175,13 @@ libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS += -I$(XEN_ROOT)/tools
 $(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenguest)
 
 testidl.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight)
-testidl.c: libxl_types.idl gentest.py $(XEN_INCLUDE)/libxl.h $(AUTOINCS)
-	$(PYTHON) gentest.py libxl_types.idl testidl.c.new
-	mv testidl.c.new testidl.c
+testidl.c: libxl_types.idl gentest.py
+	$(PYTHON) gentest.py $< [email protected]
+	mv -f [email protected] $@

Doesn't this want to be a mov-if-changed?

Quoted 1 line

We don't need to force a rebuild if testidl.c hasn't changed, I don't think.

I don't like move-if-changed, as when the prerequisites happens to be newer than the target, the rules keeps been executed on incremental builds.

Also in this case, only two targets depends on this one, "testidl.o" and "testidl", so move-if-changed would not be very useful.

Quoted 14 lines
Quoted 14 lines
tools/libs/light/Makefile +4 -1
@@ -208,14 +205,22 @@ _libxl_save_msgs_helper.h _libxl_save_msgs_callout.h: \
 	$(PERL) -w $< $@ >[email protected]
 	$(call move-if-changed,[email protected],$@)
 
+#
+# headers dependencies on generated headers
+#
 $(XEN_INCLUDE)/libxl.h: $(XEN_INCLUDE)/_libxl_types.h
 $(XEN_INCLUDE)/libxl_json.h: $(XEN_INCLUDE)/_libxl_types_json.h
 libxl_internal.h: $(XEN_INCLUDE)/libxl.h $(XEN_INCLUDE)/libxl_json.h
 libxl_internal.h: _libxl_types_internal.h _libxl_types_private.h _libxl_types_internal_private.h
-libxl_internal_json.h: _libxl_types_internal_json.h
+libxl_internal.h: _libxl_save_msgs_callout.h
 
Quoted 11 lines

tools/libs/light/Makefile _libxl_save_msgs_helper.h _libxl_save_msgs_callout.h: \ · line 223

Quoted 8 lines
tools/libs/light/Makefile +6 -1
-$(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS) $(TEST_PROG_OBJS) $(SAVE_HELPER_OBJS): $(XEN_INCLUDE)/libxl.h
+#
+# objects dependencies on headers that depends on generated headers
+#
+$(TEST_PROG_OBJS): $(XEN_INCLUDE)/libxl.h
 $(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS): libxl_internal.h
+$(SAVE_HELPER_OBJS): $(XEN_INCLUDE)/libxl.h _libxl_save_msgs_helper.h
+testidl.o: $(XEN_INCLUDE)/libxl.h

I know you're just rearranging existing the existing logic, but why doesn't #include <libxl.h> not generate suitable dependences ?

Make doesn't know how to read *.c files ;-). But more importantly, we don't have any logic to generate dependencies ahead of building the object, so make doesn't know about it.

Thanks,

Signature · 1 line
Anthony PERARD
Reviewed-by on v6 2/5
#6 lore raw

Re: [XEN PATCH for-4.17 v6 2/5] libs/light: Rework targets prerequisites

In reply to Anthony PERARD
Quoted 21 lines · Anthony PERARD

No need for $(AUTOSRCS), GNU make can generate them as needed when trying to build them as needed when trying to build the object. Also, those two AUTOSRCS don't need to be a prerequisite of "all". As for the "clean" target, those two files are already removed via "_*.c".

We don't need $(AUTOINCS) either:
- As for both _libxl_save_msgs*.h headers, we are adding more selective dependencies so the headers will still be generated as needed.
- "clean" rule already delete the _*.h files, so AUTOINCS aren't needed there.

"libxl_internal_json.h" doesn't seems to have ever existed, so the dependency is removed.

Rework objects prerequisites, to have them dependents on either "libxl.h" or "libxl_internal.h". "libxl.h" is not normally included directly in the source code as "libxl_internal.h" is used instead, but we have "libxl.h" as prerequisite of "libxl_internal.h", so generated headers will still be generated as needed.

Quoted 6 lines

Make doesn't need "libxl.h" to generate "testidl.c", "libxl.h" is only needed later when building "testidl.o". This avoid the need to regenerate "testidl.c" when only "libxl.h" changed. Also use automatic variables $< and $@.

Juergen

#7 lore raw

PATCH v6 3/5 libs/light: Makefile cleanup

In reply to Anthony PERARD

Rework "libacpi.h" include in "libxl_x86_acpi.c" as to be more selective about the include path and only add "tools/libacpi/". Also "libxl_dom.c" don't use "libacpi.h" anymore. Use "-iquote" for libacpi headers.

Get rid of the weird "$(eval stem =" in the middle of a recipe and use a make automatic variable "$(*F)" instead.

---

Notes:
v4:
- new patch

 tools/libs/light/Makefile         | 16 +++++++---------
 tools/libs/light/libxl_x86_acpi.c |  2 +-
 2 files changed, 8 insertions(+), 10 deletions(-)
tools/libs/light/Makefile +7 -9
index b28447a2ae..96daeabc47 100644
@@ -170,8 +170,7 @@ LDLIBS += $(LDLIBS-y)
 $(OBJS-y) $(PIC_OBJS) $(LIBXL_TEST_OBJS): CFLAGS += $(CFLAGS_LIBXL) -include $(XEN_ROOT)/tools/config.h
 $(ACPI_OBJS) $(ACPI_PIC_OBJS): CFLAGS += -I. -DLIBACPI_STDUTILS=\"$(CURDIR)/libxl_x86_acpi.h\"
 $(TEST_PROG_OBJS) _libxl.api-for-check: CFLAGS += $(CFLAGS_libxentoollog) $(CFLAGS_libxentoolcore)
-libxl_dom.o libxl_dom.opic: CFLAGS += -I$(XEN_ROOT)/tools  # include libacpi/x86.h
-libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS += -I$(XEN_ROOT)/tools
+libxl_x86_acpi.o libxl_x86_acpi.opic: CFLAGS += -iquote $(ACPI_PATH)
 $(SAVE_HELPER_OBJS): CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenevtchn) $(CFLAGS_libxenguest)
 
 testidl.o: CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_libxenlight)
@@ -225,13 +224,12 @@ testidl.o: $(XEN_INCLUDE)/libxl.h
 # This exploits the 'multi-target pattern rule' trick.
 # gentypes.py should be executed only once to make all the targets.
 _libxl_type%.h _libxl_type%_json.h _libxl_type%_private.h _libxl_type%.c: libxl_type%.idl gentypes.py idl.py
-	$(eval stem = $(notdir $*))
-	$(PYTHON) gentypes.py libxl_type$(stem).idl __libxl_type$(stem).h __libxl_type$(stem)_private.h \
-		__libxl_type$(stem)_json.h  __libxl_type$(stem).c
-	$(call move-if-changed,__libxl_type$(stem).h,_libxl_type$(stem).h)
-	$(call move-if-changed,__libxl_type$(stem)_private.h,_libxl_type$(stem)_private.h)
-	$(call move-if-changed,__libxl_type$(stem)_json.h,_libxl_type$(stem)_json.h)
-	$(call move-if-changed,__libxl_type$(stem).c,_libxl_type$(stem).c)
+	$(PYTHON) gentypes.py libxl_type$(*F).idl __libxl_type$(*F).h __libxl_type$(*F)_private.h \
+		__libxl_type$(*F)_json.h  __libxl_type$(*F).c
+	$(call move-if-changed,__libxl_type$(*F).h,_libxl_type$(*F).h)
+	$(call move-if-changed,__libxl_type$(*F)_private.h,_libxl_type$(*F)_private.h)
+	$(call move-if-changed,__libxl_type$(*F)_json.h,_libxl_type$(*F)_json.h)
+	$(call move-if-changed,__libxl_type$(*F).c,_libxl_type$(*F).c)
 
 .PRECIOUS: _libxl_type%.h _libxl_type%.c
 
tools/libs/light/libxl_x86_acpi.c +1 -1
index 57a6b63790..22eb160659 100644
@@ -16,7 +16,7 @@
 #include "libxl_arch.h"
 #include <xen/hvm/hvm_info_table.h>
 #include <xen/hvm/e820.h>
-#include "libacpi/libacpi.h"
+#include "libacpi.h"
 
  /* Number of pages holding ACPI tables */
 #define NUM_ACPI_PAGES 16
Signature · 1 line
Anthony PERARD
Reviewed-by on v6 3/5
#8 lore raw

Re: [XEN PATCH for-4.17 v6 3/5] libs/light: Makefile cleanup

Quoted 9 lines · Anthony PERARD

Rework "libacpi.h" include in "libxl_x86_acpi.c" as to be more selective about the include path and only add "tools/libacpi/". Also "libxl_dom.c" don't use "libacpi.h" anymore. Use "-iquote" for libacpi headers.

Get rid of the weird "$(eval stem =" in the middle of a recipe and use a make automatic variable "$(*F)" instead.

Juergen

#9 lore raw

PATCH v6 4/5 tools: Introduce macro $(xenlibs-cflags,) and introduce $(USELIBS) in subdirs

In reply to Anthony PERARD

Introduce $(xenlibs-cflags,) to get the CFLAGS needed to build with the xen library listed as argument. This mainly give the ability to use the same list of xen libs as we can use with the other macro $(xenlibs-ldlibs,). Also, we can avoid listing $(CFLAGS_xeninclude) more than once.

We will use $(USELIBS) to list the xen libraries been used by a subdirectory or a binary. Since we usually want the CFLAGS, LDFLAGS and LDLIBS of possibly several xen libs, we don't need to duplicate the list for each flags. This change to use $(USELIBS) is only done in console/ and helpers/ for now as those already use the $(xenlibs-ldlibs,) macro

---

Notes:
v6:
- new patch

 tools/console/client/Makefile |  7 ++++---
 tools/console/daemon/Makefile | 10 ++++------
 tools/helpers/Makefile        | 26 +++++++++-----------------
 tools/Rules.mk                |  6 ++++++
 4 files changed, 23 insertions(+), 26 deletions(-)
tools/console/client/Makefile +4 -3
index 62d89fdeb9..071262c9ae 100644
@@ -1,11 +1,12 @@
 XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-CFLAGS += $(CFLAGS_libxenctrl)
-CFLAGS += $(CFLAGS_libxenstore)
+USELIBS := ctrl store
+
+CFLAGS += $(call xenlibs-cflags,$(USELIBS))
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
-LDLIBS += $(call xenlibs-ldlibs,ctrl store)
+LDLIBS += $(call xenlibs-ldlibs,$(USELIBS))
 LDLIBS += $(SOCKET_LIBS)
 
 OBJS-y := main.o
tools/console/daemon/Makefile +4 -6
index 9fc3b6711f..e53c874eee 100644
@@ -1,15 +1,13 @@
 XEN_ROOT=$(CURDIR)/../../..
 include $(XEN_ROOT)/tools/Rules.mk
 
-CFLAGS += $(CFLAGS_libxenctrl)
-CFLAGS += $(CFLAGS_libxenstore)
-CFLAGS += $(CFLAGS_libxenevtchn)
-CFLAGS += $(CFLAGS_libxengnttab)
-CFLAGS += $(CFLAGS_libxenforeignmemory)
+USELIBS := ctrl store evtchn gnttab foreignmemory
+
+CFLAGS += $(call xenlibs-cflags,$(USELIBS))
 CFLAGS-$(CONFIG_ARM) += -DCONFIG_ARM
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
-LDLIBS += $(call xenlibs-ldlibs,ctrl store evtchn gnttab foreignmemory)
+LDLIBS += $(call xenlibs-ldlibs,$(USELIBS))
 LDLIBS += $(SOCKET_LIBS)
 LDLIBS += $(UTIL_LIBS)
 LDLIBS += -lrt
tools/helpers/Makefile +9 -17
index 09590eb5b6..0d4df01365 100644
@@ -15,29 +15,21 @@ TARGETS += init-dom0less
 endif
 endif
 
+XEN_INIT_DOM0_USELIBS := ctrl toollog store light
 XEN_INIT_DOM0_OBJS = xen-init-dom0.o init-dom-json.o
-$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
-$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenstore)
-$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenlight)
-$(XEN_INIT_DOM0_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
-xen-init-dom0: LDLIBS += $(call xenlibs-ldlibs,ctrl toollog store light)
+$(XEN_INIT_DOM0_OBJS): CFLAGS += $(call xenlibs-cflags,$(XEN_INIT_DOM0_USELIBS))
+xen-init-dom0: LDLIBS += $(call xenlibs-ldlibs,$(XEN_INIT_DOM0_USELIBS))
 
+INIT_XENSTORE_DOMAIN_USELIBS := toollog store ctrl guest light
 INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o init-dom-json.o
-$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
-$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenguest)
-$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
-$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenstore)
-$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(CFLAGS_libxenlight)
+$(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(call xenlibs-cflags,$(INIT_XENSTORE_DOMAIN_USELIBS))
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h
-init-xenstore-domain: LDLIBS += $(call xenlibs-ldlibs,toollog store ctrl guest light)
+init-xenstore-domain: LDLIBS += $(call xenlibs-ldlibs,$(INIT_XENSTORE_DOMAIN_USELIBS))
 
+INIT_DOM0LESS_USELIBS := ctrl evtchn toollog store light guest foreignmemory
 INIT_DOM0LESS_OBJS = init-dom0less.o init-dom-json.o
-$(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxentoollog)
-$(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxenstore)
-$(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxenlight)
-$(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxenctrl)
-$(INIT_DOM0LESS_OBJS): CFLAGS += $(CFLAGS_libxenevtchn)
-init-dom0less: LDLIBS += $(call xenlibs-ldlibs,ctrl evtchn toollog store light guest foreignmemory)
+$(INIT_DOM0LESS_OBJS): CFLAGS += $(call xenlibs-cflags,$(INIT_DOM0LESS_USELIBS))
+init-dom0less: LDLIBS += $(call xenlibs-ldlibs,$(INIT_DOM0LESS_USELIBS))
 
 .PHONY: all
 all: $(TARGETS)
tools/Rules.mk +6 -0
index 6e135387bd..d7c1f61cdf 100644
@@ -88,6 +88,12 @@ define xenlibs-dependencies
         $(USELIBS_$(lib)) $(call xenlibs-dependencies,$(USELIBS_$(lib)))))
 endef
 
+define xenlibs-cflags
+    $(CFLAGS_xeninclude) \
+    $(foreach lib,$(1), \
+	$(filter-out $(CFLAGS_xeninclude),$(CFLAGS_libxen$(lib))))
+endef
+
 # Flags for linking recursive dependencies of Xen libraries in $(1)
 define xenlibs-rpath
     $(addprefix -Wl$(comma)-rpath-link=$(XEN_ROOT)/tools/libs/,$(call xenlibs-dependencies,$(1)))
Signature · 1 line
Anthony PERARD
#10 lore raw

PATCH v6 5/5 tools: Rework $(xenlibs-ldlibs, ) to provide library flags only.

In reply to Anthony PERARD

LDLIBS is usually only the library flags (that is the -l flags), as proposed in GNU make manual, while LDFLAGS would be extra flags such as -L.

Rework the make macro $(xenlibs-ldlibs, ) to only provide the library flags. $(xenlibs-ldflags, ) already only provide the extra flags like the -rpath-link flags.

Also fix "test_%" recipe in libs/light as "libxenlight.so" in $(LDLIBS_libxenlight) is been replaced by "-lxenlight". Instead of just changing the filter, we will start using the $(xenlibs-*,) macro. For LDFLAGS, we only needs the one for libxenlight, as the one for toolcore and toollog are already in $(LDFLAGS), they are dependencies to build libxenlight.so.

---

Notes:
v6:
- new patch

 tools/console/client/Makefile |  1 +
 tools/console/daemon/Makefile |  1 +
 tools/helpers/Makefile        |  3 +++
 tools/libs/light/Makefile     |  2 +-
 tools/Rules.mk                | 16 +++++++---------
 tools/libs/libs.mk            |  1 +
 6 files changed, 14 insertions(+), 10 deletions(-)
tools/console/client/Makefile +1 -0
index 071262c9ae..ea7819c03e 100644
@@ -6,6 +6,7 @@ USELIBS := ctrl store
 CFLAGS += $(call xenlibs-cflags,$(USELIBS))
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
+LDFLAGS += $(call xenlibs-ldflags,$(USELIBS))
 LDLIBS += $(call xenlibs-ldlibs,$(USELIBS))
 LDLIBS += $(SOCKET_LIBS)
 
tools/console/daemon/Makefile +1 -0
index e53c874eee..400611fc2d 100644
@@ -7,6 +7,7 @@ CFLAGS += $(call xenlibs-cflags,$(USELIBS))
 CFLAGS-$(CONFIG_ARM) += -DCONFIG_ARM
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
+LDFLAGS += $(call xenlibs-ldflags,$(USELIBS))
 LDLIBS += $(call xenlibs-ldlibs,$(USELIBS))
 LDLIBS += $(SOCKET_LIBS)
 LDLIBS += $(UTIL_LIBS)
tools/helpers/Makefile +3 -0
index 0d4df01365..5db88dc81b 100644
@@ -18,17 +18,20 @@ endif
 XEN_INIT_DOM0_USELIBS := ctrl toollog store light
 XEN_INIT_DOM0_OBJS = xen-init-dom0.o init-dom-json.o
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(call xenlibs-cflags,$(XEN_INIT_DOM0_USELIBS))
+xen-init-dom0: LDFLAGS += $(call xenlibs-ldflags,$(XEN_INIT_DOM0_USELIBS))
 xen-init-dom0: LDLIBS += $(call xenlibs-ldlibs,$(XEN_INIT_DOM0_USELIBS))
 
 INIT_XENSTORE_DOMAIN_USELIBS := toollog store ctrl guest light
 INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o init-dom-json.o
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(call xenlibs-cflags,$(INIT_XENSTORE_DOMAIN_USELIBS))
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h
+init-xenstore-domain: LDFLAGS += $(call xenlibs-ldflags,$(INIT_XENSTORE_DOMAIN_USELIBS))
 init-xenstore-domain: LDLIBS += $(call xenlibs-ldlibs,$(INIT_XENSTORE_DOMAIN_USELIBS))
 
 INIT_DOM0LESS_USELIBS := ctrl evtchn toollog store light guest foreignmemory
 INIT_DOM0LESS_OBJS = init-dom0less.o init-dom-json.o
 $(INIT_DOM0LESS_OBJS): CFLAGS += $(call xenlibs-cflags,$(INIT_DOM0LESS_USELIBS))
+init-dom0less: LDFLAGS += $(call xenlibs-ldflags,$(INIT_DOM0LESS_USELIBS))
 init-dom0less: LDLIBS += $(call xenlibs-ldlibs,$(INIT_DOM0LESS_USELIBS))
 
 .PHONY: all
tools/libs/light/Makefile +1 -1
index 96daeabc47..273f3d0864 100644
@@ -244,7 +244,7 @@ libxenlight_test.so: $(PIC_OBJS) $(LIBXL_TEST_OBJS)
 	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS) $(APPEND_LDFLAGS)
 
 test_%: test_%.o test_common.o libxenlight_test.so
-	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(call xenlibs-ldflags,light) -o $@ $^ $(call xenlibs-ldlibs,toollog toolcore) -lyajl $(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
tools/Rules.mk +7 -9
index d7c1f61cdf..007a64f2f5 100644
@@ -105,12 +105,6 @@ define xenlibs-libs
         $(XEN_ROOT)/tools/libs/$(lib)/lib$(FILENAME_$(lib))$(libextension))
 endef
 
-# Flags for linking against all Xen libraries listed in $(1)
-define xenlibs-ldlibs
-    $(call xenlibs-rpath,$(1)) $(call xenlibs-libs,$(1)) \
-    $(foreach lib,$(1),$(xenlibs-ldlibs-$(lib)))
-endef
-
 # Provide needed flags for linking an in-tree Xen library by an external
 # project (or when it is necessary to link with "-lxen$(1)" instead of using
 # the full path to the library).
@@ -119,12 +113,16 @@ define xenlibs-ldflags
     $(foreach lib,$(1),-L$(XEN_ROOT)/tools/libs/$(lib))
 endef
 
+# Flags for linking against all Xen libraries listed in $(1)
+define xenlibs-ldlibs
+    $(foreach lib,$(1),-l$(FILENAME_$(lib)) $(xenlibs-ldlibs-$(lib)))
+endef
+
 # Flags for linking against all Xen libraries listed in $(1) but by making use
 # of -L and -l instead of providing a path to the shared library.
 define xenlibs-ldflags-ldlibs
     $(call xenlibs-ldflags,$(1)) \
-    $(foreach lib,$(1), -l$(FILENAME_$(lib))) \
-    $(foreach lib,$(1),$(xenlibs-ldlibs-$(lib)))
+    $(call xenlibs-ldlibs,$(1))
 endef
 
 define LIB_defs
@@ -132,7 +130,7 @@ define LIB_defs
  XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1)
  CFLAGS_libxen$(1) = $$(CFLAGS_xeninclude)
  SHLIB_libxen$(1) = $$(call xenlibs-rpath,$(1)) -Wl,-rpath-link=$$(XEN_libxen$(1))
- LDLIBS_libxen$(1) = $$(call xenlibs-ldlibs,$(1))
+ LDLIBS_libxen$(1) = $$(call xenlibs-ldflags,$(1)) $$(call xenlibs-ldlibs,$(1))
 endef
 
 $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
tools/libs/libs.mk +1 -0
index 0e4b5e0bd0..fc6aa7ede9 100644
@@ -17,6 +17,7 @@ CFLAGS   += -Wmissing-prototypes
 CFLAGS   += $(CFLAGS_xeninclude)
 CFLAGS   += $(foreach lib, $(USELIBS_$(LIBNAME)), $(CFLAGS_libxen$(lib)))
 
+LDFLAGS += $(call xenlibs-ldflags,$(USELIBS_$(LIBNAME)))
 LDLIBS += $(call xenlibs-ldlibs,$(USELIBS_$(LIBNAME)))
 
 PIC_OBJS := $(OBJS-y:.o=.opic)
Signature · 1 line
Anthony PERARD
#11 lore raw

Re: [XEN PATCH for-4.17 v6 5/5] tools: Rework $(xenlibs-ldlibs, ) to provide library flags only.

Quoted 4 lines · Anthony PERARD

LDLIBS is usually only the library flags (that is the -l flags), as proposed in GNU make manual, while LDFLAGS would be extra flags such as -L.

Quoted 8 lines

Rework the make macro $(xenlibs-ldlibs, ) to only provide the library flags. $(xenlibs-ldflags, ) already only provide the extra flags like the -rpath-link flags.

Also fix "test_%" recipe in libs/light as "libxenlight.so" in $(LDLIBS_libxenlight) is been replaced by "-lxenlight". Instead of just changing the filter, we will start using the $(xenlibs-*,) macro. For LDFLAGS, we only needs the one for libxenlight, as the one for

nit: s/needs/need/

Quoted 2 lines

toolcore and toollog are already in $(LDFLAGS), they are dependencies to build libxenlight.so.

I don't like this very much. toolcore and toollog are used directly by the test_% programs, so I don't think we should rely on libxenlight depending on them.

Juergen

#12 lore raw

Re: [XEN PATCH for-4.17 v6 5/5] tools: Rework $(xenlibs-ldlibs, ) to provide library flags only.

Quoted 14 lines · Juergen Gross
Quoted 4 lines · Anthony PERARD

LDLIBS is usually only the library flags (that is the -l flags), as proposed in GNU make manual, while LDFLAGS would be extra flags such as -L.

Quoted 8 lines

Rework the make macro $(xenlibs-ldlibs, ) to only provide the library flags. $(xenlibs-ldflags, ) already only provide the extra flags like the -rpath-link flags.

Also fix "test_%" recipe in libs/light as "libxenlight.so" in $(LDLIBS_libxenlight) is been replaced by "-lxenlight". Instead of just changing the filter, we will start using the $(xenlibs-*,) macro. For LDFLAGS, we only needs the one for libxenlight, as the one for

Quoted 8 lines

nit: s/needs/need/

Quoted 2 lines

toolcore and toollog are already in $(LDFLAGS), they are dependencies to build libxenlight.so.

I don't like this very much. toolcore and toollog are used directly by the test_% programs, so I don't think we should rely on libxenlight depending on them.

Ok, I can add them back, it isn't much of an issue to have duplicated flags on the command line.

Cheers,

Signature · 1 line
Anthony PERARD
Reviewed-by
#13 lore raw

Re: [XEN PATCH for-4.17 v6 5/5] tools: Rework $(xenlibs-ldlibs, ) to provide library flags only.

Quoted 20 lines · Anthony PERARD
Quoted 19 lines · Juergen Gross
Quoted 4 lines · Anthony PERARD

LDLIBS is usually only the library flags (that is the -l flags), as proposed in GNU make manual, while LDFLAGS would be extra flags such as -L.

Quoted 8 lines

Rework the make macro $(xenlibs-ldlibs, ) to only provide the library flags. $(xenlibs-ldflags, ) already only provide the extra flags like the -rpath-link flags.

Also fix "test_%" recipe in libs/light as "libxenlight.so" in $(LDLIBS_libxenlight) is been replaced by "-lxenlight". Instead of just changing the filter, we will start using the $(xenlibs-*,) macro. For LDFLAGS, we only needs the one for libxenlight, as the one for

nit: s/needs/need/

Quoted 2 lines

toolcore and toollog are already in $(LDFLAGS), they are dependencies to build libxenlight.so.

Quoted 6 lines
Quoted 3 lines

I don't like this very much. toolcore and toollog are used directly by the test_% programs, so I don't think we should rely on libxenlight depending on them.

Ok, I can add them back, it isn't much of an issue to have duplicated flags on the command line.

In that case you can add my

Juergen

#14 lore raw

PATCH v6 5/5 tools: Rework $(xenlibs-ldlibs, ) to provide library flags only.

LDLIBS is usually only the library flags (that is the -l flags), as proposed in GNU make manual, while LDFLAGS would be extra flags such as -L.

Rework the make macro $(xenlibs-ldlibs, ) to only provide the library flags. $(xenlibs-ldflags, ) already only provide the extra flags like the -rpath-link flags.

Also fix "test_%" recipe in libs/light as "libxenlight.so" in $(LDLIBS_libxenlight) is been replaced by "-lxenlight". Instead of just changing the filter, we will start using the $(xenlibs-*,) macro.

---

Notes:
v6.1:
- For test_% recipe, add toolcore and toollog to the $(xenlibs-ldflags,) macro, to not have to reli on the flags been already present in $(LDFLAGS).

v6:
- new patch

 tools/Rules.mk                | 16 +++++++---------
 tools/console/client/Makefile |  1 +
 tools/console/daemon/Makefile |  1 +
 tools/helpers/Makefile        |  3 +++
 tools/libs/libs.mk            |  1 +
 tools/libs/light/Makefile     |  2 +-
 6 files changed, 14 insertions(+), 10 deletions(-)
tools/Rules.mk +7 -9
index d7c1f61cdf..007a64f2f5 100644
@@ -105,12 +105,6 @@ define xenlibs-libs
         $(XEN_ROOT)/tools/libs/$(lib)/lib$(FILENAME_$(lib))$(libextension))
 endef
 
-# Flags for linking against all Xen libraries listed in $(1)
-define xenlibs-ldlibs
-    $(call xenlibs-rpath,$(1)) $(call xenlibs-libs,$(1)) \
-    $(foreach lib,$(1),$(xenlibs-ldlibs-$(lib)))
-endef
-
 # Provide needed flags for linking an in-tree Xen library by an external
 # project (or when it is necessary to link with "-lxen$(1)" instead of using
 # the full path to the library).
@@ -119,12 +113,16 @@ define xenlibs-ldflags
     $(foreach lib,$(1),-L$(XEN_ROOT)/tools/libs/$(lib))
 endef
 
+# Flags for linking against all Xen libraries listed in $(1)
+define xenlibs-ldlibs
+    $(foreach lib,$(1),-l$(FILENAME_$(lib)) $(xenlibs-ldlibs-$(lib)))
+endef
+
 # Flags for linking against all Xen libraries listed in $(1) but by making use
 # of -L and -l instead of providing a path to the shared library.
 define xenlibs-ldflags-ldlibs
     $(call xenlibs-ldflags,$(1)) \
-    $(foreach lib,$(1), -l$(FILENAME_$(lib))) \
-    $(foreach lib,$(1),$(xenlibs-ldlibs-$(lib)))
+    $(call xenlibs-ldlibs,$(1))
 endef
 
 define LIB_defs
@@ -132,7 +130,7 @@ define LIB_defs
  XEN_libxen$(1) = $$(XEN_ROOT)/tools/libs/$(1)
  CFLAGS_libxen$(1) = $$(CFLAGS_xeninclude)
  SHLIB_libxen$(1) = $$(call xenlibs-rpath,$(1)) -Wl,-rpath-link=$$(XEN_libxen$(1))
- LDLIBS_libxen$(1) = $$(call xenlibs-ldlibs,$(1))
+ LDLIBS_libxen$(1) = $$(call xenlibs-ldflags,$(1)) $$(call xenlibs-ldlibs,$(1))
 endef
 
 $(foreach lib,$(LIBS_LIBS),$(eval $(call LIB_defs,$(lib))))
tools/console/client/Makefile +1 -0
index 071262c9ae..ea7819c03e 100644
@@ -6,6 +6,7 @@ USELIBS := ctrl store
 CFLAGS += $(call xenlibs-cflags,$(USELIBS))
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
+LDFLAGS += $(call xenlibs-ldflags,$(USELIBS))
 LDLIBS += $(call xenlibs-ldlibs,$(USELIBS))
 LDLIBS += $(SOCKET_LIBS)
 
tools/console/daemon/Makefile +1 -0
index e53c874eee..400611fc2d 100644
@@ -7,6 +7,7 @@ CFLAGS += $(call xenlibs-cflags,$(USELIBS))
 CFLAGS-$(CONFIG_ARM) += -DCONFIG_ARM
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
 
+LDFLAGS += $(call xenlibs-ldflags,$(USELIBS))
 LDLIBS += $(call xenlibs-ldlibs,$(USELIBS))
 LDLIBS += $(SOCKET_LIBS)
 LDLIBS += $(UTIL_LIBS)
tools/helpers/Makefile +3 -0
index 0d4df01365..5db88dc81b 100644
@@ -18,17 +18,20 @@ endif
 XEN_INIT_DOM0_USELIBS := ctrl toollog store light
 XEN_INIT_DOM0_OBJS = xen-init-dom0.o init-dom-json.o
 $(XEN_INIT_DOM0_OBJS): CFLAGS += $(call xenlibs-cflags,$(XEN_INIT_DOM0_USELIBS))
+xen-init-dom0: LDFLAGS += $(call xenlibs-ldflags,$(XEN_INIT_DOM0_USELIBS))
 xen-init-dom0: LDLIBS += $(call xenlibs-ldlibs,$(XEN_INIT_DOM0_USELIBS))
 
 INIT_XENSTORE_DOMAIN_USELIBS := toollog store ctrl guest light
 INIT_XENSTORE_DOMAIN_OBJS = init-xenstore-domain.o init-dom-json.o
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += $(call xenlibs-cflags,$(INIT_XENSTORE_DOMAIN_USELIBS))
 $(INIT_XENSTORE_DOMAIN_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h
+init-xenstore-domain: LDFLAGS += $(call xenlibs-ldflags,$(INIT_XENSTORE_DOMAIN_USELIBS))
 init-xenstore-domain: LDLIBS += $(call xenlibs-ldlibs,$(INIT_XENSTORE_DOMAIN_USELIBS))
 
 INIT_DOM0LESS_USELIBS := ctrl evtchn toollog store light guest foreignmemory
 INIT_DOM0LESS_OBJS = init-dom0less.o init-dom-json.o
 $(INIT_DOM0LESS_OBJS): CFLAGS += $(call xenlibs-cflags,$(INIT_DOM0LESS_USELIBS))
+init-dom0less: LDFLAGS += $(call xenlibs-ldflags,$(INIT_DOM0LESS_USELIBS))
 init-dom0less: LDLIBS += $(call xenlibs-ldlibs,$(INIT_DOM0LESS_USELIBS))
 
 .PHONY: all
tools/libs/libs.mk +1 -0
index 0e4b5e0bd0..fc6aa7ede9 100644
@@ -17,6 +17,7 @@ CFLAGS   += -Wmissing-prototypes
 CFLAGS   += $(CFLAGS_xeninclude)
 CFLAGS   += $(foreach lib, $(USELIBS_$(LIBNAME)), $(CFLAGS_libxen$(lib)))
 
+LDFLAGS += $(call xenlibs-ldflags,$(USELIBS_$(LIBNAME)))
 LDLIBS += $(call xenlibs-ldlibs,$(USELIBS_$(LIBNAME)))
 
 PIC_OBJS := $(OBJS-y:.o=.opic)
tools/libs/light/Makefile +1 -1
index 96daeabc47..04ea2a82c0 100644
@@ -244,7 +244,7 @@ libxenlight_test.so: $(PIC_OBJS) $(LIBXL_TEST_OBJS)
 	$(CC) $(LDFLAGS) -Wl,$(SONAME_LDFLAG) -Wl,libxenlight.so.$(MAJOR) $(SHLIB_LDFLAGS) -o $@ $^ $(LDLIBS) $(APPEND_LDFLAGS)
 
 test_%: test_%.o test_common.o libxenlight_test.so
-	$(CC) $(LDFLAGS) -o $@ $^ $(filter-out %libxenlight.so, $(LDLIBS_libxenlight)) $(LDLIBS_libxentoollog) $(LDLIBS_libxentoolcore) -lyajl $(APPEND_LDFLAGS)
+	$(CC) $(LDFLAGS) $(call xenlibs-ldflags,toollog toolcore light) -o $@ $^ $(call xenlibs-ldlibs,toollog toolcore) -lyajl $(APPEND_LDFLAGS)
 
 libxl-save-helper: $(SAVE_HELPER_OBJS) libxenlight.so
 	$(CC) $(LDFLAGS) -o $@ $(SAVE_HELPER_OBJS) $(LDLIBS_libxentoollog) $(LDLIBS_libxenctrl) $(LDLIBS_libxenguest) $(LDLIBS_libxentoolcore) $(APPEND_LDFLAGS)
Signature · 1 line
Anthony PERARD
#15 lore raw
In reply to Anthony PERARD

The "for-4.17" in the subject is a mistake, the series is for staging.

It is just left over from the last time I've sent the series.

Cheers,

Signature · 1 line
Anthony PERARD