blob: 977594d9344a920910d19a8589d6d4530b990c92 [file] [log] [blame]
Matthew Barth6292aee2016-10-06 10:15:48 -05001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([phosphor-hwmon], [1.0], [https://github.com/openbmc/phosphor-hwmon/issues])
Brad Bishop20938e42016-12-19 08:58:31 -05004AC_LANG([C++])
Matthew Barth6292aee2016-10-06 10:15:48 -05005AC_CONFIG_HEADERS([config.h])
Patrick Venture69a68ed2019-03-06 10:37:30 -08006AM_INIT_AUTOMAKE([subdir-objects -Wall -Wno-portability -Werror foreign dist-xz])
Matthew Barth6292aee2016-10-06 10:15:48 -05007AM_SILENT_RULES([yes])
8
Patrick Venture69a68ed2019-03-06 10:37:30 -08009# 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
Matthew Barth6292aee2016-10-06 10:15:48 -050022# Checks for programs.
23AC_PROG_CXX
24AM_PROG_AR
25AC_PROG_INSTALL
26AC_PROG_MAKE_SET
27
28# Checks for libraries.
Patrick Venture09d9c232019-02-13 07:40:21 -080029PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus])
30PKG_CHECK_MODULES([SDEVENTPLUS], [sdeventplus])
31PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces])
32PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
33PKG_CHECK_MODULES([GPIOPLUS], [gpioplus])
William A. Kennington III2227bd52019-06-19 11:32:22 -070034PKG_CHECK_MODULES([STDPLUS], [stdplus])
Patrick Venture17cfad62019-03-11 14:14:30 -070035# We need the header only CLI library
36AC_CHECK_HEADERS(
37 [CLI/CLI.hpp],
38 [],
39 [AC_MSG_ERROR([Could not find CLI11 CLI/CLI.hpp])]
40)
Patrick Venture9f514812018-06-27 10:19:32 -070041AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
Matthew Barth6292aee2016-10-06 10:15:48 -050042
43# Checks for typedefs, structures, and compiler characteristics.
Patrick Venture619190d2018-09-10 13:07:40 -070044AX_CXX_COMPILE_STDCXX_17([noext])
Brad Bishop3b1b5d42016-12-05 15:05:57 -050045AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS])
Matthew Barth6292aee2016-10-06 10:15:48 -050046
47# Checks for library functions.
Brad Bishop0be1f8d2017-03-06 21:52:00 -050048LT_INIT
Matthew Barth6292aee2016-10-06 10:15:48 -050049
Patrick Venture5d8f5702019-03-06 10:24:04 -080050# Make it possible for users to choose if they want test support
51# explicitly or not at all
52AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
53 [Build test cases]))
54
Matthew Barth6292aee2016-10-06 10:15:48 -050055# Check/set gtest specific functions.
Patrick Venture5d8f5702019-03-06 10:24:04 -080056AS_IF([test "x$enable_tests" != "xno"], [
57 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
58 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
59 AX_PTHREAD
60
61 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
62 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
63 AC_LANG_PUSH([C++])
64 AC_CHECK_HEADERS([gtest/gtest.h], [
65 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
66 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
67 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
68 ], [
69 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
70 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
71 ])
72 ])
73 ], [
74 AS_IF([test "x$enable_tests" = "xyes"], [
75 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
76 ])
77 ])
78 AC_LANG_POP([C++])
79 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
80
81 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
82 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
83 AC_LANG_PUSH([C++])
84 AC_CHECK_HEADERS([gmock/gmock.h], [], [
85 AS_IF([test "x$enable_tests" = "xyes"], [
86 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
87 ])
88 ])
89 AC_LANG_POP([C++])
90 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
91
92 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
93 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
94 AC_CHECK_LIB([gtest], [main], [
95 AS_IF([test "x$GTEST_LIBS" = "x"], [
96 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
97 ])
98 ], [
99 AS_IF([test "x$enable_tests" = "xyes"], [
100 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
101 ])
102 ])
103 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
104
105 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
106 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
107 AC_CHECK_LIB([gmock], [main], [
108 AS_IF([test "x$GMOCK_LIBS" = "x"], [
109 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
110 ])
111 ], [
112 AS_IF([test "x$enable_tests" = "xyes"], [
113 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
114 ])
115 ])
116 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
117])
Matthew Barth6292aee2016-10-06 10:15:48 -0500118
Patrick Venturecaac77d2018-04-17 17:38:02 -0700119# Add --enable-oe-sdk flag to configure script
Matthew Barth6292aee2016-10-06 10:15:48 -0500120AC_ARG_ENABLE([oe-sdk],
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800121 AS_HELP_STRING(
122 [--enable-oe-sdk],
123 [Link testcases absolutely against OE SDK so they can be ran within it.]
124 )
Matthew Barth6292aee2016-10-06 10:15:48 -0500125)
Patrick Venturecaac77d2018-04-17 17:38:02 -0700126
Patrick Venture7e276652019-03-13 08:17:03 -0700127# Check for valgrind
128AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
129m4_foreach([vgtool], [valgrind_tool_list],
130 [AX_VALGRIND_DFLT(vgtool, [off])])
131AX_VALGRIND_DFLT([memcheck], [on])
132AX_VALGRIND_CHECK
133AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
134m4_foreach([vgtool], [valgrind_tool_list],
135 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
136
Patrick Venture69a68ed2019-03-06 10:37:30 -0800137# Code coverage
138AX_CODE_COVERAGE
139m4_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([])
143
Patrick Venturecaac77d2018-04-17 17:38:02 -0700144# Check for OECORE_TARGET_SYSROOT in the environment.
Matthew Barth6292aee2016-10-06 10:15:48 -0500145AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800146 [Path to the OE SDK SYSROOT]
147)
Patrick Venturecaac77d2018-04-17 17:38:02 -0700148
149# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
150# used in test/Makefile.am
Matthew Barth6292aee2016-10-06 10:15:48 -0500151AS_IF([test "x$enable_oe_sdk" == "xyes"],
152 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
153 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
154 )
155 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
156 [
157 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
158 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
159 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
160 ]
161 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
162)
163
Patrick Venturec1cece72017-11-07 12:09:49 -0800164# When a sensor read fails, set the Value on dbus with -errno.
Brandon Kim79205b22019-06-20 12:18:24 -0700165# It will also skip the "Remove RCs" check.
166# Incompatible with update-functional-on-fail.
Patrick Venturec1cece72017-11-07 12:09:49 -0800167AC_ARG_ENABLE([negative-errno-on-fail],
Brandon Kim79205b22019-06-20 12:18:24 -0700168 AS_HELP_STRING(
169 [--enable-negative-errno-on-fail],
170 [Set sensor value to -errno on read failures. Incompatible with update-functional-on-fail]
171 )
Patrick Venturec1cece72017-11-07 12:09:49 -0800172)
173
174AC_ARG_VAR(NEGATIVE_ERRNO_ON_FAIL, [Set sensor value to -errno on read failures])
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800175AS_IF(
176 [test "x$enable_negative_errno_on_fail" == "xyes"],
177 [NEGATIVE_ERRNO_ON_FAIL="yes"]
178 AC_DEFINE_UNQUOTED(
179 [NEGATIVE_ERRNO_ON_FAIL],
Brandon Kim79205b22019-06-20 12:18:24 -0700180 ["$NEGATIVE_ERRNO_ON_FAIL"],
181 [Set sensor value to -errno on read failures]
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800182 )
Patrick Venturec1cece72017-11-07 12:09:49 -0800183)
184
Brandon Kim79205b22019-06-20 12:18:24 -0700185# When a sensor read fails, update the OperationalState interface's Functional property.
186# This will mark the sensor as not functional and skip reading from that sensor.
187# It will skip the "Remove RCs" check during value interface creation in MainLoop::getObject.
188# However, it will perform the "Remove RCs" checks during MainLoop::read.
189# Incompatible with negative-errno-on-fail.
190AC_ARG_ENABLE([update-functional-on-fail],
191 AS_HELP_STRING(
192 [--enable-update-functional-on-fail],
193 [Update functional property on read failures. Incompatible with negative-errno-on-fail]
194 )
195)
196
197AC_ARG_VAR(UPDATE_FUNCTIONAL_ON_FAIL, [Update functional property on read failures])
198AS_IF(
199 [test "x$enable_update_functional_on_fail" == "xyes"],
200 [UPDATE_FUNCTIONAL_ON_FAIL="yes"]
201 AC_DEFINE_UNQUOTED(
202 [UPDATE_FUNCTIONAL_ON_FAIL],
203 ["$UPDATE_FUNCTIONAL_ON_FAIL"],
204 [Update functional property on sensor read failures]
205 )
206)
207
208AS_IF([test "x$enable_negative_errno_on_fail" == "xyes"], [
209 AS_IF([test "x$enable_update_functional_on_fail" == "xyes"], [
210 AC_MSG_ERROR([Invalid configuration enabling both negative-errno-on-fail and update-functional-on-fail.])
211 ])
212])
213
Brad Bishopb9e2b072016-12-19 13:47:10 -0500214AC_ARG_VAR(BUSNAME_PREFIX, [The DBus busname prefix.])
215AC_ARG_VAR(SENSOR_ROOT, [The DBus sensors namespace root.])
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800216AS_IF(
217 [test "x$BUSNAME_PREFIX" == "x"],
218 [BUSNAME_PREFIX="xyz.openbmc_project.Hwmon"]
219)
220AS_IF(
221 [test "x$SENSOR_ROOT" == "x"],
222 [SENSOR_ROOT="/xyz/openbmc_project/sensors"]
223)
224AC_DEFINE_UNQUOTED(
225 [BUSNAME_PREFIX],
226 ["$BUSNAME_PREFIX"],
227 [The DBus busname prefix.]
228)
229AC_DEFINE_UNQUOTED(
230 [SENSOR_ROOT],
231 ["$SENSOR_ROOT"],
232 [The DBus sensors namespace root.]
233)
Brad Bishopb9e2b072016-12-19 13:47:10 -0500234
Matthew Barth6292aee2016-10-06 10:15:48 -0500235# Create configured output
Patrick Venture609fe982018-04-17 17:51:56 -0700236AC_CONFIG_FILES([Makefile test/Makefile tools/Makefile msl/Makefile])
Matthew Barth6292aee2016-10-06 10:15:48 -0500237AC_OUTPUT