Skip to content
Browse files

Build system added.

Do note that while the test case runs, it does no actual testing yet.
  • Loading branch information...
1 parent c764458 commit 4845ce69ad81f6fe72d9793a56484d8e2cafc5b0 @algernon committed
Showing with 219 additions and 12 deletions.
  1. +11 −0 .gitignore
  2. +3 −0 Makefile.am
  3. +7 −0 autogen.sh
  4. +137 −0 configure.ac
  5. +6 −0 src/Makefile.am
  6. +10 −0 tests/Makefile.am
  7. +3 −0 tests/run-tests.sh
  8. +28 −0 tests/test.c
  9. +8 −0 tests/test.h
  10. +6 −12 tests/{test1.c → test_bson_build.c}
View
11 .gitignore
@@ -2,3 +2,14 @@
*.o
Makefile.in
Makefile
+aclocal.m4
+autom4te.cache/
+config.guess
+config.h.in
+config.sub
+configure
+depcomp
+install-sh
+ltmain.sh
+m4/
+missing
View
3 Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS = src tests
+
+ACLOCAL_AMFLAGS = -I m4 --install
View
7 autogen.sh
@@ -0,0 +1,7 @@
+#! /bin/sh
+
+libtoolize --force
+aclocal -I m4 --install
+autoheader
+automake --foreign --add-missing
+autoconf
View
137 configure.ac
@@ -0,0 +1,137 @@
+dnl Process this file with autoconf to produce a configure script.
+dnl
+AC_INIT(src/bson.c)
+AC_CONFIG_MACRO_DIR([m4])
+
+dnl ***************************************************************************
+dnl definitions
+
+PACKAGE="libmongo-client"
+VERSION="0"
+
+dnl ***************************************************************************
+dnl dependencies
+
+GLIB_MIN_VERSION="2.10.0"
+
+dnl ***************************************************************************
+dnl Initial setup
+
+AM_INIT_AUTOMAKE($PACKAGE, $VERSION, no-define)
+AM_CONFIG_HEADER(config.h)
+
+dnl ***************************************************************************
+dnl Checks for programs.
+AC_PROG_CC
+AM_PROG_CC_STDC
+AC_PROG_CC_C99
+if test "x$ac_cv_prog_cc_c99" = "xno"; then
+ AC_MSG_ERROR("C99 standard compliant C compiler required. Try GCC 3.x or later.")
+fi
+AC_PROG_MAKE_SET
+PKG_PROG_PKG_CONFIG
+LT_INIT()
+
+dnl ***************************************************************************
+dnl How to do static linking?
+dnl ***************************************************************************
+AC_MSG_CHECKING(how to enable static linking for certain libraries)
+ldversion=`ld -V 2>&1 | head -1`
+if echo $ldversion | egrep "GNU|Solaris" > /dev/null; then
+ LD_START_STATIC="-Wl,-Bstatic"
+ LD_END_STATIC="-Wl,-Bdynamic"
+ AC_MSG_RESULT(GNU or Solaris)
+elif test $ostype = "HP-UX" > /dev/null; then
+ LD_START_STATIC="-Wl,-a,archive"
+ LD_END_STATIC="-Wl,-a,shared_archive"
+ AC_MSG_RESULT(HP-UX)
+elif test "$ostype" = "AIX"; then
+ LD_START_STATIC="-Wl,-bstatic"
+ LD_END_STATIC="-Wl,-bdynamic"
+ AC_MSG_RESULT(AIX)
+else
+ LD_START_STATIC=""
+ LD_END_STATIC=""
+ AC_MSG_RESULT([no clues, linking everything dynamically, please send appropriate ld arguments to algernon@balabit.hu])
+fi
+
+dnl ***************************************************************************
+dnl Miscellanneous headers
+dnl ***************************************************************************
+
+AC_HEADER_STDC
+
+dnl ***************************************************************************
+dnl Header checks
+dnl ***************************************************************************
+
+AC_CACHE_CHECK(for struct sockaddr_storage, blb_cv_c_struct_sockaddr_storage,
+ [AC_EGREP_HEADER([sockaddr_storage], sys/socket.h, blb_cv_c_struct_sockaddr_storage=yes,blb_cv_c_struct_sockaddr_storage=no)])
+
+if test "$blb_cv_c_struct_sockaddr_storage" = "yes"; then
+ AC_DEFINE(HAVE_STRUCT_SOCKADDR_STORAGE,[1],[struct sockaddr_storage is present on your system])
+fi
+
+AC_CACHE_CHECK(for struct sockaddr_in6, blb_cv_c_struct_sockaddr_in6,
+ [AC_EGREP_HEADER([sockaddr_in6], netinet/in.h, blb_cv_c_struct_sockaddr_in6=yes,blb_cv_c_struct_sockaddr_in6=no)])
+
+dnl ***************************************************************************
+dnl Checks for libraries
+AC_CHECK_LIB(socket, socket, BASE_LIBS="$BASE_LIBS -lsocket")
+AC_CHECK_LIB(nsl, gethostbyname, BASE_LIBS="$BASE_LIBS -lnsl")
+AC_CHECK_LIB(resolv, res_init, RESOLV_LIBS="-lresolv")
+
+AC_CHECK_FUNCS(inet_aton inet_ntoa getaddrinfo)
+
+dnl ***************************************************************************
+dnl GLib headers/libraries
+dnl ***************************************************************************
+
+GLIB_ADDONS="gmodule-2.0"
+PKG_CHECK_MODULES(GLIB, glib-2.0 >= $GLIB_MIN_VERSION $GLIB_ADDONS,,)
+
+old_CPPFLAGS=$CPPFLAGS
+CPPFLAGS="$GLIB_CFLAGS"
+
+AC_CACHE_CHECK(sanity checking Glib headers,
+ blb_cv_glib_sane,
+[AC_TRY_RUN([
+#include <glib.h>
+
+int main()
+{
+ if (sizeof(long) != GLIB_SIZEOF_LONG)
+ return 1;
+ return 0;
+}
+],
+blb_cv_glib_sane=yes,
+blb_cv_glib_sane=no,
+blb_cv_glib_sane=yes)])
+CPPFLAGS=$old_CPPFLAGS
+
+if test "x$blb_cv_glib_sane" = "xno"; then
+ AC_MSG_ERROR([Glib headers inconsistent with current compiler setting. You might be using 32 bit Glib with a 64 bit compiler, check PKG_CONFIG_PATH])
+fi
+
+dnl ***************************************************************************
+dnl misc features to be enabled
+dnl ***************************************************************************
+
+AC_MSG_CHECKING(whether to enable IPv6 support)
+if test "x$blb_cv_c_struct_sockaddr_in6" = "xyes"; then
+ enable_ipv6=yes
+ AC_MSG_RESULT(yes)
+else
+ enable_ipv6=no
+ AC_MSG_RESULT(no)
+fi
+
+AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [package name])
+AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [version number])
+
+AC_OUTPUT(
+ Makefile
+ src/Makefile
+ tests/Makefile
+)
View
6 src/Makefile.am
@@ -0,0 +1,6 @@
+lib_LTLIBRARIES = libmongo-client.la
+libmongo_client_la_LIBADD = @GLIB_LIBS@
+libmongo_client_la_CFLAGS = @GLIB_CFLAGS@
+
+libmongo_client_la_SOURCES = \
+ bson.c bson.h
View
10 tests/Makefile.am
@@ -0,0 +1,10 @@
+check_PROGRAMS = test_bson_build
+
+TESTS = run-tests.sh
+
+AM_CFLAGS = -I$(top_srcdir)/src/ @GLIB_CFLAGS@
+LDADD = $(top_builddir)/src/libmongo-client.la @GLIB_LIBS@
+
+test_srcs = test.c test.h
+
+test_bson_build_SOURCES = test_bson_build.c $(test_srcs)
View
3 tests/run-tests.sh
@@ -0,0 +1,3 @@
+#! /bin/sh
+
+./test1
View
28 tests/test.c
@@ -0,0 +1,28 @@
+#include "test.h"
+
+#include <glib.h>
+#include <ctype.h>
+#include <stdio.h>
+
+gboolean
+test_bson_dump (bson *b)
+{
+ gint32 i;
+ const guint8 *d;
+
+ d = bson_data (b);
+ if (!d)
+ return FALSE;
+
+ for (i = 0; i < bson_size (b); i++)
+ {
+ if (isprint (d[i]))
+ printf ("%c", d[i]);
+ else
+ printf ("\\x%02x", d[i]);
+ }
+
+ printf ("\n");
+
+ return TRUE;
+}
View
8 tests/test.h
@@ -0,0 +1,8 @@
+#ifndef LIBMONGO_CLIENT_TEST_H
+#define LIBMONGO_CLIENT_TEST_H 1
+
+#include "bson.h"
+
+gboolean test_bson_dump (bson *b);
+
+#endif
View
18 tests/test1.c → tests/test_bson_build.c
@@ -3,6 +3,7 @@
#include <ctype.h>
#include "bson.h"
+#include "test.h"
int
main (void)
@@ -14,6 +15,8 @@ main (void)
const guint8 *d;
+ gboolean r;
+
a = bson_new ();
bson_append_string (a, "0", "awesome", -1);
bson_append_double (a, "1", 5.05);
@@ -28,17 +31,8 @@ main (void)
d = bson_data (b);
- for (i = 0; i < bson_size (b); i++)
- {
- if (isprint (d[i]))
- printf ("%c", d[i]);
- else
- printf ("\\x%02x", d[i]);
- }
-
- printf ("\n");
+ r = test_bson_dump (b);
bson_free (b);
-
- return 0;
-}
+ return (r) ? 0 : -1;
+}

0 comments on commit 4845ce6

Please sign in to comment.
Something went wrong with that request. Please try again.