bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

package: make bison a relocatable package


From: Akim Demaille
Subject: package: make bison a relocatable package
Date: Tue, 25 Dec 2018 10:06:13 +0100

Hi!

Tested by hand; it works.  The CI should certainly make sure
there are no regressions in the future, but user feedback would
also be most useful ;-)

Cheers!

commit a4ede8f85b0c9a254fcb01e5888cee1983095669
Author: Akim Demaille <address@hidden>
Date:   Tue Dec 25 08:19:50 2018 +0100

    package: make bison a relocatable package
    
    Suggested by David Barto
    https://lists.gnu.org/archive/html/help-bison/2015-02/msg00004.html
    and Victor Zverovich.
    https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00121.html
    
    This is very easy to do, thanks to work by Bruno Haible in gnulib.
    See "Supporting Relocation" in gnulib's documentation.
    
    * bootstrap.conf: We need relocatable-prog and relocatable-script (for 
yacc).
    
    * src/yacc.in: New.
    * configure.ac, src/local.mk: Instantiate it.
    * src/main.c, src/output.c (main, pkgdatadir): Use relocatable2.
    
    * doc/bison.texi (FAQ): Document it.

diff --git a/NEWS b/NEWS
index 0db77cc7..dc5589a7 100644
--- a/NEWS
+++ b/NEWS
@@ -24,6 +24,15 @@ GNU Bison NEWS
 
 ** New features
 
+*** Bison is now relocatable
+
+  If you pass '--enable-relocatable' to 'configure', Bison is relocatable.
+
+  A relocatable program can be moved or copied to a different location on
+  the file system.  It can also be used through mount points for network
+  sharing.  It is possible to make symlinks to the installed and moved
+  programs, and invoke them through the symlink.
+
 *** %expect and %expect-rr modifiers on individual rules
 
   One can now document (and check) which rules participate in shift/reduce
diff --git a/README b/README
index 7a3e9956..aa8961e2 100644
--- a/README
+++ b/README
@@ -8,6 +8,16 @@ Bison requires GNU m4 1.4.6 or later.  See:
 
       https://ftp.gnu.org/gnu/m4/m4-1.4.6.tar.gz
 
+** Relocatability
+If you pass '--enable-relocatable' to 'configure', Bison is relocatable.
+
+A relocatable program can be moved or copied to a different location on the
+file system.  It can also be used through mount points for network sharing.
+It is possible to make symlinks to the installed and moved programs, and
+invoke them through the symlink.
+
+See "Enabling Relocatability" in the documentation.
+
 ** Internationalization
 Bison supports two catalogs: one for Bison itself (i.e., for the
 maintainer-side parser generation), and one for the generated parsers (i.e.,
diff --git a/THANKS b/THANKS
index 86c23eef..cc3cc883 100644
--- a/THANKS
+++ b/THANKS
@@ -40,6 +40,7 @@ Dagobert Michelsen        address@hidden
 Daniel Frużyński          address@hidden
 Daniel Galloway           address@hidden
 Daniel Hagerty            address@hidden
+David Barto               address@hidden
 David J. MacKenzie        address@hidden
 David Kastrup             address@hidden
 David Michael             address@hidden
@@ -174,6 +175,7 @@ Troy A. Johnson           address@hidden
 Tys Lefering              address@hidden
 Valentin Tolmer           address@hidden
 Victor Khomenko           address@hidden
+Victor Zverovich          address@hidden
 Vin Shelton               address@hidden
 W.C.A. Wijngaards         address@hidden
 Wayne Green               address@hidden
diff --git a/bootstrap.conf b/bootstrap.conf
index 7e9aa1fc..c19f94f1 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -35,6 +35,7 @@ gnulib_modules='
   quote quotearg
   readme-release
   realloc-posix
+  relocatable-prog relocatable-script
   spawn-pipe stdbool stpcpy strdup-posix strerror strverscmp
   timevar
   unistd unistd-safer unlink unlocked-io
diff --git a/build-aux/.gitignore b/build-aux/.gitignore
index 0d8a2b30..e108a7fb 100644
--- a/build-aux/.gitignore
+++ b/build-aux/.gitignore
@@ -23,3 +23,7 @@
 /useless-if-before-free
 /vc-list-files
 /ylwrap
+/config.libpath
+/install-reloc
+/reloc-ldflags
+/relocatable.sh.in
diff --git a/configure.ac b/configure.ac
index 61b07ca1..a1247eae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -203,6 +203,7 @@ AC_ARG_ENABLE([yacc],
      [do not build a yacc command or an -ly library])],
   , [enable_yacc=yes])
 AM_CONDITIONAL([ENABLE_YACC], [test "$enable_yacc" = yes])
