Commit 520682e59647eadf697e6384021e6781164b11b0

Guillem Jover 2011-02-23T14:04:57

Add support for transparent compilation This means that software being ported should not need to be modified in the usual case, as the libbsd headers will take over the standard namespace and fill the missing gaps, and include the system headers. To use this the new libbsd-transparent.pc file can be used through pkg-config, which should end up doing the right thing.

diff --git a/Makefile b/Makefile
index b333ef7..553b464 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,7 @@ LIB_VERSION_MICRO := 0
 LIB_VERSION := $(LIB_VERSION_MAJOR).$(LIB_VERSION_MINOR).$(LIB_VERSION_MICRO)
 
 LIB_PKGCONFIG := $(LIB_NAME).pc
+LIB_PKGCONFIG_TRANS := $(LIB_NAME)-transparent.pc
 LIB_STATIC := $(LIB_NAME).a
 LIB_SHARED_SO := $(LIB_NAME).so
 LIB_SONAME := $(LIB_SHARED_SO).$(LIB_VERSION_MAJOR)
@@ -121,7 +122,7 @@ CFLAGS ?= -g -Wall -Wextra -Wno-unused-variable
 LDFLAGS ?=
 
 # Internal makefile variables
-MK_CPPFLAGS := -Iinclude/ -include bsd/bsd.h -D_GNU_SOURCE -D__REENTRANT
+MK_CPPFLAGS := -Iinclude/bsd/ -Iinclude/ -DLIBBSD_TRANSPARENT -D_GNU_SOURCE -D__REENTRANT
 MK_CFLAGS :=
 MK_LDFLAGS :=
 
@@ -137,7 +138,7 @@ pkgconfigdir	= ${usrlibdir}/pkgconfig
 mandir		= ${prefix}/share/man
 
 .PHONY: libs
-libs: $(LIB_STATIC) $(LIB_SHARED_SO) $(LIB_PKGCONFIG)
+libs: $(LIB_STATIC) $(LIB_SHARED_SO) $(LIB_PKGCONFIG) $(LIB_PKGCONFIG_TRANS)
 
 .PHONY: man
 man: $(LIB_MANS)
@@ -207,6 +208,7 @@ install: libs man
 	done
 	install -m644 $(LIB_MANS) $(DESTDIR)$(mandir)/man3
 	install -m644 $(LIB_PKGCONFIG) $(DESTDIR)$(pkgconfigdir)
+	install -m644 $(LIB_PKGCONFIG_TRANS) $(DESTDIR)$(pkgconfigdir)
 ifeq ($(libdir),$(usrlibdir))
 	# If both dirs are the same, do a relative symlink.
 	ln -sf $(LIB_SHARED) $(DESTDIR)$(usrlibdir)/$(LIB_SHARED_SO)
@@ -219,6 +221,7 @@ endif
 .PHONY: clean
 clean:
 	rm -f $(LIB_PKGCONFIG)
+	rm -f $(LIB_PKGCONFIG_TRANS)
 	rm -f $(LIB_SRCS_GEN) $(LIB_MANS_GEN)
 	rm -f $(LIB_STATIC_OBJS)
 	rm -f $(LIB_STATIC)
diff --git a/include/bsd/err.h b/include/bsd/err.h
index 489138b..b622655 100644
--- a/include/bsd/err.h
+++ b/include/bsd/err.h
@@ -29,9 +29,15 @@
 #define LIBBSD_ERR_H
 
 #include <sys/cdefs.h>
-#include <err.h>
+
 #include <stdarg.h>
 
+#ifdef LIBBSD_TRANSPARENT
+#include_next <err.h>
+#else
+#include <err.h>
+#endif
+
 __BEGIN_DECLS
 extern void warnc (int code, const char *format, ...);
 extern void vwarnc (int code, const char *format, va_list ap);
diff --git a/include/bsd/getopt.h b/include/bsd/getopt.h
index 699a00e..b0057cf 100644
--- a/include/bsd/getopt.h
+++ b/include/bsd/getopt.h
@@ -29,7 +29,12 @@
 #define LIBBSD_GETOPT_H
 
 #include <sys/cdefs.h>
+
+#ifdef LIBBSD_TRANSPARENT
+#include_next <getopt.h>
+#else
 #include <getopt.h>
+#endif
 
 __BEGIN_DECLS
 extern int optreset;
diff --git a/include/bsd/stdio.h b/include/bsd/stdio.h
index 882f374..dfde0c3 100644
--- a/include/bsd/stdio.h
+++ b/include/bsd/stdio.h
@@ -29,7 +29,12 @@
 
 #include <sys/cdefs.h>
 #include <sys/types.h>
