Patrick Venture | 123b5c0 | 2019-03-05 14:01:00 -0800 | [diff] [blame^] | 1 | # Initialization |
| 2 | AC_PREREQ([2.69]) |
| 3 | AC_INIT([ipmi-blob-tool], [0.1], [https://github.com/openbmc/ipmi-blob-tool/issues]) |
| 4 | AC_LANG([C++]) |
| 5 | AC_CONFIG_HEADERS([config.h]) |
| 6 | AC_CONFIG_MACRO_DIRS([m4]) |
| 7 | AC_CONFIG_AUX_DIR([build-aux]) |
| 8 | AM_INIT_AUTOMAKE([nostdinc foreign subdir-objects -Wall -Werror dist-xz tar-ustar]) |
| 9 | AM_SILENT_RULES([yes]) |
| 10 | |
| 11 | # Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS |
| 12 | # It is important that this comes before AC_PROG_C{C,XX}, as we are attempting |
| 13 | # to stop them from populating default CFLAGS and CXXFLAGS. |
| 14 | AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no]) |
| 15 | AS_IF([test "x$enable_code_coverage" != "xno"], [ |
| 16 | AS_IF([test "x${CXXFLAGS+set}" != "xset"], [ |
| 17 | AC_SUBST(CXXFLAGS, [""]) |
| 18 | ]) |
| 19 | AS_IF([test "x${CFLAGS+set}" != "xset"], [ |
| 20 | AC_SUBST(CFLAGS, [""]) |
| 21 | ]) |
| 22 | ]) |
| 23 | |
| 24 | # Checks for programs. |
| 25 | AC_PROG_CXX |
| 26 | AC_PROG_CC |
| 27 | AM_PROG_AR |
| 28 | AC_PROG_INSTALL |
| 29 | AC_PROG_MAKE_SET |
| 30 | |
| 31 | # Checks for libtool |
| 32 | LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot' |
| 33 | |
| 34 | # Make sure the pkgconfigdata is configured for automake |
| 35 | PKG_INSTALLDIR |
| 36 | |
| 37 | # Checks for typedefs, structures, and compiler characteristics. |
| 38 | AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory]) |
| 39 | AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS]) |
| 40 | AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS]) |
| 41 | |
| 42 | # Make it possible for users to choose if they want test support |
| 43 | # explicitly or not at all |
| 44 | AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests], |
| 45 | [Build test cases])) |
| 46 | |
| 47 | # Check/set gtest specific functions. |
| 48 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 49 | PKG_CHECK_MODULES([GTEST], [gtest], [], [true]) |
| 50 | PKG_CHECK_MODULES([GMOCK], [gmock], [], [true]) |
| 51 | AX_PTHREAD |
| 52 | |
| 53 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 54 | AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS]) |
| 55 | AC_LANG_PUSH([C++]) |
| 56 | AC_CHECK_HEADERS([gtest/gtest.h], [ |
| 57 | AS_IF([test "x$GTEST_CFLAGS" = "x"], [ |
| 58 | AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [ |
| 59 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS]) |
| 60 | ], [ |
| 61 | AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS]) |
| 62 | AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS]) |
| 63 | ]) |
| 64 | ]) |
| 65 | ], [ |
| 66 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 67 | AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h]) |
| 68 | ]) |
| 69 | ]) |
| 70 | AC_LANG_POP([C++]) |
| 71 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 72 | |
| 73 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 74 | AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS]) |
| 75 | AC_LANG_PUSH([C++]) |
| 76 | AC_CHECK_HEADERS([gmock/gmock.h], [], [ |
| 77 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 78 | AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h]) |
| 79 | ]) |
| 80 | ]) |
| 81 | AC_LANG_POP([C++]) |
| 82 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS]) |
| 83 | |
| 84 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 85 | AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS]) |
| 86 | AC_CHECK_LIB([gtest], [main], [ |
| 87 | AS_IF([test "x$GTEST_LIBS" = "x"], [ |
| 88 | AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS]) |
| 89 | ]) |
| 90 | ], [ |
| 91 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 92 | AC_MSG_ERROR([Testing enabled but couldn't find gtest libs]) |
| 93 | ]) |
| 94 | ]) |
| 95 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 96 | |
| 97 | AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 98 | AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS]) |
| 99 | AC_CHECK_LIB([gmock], [main], [ |
| 100 | AS_IF([test "x$GMOCK_LIBS" = "x"], [ |
| 101 | AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS]) |
| 102 | ]) |
| 103 | ], [ |
| 104 | AS_IF([test "x$enable_tests" = "xyes"], [ |
| 105 | AC_MSG_ERROR([Testing enabled but couldn't find gmock libs]) |
| 106 | ]) |
| 107 | ]) |
| 108 | AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS]) |
| 109 | ]) |
| 110 | |
| 111 | # Check for valgrind |
| 112 | AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no]) |
| 113 | m4_foreach([vgtool], [valgrind_tool_list], |
| 114 | [AX_VALGRIND_DFLT(vgtool, [off])]) |
| 115 | AX_VALGRIND_DFLT([memcheck], [on]) |
| 116 | AX_VALGRIND_CHECK |
| 117 | AM_EXTRA_RECURSIVE_TARGETS([check-valgrind]) |
| 118 | m4_foreach([vgtool], [valgrind_tool_list], |
| 119 | [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)]) |
| 120 | |
| 121 | # Code coverage |
| 122 | AX_CODE_COVERAGE |
| 123 | AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage]) |
| 124 | AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [ |
| 125 | AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS]) |
| 126 | ]) |
| 127 | |
| 128 | # Append -Werror after doing autoconf compiler checks |
| 129 | # Otherwise some perfectly valid checks can fail and cause our |
| 130 | # final configuratin to be broken. |
| 131 | AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS])) |
| 132 | AS_IF([test "x$enable_tests" != "xno"], [ |
| 133 | AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS]) |
| 134 | AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS]) |
| 135 | ]) |
| 136 | |
| 137 | # Create configured output |
| 138 | AC_CONFIG_FILES([Makefile src/Makefile test/Makefile]) |
| 139 | AC_CONFIG_FILES([src/ipmiblob.pc]) |
| 140 | AC_OUTPUT |