blob: 5075c6706987c0dc0379bd09253afe9dac182f8a [file] [log] [blame]
Patrick Venturee6206562018-03-08 15:36:53 -08001# Initialization
2AC_PREREQ([2.69])
Patrick Ventured7523572018-11-26 09:01:54 -08003AC_INIT([swampd], [0.1], [https://github.com/openbmc/phosphor-pid-control/issues])
Patrick Venturee6206562018-03-08 15:36:53 -08004AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
Patrick Venture90e9dbc2019-03-19 09:10:41 -07006AM_INIT_AUTOMAKE([subdir-objects -Wall -Wno-portability -Werror foreign dist-xz])
Patrick Venturee6206562018-03-08 15:36:53 -08007AM_SILENT_RULES([yes])
8
Patrick Venture94feffa2019-03-06 09:54:49 -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
Patrick Venturee6206562018-03-08 15:36:53 -080022# Checks for programs.
23AC_PROG_CXX
24AM_PROG_AR
25AC_PROG_INSTALL
26AC_PROG_MAKE_SET
27
Patrick Venturee6206562018-03-08 15:36:53 -080028# Checks for typedefs, structures, and compiler characteristics.
Patrick Venture54c2e5e2018-09-10 13:06:38 -070029AX_CXX_COMPILE_STDCXX_17([noext])
Patrick Ventureab28cb32018-06-20 18:37:48 -070030AX_APPEND_COMPILE_FLAGS([-fpic -Wall -Werror], [CXXFLAGS])
Patrick Venturee6206562018-03-08 15:36:53 -080031
32# Checks for libraries.
Patrick Venturee54c7ff2018-11-21 21:30:56 -080033PKG_CHECK_MODULES(
34 [SYSTEMD],
35 [libsystemd >= 221],
36 [],
37 [AC_MSG_ERROR(["systemd required and not found"])]
38)
Patrick Venturef72ad442019-02-13 07:28:58 -080039PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus])
40PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
41PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [phosphor-dbus-interfaces])
William A. Kennington III331143c2019-02-07 15:52:44 -080042PKG_CHECK_MODULES(
43 [LIBIPMID],
44 [libipmid],
45 [],
46 [AC_MSG_ERROR([Could not find libipmid...openbmc/phosphor-host-ipmid package required])]
Patrick Venturee54c7ff2018-11-21 21:30:56 -080047)
48AC_CHECK_HEADER(
Patrick Venture31eebcd2019-02-12 07:23:42 -080049 nlohmann/json.hpp,
50 [],
51 [AC_MSG_ERROR([Could not find nlohmann/json.hpp])]
52)
Patrick Ventureb5cc37c2019-03-11 09:11:55 -070053# We need the header only CLI library
54AC_CHECK_HEADERS(
55 [CLI/CLI.hpp],
56 [],
57 [AC_MSG_ERROR([Could not find CLI11 CLI/CLI.hpp])]
58)
James Feistce6a3f32019-03-12 11:20:16 -070059
60# check for boost headers
61AC_CHECK_HEADER(
62 boost/asio/io_context.hpp,
63 [],
64 [AC_MSG_ERROR([Could not find boost/asio/io_context.hpp])]
65)
66AC_CHECK_HEADER(
67 boost/asio/steady_timer.hpp,
68 [],
69 [AC_MSG_ERROR([Could not find boost/asio/steady_timer.hpp])]
70)
71AX_APPEND_COMPILE_FLAGS(["-DBOOST_ASIO_DISABLE_THREADS"], [CPPFLAGS])
72AX_APPEND_COMPILE_FLAGS(["-DBOOST_ERROR_CODE_HEADER_ONLY"], [CPPFLAGS])
73AX_APPEND_COMPILE_FLAGS(["-DBOOST_SYSTEM_NO_DEPRECATED"], [CPPFLAGS])
74AX_APPEND_COMPILE_FLAGS(["-DBOOST_ASIO_NO_DEPRECATED"], [CPPFLAGS])
Patrick Venturee6206562018-03-08 15:36:53 -080075
76# Checks for library functions.
77LT_INIT # Required for systemd linking
78
Patrick Venture90f9bb52019-03-06 09:39:11 -080079# Make it possible for users to choose if they want test support
80# explicitly or not at all
81AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
82 [Build test cases]))
83
Vijay Khemka55845432019-06-19 14:25:40 -070084PKG_PROG_PKG_CONFIG
85AC_ARG_WITH([systemdsystemunitdir],
86 [AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],
87 [],
88 [with_systemdsystemunitdir=auto]
89)
90AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"],
91 [def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
92 AS_IF([test "x$def_systemdsystemunitdir" = "x"],
93 [AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
94 [AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])]
95 )
96 with_systemdsystemunitdir=no],
97 [with_systemdsystemunitdir="$def_systemdsystemunitdir"]
98 )]
99)
100AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
101 [AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])]
102)
103AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
104
Patrick Venturee6206562018-03-08 15:36:53 -0800105# Check/set gtest specific functions.
Patrick Venture90f9bb52019-03-06 09:39:11 -0800106AS_IF([test "x$enable_tests" != "xno"], [
107 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
108 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
109 AX_PTHREAD
110
111 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
112 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
113 AC_LANG_PUSH([C++])
114 AC_CHECK_HEADERS([gtest/gtest.h], [
115 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
116 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
117 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
118 ], [
119 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
120 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
121 ])
122 ])
123 ], [
124 AS_IF([test "x$enable_tests" = "xyes"], [
125 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
126 ])
127 ])
128 AC_LANG_POP([C++])
129 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
130
131 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
132 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
133 AC_LANG_PUSH([C++])
134 AC_CHECK_HEADERS([gmock/gmock.h], [], [
135 AS_IF([test "x$enable_tests" = "xyes"], [
136 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
137 ])
138 ])
139 AC_LANG_POP([C++])
140 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
141
142 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
143 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
144 AC_CHECK_LIB([gtest], [main], [
145 AS_IF([test "x$GTEST_LIBS" = "x"], [
146 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
147 ])
148 ], [
149 AS_IF([test "x$enable_tests" = "xyes"], [
150 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
151 ])
152 ])
153 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
154
155 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
156 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
157 AC_CHECK_LIB([gmock], [main], [
158 AS_IF([test "x$GMOCK_LIBS" = "x"], [
159 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
160 ])
161 ], [
162 AS_IF([test "x$enable_tests" = "xyes"], [
163 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
164 ])
165 ])
166 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
167])
Patrick Venturee6206562018-03-08 15:36:53 -0800168
Patrick Venture94feffa2019-03-06 09:54:49 -0800169# Code coverage
170AX_CODE_COVERAGE
Patrick Venture94feffa2019-03-06 09:54:49 -0800171AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
172 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
173])
Patrick Venture90e9dbc2019-03-19 09:10:41 -0700174m4_ifdef([_AX_CODE_COVERAGE_RULES],
175 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
176 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
177AX_ADD_AM_MACRO_STATIC([])
Patrick Venture94feffa2019-03-06 09:54:49 -0800178
Patrick Venturee6206562018-03-08 15:36:53 -0800179AC_ARG_ENABLE([oe-sdk],
Patrick Venturef77ecc72018-11-26 09:08:49 -0800180 AS_HELP_STRING(
181 [--enable-oe-sdk],
182 [Link testcases absolutely against OE SDK so they can be ran within it.]
183 )
Patrick Venturee6206562018-03-08 15:36:53 -0800184)
185AC_ARG_VAR(OECORE_TARGET_SYSROOT,
Patrick Venturef77ecc72018-11-26 09:08:49 -0800186 [Path to the OE SDK SYSROOT]
187)
Patrick Venturee6206562018-03-08 15:36:53 -0800188AS_IF([test "x$enable_oe_sdk" == "xyes"],
189 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
190 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
191 )
192 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
193 [
194 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
195 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
196 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
197 ]
198 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
199)
200
James Feist7136a5a2018-07-19 09:52:05 -0700201AC_ARG_ENABLE([configure-dbus],
Patrick Venturef77ecc72018-11-26 09:08:49 -0800202 AS_HELP_STRING(
203 [--enable-configure-dbus], [Enable configuring pid from D-Bus.]
204 )
205)
James Feist7136a5a2018-07-19 09:52:05 -0700206AM_CONDITIONAL(CONFIGURE_DBUS, [test "x$enable_configure_dbus" = "xyes"])
207AS_IF([test "x$enable_configure_dbus" = "xyes"],
James Feistce15e022018-09-26 10:01:33 -0700208 [AC_DEFINE(CONFIGURE_DBUS, [1], [Read configuration from D-Bus.])],
209 [AC_DEFINE(CONFIGURE_DBUS, [0], [Do not read configuration from D-Bus.])]
James Feist7136a5a2018-07-19 09:52:05 -0700210)
211
Vijay Khemka55845432019-06-19 14:25:40 -0700212AC_ARG_VAR(SYSTEMD_TARGET, "Target for starting this service")
213AS_IF([test "x$SYSTEMD_TARGET" == "x"], [SYSTEMD_TARGET="multi-user.target"])
214
Vijay Khemka304c0332020-05-27 17:54:36 -0700215# Make a fully expanded variable for the service definition
216if test "x$prefix" = xNONE; then
217 prefix=$ac_default_prefix
218fi
219# Let make expand exec_prefix.
220if test "x$exec_prefix" = xNONE; then
221 exec_prefix='${prefix}'
222fi
223eval "eval BINDIR=$bindir"
224AC_SUBST([BINDIR])
225
Patrick Venturee6206562018-03-08 15:36:53 -0800226# Create configured output
Patrick Venture7a841b62018-06-13 09:39:46 -0700227AC_CONFIG_FILES([Makefile test/Makefile])
Vijay Khemka55845432019-06-19 14:25:40 -0700228AC_CONFIG_FILES([phosphor-pid-control.service])
Patrick Venturee6206562018-03-08 15:36:53 -0800229AC_OUTPUT