[PATCH] Add --jobserver/jobserver option for GCC -flto=jobserver

"H.J. Lu" <[email protected]>
Newsgroups gmane.comp.sysutils.automake.patches
Message-ID <[email protected]>
From

https://lists.gnu.org/archive/html/automake/2020-02/msg00012.html

GCC introduced some time ago option -flto=jobserver in order to use the
GNU Make jobserver when parallelising LTO builds.  It is actually a
similar "recursive make".  When doing a recursive make, you need to
place a '+' character at the beginning of the recipe line in order to
let GNU Make pass the jobserver file descriptors to the child processes.

Add the --jobserver option to add a '+' character to the recipe line in
program.am and ltlibrary.am.

	* NEWS: Mention --jobserver and jobserver.
	* bin/automake.in ($enable_jobserver): New.
	(preprocess_file): Set $enable_jobserver to '+ ' for option
	jobserver.  Map keyword JOBSERVER to $enable_jobserver.
	(usage): Add --jobserver.
	(parse_arguments): Set $enable_jobserver to '+ ' for --jobserver.
	* doc/automake.texi: Document --jobserver and jobserver.
	* lib/Automake/Options.pm (_is_valid_easy_option): Add jobserver.
	* lib/am/ltlibrary.am (%LTLIBRARY%): Add %VERBOSE%.
	* lib/am/program.am (%PROGRAM%%EXEEXT%): Likewise.
	* t/jobserver1.sh: New test.
	* t/jobserver2.sh: Likewise.
	* t/list-of-tests.mk (handwritten_TESTS): Add t/jobserver1.sh
	and t/jobserver2.sh.
---
 NEWS                    |  2 ++
 bin/automake.in         |  8 ++++++++
 doc/automake.texi       | 11 +++++++++++
 lib/Automake/Options.pm |  1 +
 lib/am/ltlibrary.am     |  2 +-
 lib/am/program.am       |  2 +-
 t/jobserver1.sh         | 40 ++++++++++++++++++++++++++++++++++++++++
 t/jobserver2.sh         | 41 +++++++++++++++++++++++++++++++++++++++++
 t/list-of-tests.mk      |  2 ++
 9 files changed, 107 insertions(+), 2 deletions(-)
 create mode 100644 t/jobserver1.sh
 create mode 100644 t/jobserver2.sh

diff --git a/NEWS b/NEWS
index 9c69e48d1..142abd988 100644
--- a/NEWS
+++ b/NEWS
@@ -66,6 +66,8 @@ New in ?.?.?:
 
 * New features added
 
+  - Add --jobserver and jobserver options to support GCC -flto=jobserver.
+
   - In the testsuite summary, the "for $(PACKAGE_STRING)" suffix
     can be overridden with the AM_TESTSUITE_SUMMARY_HEADER variable.
 
diff --git a/bin/automake.in b/bin/automake.in
index a88b835a5..2d4ac1642 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -268,6 +268,9 @@ use constant QUEUE_STRING    => "string";
 # TRUE if we should always generate Makefile.in.
 my $force_generation = 1;
 
+# '+ ' if we should enable GNU make jobserver in Makefile.in.
+my $enable_jobserver = '';
+
 # From the Perl manual.
 my $symlink_exists = (eval 'symlink ("", "");', $@ eq '');
 
