blob: 1e906a890434f7265ccd0ae83b3369d430ca2773 [file] [log] [blame]
Patrick Ventureef3aead2018-09-12 08:53:29 -07001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([phosphor-ipmi-blobs], [1.0], [https://github.com/openbmc/phosphor-ipmi-blobs/issues])
4AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
Patrick Venture540b64d2018-11-28 14:56:28 -08006AC_CONFIG_MACRO_DIRS([m4])
Patrick Ventureef3aead2018-09-12 08:53:29 -07007AM_INIT_AUTOMAKE([subdir-objects -Wall -Werror foreign dist-xz])
8AM_SILENT_RULES([yes])
9
Patrick Venturea2efc762019-03-06 13:23:42 -080010# Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
11# It is important that this comes before AC_PROG_C{C,XX}, as we are attempting
12# to stop them from populating default CFLAGS and CXXFLAGS.
13AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
14AS_IF([test "x$enable_code_coverage" != "xno"], [
15 AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
16 AC_SUBST(CXXFLAGS, [""])
17 ])
18 AS_IF([test "x${CFLAGS+set}" != "xset"], [
19 AC_SUBST(CFLAGS, [""])
20 ])
21])
22
Patrick Ventureef3aead2018-09-12 08:53:29 -070023# Checks for programs.
24AC_PROG_CXX
25AM_PROG_AR
26AC_PROG_INSTALL
27AC_PROG_MAKE_SET
28
29# Checks for typedefs, structures, and compiler characteristics.
Patrick Venturef222cf52018-09-12 10:15:48 -070030AX_CXX_COMPILE_STDCXX_17([noext])
Patrick Ventureef3aead2018-09-12 08:53:29 -070031AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
32
Patrick Ventureef3aead2018-09-12 08:53:29 -070033# Checks for library functions.
Patrick Venture6c415c62018-11-14 14:01:36 -080034LT_INIT([dlopen disable-static shared]) # Required for systemd linking
Patrick Venture4dc584d2018-09-27 15:00:46 -070035LT_LIB_DLLOAD
36
37# Checks for libraries.
Patrick Venture97898c92019-02-13 07:43:45 -080038PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
William A. Kennington IIIacebece2019-02-07 15:15:44 -080039PKG_CHECK_MODULES(
40 [LIBIPMID],
41 [libipmid],
42 [],
43 [AC_MSG_ERROR([Could not find libipmid...openbmc/phosphor-host-ipmid package required])]
Patrick Venture5e70a6b2018-11-21 21:12:38 -080044)
45AC_CHECK_HEADER(
46 experimental/filesystem,
47 [],
48 [AC_MSG_ERROR([Could not find experimental/filesystem...libstdc++fs developement package required])]
49)
Patrick Venture4dc584d2018-09-27 15:00:46 -070050AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
Patrick Ventureef3aead2018-09-12 08:53:29 -070051
Patrick Venturefb808d12019-03-06 13:16:30 -080052# Make it possible for users to choose if they want test support
53# explicitly or not at all
54AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
55 [Build test cases]))
56
Patrick Ventureef3aead2018-09-12 08:53:29 -070057# Check/set gtest specific functions.
Patrick Venturefb808d12019-03-06 13:16:30 -080058AS_IF([test "x$enable_tests" != "xno"], [
59 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
60 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
61 AX_PTHREAD
62
63 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
64 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
65 AC_LANG_PUSH([C++])
66 AC_CHECK_HEADERS([gtest/gtest.h], [
67 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
68 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
69 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
70 ], [
71 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
72 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
73 ])
74 ])
75 ], [
76 AS_IF([test "x$enable_tests" = "xyes"], [
77 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
78 ])
79 ])
80 AC_LANG_POP([C++])
81 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
82
83 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
84 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
85 AC_LANG_PUSH([C++])
86 AC_CHECK_HEADERS([gmock/gmock.h], [], [
87 AS_IF([test "x$enable_tests" = "xyes"], [
88 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
89 ])
90 ])
91 AC_LANG_POP([C++])
92 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
93
94 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
95 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
96 AC_CHECK_LIB([gtest], [main], [
97 AS_IF([test "x$GTEST_LIBS" = "x"], [
98 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
99 ])
100 ], [
101 AS_IF([test "x$enable_tests" = "xyes"], [
102 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
103 ])
104 ])
105 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
106
107 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
108 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
109 AC_CHECK_LIB([gmock], [main], [
110 AS_IF([test "x$GMOCK_LIBS" = "x"], [
111 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
112 ])
113 ], [
114 AS_IF([test "x$enable_tests" = "xyes"], [
115 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
116 ])
117 ])
118 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
119])
Patrick Ventureef3aead2018-09-12 08:53:29 -0700120
Patrick Venturefd4cdea2019-03-07 07:38:28 -0800121# Check for valgrind
122AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
123m4_foreach([vgtool], [valgrind_tool_list],
124 [AX_VALGRIND_DFLT(vgtool, [off])])
125AX_VALGRIND_DFLT([memcheck], [on])
126AX_VALGRIND_CHECK
127AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
128m4_foreach([vgtool], [valgrind_tool_list],
129 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
130
Patrick Venturea2efc762019-03-06 13:23:42 -0800131# Code coverage
132AX_CODE_COVERAGE
133AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
134AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
135 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
136])
137
Patrick Ventureef3aead2018-09-12 08:53:29 -0700138# Add --enable-oe-sdk flag to configure script
139AC_ARG_ENABLE([oe-sdk],
140 AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
141)
142
143# Check for OECORE_TARGET_SYSROOT in the environment.
144AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venture5e70a6b2018-11-21 21:12:38 -0800145 [Path to the OE SDK SYSROOT]
146)
Patrick Ventureef3aead2018-09-12 08:53:29 -0700147
148# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
149# used in test/Makefile.am
150AS_IF([test "x$enable_oe_sdk" == "xyes"],
151 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
152 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
153 )
154 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
155 [
156 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
157 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
158 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
159 ]
160 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
161)
162
Patrick Venture8aee0572018-11-28 14:59:23 -0800163AC_ARG_VAR(BLOB_LIB_PATH, [The file path to search for libraries.])
164AS_IF([test "x$BLOB_LIB_PATH" == "x"], [BLOB_LIB_PATH="/usr/lib/blob-ipmid"])
165AC_DEFINE_UNQUOTED([BLOB_LIB_PATH], ["$BLOB_LIB_PATH"], [The file path to search for libraries.])
166
Patrick Ventureef3aead2018-09-12 08:53:29 -0700167# Create configured output
168AC_CONFIG_FILES([Makefile test/Makefile])
169AC_OUTPUT