From 520682e59647eadf697e6384021e6781164b11b0 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Wed, 23 Feb 2011 14:04:57 +0100 Subject: [PATCH] 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. --- Makefile | 7 +++++-- include/bsd/err.h | 8 +++++++- include/bsd/getopt.h | 5 +++++ include/bsd/stdio.h | 5 +++++ include/bsd/stdlib.h | 9 +++++++++ include/bsd/string.h | 6 ++++++ include/bsd/sys/cdefs.h | 4 ++++ include/bsd/unistd.h | 6 ++++++ libbsd-transparent.pc.in | 11 +++++++++++ src/bsd_getopt.c | 2 +- src/err.c | 2 +- src/flopen.c | 1 - src/progname.c | 3 +-- src/readpassphrase.c | 2 +- 14 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 libbsd-transparent.pc.in 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 -#include + #include +#ifdef LIBBSD_TRANSPARENT +#include_next +#else +#include +#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 + +#ifdef LIBBSD_TRANSPARENT +#include_next +#else #include +#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 #include + +#ifdef LIBBSD_TRANSPARENT +#include_next +#else #include +#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 #include #include + +#ifdef LIBBSD_TRANSPARENT +#include_next +#else #include +#endif /* For compatibility with NetBSD, which defines humanize_number here. */ +#ifdef LIBBSD_TRANSPARENT #include +#else +#include +#endif /* FIXME: Temporary inclusions to avoid API breakage, will be removed soon. */ #include 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 #include +#ifdef LIBBSD_TRANSPARENT +#include_next +#else +#include +#endif + /* FIXME: Temporary inclusion to avoid API breakage, will be removed soon. */ #include 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 +#else #include +#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 #include +#ifdef LIBBSD_TRANSPARENT +#include_next +#else +#include +#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 +#include 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 +#include #include #include 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 #include #include - #include 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 #include - -#include +#include 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 #include #include -#include +#include #ifndef TCSASOFT #define TCSASOFT 0