Refix bug causing plover_get_program_directory() to fail when executable is in a root directory
1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_valgrind_check.html
3 # ===========================================================================
11 # Checks whether Valgrind is present and, if so, allows running `make
12 # check` under a variety of Valgrind tools to check for memory and
15 # Defines VALGRIND_CHECK_RULES which should be substituted in your
16 # Makefile; and $enable_valgrind which can be used in subsequent configure
17 # output. VALGRIND_ENABLED is defined and substituted, and corresponds to
18 # the value of the --enable-valgrind option, which defaults to being
19 # enabled if Valgrind is installed and disabled otherwise.
21 # If unit tests are written using a shell script and automake's
22 # LOG_COMPILER system, the $(VALGRIND) variable can be used within the
23 # shell scripts to enable Valgrind, as described here:
25 # https://www.gnu.org/software/gnulib/manual/html_node/Running-self_002dtests-under-valgrind.html
35 # @VALGRIND_CHECK_RULES@
36 # VALGRIND_SUPPRESSIONS_FILES = my-project.supp
37 # EXTRA_DIST = my-project.supp
39 # This results in a "check-valgrind" rule being added to any Makefile.am
40 # which includes "@VALGRIND_CHECK_RULES@" (assuming the module has been
41 # configured with --enable-valgrind). Running `make check-valgrind` in
42 # that directory will run the module's test suite (`make check`) once for
43 # each of the available Valgrind tools (out of memcheck, helgrind, drd and
44 # sgcheck), and will output results to test-suite-$toolname.log for each.
45 # The target will succeed if there are zero errors and fail otherwise.
47 # Alternatively, a "check-valgrind-$TOOL" rule will be added, for $TOOL in
48 # memcheck, helgrind, drd and sgcheck. These are useful because often only
49 # some of those tools can be ran cleanly on a codebase.
51 # The macro supports running with and without libtool.
55 # Copyright (c) 2014, 2015, 2016 Philip Withnall <philip.withnall@collabora.co.uk>
57 # Copying and distribution of this file, with or without modification, are
58 # permitted in any medium without royalty provided the copyright notice
59 # and this notice are preserved. This file is offered as-is, without any
64 AC_DEFUN([AX_VALGRIND_CHECK],[
65 dnl Check for --enable-valgrind
66 AC_ARG_ENABLE([valgrind],
67 [AS_HELP_STRING([--enable-valgrind], [Whether to enable Valgrind on the unit tests])],
68 [enable_valgrind=$enableval],[enable_valgrind=])
70 AS_IF([test "$enable_valgrind" != "no"],[
72 AC_CHECK_PROG([VALGRIND],[valgrind],[valgrind])
73 AS_IF([test "$VALGRIND" = ""],[
74 AS_IF([test "$enable_valgrind" = "yes"],[
75 AC_MSG_ERROR([Could not find valgrind; either install it or reconfigure with --disable-valgrind])
84 AM_CONDITIONAL([VALGRIND_ENABLED],[test "$enable_valgrind" = "yes"])
85 AC_SUBST([VALGRIND_ENABLED],[$enable_valgrind])
87 # Check for Valgrind tools we care about.
88 m4_define([valgrind_tool_list],[[memcheck], [helgrind], [drd], [exp-sgcheck]])
90 AS_IF([test "$VALGRIND" != ""],[
91 m4_foreach([vgtool],[valgrind_tool_list],[
92 m4_define([vgtooln],AS_TR_SH(vgtool))
93 m4_define([ax_cv_var],[ax_cv_valgrind_tool_]vgtooln)
94 AC_CACHE_CHECK([for Valgrind tool ]vgtool,ax_cv_var,[
96 AS_IF([`$VALGRIND --tool=vgtool --help >/dev/null 2>&1`],[
101 AC_SUBST([VALGRIND_HAVE_TOOL_]vgtooln,[$ax_cv_var])
105 [VALGRIND_CHECK_RULES='
109 # - VALGRIND_SUPPRESSIONS_FILES: Space-separated list of Valgrind suppressions
110 # files to load. (Default: empty)
111 # - VALGRIND_FLAGS: General flags to pass to all Valgrind tools.
112 # (Default: --num-callers=30)
113 # - VALGRIND_$toolname_FLAGS: Flags to pass to Valgrind $toolname (one of:
114 # memcheck, helgrind, drd, sgcheck). (Default: various)
117 VALGRIND_SUPPRESSIONS ?= $(addprefix --suppressions=,$(VALGRIND_SUPPRESSIONS_FILES))
118 VALGRIND_FLAGS ?= --num-callers=30
119 VALGRIND_memcheck_FLAGS ?= --leak-check=full --show-reachable=no
120 VALGRIND_helgrind_FLAGS ?= --history-level=approx
121 VALGRIND_drd_FLAGS ?=
122 VALGRIND_sgcheck_FLAGS ?=
125 valgrind_tools = memcheck helgrind drd sgcheck
126 valgrind_log_files = $(addprefix test-suite-,$(addsuffix .log,$(valgrind_tools)))
128 valgrind_memcheck_flags = --tool=memcheck $(VALGRIND_memcheck_FLAGS)
129 valgrind_helgrind_flags = --tool=helgrind $(VALGRIND_helgrind_FLAGS)
130 valgrind_drd_flags = --tool=drd $(VALGRIND_drd_FLAGS)
131 valgrind_sgcheck_flags = --tool=exp-sgcheck $(VALGRIND_sgcheck_FLAGS)
133 valgrind_quiet = $(valgrind_quiet_$(V))
134 valgrind_quiet_ = $(valgrind_quiet_$(AM_DEFAULT_VERBOSITY))
135 valgrind_quiet_0 = --quiet
137 # Support running with and without libtool.
139 valgrind_lt = $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=execute
144 # Use recursive makes in order to ignore errors during check
146 ifeq ($(VALGRIND_ENABLED),yes)
147 -$(foreach tool,$(valgrind_tools), \
148 $(if $(VALGRIND_HAVE_TOOL_$(tool))$(VALGRIND_HAVE_TOOL_exp_$(tool)), \
149 $(MAKE) $(AM_MAKEFLAGS) -k check-valgrind-tool VALGRIND_TOOL=$(tool); \
153 @echo "Need to reconfigure with --enable-valgrind"
157 VALGRIND_TESTS_ENVIRONMENT = \
158 $(TESTS_ENVIRONMENT) \
159 env VALGRIND=$(VALGRIND) \
160 G_SLICE=always-malloc,debug-blocks \
161 G_DEBUG=fatal-warnings,fatal-criticals,gc-friendly
163 VALGRIND_LOG_COMPILER = \
165 $(VALGRIND) $(VALGRIND_SUPPRESSIONS) --error-exitcode=1 $(VALGRIND_FLAGS)
168 ifeq ($(VALGRIND_ENABLED),yes)
169 $(MAKE) check-TESTS \
170 TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
171 LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
172 LOG_FLAGS="$(valgrind_$(VALGRIND_TOOL)_flags)" \
173 TEST_SUITE_LOG=test-suite-$(VALGRIND_TOOL).log
175 @echo "Need to reconfigure with --enable-valgrind"
178 check-valgrind-memcheck:
179 ifeq ($(VALGRIND_ENABLED),yes)
180 $(MAKE) check-TESTS \
181 TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
182 LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
183 LOG_FLAGS="$(valgrind_memcheck_flags)" \
184 TEST_SUITE_LOG=test-suite-memcheck.log
186 @echo "Need to reconfigure with --enable-valgrind"
189 check-valgrind-helgrind:
190 ifeq ($(VALGRIND_ENABLED),yes)
191 $(MAKE) check-TESTS \
192 TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
193 LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
194 LOG_FLAGS="$(valgrind_helgrind_flags)" \
195 TEST_SUITE_LOG=test-suite-helgrind.log
197 @echo "Need to reconfigure with --enable-valgrind"
201 ifeq ($(VALGRIND_ENABLED),yes)
202 $(MAKE) check-TESTS \
203 TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
204 LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
205 LOG_FLAGS="$(valgrind_drd_flags)" \
206 TEST_SUITE_LOG=test-suite-drd.log
208 @echo "Need to reconfigure with --enable-valgrind"
211 check-valgrind-sgcheck:
212 ifeq ($(VALGRIND_ENABLED),yes)
213 $(MAKE) check-TESTS \
214 TESTS_ENVIRONMENT="$(VALGRIND_TESTS_ENVIRONMENT)" \
215 LOG_COMPILER="$(VALGRIND_LOG_COMPILER)" \
216 LOG_FLAGS="$(valgrind_sgcheck_flags)" \
217 TEST_SUITE_LOG=test-suite-sgcheck.log
219 @echo "Need to reconfigure with --enable-valgrind"
222 A''M_DISTCHECK_CONFIGURE_FLAGS ?=
223 A''M_DISTCHECK_CONFIGURE_FLAGS += --disable-valgrind
226 MOSTLYCLEANFILES += $(valgrind_log_files)
228 .PHONY: check-valgrind check-valgrind-tool
231 AC_SUBST([VALGRIND_CHECK_RULES])
232 m4_ifdef([_AM_SUBST_NOTMAKE], [_AM_SUBST_NOTMAKE([VALGRIND_CHECK_RULES])])