+AC_CONFIG_FILES([src/yacc], [chmod +x src/yacc])
 
 # Checks for programs.
 AM_MISSING_PROG([DOT], [dot])
diff --git a/doc/.gitignore b/doc/.gitignore
index 651eab93..31d36f60 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -30,3 +30,4 @@
 /stamp-vti
 /version.texi
 /yacc.1
+/relocatable.texi
diff --git a/doc/bison.texi b/doc/bison.texi
index e1a5aaba..7bfc2879 100644
--- a/doc/bison.texi
+++ b/doc/bison.texi
@@ -382,6 +382,7 @@ Frequently Asked Questions
 * Strings are Destroyed::       @code{yylval} Loses Track of Strings
 * Implementing Gotos/Loops::    Control Flow in the Calculator
 * Multiple start-symbols::      Factoring closely related grammars
+* Enabling Relocatability::     Moving Bison/using it through network shares
 * Secure?  Conform?::           Is Bison POSIX safe?
 * I can't build Bison::         Troubleshooting
 * Where can I find help?::      Troubleshouting
@@ -12875,6 +12876,7 @@ are addressed.
 * Implementing Gotos/Loops::    Control Flow in the Calculator
 * Multiple start-symbols::      Factoring closely related grammars
 * Secure?  Conform?::           Is Bison POSIX safe?
+* Enabling Relocatability::     Moving Bison/using it through network shares
 * I can't build Bison::         Troubleshooting
 * Where can I find help?::      Troubleshouting
 * Bug Reports::                 Troublereporting
@@ -13156,6 +13158,8 @@ However, Bison is intended to be a reliable program 
that conforms to the
 POSIX specification for Yacc.  If you run into problems, please send us a
 bug report.
 
address@hidden relocatable.texi
+
 @node I can't build Bison
 @section I can't build Bison
 
@@ -13209,7 +13213,7 @@ hearts.
 I found a bug.  What should I include in the bug report?
 @end quotation
 
