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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
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