@@ -6787,6 +6790,8 @@ sub preprocess_file
 {
   my ($file, %transform) = @_;
 
+  $enable_jobserver = '+ ' if option 'jobserver';
+
   # Complete %transform with global options.
   # Note that %transform goes last, so it overrides global options.
   %transform = ( 'MAINTAINER-MODE'
@@ -6814,6 +6819,7 @@ sub preprocess_file
 
 		 'LIBTOOL'      => !! var ('LIBTOOL'),
 		 'NONLIBTOOL'   => 1,
+		 'JOBSERVER'    => $enable_jobserver,
 		%transform);
 
   if (! defined ($_ = $am_file_cache{$file}))
@@ -8100,6 +8106,7 @@ Operation modes:
       --version            print version number, then exit
   -v, --verbose            verbosely list files processed
       --no-force           only update Makefile.in's that are out of date
+      --jobserver          enable GNU make jobserver
   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY
 
 Dependency tracking:
@@ -8176,6 +8183,7 @@ sub parse_arguments ()
      'include-deps'	=> sub { $ignore_deps = 0; },
      'i|ignore-deps'	=> sub { $ignore_deps = 1; },
      'no-force'	=> sub { $force_generation = 0; },
+     'jobserver'	=> sub { $enable_jobserver = '+ '; },
      'f|force-missing'  => \$force_missing,
      'a|add-missing'	=> \$add_missing,
      'c|copy'		=> \$copy_missing,
diff --git a/doc/automake.texi b/doc/automake.texi
index 17bc2dae6..d09b1d94a 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -2719,6 +2719,11 @@ This enables the dependency tracking feature.  This feature is enabled
 by default.  This option is provided for historical reasons only and
 probably should not be used.
 
+@item --jobserver
+@opindex --jobserver
+This enables the GNU make jobserver feature support for GCC -flto=jobserver
+option.
+
 @item --no-force
 @opindex --no-force
 Ordinarily @command{automake} creates all @file{Makefile.in}s mentioned in
@@ -10326,6 +10331,12 @@ options below.  This option should be used in the top-level
 @file{configure.ac}; it will be ignored otherwise.  It will also be
 ignored in sub-packages of nested packages (@pxref{Subpackages}).
 
+@item @option{jobserver}
+@cindex Option, @option{jobserver}
+@opindex jobserver
+Enable the GNU make jobserver feature support for GCC -flto=jobserver
+option.
+
 @item @option{info-in-builddir}
 @cindex Option, @option{info-in-builddir}
 @opindex info-in-builddir
diff --git a/lib/Automake/Options.pm b/lib/Automake/Options.pm
index b846fee87..170ee271a 100644
--- a/lib/Automake/Options.pm
+++ b/lib/Automake/Options.pm
@@ -280,6 +280,7 @@ sub _is_valid_easy_option ($)
     dist-zip
     dist-zstd
     info-in-builddir
+    jobserver
     no-define
     no-dependencies
     no-dist
diff --git a/lib/am/ltlibrary.am b/lib/am/ltlibrary.am
index 5e5f6ca5b..d8cf2665b 100644
--- a/lib/am/ltlibrary.am
+++ b/lib/am/ltlibrary.am
@@ -15,4 +15,4 @@
 ## along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 %LTLIBRARY%: $(%XLTLIBRARY%_OBJECTS) $(%XLTLIBRARY%_DEPENDENCIES) $(EXTRA_%XLTLIBRARY%_DEPENDENCIES) %DIRSTAMP%
-	%VERBOSE%$(%XLINK%) %RPATH% $(%XLTLIBRARY%_OBJECTS) $(%XLTLIBRARY%_LIBADD) $(LIBS)
+	%JOBSERVER%%VERBOSE%$(%XLINK%) %RPATH% $(%XLTLIBRARY%_OBJECTS) $(%XLTLIBRARY%_LIBADD) $(LIBS)
diff --git a/lib/am/program.am b/lib/am/program.am
index 9a243b399..4df9cbeee 100644
--- a/lib/am/program.am
+++ b/lib/am/program.am
@@ -21,4 +21,4 @@
 ## Or maybe not... sadly, incremental linkers are rarer than losing
 ## systems.
 	@rm -f %PROGRAM%%EXEEXT%
-	%VERBOSE%$(%XLINK%) $(%XPROGRAM%_OBJECTS) $(%XPROGRAM%_LDADD) $(LIBS)
+	%JOBSERVER%%VERBOSE%$(%XLINK%) $(%XPROGRAM%_OBJECTS) $(%XPROGRAM%_LDADD) $(LIBS)
diff --git a/t/jobserver1.sh b/t/jobserver1.sh
new file mode 100644
index 000000000..cd4cfc44c
--- /dev/null
+++ b/t/jobserver1.sh
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2020 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# Test GNU make jobserver support.
+
+required='GNUmake gcc'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+echo bin_PROGRAMS = foo > Makefile.am
+echo 'int main (void) { return 0; }' > foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing --jobserver
+./configure
+
+$MAKE foo
+
+# Check for the '+' prefix on the recipe line.
+grep "^	+ \$(AM_V_CCLD)" Makefile || exit 1
+
+:
diff --git a/t/jobserver2.sh b/t/jobserver2.sh
new file mode 100644
index 000000000..7fd2ad7df
--- /dev/null
+++ b/t/jobserver2.sh
@@ -0,0 +1,41 @@
+#! /bin/sh
+# Copyright (C) 2020 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# Test GNU make jobserver support.
+
+required='GNUmake gcc'
+. test-init.sh
+
+cat >> configure.ac <<'END'
+AC_PROG_CC
+AC_OUTPUT
+END
+
+echo AUTOMAKE_OPTIONS = jobserver > Makefile.am
+echo bin_PROGRAMS = foo >> Makefile.am
+echo 'int main (void) { return 0; }' > foo.c
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE --add-missing
+./configure
+
+$MAKE foo
+
+# Check for the '+' prefix on the recipe line.
+grep "^	+ \$(AM_V_CCLD)" Makefile || exit 1
+
+:
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index f44eed0e5..768e83ab9 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -579,6 +579,8 @@ t/java-noinst.sh \
 t/java-rebuild.sh \
 t/java-sources.sh \
 t/java-uninstall.sh \
+t/jobserver1.sh \
+t/jobserver2.sh \
 t/ldadd.sh \
 t/ldflags.sh \
 t/lex.sh \
-- 
2.28.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.