blob: 5e4bbddf16b89ad487763bf310875a210aced3da [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])
Matt Spinler5e034af2020-06-24 15:21:53 -050035PKG_CHECK_MODULES([FMT], [fmt])
Patrick Venture17cfad62019-03-11 14:14:30 -070036# We need the header only CLI library
37AC_CHECK_HEADERS(
38 [CLI/CLI.hpp],
39 [],
40 [AC_MSG_ERROR([Could not find CLI11 CLI/CLI.hpp])]
41)
Patrick Venture9f514812018-06-27 10:19:32 -070042AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
Matthew Barth6292aee2016-10-06 10:15:48 -050043
44# Checks for typedefs, structures, and compiler characteristics.
Patrick Venture619190d2018-09-10 13:07:40 -070045AX_CXX_COMPILE_STDCXX_17([noext])
Brad Bishop3b1b5d42016-12-05 15:05:57 -050046AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS])
Matthew Barth6292aee2016-10-06 10:15:48 -050047
48# Checks for library functions.
Brad Bishop0be1f8d2017-03-06 21:52:00 -050049LT_INIT
Matthew Barth6292aee2016-10-06 10:15:48 -050050
Patrick Venture5d8f5702019-03-06 10:24:04 -080051# Make it possible for users to choose if they want test support
52# explicitly or not at all
53AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
54 [Build test cases]))
55
Matthew Barth6292aee2016-10-06 10:15:48 -050056# Check/set gtest specific functions.
Patrick Venture5d8f5702019-03-06 10:24:04 -080057AS_IF([test "x$enable_tests" != "xno"], [
58 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
59 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
60 AX_PTHREAD
61
62 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
63 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
64 AC_LANG_PUSH([C++])
65 AC_CHECK_HEADERS([gtest/gtest.h], [
66 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
67 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
68 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
69 ], [
70 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
71 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
72 ])
73 ])
74 ], [
75 AS_IF([test "x$enable_tests" = "xyes"], [
76 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
77 ])
78 ])
79 AC_LANG_POP([C++])
80 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
81
82 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
83 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
84 AC_LANG_PUSH([C++])
85 AC_CHECK_HEADERS([gmock/gmock.h], [], [
86 AS_IF([test "x$enable_tests" = "xyes"], [
87 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
88 ])
89 ])
90 AC_LANG_POP([C++])
91 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
92
93 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
94 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
95 AC_CHECK_LIB([gtest], [main], [
96 AS_IF([test "x$GTEST_LIBS" = "x"], [
97 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
98 ])
99 ], [
100 AS_IF([test "x$enable_tests" = "xyes"], [
101 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
102 ])
103 ])
104 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
105
106 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
107 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
108 AC_CHECK_LIB([gmock], [main], [
109 AS_IF([test "x$GMOCK_LIBS" = "x"], [
110 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
111 ])
112 ], [
113 AS_IF([test "x$enable_tests" = "xyes"], [
114 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
115 ])
116 ])
117 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
118])
Matthew Barth6292aee2016-10-06 10:15:48 -0500119
Patrick Venturecaac77d2018-04-17 17:38:02 -0700120# Add --enable-oe-sdk flag to configure script
Matthew Barth6292aee2016-10-06 10:15:48 -0500121AC_ARG_ENABLE([oe-sdk],
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800122 AS_HELP_STRING(
123 [--enable-oe-sdk],
124 [Link testcases absolutely against OE SDK so they can be ran within it.]
125 )
Matthew Barth6292aee2016-10-06 10:15:48 -0500126)
Patrick Venturecaac77d2018-04-17 17:38:02 -0700127
Patrick Venture7e276652019-03-13 08:17:03 -0700128# Check for valgrind
129AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
130m4_foreach([vgtool], [valgrind_tool_list],
131 [AX_VALGRIND_DFLT(vgtool, [off])])
132AX_VALGRIND_DFLT([memcheck], [on])
133AX_VALGRIND_CHECK
134AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
135m4_foreach([vgtool], [valgrind_tool_list],
136 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
137
Patrick Venture69a68ed2019-03-06 10:37:30 -0800138# Code coverage
139AX_CODE_COVERAGE
140m4_ifdef([_AX_CODE_COVERAGE_RULES],
141 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
142 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
143AX_ADD_AM_MACRO_STATIC([])
144
Patrick Venturecaac77d2018-04-17 17:38:02 -0700145# Check for OECORE_TARGET_SYSROOT in the environment.
Matthew Barth6292aee2016-10-06 10:15:48 -0500146AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800147 [Path to the OE SDK SYSROOT]
148)
Patrick Venturecaac77d2018-04-17 17:38:02 -0700149
150# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
151# used in test/Makefile.am
Matthew Barth6292aee2016-10-06 10:15:48 -0500152AS_IF([test "x$enable_oe_sdk" == "xyes"],
153 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
154 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
155 )
156 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
157 [
158 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
159 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
160 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
161 ]
162 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
163)
164
Patrick Venturec1cece72017-11-07 12:09:49 -0800165# When a sensor read fails, set the Value on dbus with -errno.
Brandon Kim79205b22019-06-20 12:18:24 -0700166# It will also skip the "Remove RCs" check.
167# Incompatible with update-functional-on-fail.
Patrick Venturec1cece72017-11-07 12:09:49 -0800168AC_ARG_ENABLE([negative-errno-on-fail],
Brandon Kim79205b22019-06-20 12:18:24 -0700169 AS_HELP_STRING(
170 [--enable-negative-errno-on-fail],
171 [Set sensor value to -errno on read failures. Incompatible with update-functional-on-fail]
172 )
Patrick Venturec1cece72017-11-07 12:09:49 -0800173)
174
175AC_ARG_VAR(NEGATIVE_ERRNO_ON_FAIL, [Set sensor value to -errno on read failures])
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800176AS_IF(
177 [test "x$enable_negative_errno_on_fail" == "xyes"],
178 [NEGATIVE_ERRNO_ON_FAIL="yes"]
179 AC_DEFINE_UNQUOTED(
180 [NEGATIVE_ERRNO_ON_FAIL],
Brandon Kim79205b22019-06-20 12:18:24 -0700181 ["$NEGATIVE_ERRNO_ON_FAIL"],
182 [Set sensor value to -errno on read failures]
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800183 )
Patrick Venturec1cece72017-11-07 12:09:49 -0800184)
185
Brandon Kim79205b22019-06-20 12:18:24 -0700186# When a sensor read fails, update the OperationalState interface's Functional property.
187# This will mark the sensor as not functional and skip reading from that sensor.
188# It will skip the "Remove RCs" check during value interface creation in MainLoop::getObject.
189# However, it will perform the "Remove RCs" checks during MainLoop::read.
190# Incompatible with negative-errno-on-fail.
191AC_ARG_ENABLE([update-functional-on-fail],
192 AS_HELP_STRING(
193 [--enable-update-functional-on-fail],
194 [Update functional property on read failures. Incompatible with negative-errno-on-fail]
195 )
196)
197
198AC_ARG_VAR(UPDATE_FUNCTIONAL_ON_FAIL, [Update functional property on read failures])
199AS_IF(
200 [test "x$enable_update_functional_on_fail" == "xyes"],
201 [UPDATE_FUNCTIONAL_ON_FAIL="yes"]
202 AC_DEFINE_UNQUOTED(
203 [UPDATE_FUNCTIONAL_ON_FAIL],
204 ["$UPDATE_FUNCTIONAL_ON_FAIL"],
205 [Update functional property on sensor read failures]
206 )
207)
208
209AS_IF([test "x$enable_negative_errno_on_fail" == "xyes"], [
210 AS_IF([test "x$enable_update_functional_on_fail" == "xyes"], [
211 AC_MSG_ERROR([Invalid configuration enabling both negative-errno-on-fail and update-functional-on-fail.])
212 ])
213])
214
Brad Bishopb9e2b072016-12-19 13:47:10 -0500215AC_ARG_VAR(BUSNAME_PREFIX, [The DBus busname prefix.])
216AC_ARG_VAR(SENSOR_ROOT, [The DBus sensors namespace root.])
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800217AS_IF(
218 [test "x$BUSNAME_PREFIX" == "x"],
219 [BUSNAME_PREFIX="xyz.openbmc_project.Hwmon"]
220)
221AS_IF(
222 [test "x$SENSOR_ROOT" == "x"],
223 [SENSOR_ROOT="/xyz/openbmc_project/sensors"]
224)
225AC_DEFINE_UNQUOTED(
226 [BUSNAME_PREFIX],
227 ["$BUSNAME_PREFIX"],
228 [The DBus busname prefix.]
229)
230AC_DEFINE_UNQUOTED(
231 [SENSOR_ROOT],
232 ["$SENSOR_ROOT"],
233 [The DBus sensors namespace root.]
234)
Brad Bishopb9e2b072016-12-19 13:47:10 -0500235
Matthew Barth6292aee2016-10-06 10:15:48 -0500236# Create configured output
Patrick Venture609fe982018-04-17 17:51:56 -0700237AC_CONFIG_FILES([Makefile test/Makefile tools/Makefile msl/Makefile])
Matthew Barth6292aee2016-10-06 10:15:48 -0500238AC_OUTPUT