+
+#ifdef LIBBSD_TRANSPARENT
+#include_next <stdio.h>
+#else
 #include <stdio.h>
+#endif
 
 __BEGIN_DECLS
 const char *fmtcheck(const char *, const char *);
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index bf30f36..6736ed1 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -32,10 +32,19 @@
 #include <sys/cdefs.h>
 #include <sys/stat.h>
 #include <stdint.h>
+
+#ifdef LIBBSD_TRANSPARENT
+#include_next <stdlib.h>
+#else
 #include <stdlib.h>
+#endif
 
 /* For compatibility with NetBSD, which defines humanize_number here. */
+#ifdef LIBBSD_TRANSPARENT
 #include <libutil.h>
+#else
+#include <bsd/libutil.h>
+#endif
 
 /* FIXME: Temporary inclusions to avoid API breakage, will be removed soon. */
 #include <bsd/stdio.h>
diff --git a/include/bsd/string.h b/include/bsd/string.h
index cf72cc0..edc16fc 100644
--- a/include/bsd/string.h
+++ b/include/bsd/string.h
@@ -30,6 +30,12 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+#ifdef LIBBSD_TRANSPARENT
+#include_next <string.h>
+#else
+#include <string.h>
+#endif
+
 /* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */
 #include <bsd/stdio.h>
 
diff --git a/include/bsd/sys/cdefs.h b/include/bsd/sys/cdefs.h
index 4d9aa49..87d8a48 100644
--- a/include/bsd/sys/cdefs.h
+++ b/include/bsd/sys/cdefs.h
@@ -27,7 +27,11 @@
 #ifndef LIBBSD_CDEFS_H
 #define LIBBSD_CDEFS_H
 
+#ifdef LIBBSD_TRANSPARENT
+#include_next <sys/cdefs.h>
+#else
 #include <sys/cdefs.h>
+#endif
 
 #ifndef __dead2
 # define __dead2
diff --git a/include/bsd/unistd.h b/include/bsd/unistd.h
index 2a22fbc..ac56787 100644
--- a/include/bsd/unistd.h
+++ b/include/bsd/unistd.h
@@ -30,6 +30,12 @@
 #include <sys/cdefs.h>
 #include <sys/stat.h>
 
+#ifdef LIBBSD_TRANSPARENT
+#include_next <unistd.h>
+#else
+#include <unistd.h>
+#endif
+
 #ifndef S_ISTXT
 #define S_ISTXT S_ISVTX
 #endif
diff --git a/libbsd-transparent.pc.in b/libbsd-transparent.pc.in
new file mode 100644
index 0000000..2549e1c
--- /dev/null
+++ b/libbsd-transparent.pc.in
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+
+Name: libbsd
+Description: Utility functions from BSD systems (transparent)
+Version: @VERSION@
+URL: http://libbsd.freedesktop.org/
+Libs: -L${libdir} -lbsd
+Cflags: -isystem ${includedir}/bsd -DLIBBSD_TRANSPARENT
diff --git a/src/bsd_getopt.c b/src/bsd_getopt.c
index a213d9b..f5fb304 100644
--- a/src/bsd_getopt.c
+++ b/src/bsd_getopt.c
@@ -24,7 +24,7 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <bsd/getopt.h>
+#include <getopt.h>
 
 int optreset = 0;
 
diff --git a/src/err.c b/src/err.c
index d33f08e..e5c604d 100644
--- a/src/err.c
+++ b/src/err.c
@@ -24,7 +24,7 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <bsd/err.h>
+#include <err.h>
 #include <errno.h>
 #include <stdarg.h>
 
diff --git a/src/flopen.c b/src/flopen.c
index 754c9c0..f5f7338 100644
--- a/src/flopen.c
+++ b/src/flopen.c
@@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <stdarg.h>
 #include <unistd.h>
-
 #include <libutil.h>
 
 int
diff --git a/src/progname.c b/src/progname.c
index 1079429..f24071a 100644
--- a/src/progname.c
+++ b/src/progname.c
@@ -31,8 +31,7 @@
 
 #include <errno.h>
 #include <string.h>
-
-#include <bsd/stdlib.h>
+#include <stdlib.h>
 
 static const char *__progname = NULL;
 
diff --git a/src/readpassphrase.c b/src/readpassphrase.c
index 601da49..1f4fe0e 100644
--- a/src/readpassphrase.c
+++ b/src/readpassphrase.c
@@ -29,7 +29,7 @@
 #include <string.h>
 #include <termios.h>
 #include <unistd.h>
-#include <bsd/readpassphrase.h>
+#include <readpassphrase.h>
 
 #ifndef TCSASOFT
 #define TCSASOFT 0