poke-devel
[Top][All Lists]
Advanced

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

[PATCH 3/5] Allow Poke to be built relocatable


From: Georgiy Tugai
Subject: [PATCH 3/5] Allow Poke to be built relocatable
Date: Thu, 25 Mar 2021 20:14:13 +0000

./configure --enable-relocatable

2021-03-25  Georgiy Tugai  <georgiy@crossings.link>

        * .gitignore: exclude gl-libpoke/Makefile.am
        * bootstrap.conf (gnulib_modules): add relocatable-prog
        (libpoke_modules): add relocatable-lib-lgpl
        (bootstrap_post_import_hook): switch gl-libpoke/ to
        --makefile-name mode, so we can chance AM_CPPFLAGS for
        relocatable-lib-lgpl
        * configure.ac: Add SHLIBS_IN_BINDIR conditional for
        relocatable-lib-lgpl. Add gl-libpoke since it is not (fully) taken
        care of by bootstrap anymore.
        * doc/.gitignore: Add relocatable.texi
        * gl-libpoke/Makefile.am: New file, sets AM_CPPFLAGS for Gnulib to
        be built in "library" mode (-DIN_LIBRARY)
        * libpoke/Makefile.am: Changes for relocatable-lib-lgpl
        * libpoke/libpoke.c (pk_compiler_new): Relocatable PKGDATADIR
        * libpoke/pkl.c (pkl_resolve_module): Likewise
        * poke/Makefile.am: Changes for relocatable-prog
        * poke/pk-map.c (pk_map_resolve_map): Relocatable PKGDATADIR
        * poke/poke.c (initialize): Relocatable PKGDATADIR, PKGINFODIR
        (main): Move set_program_name to earliest position and pass
        argv[0], to detect relocation
---
 .gitignore             |  3 ++-
 ChangeLog              | 23 +++++++++++++++++++++++
 bootstrap.conf         |  4 +++-
 configure.ac           |  5 +++++
 doc/.gitignore         |  1 +
 gl-libpoke/Makefile.am | 27 +++++++++++++++++++++++++++
 libpoke/Makefile.am    |  8 +++++++-
 libpoke/libpoke.c      |  3 ++-
 libpoke/pkl.c          |  3 ++-
 poke/Makefile.am       | 10 ++++++++--
 poke/pk-map.c          |  3 ++-
 poke/pk-term.c         |  3 ++-
 poke/poke.c            | 14 ++++++++------
 13 files changed, 92 insertions(+), 15 deletions(-)
 create mode 100644 gl-libpoke/Makefile.am

diff --git a/.gitignore b/.gitignore
index efb4e6c3..55dde2e7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,7 +22,8 @@ config.h.in
 /config.status
 /configure.lineno
 /gl
