Re: PKG_LIB_DIR/PKGMODULEDIR expansion issues
"Matsumura, George" <[email protected]> Sat, 16 Jul 2022 04:31:35 -0600
| Newsgroups | gmane.linux.printing.gimp-print.devel |
|---|---|
| Message-ID | <[email protected]> |
Greetings,
In order to solve the mentioned issues, I was able to create the
attached prefix_defines.patch which moves the expansion of the ${prefix}
and ${exec_prefix} variables to build time through make as opposed to
configure time through autoconf. This is in accordance with the
suggestion here:
https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Installation-Directory-Variables.html
Specifically, this guideline was followed:
"In order to support these features, it is essential that
datarootdir remains defined as ‘${prefix}/share’, so that its value
can be expanded based on the current value of prefix.
A corollary is that you should not use these variables except in
makefiles. For instance, instead of trying to evaluate datadir in
configure and hard-coding it in makefiles using e.g.,
‘AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])’,
you should add -DDATADIR='$(datadir)' to your makefile's definition
of CPPFLAGS (AM_CPPFLAGS if you are also using Automake)."
This approach is somewhat similar to that which existed in gutenprint
before commit b6043e. I wasn't sure if there was a particular reason why
this method was undesirable/removed at the time.
As a consequence of my build of gutenprint not being able to find the
modules, I hit the segfault described here:
https://sourceforge.net/p/gimp-print/bugs/732/
The attached no_modules_segfault.patch alters this behaviour so that
stp_printer_model_count is called instead of stp_list_get_length,
leading to an informative warning being printed in the case of no
modules instead of a segmentation fault. This is consistent with usage
in the rest of the code.
Thank you for reading this, and any consideration of these changes would
be very much appreciated. I apologize for any mistakes I made in
creating the patches. If there is anything I can do to improve them,
please let me know.
Regards,
George
On 7/1/22 21:30, Matsumura, George wrote:
> Greetings,
>
> My build of Gutenprint, built through Void Linux's standardized build
> process, was unable to find the module directories due to PKGMODULEDIR
> being defined in config.h as:
> #define PKGMODULEDIR "${exec_prefix}/lib64/gutenprint/5.3/modules"
>
> Since the C processor cannot expand exec_prefix, it remains in the path
> at runtime and cannot be resolved.
>
> Attached is the config.summary from the build. In particular, the
> following flag passed to configure seemed to be responsible:
> --libdir=\${exec_prefix}/lib64
>
> There seems to be a specific case in configure.ac for when libdir is
> defined as \${exec_prefix}/lib, but this would not cover my case.
>
> This seems to be similar to the problem described here:
> https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/html_node/Defining-Directories.html
>
> Is there a recommended way to patch configure.ac so that such an option
> works correctly? The above reference suggests either moving definitions
> to compile-time options in Makefile.am, which, looking at the repository
> history, seems to have been done in gutenprint in the past, or using an
> additional macro to resolve the pathname.
>
> Thank you for reading this and in advance for any reply.
>
> Regards,
> George
_______________________________________________
Gimp-print-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gimp-print-devel
prefix_defines.patch
(text/x-patch, 5.3 KB)
diff -ruN a/configure.ac b/configure.ac
--- a/configure.ac 2020-06-04 17:28:41.000000000 -0600
+++ b/configure.ac 2022-07-16 02:25:56.165190427 -0600
@@ -671,81 +671,17 @@
AH_TEMPLATE(GUTENPRINT_BASE_VERSION,, [Gutenprint base version])
AC_DEFINE_UNQUOTED(GUTENPRINT_BASE_VERSION, "${GUTENPRINT_BASE_VERSION}")
-dnl Set PACKAGE_LOCALE_DIR in config.h
-AH_TEMPLATE(PACKAGE_LOCALE_DIR,, [Package locale directory])
-if test "x${prefix}" = "xNONE"; then
- AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, ["${ac_default_prefix}/share/locale"])
-else
- AC_DEFINE_UNQUOTED(PACKAGE_LOCALE_DIR, ["${prefix}/share/locale"])
-fi
+PACKAGE_LOCALE_DIR="${prefix}/share/locale"
-dnl Set PACKAGE_DATA_DIR in config.h.
-AH_TEMPLATE(PACKAGE_DATA_DIR,, [Package data directory])
-if test "x${datadir}" = 'x${prefix}/share'; then
- if test "x${prefix}" = "xNONE"; then
- PACKAGE_DATA_DIR="${ac_default_prefix}/share/${PACKAGE}"
- else
- PACKAGE_DATA_DIR="${prefix}/share/${PACKAGE}"
- fi
-elif test "x${datadir}" = 'x${datarootdir}'; then
- if test "x${datarootdir}" = 'x${prefix}/share'; then
- if test "x${prefix}" = "xNONE"; then
- PACKAGE_DATA_DIR="${ac_default_prefix}/share/${PACKAGE}"
- else
- PACKAGE_DATA_DIR="${prefix}/share/${PACKAGE}"
- fi
- else
- PACKAGE_DATA_DIR="${datarootdir}/${PACKAGE}"
- fi
-else
- PACKAGE_DATA_DIR="${datadir}/${PACKAGE}"
-fi
+PACKAGE_DATA_DIR="${datadir}/${PACKAGE}"
-AC_DEFINE_UNQUOTED(PACKAGE_DATA_DIR, "${PACKAGE_DATA_DIR}")
-
-dnl Set PACKAGE_LIB_DIR in config.h.
-AH_TEMPLATE(PACKAGE_LIB_DIR,, [Package lib directory])
-if test "x${libdir}" = 'x${exec_prefix}/lib'; then
- if test "x${exec_prefix}" = "xNONE"; then
- if test "x${prefix}" = "xNONE"; then
- PACKAGE_LIB_DIR="${ac_default_prefix}/lib/${PACKAGE}"
- else
- PACKAGE_LIB_DIR="${prefix}/lib/${PACKAGE}"
- fi
- else
- PACKAGE_LIB_DIR="${exec_prefix}/lib/${PACKAGE}"
- fi
-else
- PACKAGE_LIB_DIR="${libdir}/${PACKAGE}"
-fi
-
-AC_DEFINE_UNQUOTED(PACKAGE_LIB_DIR, ["${PACKAGE_LIB_DIR}"])
-
-dnl Set PACKAGE_BIN_DIR in config.h.
-AH_TEMPLATE(PACKAGE_BIN_DIR,, [Package bin directory])
-if test "x${bindir}" = 'x${exec_prefix}/bin'; then
- if test "x${exec_prefix}" = "xNONE"; then
- if test "x${prefix}" = "xNONE"; then
- PACKAGE_BIN_DIR="${ac_default_prefix}/bin"
- else
- PACKAGE_BIN_DIR="${prefix}/bin"
- fi
- else
- PACKAGE_BIN_DIR="${exec_prefix}/bin"
- fi
-else
- PACKAGE_BIN_DIR="${bindir}"
-fi
+PACKAGE_LIB_DIR="${libdir}/${PACKAGE}"
-AC_DEFINE_UNQUOTED(PACKAGE_BIN_DIR, ["${PACKAGE_BIN_DIR}"])
+PACKAGE_BIN_DIR="${bindir}"
-AH_TEMPLATE(PKGXMLDATADIR,, [Package XML data directory])
PKGXMLDATADIR="${PACKAGE_DATA_DIR}/${GUTENPRINT_RELEASE_VERSION}/xml"
-AC_DEFINE_UNQUOTED(PKGXMLDATADIR, ["$PKGXMLDATADIR"], )
-AH_TEMPLATE(PKGMODULEDIR,, [Package module directory])
PKGMODULEDIR="${PACKAGE_LIB_DIR}/${GUTENPRINT_RELEASE_VERSION}/modules"
-AC_DEFINE_UNQUOTED(PKGMODULEDIR, ["$PKGMODULEDIR"])
dnl Compiler flags
if test x$ac_compiler_gnu = "xyes"; then
@@ -1107,6 +1043,12 @@
AC_SUBST(LIBUSB_BACKEND_LIBDEPS)
AC_SUBST(PKGROOT)
AC_SUBST(MINIMAL_PRINTERS_TO_TEST)
+AC_SUBST(PACKAGE_LOCALE_DIR)
+AC_SUBST(PACKAGE_DATA_DIR)
+AC_SUBST(PACKAGE_LIB_DIR)
+AC_SUBST(PACKAGE_BIN_DIR)
+AC_SUBST(PKGXMLDATADIR)
+AC_SUBST(PKGMODULEDIR)
dnl Optional architecture options to be applied after all autoconf tests
dnl are done...
@@ -1252,10 +1194,10 @@
# Configure intentionally does not expand exec_prefix to allow make
# to do so.
echo " Exec prefix: `eval eval echo $exec_prefix` ($exec_prefix)" |tee -a config.summary
-echo " Data directory: $PACKAGE_DATA_DIR" |tee -a config.summary
+echo " Data directory: `eval eval echo $PACKAGE_DATA_DIR` ($PACKAGE_DATA_DIR)" |tee -a config.summary
echo " Library directory: `eval eval echo $PACKAGE_LIB_DIR` ($PACKAGE_LIB_DIR)" |tee -a config.summary
echo " Executable directory: `eval eval echo $PACKAGE_BIN_DIR` ($PACKAGE_BIN_DIR)" |tee -a config.summary
-echo " XML data directory: $PKGXMLDATADIR" |tee -a config.summary
+echo " XML data directory: `eval eval echo $PKGXMLDATADIR` ($PKGXMLDATADIR)" |tee -a config.summary
echo " Module directory: `eval eval echo $PKGMODULEDIR` ($PKGMODULEDIR)" |tee -a config.summary
echo " Install sample images: $INSTALL_SAMPLES" |tee -a config.summary
echo |tee -a config.summary
diff -ruN a/scripts/global.mk b/scripts/global.mk
--- a/scripts/global.mk 2019-05-24 08:41:34.000000000 -0600
+++ b/scripts/global.mk 2022-07-16 03:23:54.811452280 -0600
@@ -6,7 +6,7 @@
#export STP_MODULE_PATH = $(top_builddir)/src/main/.libs:$(top_builddir)/src/main
#export STP_DATA_PATH = $(top_srcdir)/src/xml
-AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include $(LOCAL_CPPFLAGS) $(GNUCFLAGS)
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include $(LOCAL_CPPFLAGS) $(GNUCFLAGS) -DPACKAGE_LOCALE_DIR=\"$(PACKAGE_LOCALE_DIR)\" -DPACKAGE_DATA_DIR=\"$(PACKAGE_DATA_DIR)\" -DPACKAGE_LIB_DIR=\"$(PACKAGE_LIB_DIR)\" -DPACKAGE_BIN_DIR=\"$(PACKAGE_BIN_DIR)\" -DPKGMODULEDIR=\"$(PKGMODULEDIR)\" -DPKGXMLDATADIR=\"$(PKGXMLDATADIR)\"
LIBS = $(INTLLIBS) @LIBS@
no_modules_segfault.patch
(text/x-patch, 531 B)
diff -ruN a/src/main/printers.c b/src/main/printers.c
--- a/src/main/printers.c 2019-05-25 08:34:21.000000000 -0600
+++ b/src/main/printers.c 2022-07-01 02:21:01.400753898 -0600
@@ -966,7 +966,10 @@
void
stpi_find_duplicate_printers(void)
{
- size_t nelts = stp_list_get_length(printer_list);
+ size_t nelts = stp_printer_model_count();
+ if (nelts == 0)
+ return;
+
const char **str_data = stp_zalloc(sizeof(const char *) * nelts);
stp_list_item_t *printer_item = stp_list_get_start(printer_list);
size_t i = 0;