@@ -5,14 +5,48 @@ dnl file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
dnl BITCOIN_SUBDIR_TO_INCLUDE([CPPFLAGS-VARIABLE-NAME],[SUBDIRECTORY-NAME],[HEADER-FILE])
6
6
dnl SUBDIRECTORY-NAME must end with a path separator
7
7
AC_DEFUN ( [ BITCOIN_SUBDIR_TO_INCLUDE] ,[
8
- if test "$2 " = ""; then
8
+ m4_pushdef ( [ _result_var] ,[ $1 ] )
9
+ m4_pushdef ( [ _rel_path] ,[ $2 ] )
10
+ m4_pushdef ( [ _header_file] ,[ $3 .h] )
11
+ if test "[ ] _rel_path" = ""; then
9
12
AC_MSG_RESULT ( [ default] )
10
13
else
11
- echo "#include <$2$3 .h>" >conftest.cpp
12
- newinclpath=`${CXXCPP} ${CPPFLAGS} -M conftest.cpp 2>/dev/null | [ tr -d '\\n\\r\\\\' | sed -e 's/^.*[ [ :space:] :] \(\/[ ^[ :space:] ] *\)] $3 [ \.h[ [ :space:] ] .*$/\1/' -e t -e d`]
14
+ echo '[ #] include <'"_rel_path"'/_header_file>' >conftest.cpp
15
+ newinclpath=$(
16
+ ${CXXCPP} ${CPPFLAGS} -M conftest.cpp 2>/dev/null |
17
+ ${SED} -E m4_bpatsubsts ( [ [
18
+ :build_line
19
+ # If the line doesn't end with a backslash, it is complete; go on to process it
20
+ /\\$/!b have_complete_line
21
+ # Otherwise, read the next line, and concatenate it to the current one with a space
22
+ N
23
+ s/\\\n/ /
24
+ # Then go back and check for a trailing backslash again.
25
+ t build_line
26
+
27
+ # When we get here, we have the completed line, with all continuations collapsed.
28
+ :have_complete_line
29
+ s/^[ ^:] *:[ [ :space:] ] *(([ ^[ :space:] \] |\\.)*[ [ :space:] ] )*(([ ^[ :space:] \] |\\.)*)(\\|\\\\|\/)?] ] patsubst ( ]_header_file [ ,[ \.] ,[ \\.] )[ [ ([ [ :space:] ] .*)?$/\3/
30
+ # ^^^^^^^ The Make line begins with a target (which we don't care about)
31
+ # ^^^^^^^^^^^^ Ignore any spaces following it
32
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Match any number of other dependencies
33
+ # ^^^^^^^^^^^^^^^^^^^^^^ Match any path components for our dependency; note this is reference 3, which we are replacing with
34
+ # ^^^^^^^^^^^^^ Accept the path ending in a backslash, a double-backslash (ie escaped), or a forward slash
35
+ # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The filename must match exactly (periods are escaped, since a normal period matches any character in regex)
36
+ # ^^^^^^^^^^^^^^^^^ Filename must be followed by a space, but after that we don't care; we still need to match it all so it gets replaced, however
37
+ # Delete the line, but only if we failed to find the directory (t jumps past the d if we matched)
38
+ t
39
+ d
40
+ ] ] ,[
41
+ \s*\(#.*\)?$] ,[ ] ,[
42
+ \(.*\)] ,[ -e '\1'] )
43
+ dnl ^^^^^^^^^^^^^^^^^^^^^^^ Deletes comments and processes sed expressions into -e arguments
44
+ )
45
+
13
46
AC_MSG_RESULT ( [ ${newinclpath}] )
14
47
if test "${newinclpath}" != ""; then
15
- eval "$1 =\"\$$1 \"' -I${newinclpath}'"
48
+ eval "_result_var =\"\$_result_var \"' -I${newinclpath}'"
16
49
fi
17
50
fi
51
+ m4_popdef ( [ _result_var] ,[ _rel_path] ,[ _header_file] )
18
52
] )
0 commit comments