-/gl-libpoke
+/gl-libpoke/**
+!/gl-libpoke/Makefile.am
 /gl-libutils
 /gl-gui
 /po/.gitignore
diff --git a/ChangeLog b/ChangeLog
index 604ca010..2a115b12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2021-03-25  Georgiy Tugai  <georgiy@crossings.link>
+
+       * .gitignore: exclude gl-libpoke/Makefile.am
+       * bootstrap.conf (gnulib_modules): add relocatable-prog
+       (libpoke_modules): add relocatable-lib-lgpl
+       (bootstrap_post_import_hook): switch gl-libpoke/ to
+       --makefile-name mode, so we can chance AM_CPPFLAGS for
+       relocatable-lib-lgpl
+       * configure.ac: Add SHLIBS_IN_BINDIR conditional for
+       relocatable-lib-lgpl. Add gl-libpoke since it is not (fully) taken
+       care of by bootstrap anymore.
+       * doc/.gitignore: Add relocatable.texi
+       * gl-libpoke/Makefile.am: New file, sets AM_CPPFLAGS for Gnulib to
+       be built in "library" mode (-DIN_LIBRARY)
+       * libpoke/Makefile.am: Changes for relocatable-lib-lgpl
+       * libpoke/libpoke.c (pk_compiler_new): Relocatable PKGDATADIR
+       * libpoke/pkl.c (pkl_resolve_module): Likewise
+       * poke/Makefile.am: Changes for relocatable-prog
+       * poke/pk-map.c (pk_map_resolve_map): Relocatable PKGDATADIR
+       * poke/poke.c (initialize): Relocatable PKGDATADIR, PKGINFODIR
+       (main): Move set_program_name to earliest position and pass
+       argv[0], to detect relocation
+
 2021-03-25  Georgiy Tugai  <georgiy@crossings.link>

        * bootstrap.conf: Add Gnulib modules arpa_inet, getsockname,
diff --git a/bootstrap.conf b/bootstrap.conf
index 43d24631..d155aefc 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -49,6 +49,7 @@ gnulib_modules="
   pthread
   readline
   regex
+  relocatable-prog
   sigaction
   signal-h
   socket
@@ -86,6 +87,7 @@ libpoke_modules="
   mkstemp
   printf-posix
   random
+  relocatable-lib-lgpl
   secure_getenv
   snprintf
   stdarg
@@ -225,7 +227,7 @@ bootstrap_post_import_hook ()
   ${GNULIB_SRCDIR}/gnulib-tool --copy-file doc/INSTALL INSTALL.generic

   # create gl-libpoke
-  ${GNULIB_SRCDIR}/gnulib-tool --import --lib=libgnu --source-base=gl-libpoke 
--m4-base=m4/libpoke --doc-base=doc --aux-dir=build-aux 
--no-conditional-dependencies --libtool --without-tests --macro-prefix=libpoke 
${libpoke_modules}
+  ${GNULIB_SRCDIR}/gnulib-tool --import --lib=libgnu --source-base=gl-libpoke 
--m4-base=m4/libpoke --doc-base=doc --aux-dir=build-aux 
--no-conditional-dependencies --libtool --without-tests --macro-prefix=libpoke 
--makefile-name=Makefile.gnulib ${libpoke_modules}

   # create gl-gui
   ${GNULIB_SRCDIR}/gnulib-tool --import --lib=libgnu --source-base=gl-gui 
--m4-base=m4/gui --doc-base=doc --aux-dir=build-aux 
--no-conditional-dependencies --libtool --without-tests --macro-prefix=gui 
${gui_modules}
diff --git a/configure.ac b/configure.ac
index 7ca26abb..2b19683d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -173,6 +173,10 @@ dnl following macro is also supposed to work when 
cross-compiling.

 AC_C_BIGENDIAN

+dnl Gnulib libpoke relocatable-lib-lgpl needs this
+AM_CONDITIONAL([SHLIBS_IN_BINDIR],
+               [case "$host_os" in mingw* | cygwin*) true;; *) false;; esac])
+
 dnl The following M4 macro from gnulib sets HOST_CPU_C_ABI_32BIT to
 dnl 'yes' if the C language ABI is a 32-bit one, to 'no' if it is
 dnl 64-bit, or to 'unknown'.
@@ -270,6 +274,7 @@ AC_CONFIG_FILES(Makefile
                 testsuite/poke.mi-json/Makefile)
 AC_CONFIG_FILES([run],
                 [chmod +x,-w run])
+AC_CONFIG_SUBDIRS([gl-libpoke])

 dnl pkg-config description
 AX_CREATE_PKGCONFIG_INFO('libpoke/poke.pc', , , 'libpoke')
diff --git a/doc/.gitignore b/doc/.gitignore
index cf41366f..a5528697 100644
--- a/doc/.gitignore
+++ b/doc/.gitignore
@@ -1,3 +1,4 @@
 /gendocs_template
 /gendocs_template_min
 /parse-datetime.texi
+/relocatable.texi
diff --git a/gl-libpoke/Makefile.am b/gl-libpoke/Makefile.am
new file mode 100644
index 00000000..df8bc0a1
--- /dev/null
+++ b/gl-libpoke/Makefile.am
@@ -0,0 +1,27 @@
+AUTOMAKE_OPTIONS = 1.11 gnits
+
+SUBDIRS =
+noinst_HEADERS =
+noinst_LIBRARIES =
+noinst_LTLIBRARIES =
+EXTRA_DIST =
+BUILT_SOURCES =
+SUFFIXES =
+MOSTLYCLEANFILES = core *.stackdump
+MOSTLYCLEANDIRS =
+CLEANFILES =
+DISTCLEANFILES =
+MAINTAINERCLEANFILES =
+
+AM_CFLAGS =
+AM_CPPFLAGS =
+
+AM_CPPFLAGS += -DIN_LIBRARY -DENABLE_COSTLY_RELOCATABLE
+
+if SHLIBS_IN_BINDIR
+AM_CPPFLAGS += -DINSTALLDIR=\"$(bindir)\"
+else
+AM_CPPFLAGS += -DINSTALLDIR=\"$(libdir)\"
+endif
+
+include Makefile.gnulib
diff --git a/libpoke/Makefile.am b/libpoke/Makefile.am
index 97baca8b..7ecf8e16 100644
--- a/libpoke/Makefile.am
+++ b/libpoke/Makefile.am
@@ -22,6 +22,8 @@ CLEANFILES =
 DISTCLEANFILES =
 MAINTAINERCLEANFILES =

+RELOCATABLE_LIBRARY_PATH = $(libdir)
+
 dist_pkgdata_DATA = pkl-rt.pk std.pk
 dist_pkgconfig_lib_DATA = $(pkgconfig_libfile)

@@ -185,13 +187,17 @@ libpoke_la_CPPFLAGS = -I$(top_builddir)/gl-libpoke 
-I$(top_srcdir)/gl-libpoke \
                       -DPKGINFODIR=\"$(infodir)\" \
                       -DLOCALEDIR=\"$(localedir)\" \
                       $(CFLAG_VISIBILITY) \
-                      -DBUILDING_LIBPOKE
+                      -DBUILDING_LIBPOKE \
+                      -DINSTALLDIR=\"$(libdir)\"
 libpoke_la_CFLAGS = -Wall $(BDW_GC_CFLAGS) $(LIBNBD_CFLAGS)
 libpoke_la_LIBADD = ../gl-libpoke/libgnu.la libpvmjitter.la \
                     $(BDW_GC_LIBS) \
                     $(LIBNBD_LIBS)
 libpoke_la_LDFLAGS = -version-info $(LTV_CURRENT):$(LTV_REVISION):$(LTV_AGE) \
                      -lc -no-undefined
+if RELOCATABLE_VIA_LD
+libpoke_la_LDFLAGS += `$(RELOCATABLE_LDFLAGS) $(libdir)`
+endif

 # Delete a few files created by AX_CREATE_PKGCONFIG_INFO at make
 # distclean.
diff --git a/libpoke/libpoke.c b/libpoke/libpoke.c
index 5ca5b1dd..9904b320 100644
--- a/libpoke/libpoke.c
+++ b/libpoke/libpoke.c
@@ -17,6 +17,7 @@
  */

 #include <config.h>
