summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordevzero2000 <devzero2000>2011-04-14 12:40:49 +0000
committerdevzero2000 <devzero2000>2011-04-14 12:40:49 +0000
commitec66844aad93ab37beb5b651b63f8c812dfa3adb (patch)
tree740ff52d7d850b10052617ac7a7a873fd53a3632
parent1ea75a70f80b7dbf76411743b25ddd18833a4617 (diff)
downloadlibpopt-ec66844aad93ab37beb5b651b63f8c812dfa3adb.tar.gz
Rewrite the logic in poptReadDefaultConfig for
finding the popt alias file Introduce in Makefile.am an automatically generated configmake.h for setting the gnu standard directory and include it in system.h. So it is possible to semplify poptReadDefaultConfig a bit.
-rw-r--r--Makefile.am65
-rwxr-xr-xconfigure.ac4
-rw-r--r--poptconfig.c14
-rw-r--r--system.h3
4 files changed, 71 insertions, 15 deletions
diff --git a/Makefile.am b/Makefile.am
index 9095994..76e8fcb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,69 @@ AM_CPPFLAGS = -I. -I$(top_srcdir)
AM_CFLAGS = $(POPT_CFLAGS)
AM_LDFLAGS = $(POPT_LDFLAGS)
+## begin configmake
+
+# Retrieve values of the variables through 'configure' followed by
+# 'make', not directly through 'configure', so that a user who
+# sets some of these variables consistently on the 'make' command
+# line gets correct results.
+#
+# One advantage of this approach, compared to the classical
+# approach of adding -DLIBDIR=\"$(libdir)\" etc. to AM_CPPFLAGS,
+# is that it protects against the use of undefined variables.
+# If, say, $(libdir) is not set in the Makefile, LIBDIR is not
+# defined by this module, and code using LIBDIR gives a
+# compilation error.
+#
+# Another advantage is that 'make' output is shorter.
+#
+# Listed in the same order as the GNU makefile conventions.
+# The Automake-defined pkg* macros are appended, in the order
+# listed in the Automake 1.10a+ documentation.
+configmake.h: Makefile
+ $(AM_V_GEN)rm -f $@-t && \
+ { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+ echo '#define PREFIX "$(prefix)"'; \
+ echo '#define EXEC_PREFIX "$(exec_prefix)"'; \
+ echo '#define BINDIR "$(bindir)"'; \
+ echo '#define SBINDIR "$(sbindir)"'; \
+ echo '#define LIBEXECDIR "$(libexecdir)"'; \
+ echo '#define DATAROOTDIR "$(datarootdir)"'; \
+ echo '#define DATADIR "$(datadir)"'; \
+ echo '#define SYSCONFDIR "$(sysconfdir)"'; \
+ echo '#define SHAREDSTATEDIR "$(sharedstatedir)"'; \
+ echo '#define LOCALSTATEDIR "$(localstatedir)"'; \
+ echo '#define INCLUDEDIR "$(includedir)"'; \
+ echo '#define OLDINCLUDEDIR "$(oldincludedir)"'; \
+ echo '#define DOCDIR "$(docdir)"'; \
+ echo '#define INFODIR "$(infodir)"'; \
+ echo '#define HTMLDIR "$(htmldir)"'; \
+ echo '#define DVIDIR "$(dvidir)"'; \
+ echo '#define PDFDIR "$(pdfdir)"'; \
+ echo '#define PSDIR "$(psdir)"'; \
+ echo '#define LIBDIR "$(libdir)"'; \
+ echo '#define LISPDIR "$(lispdir)"'; \
+ echo '#define LOCALEDIR "$(localedir)"'; \
+ echo '#define MANDIR "$(mandir)"'; \
+ echo '#define MANEXT "$(manext)"'; \
+ echo '#define PKGDATADIR "$(pkgdatadir)"'; \
+ echo '#define PKGINCLUDEDIR "$(pkgincludedir)"'; \
+ echo '#define PKGLIBDIR "$(pkglibdir)"'; \
+ echo '#define PKGLIBEXECDIR "$(pkglibexecdir)"'; \
+ echo '#define POPT_ALIAS "$(sysconfdir)/popt"'; \
+ } | sed '/""/d' > $@-t && \
+ if test -f $@ && cmp $@-t $@ > /dev/null; then \
+ rm -f $@-t; \
+ else \
+ rm -f $@; mv $@-t $@; \
+ fi
+
+BUILT_SOURCES = configmake.h
+CLEANFILES = configmake.h configmake.h-t
+
+
+## end configmake
+
EXTRA_DIST = lookup3.c autogen.sh CHANGES \
footer_no_timestamp.html libpopt.vers \
$(TESTS) test-poptrc\
@@ -67,7 +130,7 @@ endif
dist_man_MANS = popt.3
-BUILT_SOURCES = popt.pc
+BUILT_SOURCES += popt.pc
distclean-local:
rm -rf .ccache
diff --git a/configure.ac b/configure.ac
index 7037739..c9e3ad6 100755
--- a/configure.ac
+++ b/configure.ac
@@ -191,10 +191,6 @@ AC_ARG_ENABLE(doxygen,
[DOXYGEN_ENABLE=yes])
AM_CONDITIONAL([DOXYGEN_ENABLE], [test x$DOXYGEN != xNO_DOXYGEN])
-# Define for popt_sysconfig
-popt_sysconfdir="${sysconfdir}"
-eval "popt_sysconfdir=\"${popt_sysconfdir}\"" # expand contained ${prefix}
-AC_DEFINE_UNQUOTED([POPT_SYSCONFDIR], ["$popt_sysconfdir"], [Full path to default POPT configuration directory])
# Check for gcov support.
# Check for lcov Makefile conditional
diff --git a/poptconfig.c b/poptconfig.c
index 3f88758..c569fab 100644
--- a/poptconfig.c
+++ b/poptconfig.c
@@ -492,27 +492,21 @@ int poptReadConfigFiles(poptContext con, const char * paths)
int poptReadDefaultConfig(poptContext con, /*@unused@*/ UNUSED(int useEnv))
{
- static const char _popt_sysconfdir[] = POPT_SYSCONFDIR "/popt";
- static const char _popt_etc[] = "/etc/popt";
+ static const char _popt_alias[] = POPT_ALIAS;
char * home;
int rc = 0; /* assume success */
if (con->appName == NULL) goto exit;
- if (strcmp(_popt_sysconfdir, _popt_etc)) {
- rc = poptReadConfigFile(con, _popt_sysconfdir);
- if (rc) goto exit;
- }
-
- rc = poptReadConfigFile(con, _popt_etc);
+ rc = poptReadConfigFile(con, _popt_alias);
if (rc) goto exit;
#if defined(HAVE_GLOB_H)
- if (!stat("/etc/popt.d", &sb) && S_ISDIR(sb.st_mode)) {
+ if (!stat("SYSCONFDIR/popt.d", &sb) && S_ISDIR(sb.st_mode)) {
const char ** av = NULL;
int ac = 0;
- if ((rc = poptGlob(con, "/etc/popt.d/*", &ac, &av)) == 0) {
+ if ((rc = poptGlob(con, "SYSCONFDIR/popt.d/*", &ac, &av)) == 0) {
int i;
for (i = 0; rc == 0 && i < ac; i++) {
const char * fn = av[i];
diff --git a/system.h b/system.h
index 781976d..8e64d89 100644
--- a/system.h
+++ b/system.h
@@ -187,4 +187,7 @@ static inline char * stpcpy (char *dest, const char * src) {
#endif
#define UNUSED(x) x __attribute__((__unused__))
+/* Include configmake.h autogenerated from Makefile.am */
+
+#include "configmake.h"
#include "popt.h"