Skip to content

Commit b2a018a

Browse files
committed
Merge branch 'subdir_incl_compat' into sys_leveldb
2 parents 1248d0d + 1490995 commit b2a018a

File tree

1 file changed

+38
-4
lines changed

1 file changed

+38
-4
lines changed

build-aux/m4/bitcoin_subdir_to_include.m4

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,48 @@ dnl file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
dnl BITCOIN_SUBDIR_TO_INCLUDE([CPPFLAGS-VARIABLE-NAME],[SUBDIRECTORY-NAME],[HEADER-FILE])
66
dnl SUBDIRECTORY-NAME must end with a path separator
77
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
912
AC_MSG_RESULT([default])
1013
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+
1346
AC_MSG_RESULT([${newinclpath}])
1447
if test "${newinclpath}" != ""; then
15-
eval "$1=\"\$$1\"' -I${newinclpath}'"
48+
eval "_result_var=\"\$_result_var\"' -I${newinclpath}'"
1649
fi
1750
fi
51+
m4_popdef([_result_var],[_rel_path],[_header_file])
1852
])

0 commit comments

Comments
 (0)