blob: bb12c7b0aa4eb70ff7c56d1642a926bddc45f4b6 [file] [log] [blame]
Patrick Ventured26fff42018-09-18 15:37:59 -07001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([phosphor-ipmi-ethstats], [1.0], [https://www.github.com/openbmc/phosphor-ipmi-ethstats/issues])
4AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
Patrick Venture6bb5cfc2019-03-18 18:45:08 -07006AM_INIT_AUTOMAKE([subdir-objects -Wall -Wno-portability -Werror foreign dist-xz])
Patrick Ventured26fff42018-09-18 15:37:59 -07007AM_SILENT_RULES([yes])
8
Patrick Venture6bb5cfc2019-03-18 18:45:08 -07009# Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
10# It is important that this comes before AC_PROG_C{C,XX}, as we are attempting
11# to stop them from populating default CFLAGS and CXXFLAGS.
12AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
13AS_IF([test "x$enable_code_coverage" != "xno"], [
14 AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
15 AC_SUBST(CXXFLAGS, [""])
16 ])
17 AS_IF([test "x${CFLAGS+set}" != "xset"], [
18 AC_SUBST(CFLAGS, [""])
19 ])
20])
21
Patrick Ventured26fff42018-09-18 15:37:59 -070022# Checks for programs.
23AC_PROG_CXX
24AM_PROG_AR
25AC_PROG_INSTALL
26AC_PROG_MAKE_SET
27
28# Checks for typedefs, structures, and compiler characteristics.
29AX_CXX_COMPILE_STDCXX_17([noext])
30AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
31
32# Checks for libraries.
William A. Kennington III539f03f2019-02-12 13:28:45 -080033PKG_CHECK_MODULES([LIBIPMID], [libipmid])
Patrick Ventured26fff42018-09-18 15:37:59 -070034AC_CHECK_HEADER(experimental/filesystem, ,[AC_MSG_ERROR([Could not find experimental/filesystem...libstdc++fs developement package required])])
35
36# Checks for library functions.
37LT_INIT # Required for systemd linking
38
Patrick Venturef1586f52019-03-18 10:41:22 -070039# Make it possible for users to choose if they want test support
40# explicitly or not at all
41AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
42 [Build test cases]))
43
44 # Check/set gtest specific functions.
45AS_IF([test "x$enable_tests" != "xno"], [
46 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
47 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
48 AX_PTHREAD
49
50 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
51 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
52 AC_LANG_PUSH([C++])
53 AC_CHECK_HEADERS([gtest/gtest.h], [
54 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
55 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
56 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
57 ], [
58 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
59 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
60 ])
61 ])
62 ], [
63 AS_IF([test "x$enable_tests" = "xyes"], [
64 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
65 ])
66 ])
67 AC_LANG_POP([C++])
68 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
69
70 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
71 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
72 AC_LANG_PUSH([C++])
73 AC_CHECK_HEADERS([gmock/gmock.h], [], [
74 AS_IF([test "x$enable_tests" = "xyes"], [
75 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
76 ])
77 ])
78 AC_LANG_POP([C++])
79 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
80
81 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
82 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
83 AC_CHECK_LIB([gtest], [main], [
84 AS_IF([test "x$GTEST_LIBS" = "x"], [
85 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
86 ])
87 ], [
88 AS_IF([test "x$enable_tests" = "xyes"], [
89 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
90 ])
91 ])
92 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
93
94 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
95 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
96 AC_CHECK_LIB([gmock], [main], [
97 AS_IF([test "x$GMOCK_LIBS" = "x"], [
98 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
99 ])
100 ], [
101 AS_IF([test "x$enable_tests" = "xyes"], [
102 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
103 ])
104 ])
105 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
106])
107
Patrick Venture6bb5cfc2019-03-18 18:45:08 -0700108# Code coverage
109AX_CODE_COVERAGE
110m4_ifdef([_AX_CODE_COVERAGE_RULES],
111 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
112 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
113AX_ADD_AM_MACRO_STATIC([])
114
Patrick Ventured26fff42018-09-18 15:37:59 -0700115# Do you want to install with the Google OEM Number as well.
116AC_ARG_ENABLE([google],
Patrick Ventured72f8b52019-03-07 16:54:57 -0800117 AS_HELP_STRING(
118 [--enable-google], [Enable registering with Google OEN.]
119 )
Patrick Ventured26fff42018-09-18 15:37:59 -0700120)
Patrick Ventured72f8b52019-03-07 16:54:57 -0800121AM_CONDITIONAL(ENABLE_GOOGLE, [test "x$enable_google" = "xyes"])
122AS_IF([test "x$enable_google" = "xyes"],
123 [AC_DEFINE(ENABLE_GOOGLE, [1], [Register with Google OEN.])],
124 [AC_DEFINE(ENABLE_GOOGLE, [0], [Do not register with Google OEN.])]
Patrick Ventured26fff42018-09-18 15:37:59 -0700125)
126
127# Create configured output
Patrick Venturef1586f52019-03-18 10:41:22 -0700128AC_CONFIG_FILES([Makefile test/Makefile])
Patrick Ventured26fff42018-09-18 15:37:59 -0700129AC_OUTPUT