From 992d5548ad81ecda07631e8c2e6e215346c81e39 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Thu, 22 Feb 2024 20:16:18 -0800 Subject: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 27. Follow gnulib-tool changes 2017-03-12 Paul Eggert gnulib-tool: new option --gnu-make 2017-03-13 Paul Eggert gnulib-tool: minor --gnu-make fixups 2017-03-14 Paul Eggert gnulib-tool: fix typo in comment output 2017-05-14 Paul Eggert gnulib-tool: improve GNU Make debugging 2018-07-04 Paul Eggert gnulib-tool: minor tweaks for --gnu-make * gnulib-tool.py (main): Add --gnu-make option. Do not allow --gnu-make in test modes, since they all require Automake. * pygnulib/GLConfig.py: Add gnu_make argument to constructor. (getGnuMake, setGnuMake, resetGnuMake): New methods for accessing the gnu_make instance variable. * pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am): Use the "+=" operator with GNU Make and Automake. Transform conditionals to GNU Make syntax if --gnu-make is in use. Use a Autoconf subprocess to define values and check the return code for errors. (GLEmiter.tests_Makefile_am): Likewise. * pygnulib/GLImport.py (GLImport.actioncmd): Add "--gnu-make" to the output comment if it is in use. (GLImport.gnulib_comp): Don't require "AM_PROG_CC_C_O" when using GNU Make. * pygnulib/GLInfo.py (GLInfo.usage): Update help message to reflect addition of --gnu-make. * pygnulib/GLModuleSystem.py (GLModuleTable.transitive_closure): Don't add Automake snippets as unconditional dependencies when using --gnu-make. --- ChangeLog | 34 +++++++++++++++++++ gnulib-tool.py | 11 ++++++ gnulib-tool.py.TODO | 58 -------------------------------- pygnulib/GLConfig.py | 28 +++++++++++++++- pygnulib/GLEmiter.py | 68 ++++++++++++++++++++++++++++++++------ pygnulib/GLImport.py | 6 +++- pygnulib/GLInfo.py | 8 +++-- pygnulib/GLModuleSystem.py | 2 +- 8 files changed, 140 insertions(+), 75 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1049bc0a91..ec1e23d62f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,37 @@ +2024-02-23 Collin Funk + + gnulib-tool.py: Follow gnulib-tool changes, part 27. + Follow gnulib-tool changes + 2017-03-12 Paul Eggert + gnulib-tool: new option --gnu-make + 2017-03-13 Paul Eggert + gnulib-tool: minor --gnu-make fixups + 2017-03-14 Paul Eggert + gnulib-tool: fix typo in comment output + 2017-05-14 Paul Eggert + gnulib-tool: improve GNU Make debugging + 2018-07-04 Paul Eggert + gnulib-tool: minor tweaks for --gnu-make + * gnulib-tool.py (main): Add --gnu-make option. Do not allow --gnu-make + in test modes, since they all require Automake. + * pygnulib/GLConfig.py: Add gnu_make argument to constructor. + (getGnuMake, setGnuMake, resetGnuMake): New methods for accessing the + gnu_make instance variable. + * pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am): Use the "+=" operator + with GNU Make and Automake. Transform conditionals to GNU Make syntax if + --gnu-make is in use. Use a Autoconf subprocess to define values and + check the return code for errors. + (GLEmiter.tests_Makefile_am): Likewise. + * pygnulib/GLImport.py (GLImport.actioncmd): Add "--gnu-make" to the + output comment if it is in use. + (GLImport.gnulib_comp): Don't require "AM_PROG_CC_C_O" when using GNU + Make. + * pygnulib/GLInfo.py (GLInfo.usage): Update help message to reflect + addition of --gnu-make. + * pygnulib/GLModuleSystem.py (GLModuleTable.transitive_closure): Don't + add Automake snippets as unconditional dependencies when using + --gnu-make. + 2024-02-23 Bruno Haible unistdio/*printf tests: Update expected test results regarding %n. diff --git a/gnulib-tool.py b/gnulib-tool.py index 876a16ca9f..599dbe0984 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -358,6 +358,11 @@ def main(): action='append', choices=['2', '3orGPLv2', '3'], nargs='?') + # gnu-make + parser.add_argument('--gnu-make', + dest='gnu_make', + default=None, + action='store_true') # makefile-name parser.add_argument('--makefile-name', dest='makefile_name', @@ -602,6 +607,10 @@ def main(): if cmdargs.pobase == None and cmdargs.podomain != None: message = '%s: warning: --po-domain has no effect without a --po-base option\n' % constants.APP['name'] sys.stderr.write(message) + if modules != None and "tests" in mode and gnu_make: + message = '%s: --gnu-make not supported when including tests\n' % constants.APP['name'] + sys.stderr.write(message) + sys.exit(1) # Determine specific settings. destdir = cmdargs.destdir @@ -670,6 +679,7 @@ def main(): lgpl = True cond_dependencies = cmdargs.cond_dependencies libtool = cmdargs.libtool + gnu_make = cmdargs.gnu_make == True makefile_name = cmdargs.makefile_name if makefile_name != None: makefile_name = makefile_name[0] @@ -709,6 +719,7 @@ def main(): excl_test_categories=excl_test_categories, libname=libname, lgpl=lgpl, + gnu_make=gnu_make, makefile_name=makefile_name, libtool=libtool, conddeps=cond_dependencies, diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO index 2b33ae2308..aef3ca253b 100644 --- a/gnulib-tool.py.TODO +++ b/gnulib-tool.py.TODO @@ -903,64 +903,6 @@ Date: Tue Mar 14 12:19:40 2017 +0100 -------------------------------------------------------------------------------- -commit 60e8b9303d8ce312bb2322d4801ed08678f93d1e -Author: Paul Eggert -Date: Wed Jul 4 20:42:07 2018 -0700 - - gnulib-tool: minor tweaks for --gnu-make - - * gnulib-tool: Do not allow --gnu-make in test modes, - since they all require automake. - (func_emit_lib_Makefile_am): Don’t emit automake comment - if --gnu-make. - -commit 8224d65142d7b8cea2b8721a7d09c2cd60d2d312 -Author: Paul Eggert -Date: Mon May 15 07:41:10 2017 -0700 - - gnulib-tool: improve GNU Make debugging - - * gnulib-tool (func_emit_lib_Makefile_am): Omit unnecessary echo. - Report autoconf diagnostics when it fails, in the output makefile. - -commit fb8289f44a58c9462434eba8eaffd58c3f417c42 -Author: Paul Eggert -Date: Tue Mar 14 08:39:27 2017 -0700 - - gnulib-tool: fix typo in comment output - - * gnulib-tool (func_import): Fix typo with previous change. - -commit d6088547633af472625ab815452004c22fda6d58 -Author: Paul Eggert -Date: Mon Mar 13 15:50:44 2017 -0700 - - gnulib-tool: minor --gnu-make fixups - - * gnulib-tool (func_emit_lib_Makefile_am): - Remove useless code that was a blind alley during implementation. - Problem reported by Thien-Thi Nguyen in: - http://lists.gnu.org/archive/html/bug-gnulib/2017-03/msg00029.html - (func_import): Note the "--gnu-make" option in the output comment. - -commit dfbe4c0276701e42ffaed13a1c7a79003dc8fb30 -Author: Paul Eggert -Date: Sun Mar 12 19:18:53 2017 -0700 - - gnulib-tool: new option --gnu-make - - This is for applications like GNU Emacs that use GNU Make - features instead of Automake. - * doc/gnulib-tool.texi (Initial import): Mention --gnu-make. - * doc/gnulib.texi (Unit test modules, Build robot for gnulib): - Do not assume Automake. - * gnulib-tool (func_determine_path_separator) - (func_modules_transitive_closure, func_update_file) - (func_emit_lib_Makefile_am, func_emit_tests_Makefile_am) - (func_import): Add support for --gnu-make. - --------------------------------------------------------------------------------- - commit 9bdf6c8a0cdeb13c12e4b65dee9538c5468dbe1d Author: Bruno Haible Date: Sun Aug 19 14:06:50 2012 +0200 diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index 3fb78083c6..bdebf243cc 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -56,7 +56,8 @@ class GLConfig(object): sourcebase=None, m4base=None, pobase=None, docbase=None, testsbase=None, modules=None, avoids=None, files=None, incl_test_categories=None, excl_test_categories=None, libname=None, - lgpl=None, makefile_name=None, libtool=None, conddeps=None, macro_prefix=None, + lgpl=None, gnu_make=None, makefile_name=None, libtool=None, + conddeps=None, macro_prefix=None, podomain=None, witness_c_macro=None, vc_files=None, symbolic=None, lsymbolic=None, configure_ac=None, ac_version=None, libtests=None, single_configure=None, verbose=None, dryrun=None, @@ -130,6 +131,10 @@ class GLConfig(object): self.resetLGPL() if lgpl != None: self.setLGPL(lgpl) + # gnu-make + self.resetGnuMake() + if gnu_make != None: + self.setGnuMake(gnu_make) # makefile_name self.resetMakefileName() if makefile_name != None: @@ -776,6 +781,27 @@ class GLConfig(object): Default value is None, which means that lgpl is disabled.''' self.table['lgpl'] = None + # Define gnu-make methods. + def getGnuMake(self): + '''Return a boolean value describing whether the --gnu-make argument + was used.''' + return self.table['gnu_make'] + + def setGnuMake(self, value): + '''Set the --gnu-make argument as if it were invoked using the + command-line or disable it.''' + if type(value) is bool: + self.table['gnu_make'] = value + else: # if type(value) is not bool + raise TypeError('value must be a bool, not %s' + % type(value).__name__) + + def resetGnuMake(self): + '''Reset the --gnu-make argument to its default. This feature must be + explicitly enabled by programs who utilize GNU Make features instead + of Autmake.''' + self.table['gnu_make'] = False + def getModuleIndicatorPrefix(self): '''Return module_indicator_prefix to use inside GLEmiter class.''' return self.getIncludeGuardPrefix() diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index c7b1e61fc4..6de9aba68a 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -40,6 +40,7 @@ __copyright__ = constants.__copyright__ #=============================================================================== # Define global constants #=============================================================================== +UTILS = constants.UTILS TESTS = constants.TESTS joinpath = constants.joinpath relinverse = constants.relinverse @@ -627,6 +628,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ libname = self.config['libname'] pobase = self.config['pobase'] auxdir = self.config['auxdir'] + gnu_make = self.config['gnu_make'] makefile_name = self.config['makefile_name'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] @@ -639,9 +641,9 @@ AC_DEFUN([%V1%_LIBSOURCES], [ destfile = os.path.normpath(destfile) emit = '' - # When creating an includable Makefile.am snippet, augment variables with - # += instead of assigning them. - if makefile_name: + # When using GNU make, or when creating an includable Makefile.am snippet, + # augment variables with += instead of assigning them. + if gnu_make or makefile_name: assign = '+=' else: # if not makefile_name assign = '=' @@ -662,7 +664,8 @@ AC_DEFUN([%V1%_LIBSOURCES], [ else: # if not for_test edit_check_PROGRAMS = False emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n" - emit += "## Process this file with automake to produce Makefile.in.\n" + if not gnu_make: + emit += "## Process this file with automake to produce Makefile.in.\n" emit += self.copyright_notice() if actioncmd: # The maximum line length (excluding the terminating newline) of @@ -711,16 +714,33 @@ AC_DEFUN([%V1%_LIBSOURCES], [ '$(' + module_indicator_prefix + '_GNULIB_') # Skip the contents if it's entirely empty. if not (amsnippet1 + amsnippet2).isspace(): - allsnippets += '## begin gnulib module %s\n\n' % str(module) + allsnippets += '## begin gnulib module %s\n' % str(module) + if gnu_make: + allsnippets += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % str(module) + convert_to_gnu_make = True + else: + convert_to_gnu_make = False + allsnippets += '\n' if conddeps: if moduletable.isConditional(module): name = module.getConditionalName() - allsnippets += 'if %s\n' % name - allsnippets += amsnippet1 + if gnu_make: + allsnippets += 'ifneq (,$(%s))\n' % name + else: + allsnippets += 'if %s\n' % name + if convert_to_gnu_make: + allsnippets += re.sub(r'^if (.*)', r'ifneq (,$(\1))', amsnippet1) + else: + allsnippets += amsnippet1 if conddeps: if moduletable.isConditional(module): allsnippets += 'endif\n' - allsnippets += amsnippet2 + if convert_to_gnu_make: + allsnippets += re.sub(r'^if (.*)', r'ifneq (,$(\1))', amsnippet2) + else: + allsnippets += amsnippet2 + if gnu_make: + allsnippets += 'endif\n' allsnippets += '## end gnulib module %s\n\n' % str(module) # Test whether there are some source files in subdirectories. @@ -763,6 +783,24 @@ AC_DEFUN([%V1%_LIBSOURCES], [ emit += 'DISTCLEANFILES =\n' emit += 'MAINTAINERCLEANFILES =\n' + if gnu_make: + emit += '# Start of GNU Make output.\n' + result = sp.run([UTILS['autoconf'], '-t', 'AC_SUBST:$1 = @$1@', + joinpath(self.config['destdir'], 'configure.ac')], + capture_output=True) + if result.returncode == 0: + # sort -u + emit += '\n'.join(sorted(list(set(x.strip() for x in + result.stdout.decode(encoding='utf-8').splitlines())))) + emit += '\n' + else: + emit += '== gnulib-tool GNU Make output failed as follows ==\n' + emit += ['# stderr: ' + x + '\n' for x in + result.stderr.decode(encoding='utf-8').splitlines()] + emit += '# End of GNU Make output.\n' + else: + emit += '# No GNU Make output.\n' + # Execute edits that apply to the Makefile.am being generated. for current_edit in range(0, makefiletable.count()): dictionary = makefiletable[current_edit] @@ -895,6 +933,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ m4base = self.config['m4base'] pobase = self.config['pobase'] testsbase = self.config['testsbase'] + gnu_make = self.config['gnu_make'] makefile_name = self.config['makefile_name'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] @@ -964,9 +1003,16 @@ AC_DEFUN([%V1%_LIBSOURCES], [ # Skip the contents if it's entirely empty. if not snippet.isspace(): - snippet = ('## begin gnulib module %s\n\n' % str(module) - + snippet - + '## end gnulib module %s\n\n' % str(module)) + nonwrapped_snippet = snippet + snippet = '## begin gnulib module %s\n' % str(module) + if gnu_make: + snippet += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % str(module) + snippet += '\n' + snippet += nonwrapped_snippet + if gnu_make: + snippet += 'endif\n' + snippet += '## end gnulib module %s\n' % str(module) + snippet += '\n' # Mention long-running tests at the end. if 'longrunning-test' in module.getStatuses(): longrun_snippets += snippet diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 68b2e7b0bb..e01cb9f63e 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -365,6 +365,7 @@ class GLImport(object): conddeps = self.config.checkCondDeps() libname = self.config.getLibName() lgpl = self.config.getLGPL() + gnu_make = self.config.getGnuMake() makefile_name = self.config.getMakefileName() libtool = self.config.checkLibtool() macro_prefix = self.config.getMacroPrefix() @@ -407,6 +408,8 @@ class GLImport(object): actioncmd += ' --lgpl' else: # if lgpl != True actioncmd += ' --lgpl=%s' % lgpl + if gnu_make: + actioncmd += ' --gnu-make' if makefile_name: actioncmd += ' --makefile-name=%s' % makefile_name if conddeps: @@ -563,6 +566,7 @@ class GLImport(object): testsbase = self.config['testsbase'] lgpl = self.config['lgpl'] libname = self.config['libname'] + gnu_make = self.config['gnu_make'] makefile_name = self.config['makefile_name'] conddeps = self.config['conddeps'] libtool = self.config['libtool'] @@ -602,7 +606,7 @@ AC_DEFUN([%s_EARLY], and file.count('/') > 1): uses_subdirs = True break - if uses_subdirs: + if not gnu_make and uses_subdirs: emit += ' AC_REQUIRE([AM_PROG_CC_C_O])\n' for module in moduletable['final']: emit += ' # Code from module %s:\n' % str(module) diff --git a/pygnulib/GLInfo.py b/pygnulib/GLInfo.py index 69d3e4a7f8..808f11b06f 100644 --- a/pygnulib/GLInfo.py +++ b/pygnulib/GLInfo.py @@ -265,14 +265,16 @@ Options for --import, --add/remove-import: placed (default \"tests\"). --aux-dir=DIRECTORY Directory relative to --dir where auxiliary build tools are placed (default comes from configure.ac). + --gnu-make Output for GNU Make instead of for the default + Automake --lgpl[=2|=3orGPLv2|=3] Abort if modules aren't available under the LGPL. Also modify license template from GPL to LGPL. The version number of the LGPL can be specified; the default is currently LGPLv3. - --makefile-name=NAME Name of makefile in automake syntax in the - source-base and tests-base directories - (default \"Makefile.am\"). + --makefile-name=NAME Name of makefile in the source-base and tests-base + directories (default \"Makefile.am\", or + \"Makefile.in\" if --gnu-make). --macro-prefix=PREFIX Specify the prefix of the macros 'gl_EARLY' and 'gl_INIT'. Default is 'gl'. --po-domain=NAME Specify the prefix of the i18n domain. Usually use diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index a97e4b310e..c6f0eb15c7 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -860,7 +860,7 @@ class GLModuleTable(object): automake_snippet = \ module.getAutomakeSnippet_Conditional() pattern = re.compile('^if', re.M) - if not pattern.findall(automake_snippet): + if not self.config['gnu_make'] and not pattern.findall(automake_snippet): # A module whose Makefile.am snippet contains a # reference to an automake conditional. If we were # to use it conditionally, we would get an error -- 2.39.5