From ed6156965f371d41f99b9ddb42195145e00335a3 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 2 Nov 2023 14:49:18 -0400 Subject: [PATCH] Reduce the number of Makefiles in 'src/' by one more The libcommon Makefile was the only one left of the convenience library Makefiles to ensure that the version header was generated before the other libraries were built. By using the 'BUILT_SOURCES' variable we can ensure that 'version.i' is generated first and merge this in 'src/Makefile'. Change-Id: I0a6510af65674d1c8bb6a3a08d9a10b07e00fdd7 Signed-off-by: Michael Jeanson Reviewed-on: https://review.lttng.org/c/babeltrace/+/11203 Reviewed-by: Philippe Proulx Tested-by: jenkins --- configure.ac | 1 - src/Makefile.am | 77 +++++++++++++++---- src/bindings/python/bt2/Makefile.am | 2 +- src/bindings/python/bt2/setup.py.in | 2 +- src/cli/Makefile.am | 2 +- src/common/Makefile.am | 52 ------------- src/{common => }/gen-version-i.sh | 30 ++++---- tests/ctf-writer/Makefile.am | 2 +- tests/lib/Makefile.am | 2 +- tests/lib/conds/Makefile.am | 2 +- tests/lib/test-plugin-plugins/Makefile.am | 4 +- tests/param-validation/Makefile.am | 2 +- .../flt.lttng-utils.debug-info/Makefile.am | 4 +- tests/plugins/sink.ctf.fs/succeed/Makefile.am | 2 +- tests/plugins/src.ctf.fs/succeed/Makefile.am | 2 +- 15 files changed, 92 insertions(+), 94 deletions(-) delete mode 100644 src/common/Makefile.am rename src/{common => }/gen-version-i.sh (82%) diff --git a/configure.ac b/configure.ac index ad5a8cc9..a15ce6e6 100644 --- a/configure.ac +++ b/configure.ac @@ -818,7 +818,6 @@ AC_CONFIG_FILES([ src/bindings/python/bt2/Makefile src/bindings/python/bt2/setup.py src/cli/Makefile - src/common/Makefile src/Makefile tests/bitfield/Makefile tests/ctf-writer/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index cbc74e3e..78d98f7c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,9 +1,8 @@ # SPDX-License-Identifier: MIT -# Build 'common' first to ensure 'version.h' is generated before any -# compilation. +# Build the current dir containing the library and plugins before the cli and +# bindings. SUBDIRS = \ - common \ . \ cli @@ -12,6 +11,13 @@ SUBDIRS += bindings/python/bt2 endif noinst_HEADERS = \ + common/align.h \ + common/list.h \ + common/macros.h \ + common/mmap-align.h \ + common/safe.h \ + common/version.h \ + common/version.i \ cpp-common/bt2/clock-class.hpp \ cpp-common/bt2/clock-snapshot.hpp \ cpp-common/bt2/common-iter.hpp \ @@ -52,6 +58,39 @@ noinst_HEADERS = \ cpp-common/uuid-view.hpp \ cpp-common/vector.hpp +## This target generates an include file that contains the git version +## string of the current branch, it must be continuously updated when +## we build in the git repo and shipped in dist tarballs to reflect the +## status of the tree when it was generated. If the tree is clean and +## the current commit is a tag starting with "v", consider this a +## release version and set an empty git version. + +version_verbose = $(version_verbose_@AM_V@) +version_verbose_ = $(version_verbose_@AM_DEFAULT_V@) +version_verbose_0 = @echo " GEN " $@; + +common/version.i: + $(version_verbose)GREP=$(GREP) SED=$(SED) TOP_SRCDIR="$(top_srcdir)" $(SHELL) $(srcdir)/gen-version-i.sh + +dist_noinst_SCRIPTS = gen-version-i.sh + +# Ensure version.i is generated before any code is built. +BUILT_SOURCES = common/version.i + +## +## version.i is defined as a .PHONY target even if it's a real file, +## we want the target to be re-run on every make. +## +.PHONY: common/version.i + +CLEANFILES = common/version.i.tmp + +## +## Only clean "version.i" on dist-clean, we need to keep it on regular +## clean when it's part of a dist tarball. +## +DISTCLEANFILES = common/version.i + # # Convenience libraries # @@ -59,6 +98,7 @@ noinst_HEADERS = \ noinst_LTLIBRARIES = \ argpar/libargpar.la \ autodisc/libautodisc.la \ + common/libcommon.la \ compat/libcompat.la \ ctfser/libctfser.la \ fd-cache/libfd-cache.la \ @@ -70,6 +110,7 @@ noinst_LTLIBRARIES = \ plugins/ctf/common/metadata/libctf-parser.la \ string-format/libstring-format.la + argpar_libargpar_la_SOURCES = \ argpar/argpar.c \ argpar/argpar.h @@ -78,6 +119,18 @@ autodisc_libautodisc_la_SOURCES = \ autodisc/autodisc.c \ autodisc/autodisc.h +common_libcommon_la_SOURCES = \ + common/assert.c \ + common/assert.h \ + common/common.c \ + common/common.h \ + common/uuid.c \ + common/uuid.h + +common_libcommon_la_CPPFLAGS = \ + $(AM_CPPFLAGS) \ + -DBABELTRACE_PLUGINS_DIR=\"$(BABELTRACE_PLUGINS_DIR)\" + compat_libcompat_la_SOURCES = \ compat/bitfield.h \ compat/compiler.h \ @@ -190,11 +243,9 @@ if BABELTRACE_BUILD_WITH_MINGW plugins_ctf_common_metadata_libctf_ast_la_LIBADD = -lintl -liconv -lole32 endif -BUILT_SOURCES = \ +BUILT_SOURCES += \ plugins/ctf/common/metadata/parser.hpp -# Start with empty files to clean -CLEANFILES = ALL_LOCAL = if HAVE_BISON @@ -394,7 +445,7 @@ lib_libbabeltrace2_la_CPPFLAGS = \ lib_libbabeltrace2_la_LIBADD = \ logging/liblogging.la \ - common/libbabeltrace2-common.la \ + common/libcommon.la \ compat/libcompat.la ctf_writer_libbabeltrace2_ctf_writer_la_SOURCES = \ @@ -451,7 +502,7 @@ ctf_writer_libbabeltrace2_ctf_writer_la_LDFLAGS = \ ctf_writer_libbabeltrace2_ctf_writer_la_LIBADD = \ logging/liblogging.la \ - common/libbabeltrace2-common.la \ + common/libcommon.la \ ctfser/libctfser.la \ compat/libcompat.la @@ -489,7 +540,7 @@ python_plugin_provider_babeltrace2_python_plugin_provider_la_LIBADD = if !ENABLE_BUILT_IN_PLUGINS python_plugin_provider_babeltrace2_python_plugin_provider_la_LIBADD += \ logging/liblogging.la \ - common/libbabeltrace2-common.la \ + common/libcommon.la \ py-common/libpy-common.la \ lib/libbabeltrace2.la endif @@ -529,7 +580,7 @@ plugins_utils_babeltrace_plugin_utils_la_LIBADD = \ if !ENABLE_BUILT_IN_PLUGINS plugins_utils_babeltrace_plugin_utils_la_LIBADD += \ lib/libbabeltrace2.la \ - common/libbabeltrace2-common.la \ + common/libcommon.la \ logging/liblogging.la \ plugins/common/param-validation/libparam-validation.la endif @@ -593,7 +644,7 @@ plugins_ctf_babeltrace_plugin_ctf_la_LIBADD += \ lib/libbabeltrace2.la \ logging/liblogging.la \ plugins/common/muxing/libmuxing.la \ - common/libbabeltrace2-common.la \ + common/libcommon.la \ ctfser/libctfser.la endif @@ -623,7 +674,7 @@ plugins_text_babeltrace_plugin_text_la_LIBADD = if !ENABLE_BUILT_IN_PLUGINS plugins_text_babeltrace_plugin_text_la_LIBADD += \ lib/libbabeltrace2.la \ - common/libbabeltrace2-common.la \ + common/libcommon.la \ logging/liblogging.la \ compat/libcompat.la \ plugins/common/param-validation/libparam-validation.la @@ -649,7 +700,7 @@ plugins_lttng_utils_babeltrace_plugin_lttng_utils_la_LIBADD = \ if !ENABLE_BUILT_IN_PLUGINS plugins_lttng_utils_babeltrace_plugin_lttng_utils_la_LIBADD += \ lib/libbabeltrace2.la \ - common/libbabeltrace2-common.la \ + common/libcommon.la \ logging/liblogging.la \ plugins/common/param-validation/libparam-validation.la endif # !ENABLE_BUILT_IN_PLUGINS diff --git a/src/bindings/python/bt2/Makefile.am b/src/bindings/python/bt2/Makefile.am index edbf95b4..570c5513 100644 --- a/src/bindings/python/bt2/Makefile.am +++ b/src/bindings/python/bt2/Makefile.am @@ -96,7 +96,7 @@ STATIC_BINDINGS_DEPS = \ STATIC_LIBRARIES_DEPS = \ $(top_builddir)/src/autodisc/libautodisc.la \ $(top_builddir)/src/logging/liblogging.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/py-common/libpy-common.la \ $(top_builddir)/src/string-format/libstring-format.la diff --git a/src/bindings/python/bt2/setup.py.in b/src/bindings/python/bt2/setup.py.in index 0947521e..d7eca061 100644 --- a/src/bindings/python/bt2/setup.py.in +++ b/src/bindings/python/bt2/setup.py.in @@ -121,7 +121,7 @@ def main(): extra_objects=[ "@top_builddir@/src/autodisc/.libs/libautodisc.a", "@top_builddir@/src/logging/.libs/liblogging.a", - "@top_builddir@/src/common/.libs/libbabeltrace2-common.a", + "@top_builddir@/src/common/.libs/libcommon.a", "@top_builddir@/src/py-common/.libs/libpy-common.a", "@top_builddir@/src/string-format/.libs/libstring-format.a", ], diff --git a/src/cli/Makefile.am b/src/cli/Makefile.am index ce4f246c..d72ea16e 100644 --- a/src/cli/Makefile.am +++ b/src/cli/Makefile.am @@ -62,7 +62,7 @@ babeltrace2_bin_LDADD = \ $(top_builddir)/src/string-format/libstring-format.la \ $(top_builddir)/src/lib/libbabeltrace2.la \ $(top_builddir)/src/compat/libcompat.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la \ $(top_builddir)/src/ctfser/libctfser.la diff --git a/src/common/Makefile.am b/src/common/Makefile.am deleted file mode 100644 index 36570540..00000000 --- a/src/common/Makefile.am +++ /dev/null @@ -1,52 +0,0 @@ -# SPDX-License-Identifier: MIT - -AM_CPPFLAGS += -DBABELTRACE_PLUGINS_DIR=\"$(BABELTRACE_PLUGINS_DIR)\" - -noinst_LTLIBRARIES = libbabeltrace2-common.la - -libbabeltrace2_common_la_SOURCES = \ - assert.c \ - assert.h \ - common.c \ - common.h \ - uuid.c \ - uuid.h - -noinst_HEADERS = \ - align.h \ - list.h \ - macros.h \ - mmap-align.h \ - safe.h - -## This target generates an include file that contains the git version -## string of the current branch, it must be continuously updated when -## we build in the git repo and shipped in dist tarballs to reflect the -## status of the tree when it was generated. If the tree is clean and -## the current commit is tag a starting with "v", consider this a -## release version and set an empty git version. - -version_verbose = $(version_verbose_@AM_V@) -version_verbose_ = $(version_verbose_@AM_DEFAULT_V@) -version_verbose_0 = @echo " GEN " $@; - -version.i: - $(version_verbose)GREP=$(GREP) SED=$(SED) TOP_SRCDIR="$(top_srcdir)" $(SHELL) $(srcdir)/gen-version-i.sh - -dist_noinst_SCRIPTS = gen-version-i.sh - -## -## version.i is defined as a .PHONY target even if it's a real file, -## we want the target to be re-run on every make. -## -.PHONY: version.i - -CLEANFILES = version.i.tmp - -## -## Only clean "version.i" on dist-clean, we need to keep it on regular -## clean when it's part of a dist tarball. -## -DISTCLEANFILES = version.i - -noinst_HEADERS += version.h version.i diff --git a/src/common/gen-version-i.sh b/src/gen-version-i.sh similarity index 82% rename from src/common/gen-version-i.sh rename to src/gen-version-i.sh index a53593cd..0bb981fb 100755 --- a/src/common/gen-version-i.sh +++ b/src/gen-version-i.sh @@ -23,10 +23,10 @@ GREP=${GREP:-grep} SED=${SED:-sed} # Delete any stale "version.i.tmp" file. -rm -f version.i.tmp +rm -f common/version.i.tmp -if test ! -f version.i && test -f "$TOP_SRCDIR/include/version.i"; then - cp "$TOP_SRCDIR/include/version.i" version.i +if test ! -f common/version.i && test -f "$TOP_SRCDIR/include/version.i"; then + cp "$TOP_SRCDIR/include/version.i" common/version.i fi # If "bootstrap" and ".git" exists in the top source directory and the git @@ -44,22 +44,22 @@ if test -r "$TOP_SRCDIR/bootstrap" && test -r "$TOP_SRCDIR/.git" && (command -v git > /dev/null 2>&1); then GIT_VERSION_STR="$(cd "$TOP_SRCDIR" && git describe --always --tags --dirty --abbrev=12)" GIT_CURRENT_TAG="$(cd "$TOP_SRCDIR" && (git describe --tags --exact-match --match="v[0-9]*" HEAD || true) 2> /dev/null)" - echo "#define BT_VERSION_GIT \"$GIT_VERSION_STR\"" > version.i.tmp + echo "#define BT_VERSION_GIT \"$GIT_VERSION_STR\"" > common/version.i.tmp - if ! $GREP -- "-dirty" version.i.tmp > /dev/null && + if ! $GREP -- "-dirty" common/version.i.tmp > /dev/null && test "x$GIT_CURRENT_TAG" != "x"; then - echo "#define BT_VERSION_GIT \"\"" > version.i.tmp + echo "#define BT_VERSION_GIT \"\"" > common/version.i.tmp fi fi # If we don't have a "version.i.tmp" nor a "version.i", generate an empty # string as a failover. If a "version.i" is present, for example when building # from a distribution tarball, get the git_version using grep. -if test ! -f version.i.tmp; then - if test -f version.i; then - $GREP "^#define \bBT_VERSION_GIT\b.*" version.i > version.i.tmp +if test ! -f common/version.i.tmp; then + if test -f common/version.i; then + $GREP "^#define \bBT_VERSION_GIT\b.*" common/version.i > common/version.i.tmp else - echo '#define BT_VERSION_GIT ""' > version.i.tmp + echo '#define BT_VERSION_GIT ""' > common/version.i.tmp fi fi @@ -84,15 +84,15 @@ fi # by replacing "\n" with litteral string c-style "\n". # shellcheck disable=SC2012 echo "#define BT_VERSION_EXTRA_PATCHES \"$(ls -1 "$TOP_SRCDIR/version/extra_patches" | $GREP -v '^README.adoc' | $SED -E ':a ; N ; $!ba ; s/[^a-zA-Z0-9 \n\t\.]/-/g ; s/\r{0,1}\n/\\n/g' 2> /dev/null)\"" -} >> version.i.tmp +} >> common/version.i.tmp # If we don't have a "version.i" or we have both files (version.i, version.i.tmp) # and they are different, copy "version.i.tmp" over "version.i". # This way the dependent targets are only rebuilt when the git version # string or either one of extra version string change. -if test ! -f version.i || - test x"$(cat version.i.tmp)" != x"$(cat version.i)"; then - mv -f version.i.tmp version.i +if test ! -f common/version.i || + test x"$(cat common/version.i.tmp)" != x"$(cat common/version.i)"; then + mv -f common/version.i.tmp common/version.i fi -rm -f version.i.tmp +rm -f common/version.i.tmp diff --git a/tests/ctf-writer/Makefile.am b/tests/ctf-writer/Makefile.am index 807f54db..4bd97d26 100644 --- a/tests/ctf-writer/Makefile.am +++ b/tests/ctf-writer/Makefile.am @@ -9,7 +9,7 @@ ctf_writer_LDADD = \ $(top_builddir)/tests/utils/tap/libtap.la \ $(top_builddir)/tests/utils/libtestcommon.la \ $(top_builddir)/src/ctf-writer/libbabeltrace2-ctf-writer.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index f2c70351..643b7e00 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -8,7 +8,7 @@ COMMON_TEST_LDADD = \ $(top_builddir)/tests/utils/tap/libtap.la \ $(top_builddir)/tests/utils/libtestcommon.la \ $(top_builddir)/tests/lib/utils/liblib-utils.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la test_bt_values_LDADD = $(COMMON_TEST_LDADD) \ diff --git a/tests/lib/conds/Makefile.am b/tests/lib/conds/Makefile.am index 2527a32c..b380b009 100644 --- a/tests/lib/conds/Makefile.am +++ b/tests/lib/conds/Makefile.am @@ -8,7 +8,7 @@ conds_triggers_SOURCES = \ conds_triggers_LDADD = \ $(top_builddir)/tests/lib/utils/liblib-utils.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la \ $(top_builddir)/src/lib/libbabeltrace2.la diff --git a/tests/lib/test-plugin-plugins/Makefile.am b/tests/lib/test-plugin-plugins/Makefile.am index 1b52cafb..7c1ae9d6 100644 --- a/tests/lib/test-plugin-plugins/Makefile.am +++ b/tests/lib/test-plugin-plugins/Makefile.am @@ -10,7 +10,7 @@ plugin_minimal_la_LDFLAGS = \ -rpath / -avoid-version -module $(LD_NOTEXT) plugin_minimal_la_LIBADD = \ $(top_builddir)/src/lib/libbabeltrace2.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la # source/filter/sink plugin @@ -21,5 +21,5 @@ plugin_sfs_la_LDFLAGS = \ -rpath / -avoid-version -module $(LD_NOTEXT) plugin_sfs_la_LIBADD = \ $(top_builddir)/src/lib/libbabeltrace2.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la diff --git a/tests/param-validation/Makefile.am b/tests/param-validation/Makefile.am index 6a1db56d..14cf3d63 100644 --- a/tests/param-validation/Makefile.am +++ b/tests/param-validation/Makefile.am @@ -8,6 +8,6 @@ test_param_validation_LDADD = \ $(top_builddir)/src/param-parse/libparam-parse.la \ $(top_builddir)/src/plugins/common/param-validation/libparam-validation.la \ $(top_builddir)/src/lib/libbabeltrace2.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la \ $(top_builddir)/tests/utils/tap/libtap.la diff --git a/tests/plugins/flt.lttng-utils.debug-info/Makefile.am b/tests/plugins/flt.lttng-utils.debug-info/Makefile.am index 42687f3b..664a99b5 100644 --- a/tests/plugins/flt.lttng-utils.debug-info/Makefile.am +++ b/tests/plugins/flt.lttng-utils.debug-info/Makefile.am @@ -28,7 +28,7 @@ test_dwarf_LDADD = \ $(top_builddir)/src/plugins/lttng-utils/debug-info/libdebug-info.la \ $(top_builddir)/src/fd-cache/libfd-cache.la \ $(top_builddir)/src/logging/liblogging.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(ELFUTILS_LIBS) \ $(LIBTAP) test_dwarf_SOURCES = test-dwarf.c @@ -37,7 +37,7 @@ test_bin_info_LDADD = \ $(top_builddir)/src/plugins/lttng-utils/debug-info/libdebug-info.la \ $(top_builddir)/src/fd-cache/libfd-cache.la \ $(top_builddir)/src/logging/liblogging.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/lib/libbabeltrace2.la \ $(ELFUTILS_LIBS) \ $(LIBTAP) diff --git a/tests/plugins/sink.ctf.fs/succeed/Makefile.am b/tests/plugins/sink.ctf.fs/succeed/Makefile.am index d1b90390..b4332093 100644 --- a/tests/plugins/sink.ctf.fs/succeed/Makefile.am +++ b/tests/plugins/sink.ctf.fs/succeed/Makefile.am @@ -5,7 +5,7 @@ dist_check_SCRIPTS = test-succeed.sh # CTF trace generators GEN_TRACE_LDADD = \ $(top_builddir)/src/ctf-writer/libbabeltrace2-ctf-writer.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la gen_trace_float_SOURCES = gen-trace-float.c diff --git a/tests/plugins/src.ctf.fs/succeed/Makefile.am b/tests/plugins/src.ctf.fs/succeed/Makefile.am index fa91418f..f424a93d 100644 --- a/tests/plugins/src.ctf.fs/succeed/Makefile.am +++ b/tests/plugins/src.ctf.fs/succeed/Makefile.am @@ -5,7 +5,7 @@ dist_check_SCRIPTS = test-succeed.sh # CTF trace generators GEN_TRACE_LDADD = \ $(top_builddir)/src/ctf-writer/libbabeltrace2-ctf-writer.la \ - $(top_builddir)/src/common/libbabeltrace2-common.la \ + $(top_builddir)/src/common/libcommon.la \ $(top_builddir)/src/logging/liblogging.la gen_trace_simple_SOURCES = gen-trace-simple.c -- 2.34.1