blob: 0b46133d44a6993de52231d33862bb5bd9d635f6 [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])
William A. Kennington III374350d2019-03-15 14:14:07 -07007AM_INIT_AUTOMAKE([subdir-objects -Wall -Wno-portability -Werror foreign dist-xz])
Patrick Ventureef3aead2018-09-12 08:53:29 -07008AM_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)
Patrick Ventureb15d6542019-03-07 12:09:51 -080045PKG_CHECK_MODULES(
46 [IPMIBLOB],
47 [ipmiblob],
48 [],
49 [AC_MSG_ERROR(
50 [Could not find ipmiblob...openbmc/ipmi-blob-tool package required])
51 ]
52)
Patrick Venture4dc584d2018-09-27 15:00:46 -070053AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
Patrick Ventureef3aead2018-09-12 08:53:29 -070054
Patrick Venturefb808d12019-03-06 13:16:30 -080055# Make it possible for users to choose if they want test support
56# explicitly or not at all
57AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
58 [Build test cases]))
59
Patrick Ventureef3aead2018-09-12 08:53:29 -070060# Check/set gtest specific functions.
Patrick Venturefb808d12019-03-06 13:16:30 -080061AS_IF([test "x$enable_tests" != "xno"], [
62 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
63 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
64 AX_PTHREAD
65
66 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
67 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
68 AC_LANG_PUSH([C++])
69 AC_CHECK_HEADERS([gtest/gtest.h], [
70 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
71 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
72 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
73 ], [
74 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
75 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
76 ])
77 ])
78 ], [
79 AS_IF([test "x$enable_tests" = "xyes"], [
80 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
81 ])
82 ])
83 AC_LANG_POP([C++])
84 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
85
86 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
87 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
88 AC_LANG_PUSH([C++])
89 AC_CHECK_HEADERS([gmock/gmock.h], [], [
90 AS_IF([test "x$enable_tests" = "xyes"], [
91 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
92 ])
93 ])
94 AC_LANG_POP([C++])
95 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
96
97 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
98 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
99 AC_CHECK_LIB([gtest], [main], [
100 AS_IF([test "x$GTEST_LIBS" = "x"], [
101 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
102 ])
103 ], [
104 AS_IF([test "x$enable_tests" = "xyes"], [
105 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
106 ])
107 ])
108 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
109
110 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
111 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
112 AC_CHECK_LIB([gmock], [main], [
113 AS_IF([test "x$GMOCK_LIBS" = "x"], [
114 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
115 ])
116 ], [
117 AS_IF([test "x$enable_tests" = "xyes"], [
118 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
119 ])
120 ])
121 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
122])
Patrick Ventureef3aead2018-09-12 08:53:29 -0700123
Patrick Venturefd4cdea2019-03-07 07:38:28 -0800124# Check for valgrind
125AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
126m4_foreach([vgtool], [valgrind_tool_list],
127 [AX_VALGRIND_DFLT(vgtool, [off])])
128AX_VALGRIND_DFLT([memcheck], [on])
129AX_VALGRIND_CHECK
130AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
131m4_foreach([vgtool], [valgrind_tool_list],
132 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
133
Patrick Venturea2efc762019-03-06 13:23:42 -0800134# Code coverage
135AX_CODE_COVERAGE
Patrick Venturea2efc762019-03-06 13:23:42 -0800136AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
137 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
138])
William A. Kennington III374350d2019-03-15 14:14:07 -0700139m4_ifdef([_AX_CODE_COVERAGE_RULES],
140 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
141 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
142AX_ADD_AM_MACRO_STATIC([])
Patrick Venturea2efc762019-03-06 13:23:42 -0800143
Patrick Ventureef3aead2018-09-12 08:53:29 -0700144# Add --enable-oe-sdk flag to configure script
145AC_ARG_ENABLE([oe-sdk],
146 AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
147)
148
149# Check for OECORE_TARGET_SYSROOT in the environment.
150AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venture5e70a6b2018-11-21 21:12:38 -0800151 [Path to the OE SDK SYSROOT]
152)
Patrick Ventureef3aead2018-09-12 08:53:29 -0700153
154# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
155# used in test/Makefile.am
156AS_IF([test "x$enable_oe_sdk" == "xyes"],
157 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
158 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
159 )
160 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
161 [
162 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
163 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
164 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
165 ]
166 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
167)
168
Patrick Venture8aee0572018-11-28 14:59:23 -0800169AC_ARG_VAR(BLOB_LIB_PATH, [The file path to search for libraries.])
170AS_IF([test "x$BLOB_LIB_PATH" == "x"], [BLOB_LIB_PATH="/usr/lib/blob-ipmid"])
171AC_DEFINE_UNQUOTED([BLOB_LIB_PATH], ["$BLOB_LIB_PATH"], [The file path to search for libraries.])
172
Patrick Ventureef3aead2018-09-12 08:53:29 -0700173# Create configured output
174AC_CONFIG_FILES([Makefile test/Makefile])
175AC_OUTPUT