]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
java: allow both dist_JAVA and nodist_JAVA in the same Makefile.am
authorStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 12 Sep 2011 08:54:49 +0000 (10:54 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 12 Sep 2011 08:55:25 +0000 (10:55 +0200)
Fixes automake bug#8434.

* automake.in (handle_java): Strip `dist_' and `nodist_' from
the given prefix.  Define a new internal Makefile variable
`am__java_sources'.  Related adjustments.
* lib/am/java.am (JAVAC, JAVAROOT, CLASSPATH_ENV): Define only the
first time this am file is processed.
(class%DIR%.stamp): Stamp file renamed ...
(class%NDIR%.stamp): ... to this, so that the `dist_' and `nodist_'
prefixes are stripped from the name of the stampfile.  Adjust
declaration of dependencies by using the new automake-generated
internal variable `$(am__java_sources)'.  In the rule, use `$@'
as the name of the target, rather than hard-coding it.
* tests/java.test: Update and extend.
* tests/java-no-duplicate.test: New test.
* tests/java-mix-dist-nodist.test: Likewise.
* tests/java-compile-and-install.test: Likewise.
* tests/java-clean.test: Likewise.
* tests/java-sources.test: Likewise.
* tests/Makefile.am (TESTS): Update.

Cherry-picked from commit v1.11-337-gd76b503.

ChangeLog
automake.in
lib/am/java.am
tests/Makefile.am
tests/Makefile.in
tests/java-clean.test [new file with mode: 0755]
tests/java-compile-install.test [new file with mode: 0755]
tests/java-mix-dist-nodist.test [new file with mode: 0755]
tests/java-no-duplicate.test [new file with mode: 0755]
tests/java-sources.test [new file with mode: 0755]
tests/java.test

index 0cab567a8b134be9c89426817223ebc61833a262..5c135e9c97a41181014fcc87eda6cc4492e8cb0d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2011-04-18  Stefano Lattarini  <stefano.lattarini@gmail.com>
+
+       java: allow both dist_JAVA and nodist_JAVA in the same Makefile.am
+       Fixes automake bug#8434.
+       * automake.in (handle_java): Strip `dist_' and `nodist_' from
+       the given prefix.  Define a new internal Makefile variable
+       `am__java_sources'.  Related adjustments.
+       * lib/am/java.am (JAVAC, JAVAROOT, CLASSPATH_ENV): Define only the
+       first time this am file is processed.
+       (class%DIR%.stamp): Stamp file renamed ...
+       (class%NDIR%.stamp): ... to this, so that the `dist_' and `nodist_'
+       prefixes are stripped from the name of the stampfile.  Adjust
+       declaration of dependencies by using the new automake-generated
+       internal variable `$(am__java_sources)'.  In the rule, use `$@'
+       as the name of the target, rather than hard-coding it.
+       * tests/java.test: Update and extend.
+       * tests/java-no-duplicate.test: New test.
+       * tests/java-mix-dist-nodist.test: Likewise.
+       * tests/java-compile-and-install.test: Likewise.
+       * tests/java-clean.test: Likewise.
+       * tests/java-sources.test: Likewise.
+       * tests/Makefile.am (TESTS): Update.
+
 2011-09-11  Stefano Lattarini  <stefano.lattarini@gmail.com>
 
        tests: fix spurious failure on fast machines
index d0d986e4cfce871c28b8b49ed02772b75cda810c..9ee515c96bd97cb1c5aa4b1c8682e6f9163692f6 100755 (executable)
@@ -5107,20 +5107,32 @@ sub handle_java
                                      'java', 'noinst', 'check');
     return if ! @sourcelist;
 
