[libxml2] Respect `--sysconfdir` in source files



commit 865520f04830531fc0a610129202b645521e435f
Author: David Seifert <soap gentoo org>
Date:   Wed Mar 30 00:32:35 2022 +0200

    Respect `--sysconfdir` in source files
    
    * Prefix installations need to point to a non-root `etc`
      - Gentoo Prefix has been patching this for over 10 years:
        https://bugs.gentoo.org/317891
      - MacPorts has to manually replace paths after patching:
        
https://github.com/macports/macports-ports/blob/cc3bb736e906abe73b014da02a89ae2b70ef6295/textproc/libxml2/Portfile#L46

 CMakeLists.txt | 4 ++++
 Makefile.am    | 2 +-
 catalog.c      | 6 +++---
 libxml.h       | 4 ++++
 runtest.c      | 4 ++--
 xmlcatalog.c   | 2 +-
 xmllint.c      | 2 +-
 7 files changed, 16 insertions(+), 8 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 691978de..f97a0c9b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -361,6 +361,8 @@ endif()
 add_library(LibXml2 ${LIBXML2_HDRS} ${LIBXML2_SRCS})
 add_library(LibXml2::LibXml2 ALIAS LibXml2)
 
+target_compile_definitions(LibXml2 PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
+
 if(NOT BUILD_SHARED_LIBS)
        target_compile_definitions(LibXml2 INTERFACE LIBXML_STATIC)
        set(XML_CFLAGS "-DLIBXML_STATIC")
@@ -484,6 +486,7 @@ if(LIBXML2_WITH_PROGRAMS)
        foreach(PROGRAM ${PROGRAMS})
                add_executable(${PROGRAM} ${PROGRAM}.c)
                add_executable(LibXml2::${PROGRAM} ALIAS ${PROGRAM})
+               target_compile_definitions(${PROGRAM} PRIVATE SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
                target_link_libraries(${PROGRAM} LibXml2)
                if(HAVE_LIBHISTORY)
                        target_link_libraries(${PROGRAM} history)
@@ -539,6 +542,7 @@ if(LIBXML2_WITH_TESTS)
                )
                foreach(TEST ${TESTS_THREADS})
                        add_executable(${TEST} ${TEST}.c)
+                       target_compile_definitions(${TEST} PRIVATE 
SYSCONFDIR="${CMAKE_INSTALL_FULL_SYSCONFDIR}")
                        if(WIN32)
                                target_compile_definitions(${TEST} PRIVATE HAVE_WIN32_THREADS)
                        endif()
diff --git a/Makefile.am b/Makefile.am
index 5d06aaaf..57768dcd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -9,7 +9,7 @@ endif
 
 DIST_SUBDIRS = include . doc example fuzz python xstc
 
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(srcdir)/include
+AM_CPPFLAGS = -I$(top_builddir)/include -I$(srcdir)/include -DSYSCONFDIR='"$(sysconfdir)"'
 
 AM_CFLAGS = $(EXTRA_CFLAGS) $(THREAD_CFLAGS) $(Z_CFLAGS) $(LZMA_CFLAGS)
 
diff --git a/catalog.c b/catalog.c
index 729fa55e..b7837e3d 100644
--- a/catalog.c
+++ b/catalog.c
@@ -68,15 +68,15 @@
 #define XML_URN_PUBID "urn:publicid:"
 #define XML_CATAL_BREAK ((xmlChar *) -1)
 #ifndef XML_XML_DEFAULT_CATALOG
-#define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
+#define XML_XML_DEFAULT_CATALOG "file://" SYSCONFDIR "/xml/catalog"
 #endif
 #ifndef XML_SGML_DEFAULT_CATALOG
-#define XML_SGML_DEFAULT_CATALOG "file:///etc/sgml/catalog"
+#define XML_SGML_DEFAULT_CATALOG "file://" SYSCONFDIR "/sgml/catalog"
 #endif
 
 #if defined(_WIN32) && defined(_MSC_VER)
 #undef XML_XML_DEFAULT_CATALOG
-static char XML_XML_DEFAULT_CATALOG[256] = "file:///etc/xml/catalog";
+static char XML_XML_DEFAULT_CATALOG[256] = "file://" SYSCONFDIR "/xml/catalog";
 #if !defined(_WINDOWS_)
 void* __stdcall GetModuleHandleA(const char*);
 unsigned long __stdcall GetModuleFileNameA(void*, char*, unsigned long);
diff --git a/libxml.h b/libxml.h
index 1330552b..910ca49b 100644
--- a/libxml.h
+++ b/libxml.h
@@ -28,6 +28,10 @@
 #include "config.h"
 #include <libxml/xmlversion.h>
 
+#ifndef SYSCONFDIR
+  #define SYSCONFDIR "/etc"
+#endif
+
 #if defined(__Lynx__)
 #include <stdio.h> /* pull definition of size_t */
 #include <varargs.h>
diff --git a/runtest.c b/runtest.c
index 26443485..d4990506 100644
--- a/runtest.c
+++ b/runtest.c
@@ -2927,7 +2927,7 @@ static int urip_rlen;
  */
 static int
 uripMatch(const char * URI) {
-    if ((URI == NULL) || (!strcmp(URI, "file:///etc/xml/catalog")))
+    if ((URI == NULL) || (!strcmp(URI, "file://" SYSCONFDIR "/xml/catalog")))
         return(0);
     /* Verify we received the escaped URL */
     if (strcmp(urip_rcvsURLs[urip_current], URI))
@@ -2946,7 +2946,7 @@ uripMatch(const char * URI) {
  */
 static void *
 uripOpen(const char * URI) {
-    if ((URI == NULL) || (!strcmp(URI, "file:///etc/xml/catalog")))
+    if ((URI == NULL) || (!strcmp(URI, "file://" SYSCONFDIR "/xml/catalog")))
         return(NULL);
     /* Verify we received the escaped URL */
     if (strcmp(urip_rcvsURLs[urip_current], URI))
diff --git a/xmlcatalog.c b/xmlcatalog.c
index d4143ad1..9d926118 100644
--- a/xmlcatalog.c
+++ b/xmlcatalog.c
@@ -40,7 +40,7 @@ static char *filename = NULL;
 
 
 #ifndef XML_SGML_DEFAULT_CATALOG
-#define XML_SGML_DEFAULT_CATALOG "/etc/sgml/catalog"
+#define XML_SGML_DEFAULT_CATALOG SYSCONFDIR "/sgml/catalog"
 #endif
 
 /************************************************************************
diff --git a/xmllint.c b/xmllint.c
index 5dcb8840..b5dfbd03 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -81,7 +81,7 @@
 #endif
 
 #ifndef XML_XML_DEFAULT_CATALOG
-#define XML_XML_DEFAULT_CATALOG "file:///etc/xml/catalog"
+#define XML_XML_DEFAULT_CATALOG "file://" SYSCONFDIR "/xml/catalog"
 #endif
 
 typedef enum {


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