1 # this is my first m4 script, the style is probably completely wrong
2 # TODO: read carefully the docs about quotation, quote and indent properly
4 # Make a path absolute and remove "..", ".", "//", final slash.
6 # If you find a bug, please fix it also in the sanitize_path bash script
7 # (and test with the test-sanitize script).
8 # AC_SANITIZE_PATH([/path/to/be/sanitized], [output_variable_name])
10 # remember that `@<:@' = `[' and `@:>@' = `]'
11 # TODO: change AC_MSG_NOTICEs with a proper debug macro
12 AC_DEFUN([AC_SANITIZE_PATH],
15 # AC_MSG_NOTICE([Sanitize: called with <$1>, <$2>]) # <-
17 ac_nomiddledot='s;/\./;/;g'
18 ac_noenddot='s;/\./\?$;;'
19 ac_noslashslash='s;//\+;/;g'
20 ac_nodotdot='s;@<:@^/@:>@*/\.\.\(/\|$\);;' # note: this removes only one foo/..
21 ac_nofinalslash='s;\(.\)/$;\1;g'
24 if echo "$1" | grep '^/' >/dev/null 2>&1 ; then
25 # AC_MSG_NOTICE([Sanitize: I think <$1> is an absolute directory]) # <-
28 # AC_MSG_NOTICE([Sanitize: I think <$1> is a relative directory]) # <-
30 # AC_MSG_NOTICE([Sanitize: Absolutized to <${$2}>]) # <-
34 for ac_transform in "$ac_nomiddledot" "$ac_noenddot"; do
35 $2="`echo "${$2}" | sed -e "$ac_transform"`"
36 # AC_MSG_NOTICE([Sanitize: Removed dots to <${$2}>]) # <-
39 # remove spurious slashes
40 $2=`echo "${$2}" | sed -e "$ac_noslashslash"`
41 # AC_MSG_NOTICE([Sanitize: Removed slashes to <${$2}>]) # <-
43 # one while to remove them all
44 while echo "${$2}" | grep '\.\.\(/\|$\)' >/dev/null 2>&1; do
45 $2=`echo "${$2}" | sed -e "$ac_nodotdot"`
46 # AC_MSG_NOTICE([Sanitize: Removed dotdots to <${$2}>]) # <-
50 $2=`echo "${$2}" | sed -e "$ac_nofinalslash"`
51 # AC_MSG_NOTICE([Sanitize: Removed final slash to <${$2}>]) # <-
53 if ! test "${$2}" ; then
54 # Got an empty path, I hope it's root...
55 # AC_MSG_NOTICE([Sanitize: After all that, I think it is / ]) # <-
58 # AC_MSG_NOTICE([Sanitize: from $1, defined $2 to <${$2}>])
61 # create and AC_SUBS sanitized abs_ versions of the following variables:
67 AC_DEFUN([AC_DEVEL_ABSDIRS], [
69 if test "$csourcedir"; then
70 AC_SANITIZE_PATH([$csourcedir], abs_csourcedir)
71 AC_SUBST(abs_csourcedir)
73 if test "$headerdir"; then
74 AC_SANITIZE_PATH([$headerdir], abs_headerdir)
75 AC_SUBST(abs_headerdir)
77 if test "$utestdir"; then
78 AC_SANITIZE_PATH([$utestdir], abs_utestdir)
79 AC_SUBST(abs_utestdir)
81 if test "$docdir"; then
82 AC_SANITIZE_PATH([$docdir], abs_docdir)
85 if test "$mytestdir"; then
86 AC_SANITIZE_PATH([$mytestdir], abs_mytestdir)
87 AC_SUBST(abs_mytestdir)
89 if test "$lcov_ignore_dirs"; then
90 AC_SANITIZE_PATH([$lcov_ignore_dirs], abs_lcov_ignore_dirs)
91 AC_SUBST(abs_lcov_ignore_dirs)
96 # This macro gives configure options for enabling Check unit testing, debugging
97 # symbols, efence, LCOV, and a standard set of warnings. It also provides the
98 # --enable-devel, which sets all five options.
100 # For each option foo, if --enable-foo was asked, AM_AUX_DEVEL sets
101 # shell variable $ac_foo_enabled to 'yes' and Automake conditional FOO to
104 # --enable-check calls AM_PATH_CHECK. Note that if check.m4 was
105 # not found in the *maintainer's* machine (when autoconf is run), the
106 # resulting configure script will not have check support!
108 # --enable-debug is somewhat intrusive. It defines DEBUG and
109 # forces CFLAGS to "-g -O0", overriding the user environment variable.
111 # --enable-efence checks for the efence library.
113 # --enable-lcov checks for gcov and lcov.
115 # --enable-warnings adds a lot of extra gcc warnings flags in the
116 # variable ac_devel_default_warnings.
118 # See also the file auxdevel.am, with Makefile usage of the conditionals set by
121 # TODO: check for Doxygen binary
123 AC_DEFUN([AC_DEVEL_MACROS],
126 ac_isodate="`date +%Y-%m-%d`"
129 AC_ARG_ENABLE(warnings,
130 AS_HELP_STRING([--enable-warnings], [Enable extra GCC warnings flags]),
131 [ac_warnings_enabled=$enableval], [ac_warnings_enabled=no])
132 AC_ARG_ENABLE(efence,
133 AS_HELP_STRING([--enable-efence], [Enable EletricFence]),
134 [ac_efence_enabled=$enableval], [ac_efence_enabled=no])
136 AS_HELP_STRING([--enable-debug],
137 [Define DEBUG, force CFLAGS to "-g -O0" (overrides environment variable)]),
138 [ac_debug_enabled=$enableval], [ac_debug_enabled=no])
140 AS_HELP_STRING([--enable-lcov], [Enable gcov/lcov support]),
141 [ac_lcov_enabled=$enableval], [ac_lcov_enabled=no])
143 AC_ARG_WITH(buildversion,
144 AS_HELP_STRING([--with-buildversion=BUILDVERSION],
145 [Build version string (default: ISO date of configuration]),
146 [ac_buildversion=$withval],
147 [ac_buildversion="$ac_isodate"])
150 # Unfortunately this m4_ifdef doesn't work with older versions of autotools, so
151 # if you want to support them, you should distribute check.m4 with your package.
152 # Failing to do that will result in a cryptic error message if the user don't
153 # have Check installed.
155 # Also note that if you use this feature and don't have Check when calling
156 # autoconf, the resulting `configure' script will lack Check support. This is
157 # probably not what you want, so make sure that the maintainer has Check
158 # installed when running `make dist'.
159 m4_ifdef([AM_PATH_CHECK],
162 AS_HELP_STRING([--enable-check], [Enables unit testing with Check]),
163 [ac_check_enabled=$enableval], [ac_check_enabled=no])
165 AS_HELP_STRING([--enable-devel],
166 [Equivalent to --enable-warnings --enable-efence --enable-debug
167 --enable-check --enable-lcov]),
168 [ac_warnings_enabled=$enableval
169 ac_efence_enabled=$enableval
170 ac_debug_enabled=$enableval
171 ac_check_enabled=$enableval
172 ac_lcov_enabled=$enableval])
175 AC_DIAGNOSE([syntax], [Could not find check.m4, no support for unit testing.])
177 AS_HELP_STRING([--enable-devel],
178 [Equivalent to --enable-warnings --enable-efence --enable-debug
180 [ac_warnings_enabled=$enableval
181 ac_efence_enabled=$enableval
182 ac_debug_enabled=$enableval
183 ac_lcov_enabled=$enableval])
186 if test "$ac_warnings_enabled" = yes; then
187 AC_SUBST(ac_devel_default_warnings, ["-Wall -W \
188 -Wmissing-declarations -Wmissing-prototypes \
189 -Wredundant-decls -Wshadow -Wbad-function-cast \
190 -Wcast-qual -Wno-pointer-sign"])
192 AC_SUBST(ac_devel_default_warnings, ["-Wall -W -Wno-pointer-sign"])
195 if test "$ac_efence_enabled" = yes; then
196 AC_CHECK_LIB(efence, malloc, [],
197 [AC_MSG_ERROR([Linking to efence asked, but could not find the library])])
200 m4_ifdef([AM_PATH_CHECK],
201 [if test "$ac_check_enabled" = yes; then
205 # TODO: find unobtrusive way of disabling optimization and enabling debug
206 if test "$ac_debug_enabled" = yes; then
208 AC_MSG_WARN([Using --enable-debug, overriding user CFLAGS.])
209 AC_DEFINE([DEBUG], [1], [Set if in debug mode])
211 AC_DEFINE([NDEBUG], [1], [Set if not in debug mode])
214 # TODO: support --with-lcov, --with-gcov
215 # TODO: check also for lcov.pl, genhtml.pl, etc.
216 if test "$ac_lcov_enabled" = yes; then
217 AC_CHECK_PROGS(gcov, gcov)
218 if ! test "$gcov"; then
219 AC_MSG_ERROR([Could not find gcov utility, check your gcc instalation])
221 AC_CHECK_LIB(gcov, __gcov_init, [], [])
222 AC_CHECK_PROGS(lcov, lcov)
223 AC_CHECK_PROGS(genhtml, genhtml)
224 AC_CHECK_PROGS(gendesc, gendesc)
225 AC_CHECK_PROGS(geninfo, geninfo)
226 if ! test "$lcov" || ! test "$genhtml" || ! test "$gendesc" ||
227 ! test "$geninfo"; then
228 AC_MSG_ERROR([Could not find lcov utilities, do you have lcov installed?])
232 AM_CONDITIONAL(CHECK, [test "$ac_check_enabled" = yes])
233 AM_CONDITIONAL(DEBUG, [test "$ac_debug_enabled" = yes])
234 AM_CONDITIONAL(EFENCE, [test "$ac_efence_enabled" = yes])
235 AM_CONDITIONAL(LCOV, [test "$ac_lcov_enabled" = yes])
236 AM_CONDITIONAL(WARNINGS, [test "$ac_warnings_enabled" = yes])
238 # these allow us to append to possibly empty variables in auxdevel.am
239 AC_SUBST([AM_CFLAGS],[''])
240 AC_SUBST([LDADD],[''])
241 AC_SUBST([EXTRA_DIST],[''])
242 AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],[''])
243 AC_SUBST([CLEANFILES],[''])
244 AC_SUBST([MOSTLYCLEANFILES],[''])
246 AC_DEFINE_UNQUOTED(BUILDVERSION, "$ac_buildversion", [Tag or version of build])
248 # we need to support autoconf 2.58, in which abs_builddir/abs_srcdir are not
250 # these are also used in auxdevel.am
251 AC_SUBST(ac_devel_abs_builddir, `pwd -P`) # builddir is defined as '.'
253 AC_SANITIZE_PATH([$srcdir], ac_devel_abs_srcdir)
254 AC_SUBST(ac_devel_abs_srcdir)