Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 1 | ## Process this file with autoconf to produce configure. |
| 2 | ## In general, the safest way to proceed is to run ./autogen.sh |
| 3 | |
| 4 | AC_PREREQ(2.59) |
| 5 | |
| 6 | # Note: If you change the version, you must also update it in: |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 7 | # * Protobuf.podspec |
| 8 | # * csharp/Google.Protobuf.Tools.nuspec |
| 9 | # * csharp/src/*/AssemblyInfo.cs |
| 10 | # * csharp/src/Google.Protobuf/Google.Protobuf.nuspec |
| 11 | # * java/*/pom.xml |
| 12 | # * python/google/protobuf/__init__.py |
| 13 | # * protoc-artifacts/pom.xml |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 14 | # * src/google/protobuf/stubs/common.h |
| 15 | # * src/Makefile.am (Update -version-info for LDFLAGS if needed) |
| 16 | # |
| 17 | # In the SVN trunk, the version should always be the next anticipated release |
| 18 | # version with the "-pre" suffix. (We used to use "-SNAPSHOT" but this pushed |
| 19 | # the size of one file name in the dist tarfile over the 99-char limit.) |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 20 | AC_INIT([Protocol Buffers],[3.6.1],[protobuf@googlegroups.com],[protobuf]) |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 21 | |
| 22 | AM_MAINTAINER_MODE([enable]) |
| 23 | |
| 24 | AC_CONFIG_SRCDIR(src/google/protobuf/message.cc) |
| 25 | # The config file is generated but not used by the source code, since we only |
| 26 | # need very few of them, e.g. HAVE_PTHREAD and HAVE_ZLIB. Those macros are |
| 27 | # passed down in CXXFLAGS manually in src/Makefile.am |
| 28 | AC_CONFIG_HEADERS([config.h]) |
| 29 | AC_CONFIG_MACRO_DIR([m4]) |
| 30 | |
| 31 | AC_ARG_VAR(DIST_LANG, [language to include in the distribution package (i.e., make dist)]) |
| 32 | case "$DIST_LANG" in |
| 33 | "") DIST_LANG=all ;; |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 34 | all | cpp | csharp | java | python | javanano | objectivec | ruby | js | php) ;; |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 35 | *) AC_MSG_FAILURE([unknown language: $DIST_LANG]) ;; |
| 36 | esac |
| 37 | AC_SUBST(DIST_LANG) |
| 38 | |
| 39 | # autoconf's default CXXFLAGS are usually "-g -O2". These aren't necessarily |
| 40 | # the best choice for libprotobuf. |
| 41 | AS_IF([test "x${ac_cv_env_CFLAGS_set}" = "x"], |
| 42 | [CFLAGS=""]) |
| 43 | AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"], |
| 44 | [CXXFLAGS=""]) |
| 45 | |
| 46 | AC_CANONICAL_TARGET |
| 47 | |
| 48 | AM_INIT_AUTOMAKE([1.9 tar-ustar subdir-objects]) |
| 49 | |
| 50 | AC_ARG_WITH([zlib], |
| 51 | [AS_HELP_STRING([--with-zlib], |
| 52 | [include classes for streaming compressed data in and out @<:@default=check@:>@])], |
| 53 | [],[with_zlib=check]) |
| 54 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 55 | AC_ARG_WITH([zlib-include], |
| 56 | [AS_HELP_STRING([--with-zlib-include=PATH], |
| 57 | [zlib include directory])], |
| 58 | [CPPFLAGS="-I$withval $CPPFLAGS"]) |
| 59 | |
| 60 | AC_ARG_WITH([zlib-lib], |
| 61 | [AS_HELP_STRING([--with-zlib-lib=PATH], |
| 62 | [zlib lib directory])], |
| 63 | [LDFLAGS="-L$withval $LDFLAGS"]) |
| 64 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 65 | AC_ARG_WITH([protoc], |
| 66 | [AS_HELP_STRING([--with-protoc=COMMAND], |
| 67 | [use the given protoc command instead of building a new one when building tests (useful for cross-compiling)])], |
| 68 | [],[with_protoc=no]) |
| 69 | |
| 70 | # Checks for programs. |
| 71 | AC_PROG_CC |
| 72 | AC_PROG_CXX |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 73 | AC_PROG_CXX_FOR_BUILD |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 74 | AC_LANG([C++]) |
| 75 | ACX_USE_SYSTEM_EXTENSIONS |
| 76 | m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) |
| 77 | AM_CONDITIONAL(GCC, test "$GCC" = yes) # let the Makefile know if we're gcc |
| 78 | AC_PROG_OBJC |
| 79 | |
| 80 | # test_util.cc takes forever to compile with GCC and optimization turned on. |
| 81 | AC_MSG_CHECKING([C++ compiler flags...]) |
| 82 | AS_IF([test "x${ac_cv_env_CXXFLAGS_set}" = "x"],[ |
| 83 | AS_IF([test "$GCC" = "yes"],[ |
| 84 | PROTOBUF_OPT_FLAG="-O2" |
| 85 | CXXFLAGS="${CXXFLAGS} -g" |
| 86 | ]) |
| 87 | |
| 88 | # Protocol Buffers contains several checks that are intended to be used only |
| 89 | # for debugging and which might hurt performance. Most users are probably |
| 90 | # end users who don't want these checks, so add -DNDEBUG by default. |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 91 | CXXFLAGS="$CXXFLAGS -std=c++11 -DNDEBUG" |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 92 | |
| 93 | AC_MSG_RESULT([use default: $PROTOBUF_OPT_FLAG $CXXFLAGS]) |
| 94 | ],[ |
| 95 | AC_MSG_RESULT([use user-supplied: $CXXFLAGS]) |
| 96 | ]) |
| 97 | |
| 98 | AC_SUBST(PROTOBUF_OPT_FLAG) |
| 99 | |
| 100 | ACX_CHECK_SUNCC |
| 101 | |
| 102 | # Have to do libtool after SUNCC, other wise it "helpfully" adds Crun Cstd |
| 103 | # to the link |
| 104 | AC_PROG_LIBTOOL |
| 105 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 106 | # Check whether the linker supports version scripts |
| 107 | AC_MSG_CHECKING([whether the linker supports version scripts]) |
| 108 | save_LDFLAGS=$LDFLAGS |
| 109 | LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map" |
| 110 | cat > conftest.map <<EOF |
| 111 | { |
| 112 | global: |
| 113 | main; |
| 114 | local: |
| 115 | *; |
| 116 | }; |
| 117 | EOF |
| 118 | AC_LINK_IFELSE( |
| 119 | [AC_LANG_SOURCE([int main() { return 0; }])], |
| 120 | [have_ld_version_script=yes; AC_MSG_RESULT(yes)], |
| 121 | [have_ld_version_script=no; AC_MSG_RESULT(no)]) |
| 122 | LDFLAGS=$save_LDFLAGS |
| 123 | AM_CONDITIONAL([HAVE_LD_VERSION_SCRIPT], [test "$have_ld_version_script" == "yes"]) |
| 124 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 125 | # Checks for header files. |
| 126 | AC_HEADER_STDC |
| 127 | AC_CHECK_HEADERS([fcntl.h inttypes.h limits.h stdlib.h unistd.h]) |
| 128 | |
| 129 | # Checks for library functions. |
| 130 | AC_FUNC_MEMCMP |
| 131 | AC_FUNC_STRTOD |
| 132 | AC_CHECK_FUNCS([ftruncate memset mkdir strchr strerror strtol]) |
| 133 | |
| 134 | # Check for zlib. |
| 135 | HAVE_ZLIB=0 |
| 136 | AS_IF([test "$with_zlib" != no], [ |
| 137 | AC_MSG_CHECKING([zlib version]) |
| 138 | |
| 139 | # First check the zlib header version. |
| 140 | AC_COMPILE_IFELSE( |
| 141 | [AC_LANG_PROGRAM([[ |
| 142 | #include <zlib.h> |
| 143 | #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204) |
| 144 | # error zlib version too old |
| 145 | #endif |
| 146 | ]], [])], [ |
| 147 | AC_MSG_RESULT([ok (1.2.0.4 or later)]) |
| 148 | |
| 149 | # Also need to add -lz to the linker flags and make sure this succeeds. |
| 150 | AC_SEARCH_LIBS([zlibVersion], [z], [ |
| 151 | AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.]) |
| 152 | HAVE_ZLIB=1 |
| 153 | ], [ |
| 154 | AS_IF([test "$with_zlib" != check], [ |
| 155 | AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found]) |
| 156 | ]) |
| 157 | ]) |
| 158 | ], [ |
| 159 | AS_IF([test "$with_zlib" = check], [ |
| 160 | AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)]) |
| 161 | ], [ |
| 162 | AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)]) |
| 163 | ]) |
| 164 | ]) |
| 165 | ]) |
| 166 | AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1]) |
| 167 | |
| 168 | AS_IF([test "$with_protoc" != "no"], [ |
| 169 | PROTOC=$with_protoc |
| 170 | AS_IF([test "$with_protoc" = "yes"], [ |
| 171 | # No argument given. Use system protoc. |
| 172 | PROTOC=protoc |
| 173 | ]) |
| 174 | AS_IF([echo "$PROTOC" | grep -q '^@<:@^/@:>@.*/'], [ |
| 175 | # Does not start with a slash, but contains a slash. So, it's a relative |
| 176 | # path (as opposed to an absolute path or an executable in $PATH). |
| 177 | # Since it will actually be executed from the src directory, prefix with |
| 178 | # the current directory. We also insert $ac_top_build_prefix in case this |
| 179 | # is a nested package and --with-protoc was actually given on the outer |
| 180 | # package's configure script. |
| 181 | PROTOC=`pwd`/${ac_top_build_prefix}$PROTOC |
| 182 | ]) |
| 183 | AC_SUBST([PROTOC]) |
| 184 | ]) |
| 185 | AM_CONDITIONAL([USE_EXTERNAL_PROTOC], [test "$with_protoc" != "no"]) |
| 186 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 187 | AX_PTHREAD |
| 188 | AM_CONDITIONAL([HAVE_PTHREAD], [test "x$ax_pthread_ok" = "xyes"]) |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 189 | # We still keep this for improving pbconfig.h for unsupported platforms. |
| 190 | AC_CXX_STL_HASH |
| 191 | |
| 192 | case "$target_os" in |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 193 | mingw* | cygwin* | win* | aix*) |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 194 | ;; |
| 195 | *) |
| 196 | # Need to link against rt on Solaris |
| 197 | AC_SEARCH_LIBS([sched_yield], [rt], [], [AC_MSG_FAILURE([sched_yield was not found on your system])]) |
| 198 | ;; |
| 199 | esac |
| 200 | |
| 201 | # Enable ObjC support for conformance directory on OS X. |
| 202 | OBJC_CONFORMANCE_TEST=0 |
| 203 | case "$target_os" in |
| 204 | darwin*) |
| 205 | OBJC_CONFORMANCE_TEST=1 |
| 206 | ;; |
| 207 | esac |
| 208 | AM_CONDITIONAL([OBJC_CONFORMANCE_TEST], [test $OBJC_CONFORMANCE_TEST = 1]) |
| 209 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 210 | AX_CXX_COMPILE_STDCXX([11], [noext], [mandatory]) |
| 211 | |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 212 | # HACK: Make gmock's configure script pick up our copy of CFLAGS and CXXFLAGS, |
| 213 | # since the flags added by ACX_CHECK_SUNCC must be used when compiling gmock |
| 214 | # too. |
| 215 | export CFLAGS |
| 216 | export CXXFLAGS |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 217 | AC_CONFIG_SUBDIRS([third_party/googletest]) |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 218 | |
Austin Schuh | 40c1652 | 2018-10-28 20:27:54 -0700 | [diff] [blame] | 219 | AC_CONFIG_FILES([Makefile src/Makefile benchmarks/Makefile conformance/Makefile protobuf.pc protobuf-lite.pc]) |
Brian Silverman | 9c614bc | 2016-02-15 20:20:02 -0500 | [diff] [blame] | 220 | AC_OUTPUT |