Fix Fallbacks to Work on FreeBSD
This commit is contained in:
@@ -72,11 +72,28 @@ resolve_include() {
|
|||||||
local inc=$2
|
local inc=$2
|
||||||
for root in $srcdir $ROOTS; do
|
for root in $srcdir $ROOTS; do
|
||||||
if [ -f "$root/$inc" ]; then
|
if [ -f "$root/$inc" ]; then
|
||||||
|
# Try to reduce the file path into a canonical form (so that multiple)
|
||||||
|
# includes of the same file are successfully deduplicated, even if they
|
||||||
|
# are expressed differently.
|
||||||
local relpath="$(realpath --relative-to . "$root/$inc")"
|
local relpath="$(realpath --relative-to . "$root/$inc")"
|
||||||
if [ "$?" -eq "0" ]; then # not all realpaths support --relative-to
|
if [ "$relpath" != "" ]; then # not all realpaths support --relative-to
|
||||||
relpath="$(realpath "$root/$inc")"
|
echo "$relpath"
|
||||||
|
return 0
|
||||||
fi
|
fi
|
||||||
echo "$relpath"
|
local relpath="$(realpath "$root/$inc")"
|
||||||
|
if [ "$relpath" != "" ]; then # not all distros have realpath...
|
||||||
|
echo "$relpath"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
# Worst case, fall back to just the root + relative include path. The
|
||||||
|
# problem with this is that it is possible to emit multiple different
|
||||||
|
# resolved paths to the same file, depending on exactly how its included.
|
||||||
|
# Since the main loop below keeps a list of the resolved paths it's
|
||||||
|
# already included, in order to avoid repeated includes, this failure to
|
||||||
|
# produce a canonical/reduced path can lead to multiple inclusions of the
|
||||||
|
# same file. But it seems like the resulting single file library still
|
||||||
|
# works (hurray include guards!), so I guess it's ok.
|
||||||
|
echo "$root/$inc"
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -91,7 +108,7 @@ add_file() {
|
|||||||
# Log but only if not writing to stdout
|
# Log but only if not writing to stdout
|
||||||
echo "Processing: $file"
|
echo "Processing: $file"
|
||||||
fi
|
fi
|
||||||
# Get directory to resolve relative includes
|
# Get directory of the current so we can resolve relative includes
|
||||||
local srcdir="$(dirname "$file")"
|
local srcdir="$(dirname "$file")"
|
||||||
# Read the file
|
# Read the file
|
||||||
local line=
|
local line=
|
||||||
|
|||||||
Reference in New Issue
Block a user