blob: b555c766ab003b5eb8d2c1a57a25ab0455733a21 [file] [log] [blame]
Patrick Venturec7ca2912018-11-02 11:38:33 -07001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([phosphor-ipmi-flash], [0.1], [https://github.com/openbmc/phosphor-ipmi-flash/issues])
4AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
Patrick Venture30993b32018-11-28 14:52:00 -08006AC_CONFIG_MACRO_DIRS([m4])
Patrick Venture9dc342a2019-03-18 08:43:36 -07007AM_INIT_AUTOMAKE([subdir-objects -Wall -Wno-portability -Werror foreign dist-xz])
Patrick Venturec7ca2912018-11-02 11:38:33 -07008AM_SILENT_RULES([yes])
9
Patrick Venture2f3b4b62019-03-08 13:22:40 -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 Ventureac570a12019-05-08 08:53:16 -070023# If building tests, enable both hardware options that are configuration controlled
24AS_IF([test "x$enable_tests" = "xyes"], [enable_static_layout=yes])
25AS_IF([test "x$enable_tests" = "xyes"], [enable_tarball_ubi=yes])
26
27AS_IF([test "x$enable_tests" = "xyes"], [enable_pci_bridge=yes])
28AS_IF([test "x$enable_tests" = "xyes"], [enable_aspeed_p2a=yes])
29
30# You can only build main.o with one of the lpc implementations, however, specify both.
31AS_IF([test "x$enable_tests" = "xyes"], [enable_lpc_bridge=yes])
32AS_IF([test "x$enable_tests" = "xyes"], [enable_aspeed_lpc=yes])
33AS_IF([test "x$enable_tests" = "xyes"], [enable_nuvoton_lpc=yes])
34
Patrick Venturec7ca2912018-11-02 11:38:33 -070035# Checks for programs.
36AC_PROG_CXX
37AM_PROG_AR
38AC_PROG_INSTALL
39AC_PROG_MAKE_SET
40
41# Checks for typedefs, structures, and compiler characteristics.
42AX_CXX_COMPILE_STDCXX_17([noext])
43AX_APPEND_COMPILE_FLAGS([-Wall -Werror], [CXXFLAGS])
44
45# Checks for library functions.
46LT_INIT # Required for systemd linking
47
48# Checks for libraries.
Patrick Venture4b4ea212018-11-21 21:23:53 -080049PKG_CHECK_MODULES(
50 [SDBUSPLUS],
51 [sdbusplus],
Patrick Ventureac11ae92019-01-16 12:43:00 -080052 [AC_DEFINE(HAVE_SDBUSPLUS, [1], [Found openbmc/sdbusplus package])],
Patrick Venture4b4ea212018-11-21 21:23:53 -080053 [AC_MSG_ERROR([The openbmc/sdbusplus package is required])]
54)
Patrick Venture4845a722019-02-13 07:45:57 -080055PKG_CHECK_MODULES([PHOSPHOR_LOGGING], [phosphor-logging])
Patrick Venture8b3b3252019-03-07 07:50:13 -080056PKG_CHECK_MODULES(
57 [IPMIBLOB],
58 [ipmiblob],
59 [],
60 [AC_MSG_ERROR(
61 [Could not find ipmiblob...openbmc/ipmi-blob-tool package required])
62 ]
63)
Patrick Venturefe297fe2019-05-03 10:24:31 -070064PKG_CHECK_MODULES(
65 [PCILIB],
66 [libpci],
67 [],
68 [AC_MSG_ERROR([Could not find libpci... pciutils package required])]
69)
Patrick Venture4b4ea212018-11-21 21:23:53 -080070AC_CHECK_HEADER(
71 [blobs-ipmid],
72 [AC_MSG_ERROR(["phosphor-ipmi-blobs required and not found."])]
73)
Patrick Venturec7ca2912018-11-02 11:38:33 -070074AX_PTHREAD([], [AC_MSG_ERROR(["pthread required and not found"])])
75
Patrick Venturefa6c4d92018-11-02 18:34:53 -070076# Configurability
Patrick Venturecf10cda2019-05-15 10:35:10 -070077
78# Enable building the host tool (default: yes)
79AC_ARG_ENABLE([build-host-tool],
80 AC_HELP_STRING([--disable-build-host-tool], [Disable building the host tool])
81)
82AM_CONDITIONAL([BUILD_HOST_TOOL], [test "x$enable_build_host_tool" != "xno"])
83
Patrick Venturefa6c4d92018-11-02 18:34:53 -070084# Enable static layout for firmware image staging.
85AC_ARG_ENABLE([static-layout],
86 AS_HELP_STRING([--enable-static-layout],
87 [Enable static layout firmware update via Blobs]))
88AS_IF([test "x$enable_static_layout" = "xyes"], [
89 AX_APPEND_COMPILE_FLAGS([-DENABLE_STATIC_LAYOUT], [CXXFLAGS])
90])
Patrick Ventured46b8112018-11-15 13:38:55 -080091# Enable tarball for firmware image staging.
92AC_ARG_ENABLE([tarball-ubi],
93 AS_HELP_STRING([--enable-tarball-ubi],
94 [Enable tarball firmware update via Blobs]))
Patrick Venture80bfa672019-05-08 15:24:48 -070095AS_IF([test "x$enable_tarball_ubi" = "xyes"], [
Patrick Ventured46b8112018-11-15 13:38:55 -080096 AX_APPEND_COMPILE_FLAGS([-DENABLE_TARBALL_UBI], [CXXFLAGS])
97])
Patrick Venture002916a2018-11-15 10:38:07 -080098
Patrick Venture4306f682018-11-06 11:06:02 -080099# Enable P2A, and or LPC (block-transfer is always enabled).
Patrick Venture192d60f2018-11-06 11:11:59 -0800100AC_ARG_ENABLE([pci-bridge],
101 AS_HELP_STRING([--enable-pci-bridge],
102 [Enable pci-bridge transport mechanism]))
Patrick Ventureac570a12019-05-08 08:53:16 -0700103AM_CONDITIONAL(ENABLE_PCI_BRIDGE, [test "x$enable_pci_bridge" = "xyes"])
Patrick Venture192d60f2018-11-06 11:11:59 -0800104AS_IF([test "x$enable_pci_bridge" = "xyes"], [
105 AX_APPEND_COMPILE_FLAGS([-DENABLE_PCI_BRIDGE], [CXXFLAGS])
106])
107AC_ARG_ENABLE([lpc-bridge],
108 AS_HELP_STRING([--enable-lpc-bridge],
109 [Enable lpc-bridge transport mechanism]))
Patrick Ventureac570a12019-05-08 08:53:16 -0700110AM_CONDITIONAL(ENABLE_LPC_BRIDGE, [test "x$enable_lpc_bridge" = "xyes"])
Patrick Venture192d60f2018-11-06 11:11:59 -0800111AS_IF([test "x$enable_lpc_bridge" = "xyes"], [
112 AX_APPEND_COMPILE_FLAGS([-DENABLE_LPC_BRIDGE], [CXXFLAGS])
113])
Patrick Venturefa6c4d92018-11-02 18:34:53 -0700114
Patrick Venture002916a2018-11-15 10:38:07 -0800115# The address used for mapping P2A or LPC into the BMC's memory-space:
116# e.g. https://github.com/openbmc/linux/blob/1da2ce51886a3b2f5db2087f26c661e13ee13b84/arch/arm/boot/dts/aspeed-bmc-quanta-q71l.dts#L26
117# or https://github.com/openbmc/linux/blob/1da2ce51886a3b2f5db2087f26c661e13ee13b84/arch/arm/boot/dts/aspeed-bmc-opp-zaius.dts#L166
118# for PCI, this address is passed back to the host and is used directly.
119AC_ARG_VAR(MAPPED_ADDRESS, [The base address of the memory region reserved for mapping.])
120AS_IF([test "x$MAPPED_ADDRESS" == "x"],
Patrick Venturece6b8742019-01-15 12:11:02 -0800121 [AC_DEFINE_UNQUOTED(MAPPED_ADDRESS, [0], [Default address to 0.])],
122 [AC_DEFINE_UNQUOTED(MAPPED_ADDRESS, [$MAPPED_ADDRESS], [Value for memory region mapping.])]
Patrick Venture002916a2018-11-15 10:38:07 -0800123)
124
Patrick Venturee7728422018-11-14 20:16:33 -0800125AC_ARG_ENABLE([aspeed-lpc],
126 AS_HELP_STRING([--enable-aspeed-lpc],
127 [Enable external transfers using Aspeed LPC]))
Patrick Ventureac570a12019-05-08 08:53:16 -0700128AM_CONDITIONAL(ENABLE_ASPEED_LPC, [test "x$enable_aspeed_lpc" = "xyes"])
Patrick Venturee7728422018-11-14 20:16:33 -0800129AS_IF([test "x$enable_aspeed_lpc" = "xyes"], [
Patrick Venture39b13052019-05-01 13:23:52 -0700130 AC_CHECK_HEADER(
131 [linux/aspeed-lpc-ctrl.h],
132 [],
133 [AC_MSG_ERROR([Could not find linux/aspeed-lpc-ctrl.h])]
Patrick Venturee7728422018-11-14 20:16:33 -0800134 )
Patrick Venture39b13052019-05-01 13:23:52 -0700135
Patrick Venturee7728422018-11-14 20:16:33 -0800136 AX_APPEND_COMPILE_FLAGS([-DASPEED_LPC], [CXXFLAGS])
137])
138AC_ARG_ENABLE([nuvoton-lpc],
139 AS_HELP_STRING([--enable-nuvoton-lpc],
140 [Enable external transfers using Nuvoton LPC SHM]))
Patrick Ventureac570a12019-05-08 08:53:16 -0700141AM_CONDITIONAL(ENABLE_NUVOTON_LPC, [test "x$enable_nuvoton_lpc" = "xyes"])
Patrick Venturee7728422018-11-14 20:16:33 -0800142AS_IF([test "x$enable_nuvoton_lpc" = "xyes"], [
143 AX_APPEND_COMPILE_FLAGS([-DNUVOTON_LPC], [CXXFLAGS])
144])
145
Patrick Venturea68d3442019-04-30 12:51:07 -0700146AC_ARG_ENABLE([aspeed-p2a],
147 AS_HELP_STRING([--enable-aspeed-p2a],
148 [Enable external transfers using Aspeed PCI-to-AHB]))
Patrick Ventureac570a12019-05-08 08:53:16 -0700149AM_CONDITIONAL(ENABLE_ASPEED_P2A, [test "x$enable_aspeed_p2a" = "xyes"])
Patrick Venturea68d3442019-04-30 12:51:07 -0700150AS_IF([test "x$enable_aspeed_p2a" = "xyes"], [
151 AC_CHECK_HEADER(linux/aspeed-p2a-ctrl.h,
152 [HAVE_UAPI_LINUX_P2A_CTRL_H=""],
153 [HAVE_UAPI_LINUX_P2A_CTRL_H="-I linux/aspeed-p2a-ctrl.h"])
154 AS_IF([test "$HAVE_UAPI_LINUX_P2A_CTRL_H" != ""],
155 AC_MSG_WARN([Could not find linux/aspeed-p2a-ctrl.h: Attempting to download locally for building from openbmc/linux/+/dev-5.0])
156 AC_SUBST([PCI_BMC_DL],
157 [`mkdir -p linux;wget https://raw.githubusercontent.com/openbmc/linux/dev-5.0/include/uapi/linux/aspeed-p2a-ctrl.h -O linux/aspeed-p2a-ctrl.h`])
158 )
159 AX_APPEND_COMPILE_FLAGS([-DASPEED_P2A], [CXXFLAGS])
160])
161
Patrick Venture35a82f32018-11-15 13:34:22 -0800162AC_ARG_VAR(STATIC_HANDLER_STAGED_NAME, [The file to use for staging the firmware update.])
163AS_IF([test "x$STATIC_HANDLER_STAGED_NAME" == "x"], [STATIC_HANDLER_STAGED_NAME="/run/initramfs/bmc-image"])
164AC_DEFINE_UNQUOTED([STATIC_HANDLER_STAGED_NAME], ["$STATIC_HANDLER_STAGED_NAME"], [The file to use for staging the firmware update.])
165
Patrick Ventured46b8112018-11-15 13:38:55 -0800166AC_ARG_VAR(TARBALL_STAGED_NAME, [The file to use for staging the firmware update.])
167AS_IF([test "x$TARBALL_STAGED_NAME" == "x"], [TARBALL_STAGED_NAME="/tmp/image-update.tar"])
168AC_DEFINE_UNQUOTED([TARBALL_STAGED_NAME], ["$TARBALL_STAGED_NAME"], [The file to use for staging the firmware update.])
169
Patrick Venture35a82f32018-11-15 13:34:22 -0800170AC_ARG_VAR(HASH_FILENAME, [The file to use for the hash provided.])
171AS_IF([test "x$HASH_FILENAME" == "x"], [HASH_FILENAME="/tmp/bmc.sig"])
172AC_DEFINE_UNQUOTED([HASH_FILENAME], ["$HASH_FILENAME"], [The file to use for the hash provided.])
173
Patrick Venture440bc382018-12-13 19:10:55 -0800174AC_CHECK_HEADER(linux/ipmi.h, [HAVE_LINUX_IPMI_H=""], [HAVE_LINUX_IPMI_H="-I linux/ipmi.h"])
175AS_IF([test "$HAVE_LINUX_IPMI_H" != ""],
176 AC_MSG_WARN([Could not find linux/ipmi.h: Attempting to download locally for building from openbmc/linux/+/dev-4.18])
177 AC_SUBST([IPMI_BMC_DL],
178 [`mkdir -p linux;wget https://raw.githubusercontent.com/openbmc/linux/dev-4.18/include/uapi/linux/ipmi.h -O linux/ipmi.h`])
179)
180
181AC_CHECK_HEADER(linux/ipmi_msgdefs.h, [HAVE_LINUX_IPMIMSGDEFS_H=""], [HAVE_LINUX_IPMIMSGDEFS_H="-I linux/ipmi_msgdefs.h"])
182AS_IF([test "$HAVE_LINUX_IPMIMSGDEFS_H" != ""],
183 AC_MSG_WARN([Could not find linux/ipmi_msgdefs.h: Attempting to download locally for building from openbmc/linux/+/dev-4.18])
184 AC_SUBST([IPMIMSG_BMC_DL],
185 [`mkdir -p linux;wget https://raw.githubusercontent.com/openbmc/linux/dev-4.18/include/uapi/linux/ipmi_msgdefs.h -O linux/ipmi_msgdefs.h`])
186)
187
Patrick Venture6bc04f92019-03-06 13:49:21 -0800188# Make it possible for users to choose if they want test support
189# explicitly or not at all
190AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
191 [Build test cases]))
192
Patrick Venturec7ca2912018-11-02 11:38:33 -0700193# Check/set gtest specific functions.
Patrick Venture6bc04f92019-03-06 13:49:21 -0800194AS_IF([test "x$enable_tests" != "xno"], [
195 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
196 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
197 AX_PTHREAD
198
199 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
200 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
201 AC_LANG_PUSH([C++])
202 AC_CHECK_HEADERS([gtest/gtest.h], [
203 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
204 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
205 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
206 ], [
207 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
208 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
209 ])
210 ])
211 ], [
212 AS_IF([test "x$enable_tests" = "xyes"], [
213 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
214 ])
215 ])
216 AC_LANG_POP([C++])
217 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
218
219 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
220 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
221 AC_LANG_PUSH([C++])
222 AC_CHECK_HEADERS([gmock/gmock.h], [], [
223 AS_IF([test "x$enable_tests" = "xyes"], [
224 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
225 ])
226 ])
227 AC_LANG_POP([C++])
228 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
229
230 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
231 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
232 AC_CHECK_LIB([gtest], [main], [
233 AS_IF([test "x$GTEST_LIBS" = "x"], [
234 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
235 ])
236 ], [
237 AS_IF([test "x$enable_tests" = "xyes"], [
238 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
239 ])
240 ])
241 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
242
243 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
244 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
245 AC_CHECK_LIB([gmock], [main], [
246 AS_IF([test "x$GMOCK_LIBS" = "x"], [
247 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
248 ])
249 ], [
250 AS_IF([test "x$enable_tests" = "xyes"], [
251 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
252 ])
253 ])
254 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
255])
Patrick Venturec7ca2912018-11-02 11:38:33 -0700256
Patrick Venture4679e502019-03-19 11:27:00 -0700257# Check for valgrind
258AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
259m4_foreach([vgtool], [valgrind_tool_list],
260 [AX_VALGRIND_DFLT(vgtool, [off])])
261AX_VALGRIND_DFLT([memcheck], [on])
262AX_VALGRIND_CHECK
263AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
264m4_foreach([vgtool], [valgrind_tool_list],
265 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
266
Patrick Venture2f3b4b62019-03-08 13:22:40 -0800267# Code coverage
268AX_CODE_COVERAGE
Patrick Venture2f3b4b62019-03-08 13:22:40 -0800269AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
270 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
271])
Patrick Venture9dc342a2019-03-18 08:43:36 -0700272m4_ifdef([_AX_CODE_COVERAGE_RULES],
273 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
274 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
275AX_ADD_AM_MACRO_STATIC([])
Patrick Venture2f3b4b62019-03-08 13:22:40 -0800276
Patrick Venturec7ca2912018-11-02 11:38:33 -0700277# Add --enable-oe-sdk flag to configure script
278AC_ARG_ENABLE([oe-sdk],
279 AS_HELP_STRING([--enable-oe-sdk], [Link testcases absolutely against OE SDK so they can be ran within it.])
280)
281
282# Check for OECORE_TARGET_SYSROOT in the environment.
283AC_ARG_VAR(OECORE_TARGET_SYSROOT,
284 [Path to the OE SDK SYSROOT])
285
286# Configure OESDK_TESTCASE_FLAGS environment variable, which will be later
287# used in test/Makefile.am
288AS_IF([test "x$enable_oe_sdk" == "xyes"],
289 AS_IF([test "x$OECORE_TARGET_SYSROOT" == "x"],
290 AC_MSG_ERROR([OECORE_TARGET_SYSROOT must be set with --enable-oe-sdk])
291 )
292 AC_MSG_NOTICE([Enabling OE-SDK at $OECORE_TARGET_SYSROOT])
293 [
294 testcase_flags="-Wl,-rpath,\${OECORE_TARGET_SYSROOT}/lib"
295 testcase_flags="${testcase_flags} -Wl,-rpath,\${OECORE_TARGET_SYSROOT}/usr/lib"
296 testcase_flags="${testcase_flags} -Wl,-dynamic-linker,`find \${OECORE_TARGET_SYSROOT}/lib/ld-*.so | sort -r -n | head -n1`"
297 ]
298 AC_SUBST([OESDK_TESTCASE_FLAGS], [$testcase_flags])
299)
300
301# Create configured output
Patrick Venturebf58cd62018-12-11 09:05:46 -0800302AC_CONFIG_FILES([Makefile test/Makefile tools/Makefile])
Patrick Venturec7ca2912018-11-02 11:38:33 -0700303AC_OUTPUT