]> git.draconx.ca Git - dxcommon.git/blob - m4/base.m4
aebf6cde1438800bb825edaa970088f56bf3ae43
[dxcommon.git] / m4 / base.m4
1 dnl Copyright © 2012 Nick Bowler
2 dnl
3 dnl Base definitions for dxcommon.
4 dnl
5 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
6 dnl This is free software: you are free to do what the fuck you want to.
7 dnl There is NO WARRANTY, to the extent permitted by law.
8
9 m4_pattern_forbid([^_?DX_])
10
11 dnl DX_INIT([directory])
12 dnl
13 dnl Sets the directory of the dxcommon checkout, which is used by other macros
14 dnl to find any source files that they may need.  If this file was included
15 dnl from its original location using m4_include, which normally happens when
16 dnl using aclocal, then the directory will be determined automatically (and
17 dnl this macro does not need to be called in configure.ac at all).  Otherwise,
18 dnl this should be called prior to any other dxcommon macro.
19
20 m4_define([_DX_BASE_FILE], __file__)
21 AC_DEFUN_ONCE([DX_INIT], [dnl
22
23 dnl Care must be taken to avoid spurious expansions of things that look like
24 dnl macros in the filename; this is made especially difficult since
25 dnl m4_bpatsubst does not expand to a quoted string.
26 m4_define([_DX_BASEDIR], m4_if([$1], [],
27         [m4_bpatsubst(m4_dquote(m4_defn([_DX_BASE_FILE])),
28                       [/m4/[^/]*\.m4\(.\)$], [\1])],
29         [[$1]]))
30
31 dnl Include the stamp file, which will cause a failure at autoconf time
32 dnl if it does not exist in the checkout.  We circumvent m4_include to
33 dnl avoid warnings about multiple inclusions.
34 m4_pushdef([m4_include], [m4_builtin([include], $][@)])
35 m4_include(m4_defn([_DX_BASEDIR])[/m4/dx-stamp.m4])
36 m4_popdef([m4_include])
37 _DX_STAMP_DUMMY
38
39 dnl Autoconf scripts should use the DX_BASEDIR m4 macro instead of the
40 dnl AC_SUBSTed shell variable, but we use the same name for the macro since
41 dnl it means the same thing as the substituted variable.
42 dnl
43 dnl Autoconf versions <= 2.69 have a bug which causes the first argument of
44 dnl AC_SUBST to be expanded as a macro when using the two-argument form.  So
45 dnl until we require a newer version of autoconf, we must use the one-argument
46 dnl form of AC_SUBST.
47
48 [DX_BASEDIR]="AS_ESCAPE(m4_dquote(m4_defn([_DX_BASEDIR])))"
49 m4_pushdef([m4_pattern_allow])
50 AC_SUBST([DX_BASEDIR])
51 m4_popdef([m4_pattern_allow])
52 ])
53
54 AC_DEFUN([DX_BASEDIR], [dnl
55 AC_REQUIRE([DX_INIT])dnl
56 m4_defn([_DX_BASEDIR])dnl
57 ])