1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_extend_srcdir.html
3 # ===========================================================================
11 # The AX_EXTEND_SRCDIR macro extends $srcdir by one path component.
13 # As an example, when working in /home/michael/i3-4.12/build and calling
14 # ../configure, your $srcdir is "..". After calling AX_EXTEND_SRCDIR,
15 # $srcdir will be set to "../../i3-4.12".
17 # The result of extending $srcdir is that filenames (e.g. in the output of
18 # the "backtrace" gdb command) will include one more path component of the
19 # absolute source path. The additional path component makes it easy for
20 # users to recognize which files belong to the PACKAGE, and -- provided a
21 # dist tarball was unpacked -- which version of PACKAGE was used.
23 # As an example, in "backtrace", you will see:
25 # #0 main (argc=1, argv=0x7fffffff1fc8) at ../../i3-4.12/src/main.c:187
29 # #0 main (argc=1, argv=0x7fffffff1fc8) at ../src/main.c:187
31 # In case your code uses the __FILE__ preprocessor directive to refer to
32 # the filename of the current source file (e.g. in debug messages), using
33 # the extended path might be undesirable. For this purpose,
34 # AX_EXTEND_SRCDIR defines the output variable AX_EXTEND_SRCDIR_CPPFLAGS,
35 # which can be added to AM_CPPFLAGS in Makefile.am in order to define the
36 # preprocessor directive STRIPPED__FILE__. As an example, when compiling
37 # the file "../../i3-4.12/src/main.c", STRIPPED__FILE__ evaluates to
40 # There are some caveats: When $srcdir is "." (i.e. when ./configure was
41 # called instead of ../configure in a separate build directory),
42 # AX_EXTEND_SRCDIR will still extend $srcdir, but the intended effect will
43 # not be achieved because of the way automake specifies file paths:
44 # automake defines COMPILE to use "`test -f '$source' || echo
45 # '\$(srcdir)/'`$source" in order to prefer files in the current directory
46 # over specifying $srcdir explicitly.
48 # The AX_EXTEND_SRCDIR author is not aware of any way to influence this
49 # automake behavior. Patches very welcome.
51 # To work around this issue, you can use AX_ENABLE_BUILDDIR i.e. by adding
52 # the following code to configure.ac:
58 # Then also add this bit to Makefile.am (if you wish to use
59 # STRIPPED__FILE__ in your code):
61 # AM_CPPFLAGS = @AX_EXTEND_SRCDIR_CPPFLAGS@
65 # Copyright (c) 2016 Michael Stapelberg <michael@i3wm.org>
67 # Copying and distribution of this file, with or without modification, are
68 # permitted in any medium without royalty provided the copyright notice
69 # and this notice are preserved. This file is offered as-is, without any
74 AC_DEFUN([AX_EXTEND_SRCDIR],
79 # pwd -P is specified in IEEE 1003.1 from 2004
80 as_dir=`cd "$srcdir" && pwd -P`
81 as_base=`AS_BASENAME([$as_dir])`
82 srcdir=${srcdir}/../${as_base}
84 AC_SUBST([AX_EXTEND_SRCDIR_CPPFLAGS], ["-DSTRIPPED__FILE__=AS_ESCAPE([\"$$(basename $<)\"])"])
86 ])dnl AX_EXTEND_SRCDIR