blob: aef8ae7360c5f8f2fc23169980c876218c3f558e [file] [log] [blame]
William A. Kennington III1d250552018-08-16 00:46:34 -07001# Initialization
2AC_PREREQ([2.69])
3AC_INIT([gpioplus], [0.1], [https://github.com/openbmc/gpioplus/issues])
4AC_LANG([C++])
5AC_CONFIG_HEADERS([config.h])
6AC_CONFIG_MACRO_DIRS([m4])
7AC_CONFIG_AUX_DIR([build-aux])
8AM_INIT_AUTOMAKE([nostdinc foreign subdir-objects -Wall -Werror dist-xz tar-ustar])
9AM_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.
William A. Kennington IIId8c0a7f2018-08-16 14:00:02 -070014AS_IF([test "x$enable_tests" = "xno"], [enable_code_coverage=no])
William A. Kennington III1d250552018-08-16 00:46:34 -070015AS_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# We require the linux gpio functionality
43AC_CHECK_HEADERS([linux/gpio.h], [], [
44 AC_MSG_ERROR([Could not find linux/gpio.h])
45])
46
47# Make it possible for users to choose to disable examples
48AC_ARG_ENABLE([examples], AC_HELP_STRING([--disable-examples],
49 [Build example programs]))
50AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" != "xno"])
51
52# Make it possible for users to choose if they want test support
53# explicitly or not at all
54AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
55 [Build test cases]))
56
57# Check/set gtest specific functions.
58AS_IF([test "x$enable_tests" != "xno"], [
59 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
60 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
61 AX_PTHREAD
62
63 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
64 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
65 AC_LANG_PUSH([C++])
66 AC_CHECK_HEADERS([gtest/gtest.h], [
67 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
68 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
69 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
70 ], [
71 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
72 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
73 ])
74 ])
75 ], [
76 AS_IF([test "x$enable_tests" = "xyes"], [
77 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
78 ])
79 ])
80 AC_LANG_POP([C++])
81 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
82
83 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
84 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
85 AC_LANG_PUSH([C++])
86 AC_CHECK_HEADERS([gmock/gmock.h], [], [
87 AS_IF([test "x$enable_tests" = "xyes"], [
88 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
89 ])
90 ])
91 AC_LANG_POP([C++])
92 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
93
94 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
95 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
96 AC_CHECK_LIB([gtest], [main], [
97 AS_IF([test "x$GTEST_LIBS" = "x"], [
98 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
99 ])
100 ], [
101 AS_IF([test "x$enable_tests" = "xyes"], [
102 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
103 ])
104 ])
105 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
106
107 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
108 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
109 AC_CHECK_LIB([gmock], [main], [
110 AS_IF([test "x$GMOCK_LIBS" = "x"], [
111 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
112 ])
113 ], [
114 AS_IF([test "x$enable_tests" = "xyes"], [
115 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
116 ])
117 ])
118 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
119])
120
121# Check for valgrind
William A. Kennington IIId8c0a7f2018-08-16 14:00:02 -0700122AS_IF([test "x$enable_tests" = "xno"], [enable_valgrind=no])
123m4_foreach([vgtool], [valgrind_tool_list],
124 [AX_VALGRIND_DFLT(vgtool, [off])])
125AX_VALGRIND_DFLT([memcheck], [on])
126AX_VALGRIND_CHECK
127AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
128m4_foreach([vgtool], [valgrind_tool_list],
129 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
William A. Kennington III1d250552018-08-16 00:46:34 -0700130
131# Code coverage
William A. Kennington IIId8c0a7f2018-08-16 14:00:02 -0700132AX_CODE_COVERAGE
133AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
William A. Kennington III1d250552018-08-16 00:46:34 -0700134
135# Append -Werror after doing autoconf compiler checks
136# Otherwise some perfectly valid checks can fail and cause our
137# final configuratin to be broken.
138AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS]))
139AS_IF([test "x$enable_tests" != "xno"], [
140 AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS])
141 AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS])
142])
143
144# Create configured output
145AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile])
146AC_CONFIG_FILES([src/gpioplus.pc])
147AC_OUTPUT