mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
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.
This commit is contained in:
18
src/local.mk
18
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 $@ $@.tmp
|
||||
$(AM_V_at)$(MKDIR_P) src
|
||||
$(AM_V_at)echo '#! /bin/sh' >$@.tmp
|
||||
$(AM_V_at)echo "exec '$(bindir)/bison' -y "'"$$@"' >>$@.tmp
|
||||
$(AM_V_at)chmod a+x $@.tmp
|
||||
$(AM_V_at)mv $@.tmp $@
|
||||
|
||||
11
src/main.c
11
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);
|
||||
|
||||
{
|
||||
|
||||
14
src/output.c
14
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);
|
||||
}
|
||||
}
|
||||
|
||||
22
src/yacc.in
Normal file
22
src/yacc.in
Normal file
@@ -0,0 +1,22 @@
|
||||
#! /bin/sh
|
||||
|
||||
@relocatable_sh@
|
||||
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 "$@"
|
||||
Reference in New Issue
Block a user