blob: bd63629eacea1f66bb5a63e0678479577b766e8b [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])
Patrick Venture17cfad62019-03-11 14:14:30 -070034# We need the header only CLI library
35AC_CHECK_HEADERS(
36 [CLI/CLI.hpp],
37 [],
38 [AC_MSG_ERROR([Could not find CLI11 CLI/CLI.hpp])]
39)
Patrick Venture9f514812018-06-27 10:19:32 -070040AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
Matthew Barth6292aee2016-10-06 10:15:48 -050041
42# Checks for typedefs, structures, and compiler characteristics.
Patrick Venture619190d2018-09-10 13:07:40 -070043AX_CXX_COMPILE_STDCXX_17([noext])
Brad Bishop3b1b5d42016-12-05 15:05:57 -050044AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS])
Matthew Barth6292aee2016-10-06 10:15:48 -050045
46# Checks for library functions.
Brad Bishop0be1f8d2017-03-06 21:52:00 -050047LT_INIT
Matthew Barth6292aee2016-10-06 10:15:48 -050048
Patrick Venture5d8f5702019-03-06 10:24:04 -080049# Make it possible for users to choose if they want test support
50# explicitly or not at all
51AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
52 [Build test cases]))
53
Matthew Barth6292aee2016-10-06 10:15:48 -050054# Check/set gtest specific functions.
Patrick Venture5d8f5702019-03-06 10:24:04 -080055AS_IF([test "x$enable_tests" != "xno"], [
56 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
57 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
58 AX_PTHREAD
59
60 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
61 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
62 AC_LANG_PUSH([C++])
63 AC_CHECK_HEADERS([gtest/gtest.h], [
64 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
65 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
66 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
67 ], [
68 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
69 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
70 ])
71 ])
72 ], [
73 AS_IF([test "x$enable_tests" = "xyes"], [
74 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
75 ])
76 ])
77 AC_LANG_POP([C++])
78 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
79
80 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
81 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
82 AC_LANG_PUSH([C++])
83 AC_CHECK_HEADERS([gmock/gmock.h], [], [
84 AS_IF([test "x$enable_tests" = "xyes"], [
85 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
86 ])
87 ])
88 AC_LANG_POP([C++])
89 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
90
91 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
92 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
93 AC_CHECK_LIB([gtest], [main], [
94 AS_IF([test "x$GTEST_LIBS" = "x"], [
95 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
96 ])
97 ], [
98 AS_IF([test "x$enable_tests" = "xyes"], [
99 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
100 ])
101 ])
102 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
103
104 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
105 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
106 AC_CHECK_LIB([gmock], [main], [
107 AS_IF([test "x$GMOCK_LIBS" = "x"], [
108 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
109 ])
110 ], [
111 AS_IF([test "x$enable_tests" = "xyes"], [
112 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
113 ])
114 ])
115 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
116])
Matthew Barth6292aee2016-10-06 10:15:48 -0500117
Patrick Venturecaac77d2018-04-17 17:38:02 -0700118# Add --enable-oe-sdk flag to configure script
Matthew Barth6292aee2016-10-06 10:15:48 -0500119AC_ARG_ENABLE([oe-sdk],
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800120 AS_HELP_STRING(
121 [--enable-oe-sdk],
122 [Link testcases absolutely against OE SDK so they can be ran within it.]
123 )
Matthew Barth6292aee2016-10-06 10:15:48 -0500124)
Patrick Venturecaac77d2018-04-17 17:38:02 -0700125
Patrick Venture7e276652019-03-13 08:17:03 -0700126# Check for valgrind
127AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
128m4_foreach([vgtool], [valgrind_tool_list],
129 [AX_VALGRIND_DFLT(vgtool, [off])])
130AX_VALGRIND_DFLT([memcheck], [on])
131AX_VALGRIND_CHECK
132AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
133m4_foreach([vgtool], [valgrind_tool_list],
134 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
135
Patrick Venture69a68ed2019-03-06 10:37:30 -0800136# Code coverage
137AX_CODE_COVERAGE
138m4_ifdef([_AX_CODE_COVERAGE_RULES],
139 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
140 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
141AX_ADD_AM_MACRO_STATIC([])
142
Patrick Venturecaac77d2018-04-17 17:38:02 -0700143# Check for OECORE_TARGET_SYSROOT in the environment.
Matthew Barth6292aee2016-10-06 10:15:48 -0500144AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800145 [Path to the OE SDK SYSROOT]
146)
Patrick Venturecaac77d2018-04-17 17:38:02 -0700147
148# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
149# used in test/Makefile.am
Matthew Barth6292aee2016-10-06 10:15:48 -0500150AS_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 Venturec1cece72017-11-07 12:09:49 -0800163# When a sensor access fails, just remove the sensor from dbus instead of exiting the daemon.
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500164AC_ARG_ENABLE([remove-from-dbus-on-fail],
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800165 AS_HELP_STRING(
166 [--enable-remove-from-dbus-on-fail],
167 [Remove properties from D-Bus on access failures]
168 )
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500169)
170
171AC_ARG_VAR(REMOVE_ON_FAIL, [Remove properties from D-Bus on access failures])
172
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800173AS_IF(
174 [test "x$enable_remove_from_dbus_on_fail" == "xyes"],
175 [REMOVE_ON_FAIL="yes"]
176 AC_DEFINE_UNQUOTED(
177 [REMOVE_ON_FAIL],
178 ["$REMOVE_ON_FAIL"],
179 [Remove properties from D-Bus on access failures]
180 )
Matt Spinlerf9c83c42017-08-10 08:51:45 -0500181)
182
Patrick Venturec1cece72017-11-07 12:09:49 -0800183# When a sensor read fails, set the Value on dbus with -errno.
184# Incompatible with remove-from-dbus-on-fail.
185AC_ARG_ENABLE([negative-errno-on-fail],
186 AS_HELP_STRING([--enable-negative-errno-on-fail], [Set sensor value to -errno on read failures])
187)
188
189AC_ARG_VAR(NEGATIVE_ERRNO_ON_FAIL, [Set sensor value to -errno on read failures])
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800190AS_IF(
191 [test "x$enable_negative_errno_on_fail" == "xyes"],
192 [NEGATIVE_ERRNO_ON_FAIL="yes"]
193 AC_DEFINE_UNQUOTED(
194 [NEGATIVE_ERRNO_ON_FAIL],
195 ["$NEGATIVE_ERRNO_ON_FAIL"], [Set sensor value to -errno on read failures]
196 )
Patrick Venturec1cece72017-11-07 12:09:49 -0800197)
198
Brad Bishopb9e2b072016-12-19 13:47:10 -0500199AC_ARG_VAR(BUSNAME_PREFIX, [The DBus busname prefix.])
200AC_ARG_VAR(SENSOR_ROOT, [The DBus sensors namespace root.])
Patrick Venture9a7ef7c2018-11-21 21:37:23 -0800201AS_IF(
202 [test "x$BUSNAME_PREFIX" == "x"],
203 [BUSNAME_PREFIX="xyz.openbmc_project.Hwmon"]
204)
205AS_IF(
206 [test "x$SENSOR_ROOT" == "x"],
207 [SENSOR_ROOT="/xyz/openbmc_project/sensors"]
208)
209AC_DEFINE_UNQUOTED(
210 [BUSNAME_PREFIX],
211 ["$BUSNAME_PREFIX"],
212 [The DBus busname prefix.]
213)
214AC_DEFINE_UNQUOTED(
215 [SENSOR_ROOT],
216 ["$SENSOR_ROOT"],
217 [The DBus sensors namespace root.]
218)
Brad Bishopb9e2b072016-12-19 13:47:10 -0500219
Matthew Barth6292aee2016-10-06 10:15:48 -0500220# Create configured output
Patrick Venture609fe982018-04-17 17:51:56 -0700221AC_CONFIG_FILES([Makefile test/Makefile tools/Makefile msl/Makefile])
Matthew Barth6292aee2016-10-06 10:15:48 -0500222AC_OUTPUT