blob: ee2bc6782f2ae8b10e223bc90c832a840af1e2cd [file] [log] [blame]
lahiker428c45af02011-03-10 19:15:44 +00001AC_INIT([protobuf-c], [0.15])
lahiker42d495d352009-05-13 15:21:05 +00002AM_INIT_AUTOMAKE([1.9 foreign])
lahiker42880b6402008-08-22 22:15:42 +00003PACKAGE=protobuf-c
4AC_PROG_CC
5AC_PROG_CXX
6AC_PROG_LIBTOOL
lahiker42bb0871c2008-09-09 18:18:28 +00007AC_PATH_PROG(PROTOC, protoc)
lahiker427a45dc12008-10-01 00:29:30 +00008AC_CHECK_HEADERS(inttypes.h)
lahiker42c3a924e2009-04-21 14:08:14 +00009AC_CHECK_HEADERS(sys/poll.h)
10AC_CHECK_HEADERS(sys/select.h)
11AC_CHECK_HEADERS(alloca.h)
12AC_CHECK_HEADERS(malloc.h)
13AC_CHECK_HEADERS(winsock.h)
lahiker426b8d74e2011-03-10 19:12:35 +000014AC_CHECK_HEADERS(io.h)
15AC_CHECK_HEADERS(sys/uio.h)
16AC_CHECK_HEADERS(unistd.h)
lahiker42880b6402008-08-22 22:15:42 +000017
lahiker42457f4822010-02-05 00:31:29 +000018BUILD_PROTOC_C=1
19AC_ARG_ENABLE(protoc, [ --disable-protoc Suppress build of protoc_c],
20 if test "x$enableval" = xno ; then
21 BUILD_PROTOC_C=0
22 fi)
23AM_CONDITIONAL(BUILD_PROTOC_C, test $BUILD_PROTOC_C = 1)
24
lahiker4200e46872009-03-05 03:23:41 +000025# --- Check for the protobuf library. ---
lahiker42457f4822010-02-05 00:31:29 +000026if 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.
lahiker421e05db12009-03-04 22:12:52 +000031
lahiker42457f4822010-02-05 00:31:29 +000032 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.
lahiker42bba93ce2010-04-25 00:27:44 +000036
lahiker42@gmail.com5cf421e2011-12-21 02:28:59 +000037 You can download the google's protobuf library from
38 the following page:
39 http://code.google.com/p/protobuf/downloads/list
40
lahiker42bba93ce2010-04-25 00:27:44 +000041 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.
lahiker42457f4822010-02-05 00:31:29 +000045 ])])
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()
lahiker421e05db12009-03-04 22:12:52 +000057
lahiker429a133292010-03-17 18:29:36 +000058 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
lahiker42457f4822010-02-05 00:31:29 +000063 fi
lahiker42555ecfd2009-06-11 12:50:42 +000064fi
65
lahiker427a45dc12008-10-01 00:29:30 +000066dnl ------ define IS_LITTLE_ENDIAN ------
lahiker4200e46872009-03-05 03:23:41 +000067# 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.
lahiker427a45dc12008-10-01 00:29:30 +000075knows_endianness=0
lahiker42@gmail.com21eda3d2010-12-18 23:51:37 +000076AC_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])
80AS_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])
lahiker4200e46872009-03-05 03:23:41 +000092
lahiker42@gmail.com21eda3d2010-12-18 23:51:37 +000093AS_IF([test $knows_endianness = 0], [
94 AC_CHECK_HEADERS([endian.h], [has_endian_h=1; knows_endianness=1], [has_endian_h=0])
lahiker4200e46872009-03-05 03:23:41 +000095 if test $knows_endianness = 1 ; then
lahiker42@gmail.com21eda3d2010-12-18 23:51:37 +000096 AC_TRY_COMPILE([#include <endian.h>], [
lahiker4200e46872009-03-05 03:23:41 +000097 switch (1) { case __LITTLE_ENDIAN: break;
lahiker42@gmail.com21eda3d2010-12-18 23:51:37 +000098 case __BYTE_ORDER: break; } ],
lahiker4200e46872009-03-05 03:23:41 +000099 [is_little_endian=0], [is_little_endian=1])
lahiker42@gmail.com21eda3d2010-12-18 23:51:37 +0000100 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])
lahiker4200e46872009-03-05 03:23:41 +0000104 if test $knows_endianness = 1 ; then
lahiker42@gmail.com21eda3d2010-12-18 23:51:37 +0000105 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)
lahiker4200e46872009-03-05 03:23:41 +0000129 fi
130 fi
lahiker42@gmail.com21eda3d2010-12-18 23:51:37 +0000131])
lahiker427a45dc12008-10-01 00:29:30 +0000132
133if test $is_little_endian = 1; then
134 echo "Your system IS little-endian" 1>&2
135else
136 echo "Your system IS NOT little-endian" 1>&2
137fi
138AC_DEFINE_UNQUOTED(IS_LITTLE_ENDIAN, $is_little_endian)
139
lahiker42c2303842010-04-30 17:49:28 +0000140AC_OUTPUT(Makefile src/Makefile src/test/Makefile pkgwriteinfo libprotobuf-c.pc)
lahiker423cff75d2008-10-01 01:09:23 +0000141
142