+#include <relocatable.h>

 #include <string.h>
 #include <stdlib.h>
@@ -62,7 +63,7 @@ pk_compiler_new (struct pk_term_if *term_if)
       /* Determine the path to the compiler's runtime files.  */
       const char *libpoke_datadir = getenv ("POKEDATADIR");
       if (libpoke_datadir == NULL)
-        libpoke_datadir = PKGDATADIR;
+        libpoke_datadir = relocate (PKGDATADIR);

       libpoke_term_if = *term_if;

diff --git a/libpoke/pkl.c b/libpoke/pkl.c
index cdc9e722..f76f426c 100644
--- a/libpoke/pkl.c
+++ b/libpoke/pkl.c
@@ -17,6 +17,7 @@
  */

 #include <config.h>
+#include <relocatable.h>

 #include <gettext.h>
 #define _(str) gettext (str)
@@ -686,7 +687,7 @@ pkl_resolve_module (pkl_compiler compiler,
     const char *ext = filename_p ? "" : ".pk";
     const char *s, *e;

-    char *fixed_load_path = pk_str_replace (load_path, "%DATADIR%", 
PKGDATADIR);
+    char *fixed_load_path = pk_str_replace (load_path, "%DATADIR%", relocate 
(PKGDATADIR));

     for (s = fixed_load_path, e = s; *e; s = e + 1)
       {
diff --git a/poke/Makefile.am b/poke/Makefile.am
index 594a6885..c468ad85 100644
--- a/poke/Makefile.am
+++ b/poke/Makefile.am
@@ -26,6 +26,8 @@ BUILT_SOURCES =

 EXTRA_DIST =

+RELOCATABLE_LIBRARY_PATH = $(libdir)
+
 dist_pkgdata_DATA = pk-cmd.pk pk-dump.pk pk-save.pk pk-copy.pk \
                     pk-extract.pk pk-scrabble.pk poke.pk

@@ -50,14 +52,18 @@ poke_CPPFLAGS = -I$(top_builddir)/gl -I$(top_srcdir)/gl \
                 -DJITTER_VERSION=\"$(JITTER_VERSION)\" \
                 -DPKGDATADIR=\"$(pkgdatadir)\" \
                 -DPKGINFODIR=\"$(infodir)\" \
-                -DLOCALEDIR=\"$(localedir)\"
+                -DLOCALEDIR=\"$(localedir)\" \
+                -DINSTALLDIR=\"$(bindir)\"
 poke_CFLAGS = -Wall
 poke_LDADD = $(top_builddir)/gl/libgnu.la \
              $(top_builddir)/libpoke/libpoke.la \
              $(LTLIBREADLINE) \
              $(LTLIBTEXTSTYLE)
+if RELOCATABLE_VIA_LD
+poke_LDFLAGS = `$(RELOCATABLE_LDFLAGS) $(bindir)`
+else
 poke_LDFLAGS =
-
+endif

 AM_LFLAGS = -d
 # The Automake generated .l.c rule is broken: When executed in a VPATH build,
diff --git a/poke/pk-map.c b/poke/pk-map.c
index 67bb6056..e960ea62 100644
--- a/poke/pk-map.c
+++ b/poke/pk-map.c
@@ -17,6 +17,7 @@
  */

 #include <config.h>
+#include <relocatable.h>

 #include <stdio.h>
 #include <inttypes.h>
@@ -678,7 +679,7 @@ pk_map_resolve_map (const char *mapname, int filename_p)
     const char *s, *e;

     char *fixed_load_path
-      = pk_str_replace (map_load_path, "%DATADIR%", PKGDATADIR);
+      = pk_str_replace (map_load_path, "%DATADIR%", relocate (PKGDATADIR));

     for (s = fixed_load_path, e = s; *e; s = e + 1)
       {
diff --git a/poke/pk-term.c b/poke/pk-term.c
index 6a89697c..f799ec6b 100644
--- a/poke/pk-term.c
+++ b/poke/pk-term.c
@@ -17,6 +17,7 @@
  */

 #include <config.h>
+#include <relocatable.h>

 #include <stdlib.h> /* For exit.  */
 #include <assert.h> /* For assert. */
@@ -202,7 +203,7 @@ pk_term_init (int argc, char *argv[])
       || color_mode == color_html)
     {
       /* Find the style file.  */
-      style_file_prepare ("POKE_STYLE", "POKESTYLESDIR", PKGDATADIR,
+      style_file_prepare ("POKE_STYLE", "POKESTYLESDIR", relocate (PKGDATADIR),
                           "poke-default.css");
     }
   else
diff --git a/poke/poke.c b/poke/poke.c
index 2d7dbb1a..6343726d 100644
--- a/poke/poke.c
+++ b/poke/poke.c
@@ -18,6 +18,7 @@

 #include <config.h>
 #include <progname.h>
+#include <relocatable.h>
 #include <getopt.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -504,19 +505,16 @@ parse_args_2 (int argc, char *argv[])
 static void
 initialize (int argc, char *argv[])
 {
-  /* This is used by the `progname' gnulib module.  */
-  set_program_name ("poke");
-
   /* i18n */
   setlocale (LC_ALL, "");
-  bindtextdomain (PACKAGE, LOCALEDIR);
+  bindtextdomain (PACKAGE, relocate (LOCALEDIR));
   textdomain (PACKAGE);

   /* Determine the directory containing poke's scripts and other
      architecture-independent data.  */
   poke_datadir = getenv ("POKEDATADIR");
   if (poke_datadir == NULL)
-    poke_datadir = PKGDATADIR;
+    poke_datadir = relocate (PKGDATADIR);

   poke_picklesdir = getenv ("POKEPICKLESDIR");
   if (poke_picklesdir == NULL)
@@ -538,7 +536,7 @@ initialize (int argc, char *argv[])

   poke_infodir = getenv ("POKEINFODIR");
   if (poke_infodir == NULL)
-    poke_infodir = PKGINFODIR;
+    poke_infodir = relocate (PKGINFODIR);

   /* Initialize the terminal output.  */
   pk_term_init (argc, argv);
@@ -671,6 +669,10 @@ pk_fatal (const char *errmsg)
 int
 main (int argc, char *argv[])
 {
+  /* This is used by the `progname' and `relocatable-prog' gnulib
+     modules.  */
+  set_program_name (argv[0]);
+
   /* Determine whether the tool has been invoked interactively.  */
   poke_interactive_p = isatty (fileno (stdin));

--
2.26.2





reply via email to

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