blob: 20a11ee485a0343720e03856a97c050b12ef20c2 [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.
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
23# Checks for programs.
24AC_PROG_CXX
25AC_PROG_CC
26AM_PROG_AR
27AC_PROG_INSTALL
28AC_PROG_MAKE_SET
29
30# Checks for libtool
31LT_INIT # Removes 'unrecognized options: --with-libtool-sysroot'
32
33# Make sure the pkgconfigdata is configured for automake
34PKG_INSTALLDIR
35
36# Checks for typedefs, structures, and compiler characteristics.
37AX_CXX_COMPILE_STDCXX([17], [noext], [mandatory])
38AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CFLAGS])
39AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Wpedantic], [CXXFLAGS])
40
41# We require the linux gpio functionality
42AC_CHECK_HEADERS([linux/gpio.h], [], [
43 AC_MSG_ERROR([Could not find linux/gpio.h])
44])
45
46# Make it possible for users to choose to disable examples
47AC_ARG_ENABLE([examples], AC_HELP_STRING([--disable-examples],
48 [Build example programs]))
49AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" != "xno"])
50
51# Make it possible for users to choose if they want test support
52# explicitly or not at all
53AC_ARG_ENABLE([tests], AC_HELP_STRING([--disable-tests],
54 [Build test cases]))
55
56# Check/set gtest specific functions.
57AS_IF([test "x$enable_tests" != "xno"], [
58 PKG_CHECK_MODULES([GTEST], [gtest], [], [true])
59 PKG_CHECK_MODULES([GMOCK], [gmock], [], [true])
60 AX_PTHREAD
61
62 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
63 AX_APPEND_COMPILE_FLAGS([$GTEST_CFLAGS], [CPPFLAGS])
64 AC_LANG_PUSH([C++])
65 AC_CHECK_HEADERS([gtest/gtest.h], [
66 AS_IF([test "x$GTEST_CFLAGS" = "x"], [
67 AS_IF([test "x$PTHREAD_CFLAGS" = "x"], [
68 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=0"], [GTEST_CFLAGS])
69 ], [
70 AX_APPEND_COMPILE_FLAGS(["-DGTEST_HAS_PTHREAD=1"], [GTEST_CFLAGS])
71 AX_APPEND_COMPILE_FLAGS([$PTHREAD_CFLAGS], [GTEST_CFLAGS])
72 ])
73 ])
74 ], [
75 AS_IF([test "x$enable_tests" = "xyes"], [
76 AC_MSG_ERROR([Testing enabled but could not find gtest/gtest.h])
77 ])
78 ])
79 AC_LANG_POP([C++])
80 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
81
82 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
83 AX_APPEND_COMPILE_FLAGS([$GMOCK_CFLAGS], [CPPFLAGS])
84 AC_LANG_PUSH([C++])
85 AC_CHECK_HEADERS([gmock/gmock.h], [], [
86 AS_IF([test "x$enable_tests" = "xyes"], [
87 AC_MSG_ERROR([Testing enabled but could not find gmock/gmock.h])
88 ])
89 ])
90 AC_LANG_POP([C++])
91 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [CPPFLAGS])
92
93 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
94 AX_APPEND_COMPILE_FLAGS([$GTEST_LIBS], [LDFLAGS])
95 AC_CHECK_LIB([gtest], [main], [
96 AS_IF([test "x$GTEST_LIBS" = "x"], [
97 AX_APPEND_COMPILE_FLAGS([-lgtest], [GTEST_LIBS])
98 ])
99 ], [
100 AS_IF([test "x$enable_tests" = "xyes"], [
101 AC_MSG_ERROR([Testing enabled but couldn't find gtest libs])
102 ])
103 ])
104 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
105
106 AX_SAVE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
107 AX_APPEND_COMPILE_FLAGS([$GMOCK_LIBS], [LDFLAGS])
108 AC_CHECK_LIB([gmock], [main], [
109 AS_IF([test "x$GMOCK_LIBS" = "x"], [
110 AX_APPEND_COMPILE_FLAGS([-lgmock], [GMOCK_LIBS])
111 ])
112 ], [
113 AS_IF([test "x$enable_tests" = "xyes"], [
114 AC_MSG_ERROR([Testing enabled but couldn't find gmock libs])
115 ])
116 ])
117 AX_RESTORE_FLAGS_WITH_PREFIX(OLD, [LDFLAGS])
118])
119
120# Check for valgrind
121AS_IF([test "x$enable_tests" != "xno"], [
122 m4_foreach([vgtool], [valgrind_tool_list],
123 [AX_VALGRIND_DFLT(vgtool, [off])])
124 AX_VALGRIND_DFLT([memcheck], [on])
125 AX_VALGRIND_CHECK
126 AM_EXTRA_RECURSIVE_TARGETS([check-valgrind])
127 m4_foreach([vgtool], [valgrind_tool_list],
128 [AM_EXTRA_RECURSIVE_TARGETS([check-valgrind-]vgtool)])
129])
130
131# Code coverage
132AS_IF([test "x$enable_tests" != "xno"], [
133 AX_CODE_COVERAGE
134 AM_EXTRA_RECURSIVE_TARGETS([check-code-coverage])
135])
136
137# Append -Werror after doing autoconf compiler checks
138# Otherwise some perfectly valid checks can fail and cause our
139# final configuratin to be broken.
140AC_ARG_ENABLE([werror], AC_HELP_STRING([--disable-werror], [Whether to automatically add -Werror CFLAGS]))
141AS_IF([test "x$enable_tests" != "xno"], [
142 AX_APPEND_COMPILE_FLAGS([-Werror], [CFLAGS])
143 AX_APPEND_COMPILE_FLAGS([-Werror], [CXXFLAGS])
144])
145
146# Create configured output
147AC_CONFIG_FILES([Makefile example/Makefile src/Makefile test/Makefile])
148AC_CONFIG_FILES([src/gpioplus.pc])
149AC_OUTPUT