-    my @prefix = am_primary_prefixes ('JAVA', 1,
+    my @prefixes = am_primary_prefixes ('JAVA', 1,
                                      'java', 'noinst', 'check');
 
     my $dir;
-    foreach my $curs (@prefix)
+    my @java_sources = ();
+    foreach my $prefix (@prefixes)
       {
+        (my $curs = $prefix) =~ s/^(?:no)?dist_//;
+
        next
          if $curs eq 'EXTRA';
 
-       err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
-         if defined $dir;
+        push @java_sources, '$(' . $prefix . '_JAVA' . ')';
+
+       if (defined $dir)
+         {
+           err_var "${curs}_JAVA", "multiple _JAVA primaries in use"
+            unless $curs eq $dir;
+         }
+
        $dir = $curs;
       }
 
+    define_pretty_variable ('am__java_sources', TRUE, INTERNAL,
+                            "@java_sources");
+
     if ($dir eq 'check')
       {
         push (@check, "class$dir.stamp");
index 604df222956c44811096cd8ebc01c2b2c8cdd4ff..464b706099babda5f8a1c7c1fff3872cbbae7d5b 100644 (file)
 ## Building.  ##
 ## ---------- ##
 
+if %?FIRST%
 JAVAC = javac
 CLASSPATH_ENV = CLASSPATH=$(JAVAROOT):$(srcdir)/$(JAVAROOT)$${CLASSPATH:+":$$CLASSPATH"}
 JAVAROOT = $(top_builddir)
+endif %?FIRST%
 
-class%DIR%.stamp: $(%DIR%_JAVA)
+class%NDIR%.stamp: $(am__java_sources)
        @list1='$?'; list2=; if test -n "$$list1"; then \
          for p in $$list1; do \
            if test -f $$p; then d=; else d="$(srcdir)/"; fi; \
@@ -33,7 +35,7 @@ class%DIR%.stamp: $(%DIR%_JAVA)
          echo '$(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) $(AM_JAVACFLAGS) $(JAVACFLAGS) '"$$list2"; \
          $(CLASSPATH_ENV) $(JAVAC) -d $(JAVAROOT) $(AM_JAVACFLAGS) $(JAVACFLAGS) $$list2; \
        else :; fi
-       echo timestamp > class%DIR%.stamp
+       echo timestamp > $@
 
 
 ## ------------ ##
@@ -44,7 +46,7 @@ if %?INSTALL%
 am__installdirs += "$(DESTDIR)$(%NDIR%dir)"
 ?EXEC?.PHONY install-exec-am: install-%DIR%JAVA
 ?!EXEC?.PHONY install-data-am: install-%DIR%JAVA
-install-%DIR%JAVA: class%DIR%.stamp
+install-%DIR%JAVA: class%NDIR%.stamp
        @$(NORMAL_INSTALL)
        test -z "$(%NDIR%dir)" || $(MKDIR_P) "$(DESTDIR)$(%NDIR%dir)"
 ## A single .java file can be compiled into multiple .class files.  So
@@ -76,9 +78,9 @@ endif %?INSTALL%
 ## Cleaning.  ##
 ## ---------- ##
 
-.PHONY clean-am: clean-%DIR%JAVA
-clean-%DIR%JAVA:
-       -rm -f *.class class%DIR%.stamp
+.PHONY clean-am: clean-%NDIR%JAVA
+clean-%NDIR%JAVA:
+       -rm -f *.class class%NDIR%.stamp
 
 
 ## -------------- ##
index 35b96fe1129ea811a8f23154d762a83de0079496..7db542781ffee23453755b46a3b10f51f37ac75e 100644 (file)
@@ -454,6 +454,11 @@ java-check.test \
 java-empty-classpath.test \
 javaprim.test \
 javasubst.test \
+java-clean.test \
+java-compile-install.test \
+java-sources.test \
+java-no-duplicate.test \
+java-mix-dist-nodist.test \
 ldadd.test \
 ldflags.test \
 lex.test \
index 2227ee86ae6db2ae288f6e44ce565e64f9852cac..f77c2754133fdc7277d41743e3b9b4d41389471a 100644 (file)
@@ -732,6 +732,11 @@ java-check.test \
 java-empty-classpath.test \
 javaprim.test \
 javasubst.test \
+java-clean.test \
+java-compile-install.test \
+java-sources.test \
+java-no-duplicate.test \
+java-mix-dist-nodist.test \
 ldadd.test \
 ldflags.test \
 lex.test \
diff --git a/tests/java-clean.test b/tests/java-clean.test
new file mode 100755 (executable)
index 0000000..4dcc966
--- /dev/null
@@ -0,0 +1,57 @@
+#! /bin/sh
+# Copyright (C) 1998, 2001, 2002, 2004, 2007  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 <http://www.gnu.org/licenses/>.
+
+# Test cleaning of Java class files and timestamps.
+
+required=javac
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in <<'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+java_JAVA = Class.java
+dist_java_JAVA = ClassDist.java
+nodist_java_JAVA = ClassNoDist.java
+END
+
+echo 'class Class {}' > Class.java
+echo 'class ClassDist {}' > ClassDist.java
+echo 'class ClassNoDist {}' > ClassNoDist.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+$MAKE
+ls -l
+test -f classjava.stamp
+test -f Class.class
+test -f ClassDist.class
+test -f ClassNoDist.class
+$MAKE clean
+find . -name '*.class' -o -name '*.stamp' | grep . && Exit 1
+# We should not remove unrelated stamp files.
+echo timestamp > classjava2.stamp
+$MAKE clean
+test -f classjava2.stamp
+
+:
diff --git a/tests/java-compile-install.test b/tests/java-compile-install.test
new file mode 100755 (executable)
index 0000000..b2145fb
--- /dev/null
@@ -0,0 +1,86 @@
+#! /bin/sh
+# Copyright (C) 1998, 2001, 2002, 2004, 2007  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 <http://www.gnu.org/licenses/>.
+
+# Test on compilation and installation of Java class files.
+
+required=javac
+. ./defs || Exit 1
+
+set -e
+
+cat >>configure.in <<'EOF'
+AC_OUTPUT
+EOF
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+java_JAVA = Foo.java
+dist_java_JAVA = Bar.java
+nodist_java_JAVA = Baz.java
+
+# Java files are not distributed by default.
+EXTRA_DIST = Foo.java
+
+Baz.java:
+       rm -f $@ $@-t
+       echo 'class Baz {}' > $@-t
+       echo 'class Baz2 {}' >> $@-t
+       chmod a-w $@-t && mv -f $@-t $@
+
+test:
+       ls -l $(srcdir) . ;: For debugging.
+       test   -f $(srcdir)/Foo.java
+       test   -f $(srcdir)/Bar.java
+       test   -f Baz.java
+       test   -f aClass.class
+       test   -f Zardoz.class
+       test   -f Baz.class
+       test   -f Baz2.class
+       test ! -r Foo.class
+       test ! -r Bar.class
+
+test-install:
+       find $(prefix) ;: For debugging.
+       test   -f '$(javadir)/aClass.class'
+       test   -f '$(javadir)/Zardoz.class'
+       test   -f '$(javadir)/Baz.class'
+       test   -f '$(javadir)/Baz2.class'
+       test ! -r '$(javadir)/Foo.class'
+       test ! -r '$(javadir)/Bar.class'
+
+check-local: test
+installcheck-local: test-install
+
+.PHONY: test test-install
+
+DISTCLEANFILES = Baz.java
+END
+
+echo 'class aClass {}' > Foo.java
+echo 'class Zardoz {}' > Bar.java
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure --prefix="`pwd`"/_inst
+$MAKE
+$MAKE test
+$MAKE install
+$MAKE test-install
+$MAKE distcheck
+
+:
diff --git a/tests/java-mix-dist-nodist.test b/tests/java-mix-dist-nodist.test
new file mode 100755 (executable)
index 0000000..786f400
--- /dev/null
@@ -0,0 +1,56 @@
+#! /bin/sh
+# Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
+
+# Check that the JAVA primary can be used with both `dist_' and `nodist_'
+# modifiers in the same directory.
+
+. ./defs || Exit 1
+
+cat >> configure.in << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+# This test does not require compilation of *.java files.
+JAVAC = false
+javadir = $(prefix)
+java_JAVA = Class1.java
+dist_java_JAVA = Class2.java
+nodist_java_JAVA = Class3.java
+Class3.java:
+       @echo '$@ should not be generated!' >&2; exit 1
+END
+
+: > Class1.java
+: > Class2.java
+
+$ACLOCAL
+$AUTOCONF
+# Automake used to display non-fatal warnings with this test,
+# but those must be seen as a failure by us.
+$AUTOMAKE 2>stderr || { cat stderr >&2; Exit 1; }
+cat stderr >&2
+test ! -s stderr
+
+./configure
+
+$MAKE distdir
+ls -l $distdir # For debugging.
+test -f $distdir/Class1.java
+test -f $distdir/Class2.java
+test ! -f $distdir/Class3.java
+
+:
diff --git a/tests/java-no-duplicate.test b/tests/java-no-duplicate.test
new file mode 100755 (executable)
index 0000000..d5fec4b
--- /dev/null
@@ -0,0 +1,44 @@
+#! /bin/sh
+# Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
+
+# Test that some Java-related variables and rules are not repeatedly
+# defined.
+
+. ./defs || Exit 1
+
+set -e
+
+cat > Makefile.am << 'END'
+javadir = $(datadir)/java
+java_JAVA = a.java
+dist_java_JAVA = b.java
+nodist_java_JAVA = c.java
+END
+
+$ACLOCAL
+$AUTOMAKE
+
+$EGREP -i '\.stamp|\.class|java|classpath' Makefile.in # For debugging.
+
+for var in JAVAC JAVAROOT CLASSPATH_ENV am__java_sources; do
+  grep "^$var =" Makefile.in
+  test `grep -c "^[$sp$tab]*$var[$sp$tab]*=" Makefile.in` = 1
+done
+
+grep '^classjava\.stamp:' Makefile.in
+test `grep -c "class.*java.*\.stamp.*:" Makefile.in` = 1
+
+:
diff --git a/tests/java-sources.test b/tests/java-sources.test
new file mode 100755 (executable)
index 0000000..4a489e4
--- /dev/null
@@ -0,0 +1,61 @@
+#! /bin/sh
+# Copyright (C) 2011 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 <http://www.gnu.org/licenses/>.
+
+# Test definition of automake-generated private Makefile variable
+# `$(am__java_sources)'.
+
+. ./defs || Exit 1
+
+set -e
+
+cat >> configure.in << 'END'
+AC_OUTPUT
+END
+
+cat > Makefile.am << 'END'
+foodir = $(prefix)
+
+foo_JAVA = a.java
+dist_foo_JAVA = b.java
+nodist_foo_JAVA = c.java
+
+.PHONY: debug
+debug:
+       @echo 'am__java_sources: "$(am__java_sources)"'
+got:
+       @lst='$(am__java_sources)'; \
+         for f in $$lst; do echo $$f; done | sort > $@
+END
+
+$ACLOCAL
+$AUTOMAKE
+$AUTOCONF
+
+cat > exp << 'END'
+a.java
+b.java
+c.java
+END
+
+./configure
+$MAKE debug
+$MAKE got
+
+cat got
+cat exp
+diff exp got
+
+:
index cae56dc063ae73d10f3765c292433ac17c7225b8..4aa91d06eb72ef6d3097aefb5c947fd9b8c7af89 100755 (executable)
@@ -1,5 +1,6 @@
 #! /bin/sh
-# Copyright (C) 1998, 2001, 2002, 2004, 2007  Free Software Foundation, Inc.
+# Copyright (C) 1998, 2001, 2002, 2004, 2007, 2011 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
@@ -25,7 +26,6 @@ cat >>configure.in <<'EOF'
 AC_OUTPUT
 EOF
 
-
 cat > Makefile.am << 'END'
 javadir = $(datadir)/java
 dist_java_JAVA = a.java b.java
@@ -34,7 +34,10 @@ END
 $ACLOCAL
 $AUTOCONF
 $AUTOMAKE
-grep '^all[-a-z]*:.*classdist_java\.stamp' Makefile.in
+
+$EGREP '\.stamp|class' Makefile.in # For debugging.
+grep '^all[-a-z]*:.*classjava\.stamp' Makefile.in
+test `grep -c '^all[-a-z]*:.*classjava\.stamp' Makefile.in` -eq 1
 
 cat >a.java <<EOF
 class a