[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
make pkgdatadir relative to program path if not specified
From: |
Victor Zverovich |
Subject: |
make pkgdatadir relative to program path if not specified |
Date: |
Fri, 26 Oct 2018 12:27:51 -0700 |
Currently running bison using a path other than the install path e.g.
via a network share results in the following error
bison: .../share/bison/m4sugar/m4sugar.m4: cannot open: No such file
or directory
Fix this by setting setting pkgdatadir relative to program path if
BISON_PKGDATADIR is not specified.
---
src/output.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/output.c b/src/output.c
index 96295d17..749aad6d 100644
--- a/src/output.c
+++ b/src/output.c
@@ -21,14 +21,17 @@
#include <config.h>
#include "system.h"
+#include <errno.h>
#include <configmake.h>
#include <filename.h> /* IS_PATH_WITH_DIR */
#include <get-errno.h>
+#include <libgen.h>
#include <path-join.h>
#include <quotearg.h>
#include <spawn-pipe.h>
#include <timevar.h>
#include <wait-process.h>
+#include <progname.h>
#include "complain.h"
#include "files.h"
@@ -701,6 +704,31 @@ output (void)
char const *
pkgdatadir (void)
{
- char const *cp = getenv ("BISON_PKGDATADIR");
- return cp ? cp : PKGDATADIR;
+ static char default_pkgdatadir[PATH_MAX] = "";
+
+ char const *pkgdatadir = getenv ("BISON_PKGDATADIR");
+ if (pkgdatadir) {
+ return pkgdatadir;
+ }
+
+ if (default_pkgdatadir[0] == '\0') {
+ static const char *rel_pkgdatadir = "/../share/bison";
+ char path[PATH_MAX];
+
+ if (realpath (program_name, path) == NULL) {
+ fprintf (stderr, "unable to resolve realpath of \"%s\": %s",
+ program_name, strerror (errno));
+ abort ();
+ }
+
+ dirname (path);
+ strncat (path, rel_pkgdatadir, PATH_MAX - 1 - strlen (rel_pkgdatadir));
+ if (realpath (path, default_pkgdatadir) == NULL) {
+ fprintf (stderr, "unable to resolve realpath of \"%s\": %s",
+ path, strerror (errno));
+ abort ();
+ }
+ }
+
+ return default_pkgdatadir;
}
--
2.13.5
- make pkgdatadir relative to program path if not specified,
Victor Zverovich <=