blob: 12762f0f3bcce87ba1f8eb0a3f92c8e5578863c3 [file] [log] [blame]
Patrick Venture123b5c02019-03-05 14:01:00 -08001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([ipmi-blob-tool], [0.1], [https://github.com/openbmc/ipmi-blob-tool/issues])
4AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
6AC_CONFIG_MACRO_DIRS([m4])
7AC_CONFIG_AUX_DIR([build-aux])
Patrick Venture51372f02019-03-18 09:06:56 -07008AM_INIT_AUTOMAKE([nostdinc foreign subdir-objects -Wall -Wno-portability -Werror dist-xz tar-ustar])
Patrick Venture123b5c02019-03-05 14:01:00 -08009AM_SILENT_RULES([yes])
10
11# Make sure the default CFLAGS of `-O2 -g` don't override CODE_COVERAGE_CFLAGS
12# It is important that this comes before AC_PROG_C{C,XX}, as we are attempting
13# to stop them from populating default CFLAGS and CXXFLAGS.
14AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
15AS_IF([test "x$enable_code_coverage" != "xno"], [
16 AS_IF([test "x${CXXFLAGS+set}" != "xset"], [
17 AC_SUBST(CXXFLAGS, [""])
18 ])
19 AS_IF([test "x${CFLAGS+set}" != "xset"], [
20 AC_SUBST(CFLAGS, [""])
21 ])
22])
23
24# Checks for programs.
25AC_PROG_CXX
26AC_PROG_CC
27AM_PROG_AR
28AC_PROG_INSTALL
29AC_PROG_MAKE_SET
30
31# Checks for libtool
32LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot'
33
34# Make sure the pkgconfigdata is configured for automake
35PKG_INSTALLDIR
36
37# Checks for typedefs, structures, and compiler characteristics.
38AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
39AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS])
40AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS])
41
42# Make it possible for users to choose if they want test support
43# explicitly or not at all
44AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
45 [Build test cases]))
46
47# Check/set gtest specific functions.
48AS_IF([test "x$enable_tests" != "xno"], [
49 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
50 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
51 AX_PTHREAD
52
53 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
54 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
55 AC_LANG_PUSH([C++])
56 AC_CHECK_HEADERS([gtest/gtest.h], [
57 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
58 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
59 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
60 ], [
61 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
62 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
63 ])
64 ])
65 ], [
66 AS_IF([test "x$enable_tests" = "xyes"], [
67 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
68 ])
69 ])
70 AC_LANG_POP([C++])
71 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
72
73 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
74 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
75 AC_LANG_PUSH([C++])
76 AC_CHECK_HEADERS([gmock/gmock.h], [], [
77 AS_IF([test "x$enable_tests" = "xyes"], [
78 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
79 ])
80 ])
81 AC_LANG_POP([C++])
82 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
83
84 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
85 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
86 AC_CHECK_LIB([gtest], [main], [
87 AS_IF([test "x$GTEST_LIBS" = "x"], [
88 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
89 ])
90 ], [
91 AS_IF([test "x$enable_tests" = "xyes"], [
92 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
93 ])
94 ])
95 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
96
97 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
98 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
99 AC_CHECK_LIB([gmock], [main], [
100 AS_IF([test "x$GMOCK_LIBS" = "x"], [
101 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
102 ])
103 ], [
104 AS_IF([test "x$enable_tests" = "xyes"], [
105 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
106 ])
107 ])
108 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
109])
110
111# Check for valgrind
112AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
113m4_foreach([vgtool], [valgrind_tool_list],
114 [AX_VALGRIND_DFLT(vgtool, [off])])
115AX_VALGRIND_DFLT([memcheck], [on])
116AX_VALGRIND_CHECK
117AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
118m4_foreach([vgtool], [valgrind_tool_list],
119 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
120
121# Code coverage
122AX_CODE_COVERAGE
Patrick Venture123b5c02019-03-05 14:01:00 -0800123AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
124 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
125])
Patrick Venture51372f02019-03-18 09:06:56 -0700126AS_IF([test "x$CODE_COVERAGE_ENABLED" = "xyes"], [
127 AX_APPEND_COMPILE_FLAGS([-DHAVE_GCOV], [CODE_COVERAGE_CPPFLAGS])
128])
129m4_ifdef([_AX_CODE_COVERAGE_RULES],
130 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [true])],
131 [AM_CONDITIONAL(AUTOCONF_CODE_COVERAGE_2019_01_06, [false])])
132AX_ADD_AM_MACRO_STATIC([])
Patrick Venture123b5c02019-03-05 14:01:00 -0800133
134# Append -Werror after doing autoconf compiler checks
135# Otherwise some perfectly valid checks can fail and cause our
136# final configuratin to be broken.
137AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS]))
138AS_IF([test "x$enable_tests" != "xno"], [
139 AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS])
140 AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS])
141])
142
143# Create configured output
144AC_CONFIG_FILES([Makefile src/Makefile test/Makefile])
145AC_CONFIG_FILES([src/ipmiblob.pc])
146AC_OUTPUT