lahiker42 | 8c45af0 | 2011-03-10 19:15:44 +0000 | [diff] [blame] | 1 | AC_INIT([protobuf-c], [0.15]) |
lahiker42 | d495d35 | 2009-05-13 15:21:05 +0000 | [diff] [blame] | 2 | AM_INIT_AUTOMAKE([1.9 foreign]) |
lahiker42 | 880b640 | 2008-08-22 22:15:42 +0000 | [diff] [blame] | 3 | PACKAGE=protobuf-c |
| 4 | AC_PROG_CC |
| 5 | AC_PROG_CXX |
| 6 | AC_PROG_LIBTOOL |
lahiker42 | bb0871c | 2008-09-09 18:18:28 +0000 | [diff] [blame] | 7 | AC_PATH_PROG(PROTOC, protoc) |
lahiker42 | 7a45dc1 | 2008-10-01 00:29:30 +0000 | [diff] [blame] | 8 | AC_CHECK_HEADERS(inttypes.h) |
lahiker42 | c3a924e | 2009-04-21 14:08:14 +0000 | [diff] [blame] | 9 | AC_CHECK_HEADERS(sys/poll.h) |
| 10 | AC_CHECK_HEADERS(sys/select.h) |
| 11 | AC_CHECK_HEADERS(alloca.h) |
| 12 | AC_CHECK_HEADERS(malloc.h) |
| 13 | AC_CHECK_HEADERS(winsock.h) |
lahiker42 | 6b8d74e | 2011-03-10 19:12:35 +0000 | [diff] [blame] | 14 | AC_CHECK_HEADERS(io.h) |
| 15 | AC_CHECK_HEADERS(sys/uio.h) |
| 16 | AC_CHECK_HEADERS(unistd.h) |
lahiker42 | 880b640 | 2008-08-22 22:15:42 +0000 | [diff] [blame] | 17 | |
lahiker42 | 457f482 | 2010-02-05 00:31:29 +0000 | [diff] [blame] | 18 | BUILD_PROTOC_C=1 |
| 19 | AC_ARG_ENABLE(protoc, [ --disable-protoc Suppress build of protoc_c], |
| 20 | if test "x$enableval" = xno ; then |
| 21 | BUILD_PROTOC_C=0 |
| 22 | fi) |
| 23 | AM_CONDITIONAL(BUILD_PROTOC_C, test $BUILD_PROTOC_C = 1) |
| 24 | |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 25 | # --- Check for the protobuf library. --- |
lahiker42 | 457f482 | 2010-02-05 00:31:29 +0000 | [diff] [blame] | 26 | if test $BUILD_PROTOC_C = 1; then |
| 27 | AC_LANG_PUSH([C++]) |
| 28 | AC_CHECK_HEADER(google/protobuf/stubs/common.h,, |
| 29 | [AC_MSG_ERROR([ |
| 30 | ERROR: protobuf headers are required. |
lahiker42 | 1e05db1 | 2009-03-04 22:12:52 +0000 | [diff] [blame] | 31 | |
lahiker42 | 457f482 | 2010-02-05 00:31:29 +0000 | [diff] [blame] | 32 | You must either install protobuf from google, |
| 33 | or if you have it installed in a custom location |
| 34 | you must add '-Iincludedir' to CXXFLAGS |
| 35 | and '-Llibdir' to LDFLAGS. |
lahiker42 | bba93ce | 2010-04-25 00:27:44 +0000 | [diff] [blame] | 36 | |
lahiker42@gmail.com | 5cf421e | 2011-12-21 02:28:59 +0000 | [diff] [blame] | 37 | You can download the google's protobuf library from |
| 38 | the following page: |
| 39 | http://code.google.com/p/protobuf/downloads/list |
| 40 | |
lahiker42 | bba93ce | 2010-04-25 00:27:44 +0000 | [diff] [blame] | 41 | If you did not specify a prefix when installing |
| 42 | protobuf, try |
| 43 | './configure CXXFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib' |
| 44 | In some 64-bit environments, try LDFLAGS=-L/usr/local/lib64. |
lahiker42 | 457f482 | 2010-02-05 00:31:29 +0000 | [diff] [blame] | 45 | ])]) |
| 46 | pbc_savelibs="$LIBS" |
| 47 | LIBS="$LIBS -lprotoc -lprotobuf -lpthread" |
| 48 | AC_TRY_LINK([#include <google/protobuf/compiler/command_line_interface.h>], |
| 49 | [google::protobuf::compiler::CommandLineInterface cli;], |
| 50 | [], |
| 51 | [AC_MSG_ERROR([ |
| 52 | ERROR: |
| 53 | protobuf test program failed to link: |
| 54 | perhaps you need to add -Llibdir to your LDFLAGS.])]) |
| 55 | LIBS="$pbc_savelibs" |
| 56 | AC_LANG_POP() |
lahiker42 | 1e05db1 | 2009-03-04 22:12:52 +0000 | [diff] [blame] | 57 | |
lahiker42 | 9a13329 | 2010-03-17 18:29:36 +0000 | [diff] [blame] | 58 | dnl We need $PROTOC around for the test code generation. |
| 59 | dnl This is merely needed for c++ packed-data comparison. |
| 60 | if test "x$PROTOC" = x; then |
| 61 | echo "ERROR: missing google's protoc program; adjust \$PATH (or use --disable-protoc)" 1>&2 |
| 62 | exit 1 |
lahiker42 | 457f482 | 2010-02-05 00:31:29 +0000 | [diff] [blame] | 63 | fi |
lahiker42 | 555ecfd | 2009-06-11 12:50:42 +0000 | [diff] [blame] | 64 | fi |
| 65 | |
lahiker42 | 7a45dc1 | 2008-10-01 00:29:30 +0000 | [diff] [blame] | 66 | dnl ------ define IS_LITTLE_ENDIAN ------ |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 67 | # We try to use, where possible the headers <endian.h>, <mach/endian.h>, |
| 68 | # and <machine/endian.h>, in that order. They must define the macros |
| 69 | # __LITTLE_ENDIAN and __BYTE_ORDER. We structure the test so that if they |
| 70 | # do NOT define __LITTLE_ENDIAN or __BYTE_ORDER then we will disable |
| 71 | # the little-endian optimizations, so the resulting code should be correct, |
| 72 | # but not as fast, if there's a broken endian.h somewhere. |
| 73 | # |
| 74 | # If none of those headers exist, we fallback on a runtime test. |
lahiker42 | 7a45dc1 | 2008-10-01 00:29:30 +0000 | [diff] [blame] | 75 | knows_endianness=0 |
lahiker42@gmail.com | 21eda3d | 2010-12-18 23:51:37 +0000 | [diff] [blame] | 76 | AC_ARG_WITH([endianness], |
| 77 | [AS_HELP_STRING([--with-endianness=[little|big]], |
| 78 | [use the given endianness instead of testing headers (useful for mingw)])], |
| 79 | [],[with_endianness=no]) |
| 80 | AS_IF([test "$with_endianness" != "no"], [ |
| 81 | AS_IF([test "$with_endianness" == "little"], [ |
| 82 | is_little_endian=1 |
| 83 | ], [ |
| 84 | AS_IF([test "$with_endianness" == "big"], [ |
| 85 | is_little_endian=0 |
| 86 | ], [ |
| 87 | AC_MSG_FAILURE([--with-endianness argument must be 'little' or 'big']) |
| 88 | ]) |
| 89 | ]) |
| 90 | knows_endianness=1 |
| 91 | ]) |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 92 | |
lahiker42@gmail.com | 21eda3d | 2010-12-18 23:51:37 +0000 | [diff] [blame] | 93 | AS_IF([test $knows_endianness = 0], [ |
| 94 | AC_CHECK_HEADERS([endian.h], [has_endian_h=1; knows_endianness=1], [has_endian_h=0]) |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 95 | if test $knows_endianness = 1 ; then |
lahiker42@gmail.com | 21eda3d | 2010-12-18 23:51:37 +0000 | [diff] [blame] | 96 | AC_TRY_COMPILE([#include <endian.h>], [ |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 97 | switch (1) { case __LITTLE_ENDIAN: break; |
lahiker42@gmail.com | 21eda3d | 2010-12-18 23:51:37 +0000 | [diff] [blame] | 98 | case __BYTE_ORDER: break; } ], |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 99 | [is_little_endian=0], [is_little_endian=1]) |
lahiker42@gmail.com | 21eda3d | 2010-12-18 23:51:37 +0000 | [diff] [blame] | 100 | else |
| 101 | |
| 102 | # ------------------ try <mach/endian.h> ------------------ |
| 103 | AC_CHECK_HEADERS([mach/endian.h], [has_mach_endian_h=1; knows_endianness=1], [has_mach_endian_h=0]) |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 104 | if test $knows_endianness = 1 ; then |
lahiker42@gmail.com | 21eda3d | 2010-12-18 23:51:37 +0000 | [diff] [blame] | 105 | AC_TRY_COMPILE([#include <mach/endian.h>],[ |
| 106 | switch (1) { case __LITTLE_ENDIAN: break; |
| 107 | case __BYTE_ORDER: break; } ], |
| 108 | [is_little_endian=0], [is_little_endian=1]) |
| 109 | fi |
| 110 | # ------------------ try <machine/endian.h> ------------------ |
| 111 | if test $knows_endianness = 0; then |
| 112 | AC_CHECK_HEADERS([machine/endian.h], [has_machine_endian_h=1; knows_endianness=1], [has_machine_endian_h=0]) |
| 113 | if test $knows_endianness = 1 ; then |
| 114 | AC_TRY_COMPILE([#include <machine/endian.h>],[ |
| 115 | switch (1) { case __LITTLE_ENDIAN: break; |
| 116 | case __BYTE_ORDER: break; } ], |
| 117 | [is_little_endian=0], [is_little_endian=1]) |
| 118 | fi |
| 119 | fi |
| 120 | if test $knows_endianness = 0; then |
| 121 | AC_MSG_CHECKING([for little-endianness via runtime check]) |
| 122 | AC_RUN_IFELSE([#include <inttypes.h> |
| 123 | int main() { |
| 124 | uint32_t v = 0x01020304; |
| 125 | return memcmp (&v, "\4\3\2\1", 4) == 0 ? 0 : 1; |
| 126 | } |
| 127 | ], [is_little_endian=1; result=yes], [is_little_endian=0; result=no]) |
| 128 | AC_MSG_RESULT($result) |
lahiker42 | 00e4687 | 2009-03-05 03:23:41 +0000 | [diff] [blame] | 129 | fi |
| 130 | fi |
lahiker42@gmail.com | 21eda3d | 2010-12-18 23:51:37 +0000 | [diff] [blame] | 131 | ]) |
lahiker42 | 7a45dc1 | 2008-10-01 00:29:30 +0000 | [diff] [blame] | 132 | |
| 133 | if test $is_little_endian = 1; then |
| 134 | echo "Your system IS little-endian" 1>&2 |
| 135 | else |
| 136 | echo "Your system IS NOT little-endian" 1>&2 |
| 137 | fi |
| 138 | AC_DEFINE_UNQUOTED(IS_LITTLE_ENDIAN, $is_little_endian) |
| 139 | |
lahiker42 | c230384 | 2010-04-30 17:49:28 +0000 | [diff] [blame] | 140 | AC_OUTPUT(Makefile src/Makefile src/test/Makefile pkgwriteinfo libprotobuf-c.pc) |
lahiker42 | 3cff75d | 2008-10-01 01:09:23 +0000 | [diff] [blame] | 141 | |
| 142 | |