bison-patches
[Top][All Lists]
Advanced

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

[PATCH v2] src: make path to m4 relocatable


From: Thomas Petazzoni
Subject: [PATCH v2] src: make path to m4 relocatable
Date: Tue, 19 May 2020 22:05:22 +0200

Commit a4ede8f85b0c9a254fcb01e5888cee1983095669 ("package: make bison
a relocatable package") made Bison relocatable, but in fact it still
contains one absolute reference: the M4 variable, which points to the
M4 program. Let's fix that by using relocate(), see if an M4 binary is
available at the relocated location, and otherwise fallback to the
original M4 location.

We don't use relocate2() to store the temporary buffer and re-use it,
because m4path() is only called once.

Signed-off-by: Thomas Petazzoni <address@hidden>
---
Changes since v1:
 - Check if M4 is available at the relocated location, and if not
   fallback to the original location.
 - Style fixes.
---
 src/files.c  | 21 +++++++++++++++++++++
 src/files.h  |  3 +++
 src/output.c |  2 +-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/files.c b/src/files.c
index 71c10e34..d14d203e 100644
--- a/src/files.c
+++ b/src/files.c
@@ -21,6 +21,10 @@
 #include <config.h>
 #include "system.h"
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
 #include <configmake.h> /* PKGDATADIR */
 #include <error.h>
 #include <dirname.h>
@@ -421,6 +425,23 @@ pkgdatadir (void)
     }
 }
 
+char const *
+m4path (void)
+{
+  char const *m4 = getenv ("M4");
+  char const *m4_relocated;
+  struct stat buf;
+
+  if (m4)
+    return m4;
+
+  m4_relocated = relocate (M4);
+  if (stat (m4_relocated, &buf) == 0)
+    return m4_relocated;
+
+  return M4;
+}
+
 void
 output_file_names_free (void)
 {
diff --git a/src/files.h b/src/files.h
index 00814ad0..64b6f8b5 100644
--- a/src/files.h
+++ b/src/files.h
@@ -64,6 +64,9 @@ extern char *all_but_ext;
 /* Where our data files are installed.  */
 char const *pkgdatadir (void);
 
+/* Where the m4 program is installed.  */
+char const *m4path (void);
+
 void compute_output_file_names (void);
 void output_file_names_free (void);
 
diff --git a/src/output.c b/src/output.c
index 1871fd75..ebe75095 100644
--- a/src/output.c
+++ b/src/output.c
@@ -682,7 +682,7 @@ static void
 output_skeleton (void)
 {
   /* Compute the names of the package data dir and skeleton files.  */
-  char const *m4 = (m4 = getenv ("M4")) ? m4 : M4;
+  char const *m4 = m4path ();
   char const *datadir = pkgdatadir ();
   char *skeldir = xpath_join (datadir, "skeletons");
   char *m4sugar = xpath_join (datadir, "m4sugar/m4sugar.m4");
-- 
2.26.2




reply via email to

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