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.
This commit is contained in:
Guillem Jover 2011-02-23 14:04:57 +01:00
parent 4c01261f39
commit 520682e596
14 changed files with 62 additions and 9 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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;

View File

@ -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 *);

View File

@ -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>

View File

@ -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>

View File

@ -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

View File

@ -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

11
libbsd-transparent.pc.in Normal file
View File

@ -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

View File

@ -24,7 +24,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <bsd/getopt.h>
#include <getopt.h>
int optreset = 0;

View File

@ -24,7 +24,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <bsd/err.h>
#include <err.h>
#include <errno.h>
#include <stdarg.h>

View File

@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <stdarg.h>
#include <unistd.h>
#include <libutil.h>
int

View File

@ -31,8 +31,7 @@
#include <errno.h>
#include <string.h>
#include <bsd/stdlib.h>
#include <stdlib.h>
static const char *__progname = NULL;

View File

@ -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