-Before you send a bug report, make sure you are using the latest
+Before sending a bug report, make sure you are using the latest
 version.  Check @url{https://ftp.gnu.org/pub/gnu/bison/} or one of its
 mirrors.  Be sure to include the version number in your bug report.  If
 the bug is present in the latest version but not in a previous version,
diff --git a/doc/local.mk b/doc/local.mk
index 5af0ca01..8c02724e 100644
--- a/doc/local.mk
+++ b/doc/local.mk
@@ -19,7 +19,8 @@ info_TEXINFOS = doc/bison.texi
 doc_bison_TEXINFOS =                            \
   $(CROSS_OPTIONS_TEXI)                         \
   doc/fdl.texi                                  \
-  doc/gpl-3.0.texi
+  doc/gpl-3.0.texi                              \
+  doc/relocatable.texi
 
 # Cannot express dependencies directly on file names because of Automake.
 # Obfuscate with a variable.
diff --git a/lib/.gitignore b/lib/.gitignore
index b7d7e6d2..8bfa82ab 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -294,3 +294,18 @@
 /bitset/
 /bitsetv.c
 /bitsetv.h
+/allocator.c
+/allocator.h
+/areadlink.c
+/areadlink.h
+/canonicalize-lgpl.c
+/careadlinkat.c
+/careadlinkat.h
+/progreloc.c
+/readlink.c
+/relocatable.c
+/relocatable.h
+/relocwrapper.c
+/setenv.c
+/xreadlink.c
+/xreadlink.h
diff --git a/m4/.gitignore b/m4/.gitignore
index 187d9634..43cae90b 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -191,3 +191,7 @@
 /sys_resource_h.m4
 /timespec.m4
 /intl-thread-locale.m4
+/canonicalize.m4
+/readlink.m4
+/relocatable-lib.m4
+/relocatable.m4
diff --git a/src/local.mk b/src/local.mk
index 6d5adfd9..73d5efb5 100644
--- a/src/local.mk
+++ b/src/local.mk
@@ -13,10 +13,17 @@
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+CLEANDIRS += %D%/*.dSYM
+
 bin_PROGRAMS = src/bison
 # Prettify Automake-computed names of compiled objects.
 src_bison_SHORTNAME = bison
 
+src_bison_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
+if RELOCATABLE_VIA_LD
+  src_bison_LDFLAGS = `$(RELOCATABLE_LDFLAGS) $(bindir)`
+endif
+
 src_bison_CFLAGS = $(AM_CFLAGS) $(WERROR_CFLAGS)
 src_bison_SOURCES =                             \
   src/AnnotationList.c                          \
@@ -127,16 +134,7 @@ src_bison_LDADD =                               \
 ## ------ ##
 
 if ENABLE_YACC
-  bin_SCRIPTS = src/yacc
+  nodist_bin_SCRIPTS = src/yacc
 endif
 EXTRA_SCRIPTS = src/yacc
 MOSTLYCLEANFILES += src/yacc
-CLEANDIRS += %D%/*.dSYM
-
-src/yacc:
-       $(AM_V_GEN)rm -f $@ address@hidden
-       $(AM_V_at)$(MKDIR_P) src
-       $(AM_V_at)echo '#! /bin/sh' >address@hidden
-       $(AM_V_at)echo "exec '$(bindir)/bison' -y "'"$$@"' >>address@hidden
-       $(AM_V_at)chmod a+x address@hidden
-       $(AM_V_at)mv address@hidden $@
diff --git a/src/main.c b/src/main.c
index ebd92451..6f7acdc4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,6 +26,7 @@
 #include <configmake.h>
 #include <progname.h>
 #include <quotearg.h>
+#include <relocatable.h> /* relocate2 */
 #include <timevar.h>
 
 #include "LR0.h"
@@ -58,10 +59,16 @@
 int
 main (int argc, char *argv[])
 {
+#define DEPENDS_ON_LIBINTL 1
   set_program_name (argv[0]);
   setlocale (LC_ALL, "");
-  (void) bindtextdomain (PACKAGE, LOCALEDIR);
-  (void) bindtextdomain ("bison-runtime", LOCALEDIR);
+  {
+    char *cp = NULL;
+    char const *localedir = relocate2 (LOCALEDIR, &cp);
+    (void) bindtextdomain (PACKAGE, localedir);
+    (void) bindtextdomain ("bison-runtime", localedir);
+    free (cp);
+  }
   (void) textdomain (PACKAGE);
 
   {
diff --git a/src/output.c b/src/output.c
index b6c60cf5..dd443608 100644
--- a/src/output.c
+++ b/src/output.c
@@ -26,6 +26,7 @@
 #include <get-errno.h>
 #include <path-join.h>
 #include <quotearg.h>
+#include <relocatable.h> /* relocate2 */
 #include <spawn-pipe.h>
 #include <timevar.h>
 #include <wait-process.h>
@@ -44,6 +45,9 @@
 
 static struct obstack format_obstack;
 
+/* Memory allocated by relocate2, to free.  */
+static char *relocate_buffer = NULL;
+
 
 /*-------------------------------------------------------------------.
 | Create a function NAME which associates to the muscle NAME the     |
@@ -718,11 +722,17 @@ output (void)
     unlink_generated_sources ();
 
   obstack_free (&format_obstack, NULL);
+  free (relocate_buffer);
 }
 
 char const *
 pkgdatadir (void)
 {
-  char const *cp = getenv ("BISON_PKGDATADIR");
-  return cp ? cp : PKGDATADIR;
+  if (relocate_buffer)
+    return relocate_buffer;
+  else
+    {
+      char const *cp = getenv ("BISON_PKGDATADIR");
+      return cp ? cp : relocate2 (PKGDATADIR, &relocate_buffer);
+    }
 }
diff --git a/src/yacc.in b/src/yacc.in
new file mode 100644
index 00000000..1d45123d
--- /dev/null
+++ b/src/yacc.in
@@ -0,0 +1,22 @@
+#! /bin/sh
+
address@hidden@
+if test "@RELOCATABLE@" = yes; then
+  exec_prefix="@exec_prefix@"
+  bindir="@bindir@"
+  orig_installdir="$bindir" # see Makefile.am's *_SCRIPTS variables
+  func_find_curr_installdir # determine curr_installdir
+  func_find_prefixes
+  relocate () {
+    echo "$1/" \
+    | sed -e "s%^${orig_installprefix}/%${curr_installprefix}/%" \
+    | sed -e 's,/$,,'
+  }
+else
+  relocate () {
+    echo "$1"
+  }
+fi
+
+bindir=`relocate "@bindir@"`
+exec "$bindir/bison" -y "$@"




reply via email to

[Prev in Thread] Current Thread [Next in Thread]