bison-patches
[Top][All Lists]
Advanced

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

Re: [PATCH v2] src: make path to m4 relocatable


From: Akim Demaille
Subject: Re: [PATCH v2] src: make path to m4 relocatable
Date: Wed, 20 May 2020 08:08:38 +0200

Hi Thomas,

> Le 19 mai 2020 à 22:05, Thomas Petazzoni <address@hidden> a écrit :
> 
> 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.

Installed as follows.  Thanks!

commit 0d61c997f3d61424f330a682fcd09303d6831bac
Author: Thomas Petazzoni <address@hidden>
Date:   Tue May 19 22:05:22 2020 +0200

    src: make path to m4 relocatable
    
    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.
    
    * src/files.h, src/files.c (m4path): New.
    * src/output.c: Use it.

diff --git a/NEWS b/NEWS
index f5eb8032..a807b545 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU Bison NEWS
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Changes
+
+  When installed to be relocatable (via configure --enable-relocatable),
+  bison will now also look for a relocated m4.
 
 * Noteworthy changes in release 3.6.2 (2020-05-17) [stable]
 
diff --git a/src/files.c b/src/files.c
index 71c10e34..5b743ab5 100644
--- a/src/files.c
+++ b/src/files.c
@@ -22,13 +22,16 @@
 #include "system.h"
 
 #include <configmake.h> /* PKGDATADIR */
-#include <error.h>
 #include <dirname.h>
+#include <error.h>
 #include <get-errno.h>
 #include <quote.h>
 #include <quotearg.h>
 #include <relocatable.h> /* relocate2 */
 #include <stdio-safer.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
 #include <xstrndup.h>
 
 #include "complain.h"
@@ -421,6 +424,23 @@ pkgdatadir (void)
     }
 }
 
+char const *
+m4path (void)
+{
+  char const *m4 = getenv ("M4");
+  if (m4)
+    return m4;
+
+  /* We don't use relocate2() to store the temporary buffer and re-use
+     it, because m4path() is only called once.  */
+  char const *m4_relocated = relocate (M4);
+  struct stat buf;
+  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");




reply via email to

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