lmdb/0002-Autoconf-files.patch

222 lines
6.5 KiB
Diff

From 8e9182f6252eeb8e2390de814f4d1e9db2485edc Mon Sep 17 00:00:00 2001
From: Kristian Amlie <kristian.amlie@cfengine.com>
Date: Wed, 18 Feb 2015 09:40:20 +0100
Subject: [PATCH 2/4] Autoconf files.
---
libraries/liblmdb/Makefile | 111 -----------------------------------------
libraries/liblmdb/Makefile.am | 11 ++++
libraries/liblmdb/configure.ac | 42 ++++++++++++++++
libraries/liblmdb/mdb.c | 6 +++
4 files changed, 59 insertions(+), 111 deletions(-)
delete mode 100644 libraries/liblmdb/Makefile
create mode 100644 libraries/liblmdb/Makefile.am
create mode 100644 libraries/liblmdb/configure.ac
diff --git a/libraries/liblmdb/Makefile b/libraries/liblmdb/Makefile
deleted file mode 100644
index dbb5d698fee7..000000000000
--- a/libraries/liblmdb/Makefile
+++ /dev/null
@@ -1,111 +0,0 @@
-# Makefile for liblmdb (Lightning memory-mapped database library).
-
-########################################################################
-# Configuration. The compiler options must enable threaded compilation.
-#
-# Preprocessor macros (for CPPFLAGS) of interest...
-# Note that the defaults should already be correct for most
-# platforms; you should not need to change any of these.
-# Read their descriptions in mdb.c if you do:
-#
-# - MDB_USE_POSIX_SEM
-# - MDB_DSYNC
-# - MDB_FDATASYNC
-# - MDB_FDATASYNC_WORKS
-# - MDB_USE_PWRITEV
-# - MDB_USE_ROBUST
-#
-# There may be other macros in mdb.c of interest. You should
-# read mdb.c before changing any of them.
-#
-CC = gcc
-AR = ar
-W = -W -Wall -Wno-unused-parameter -Wbad-function-cast -Wuninitialized
-THREADS = -pthread
-OPT = -O2 -g
-CFLAGS = $(THREADS) $(OPT) $(W) $(XCFLAGS)
-LDLIBS =
-SOLIBS =
-prefix = /usr/local
-mandir = $(prefix)/man
-
-########################################################################
-
-IHDRS = lmdb.h
-ILIBS = liblmdb.a liblmdb.so
-IPROGS = mdb_stat mdb_copy mdb_dump mdb_load
-IDOCS = mdb_stat.1 mdb_copy.1 mdb_dump.1 mdb_load.1
-PROGS = $(IPROGS) mtest mtest2 mtest3 mtest4 mtest5
-all: $(ILIBS) $(PROGS)
-
-install: $(ILIBS) $(IPROGS) $(IHDRS)
- mkdir -p $(DESTDIR)$(prefix)/bin
- mkdir -p $(DESTDIR)$(prefix)/lib
- mkdir -p $(DESTDIR)$(prefix)/include
- mkdir -p $(DESTDIR)$(prefix)/man/man1
- for f in $(IPROGS); do cp $$f $(DESTDIR)$(prefix)/bin; done
- for f in $(ILIBS); do cp $$f $(DESTDIR)$(prefix)/lib; done
- for f in $(IHDRS); do cp $$f $(DESTDIR)$(prefix)/include; done
- for f in $(IDOCS); do cp $$f $(DESTDIR)$(mandir)/man1; done
-
-clean:
- rm -rf $(PROGS) *.[ao] *.[ls]o *~ testdb
-
-test: all
- rm -rf testdb && mkdir testdb
- ./mtest && ./mdb_stat testdb
-
-liblmdb.a: mdb.o midl.o
- $(AR) rs $@ mdb.o midl.o
-
-liblmdb.so: mdb.lo midl.lo
-# $(CC) $(LDFLAGS) -pthread -shared -Wl,-Bsymbolic -o $@ mdb.o midl.o $(SOLIBS)
- $(CC) $(LDFLAGS) -pthread -shared -o $@ mdb.lo midl.lo $(SOLIBS)
-
-mdb_stat: mdb_stat.o liblmdb.a
-mdb_copy: mdb_copy.o liblmdb.a
-mdb_dump: mdb_dump.o liblmdb.a
-mdb_load: mdb_load.o liblmdb.a
-mtest: mtest.o liblmdb.a
-mtest2: mtest2.o liblmdb.a
-mtest3: mtest3.o liblmdb.a
-mtest4: mtest4.o liblmdb.a
-mtest5: mtest5.o liblmdb.a
-mtest6: mtest6.o liblmdb.a
-
-mdb.o: mdb.c lmdb.h midl.h
- $(CC) $(CFLAGS) $(CPPFLAGS) -c mdb.c
-
-midl.o: midl.c midl.h
- $(CC) $(CFLAGS) $(CPPFLAGS) -c midl.c
-
-mdb.lo: mdb.c lmdb.h midl.h
- $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c mdb.c -o $@
-
-midl.lo: midl.c midl.h
- $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -c midl.c -o $@
-
-%: %.o
- $(CC) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
-
-%.o: %.c lmdb.h
- $(CC) $(CFLAGS) $(CPPFLAGS) -c $<
-
-COV_FLAGS=-fprofile-arcs -ftest-coverage
-COV_OBJS=xmdb.o xmidl.o
-
-coverage: xmtest
- for i in mtest*.c [0-9]*.c; do j=`basename \$$i .c`; $(MAKE) $$j.o; \
- gcc -o x$$j $$j.o $(COV_OBJS) -pthread $(COV_FLAGS); \
- rm -rf testdb; mkdir testdb; ./x$$j; done
- gcov xmdb.c
- gcov xmidl.c
-
-xmtest: mtest.o xmdb.o xmidl.o
- gcc -o xmtest mtest.o xmdb.o xmidl.o -pthread $(COV_FLAGS)
-
-xmdb.o: mdb.c lmdb.h midl.h
- $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -O0 $(COV_FLAGS) -c mdb.c -o $@
-
-xmidl.o: midl.c midl.h
- $(CC) $(CFLAGS) -fPIC $(CPPFLAGS) -O0 $(COV_FLAGS) -c midl.c -o $@
diff --git a/libraries/liblmdb/Makefile.am b/libraries/liblmdb/Makefile.am
new file mode 100644
index 000000000000..d3a4a4c99c5d
--- /dev/null
+++ b/libraries/liblmdb/Makefile.am
@@ -0,0 +1,15 @@
+lib_LTLIBRARIES = liblmdb.la
+liblmdb_la_SOURCES = mdb.c midl.c
+liblmdb_la_LDFLAGS=-no-undefined -avoid-version
+
+bin_PROGRAMS = mdb_stat mdb_copy mdb_load mdb_dump lmdump lmmgr
+mdb_stat_LDADD = liblmdb.la
+mdb_copy_LDADD = liblmdb.la
+mdb_load_LDADD = liblmdb.la
+mdb_dump_LDADD = liblmdb.la
+lmdump_LDADD = liblmdb.la
+lmmgr_LDADD = liblmdb.la
+
+man_MANS = mdb_stat.1 mdb_copy.1 mdb_load.1 mdb_dump.1
+
+include_HEADERS = lmdb.h
diff --git a/libraries/liblmdb/configure.ac b/libraries/liblmdb/configure.ac
new file mode 100644
index 000000000000..3db22516634b
--- /dev/null
+++ b/libraries/liblmdb/configure.ac
@@ -0,0 +1,42 @@
+AC_INIT([hello], [1.0]) # good
+AC_CANONICAL_TARGET
+AM_INIT_AUTOMAKE([foreign])
+
+AC_PROG_CC
+
+# Use either new LT_INIT or old AC_DISABLE_STATIC/AC_PROG_LIBTOOL macros
+m4_ifdef([LT_INIT],
+ [LT_INIT([disable-static])],
+ [AC_DISABLE_STATIC
+ AC_PROG_LIBTOOL])
+
+AC_ARG_WITH([pthread], [Path to pthread])
+AS_IF([test -n "$with_pthread"],
+ [LDFLAGS+=" -L$with_pthread/lib"]
+)
+AC_CHECK_LIB([pthread], [pthread_mutex_lock])
+AC_CHECK_LIB([pthreadGC2], [pthread_mutex_lock])
+AS_IF([test "$ac_cv_lib_pthread" = "no" && test "$ac_cv_lib_pthreadGC2" = "no"],
+[
+ AC_MSG_ERROR([Could not find pthreads library])
+])
+AC_CHECK_FUNCS([pthread_mutexattr_settype])
+AC_CHECK_FUNC([pthread_mutexattr_setrobust],
+[
+ AC_MSG_CHECKING([whether pthread_mutexattr_setrobust can be used on this platform])
+ AS_CASE([$target_os],
+ [*solaris*],
+ [
+ # Disable pthread_mutexattr_setrobust on Solaris, it is reported as
+ # existing on Solaris 11, but known to be broken.
+ AC_MSG_RESULT([no])
+ ],
+ [
+ AC_DEFINE([HAVE_PTHREAD_MUTEXATTR_SETROBUST])
+ AC_MSG_RESULT([yes])
+ ])
+])
+
+AC_CONFIG_SRCDIR([mdb.c])
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c
index 96c859efd9bd..695d11602a13 100644
--- a/libraries/liblmdb/mdb.c
+++ b/libraries/liblmdb/mdb.c
@@ -220,6 +220,12 @@ typedef SSIZE_T ssize_t;
#define MDB_DEVEL 0
#endif
+#ifdef HAVE_PTHREAD_MUTEXATTR_SETROBUST
+#define MDB_USE_ROBUST 1
+#else
+#define MDB_USE_ROBUST 0
+#endif
+
/** Wrapper around __func__, which is a C99 feature */
#if __STDC_VERSION__ >= 199901L
# define mdb_func_ __func__
--
2.7.0