2021-11-29 10:54:06 +00:00
|
|
|
function symlink_contents_to_dir() {
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo "arg 1 to symlink_contents_to_dir is unexpectedly empty"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "$2" ]]; then
|
|
|
|
echo "arg 2 to symlink_contents_to_dir is unexpectedly empty"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
local target="$2"
|
|
|
|
mkdir -p "$target"
|
2022-11-09 00:14:43 +00:00
|
|
|
local replace_in_files="${3:-}"
|
2021-11-29 10:54:06 +00:00
|
|
|
if [[ -f "$1" ]]; then
|
2022-11-09 00:14:43 +00:00
|
|
|
symlink_to_dir "$1" "$target" "$replace_in_files"
|
2021-11-29 10:54:06 +00:00
|
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
|
|
|
local actual=$(readlink "$1")
|
2022-11-09 00:14:43 +00:00
|
|
|
symlink_contents_to_dir "$actual" "$target" "$replace_in_files"
|
2021-11-29 10:54:06 +00:00
|
|
|
elif [[ -d "$1" ]]; then
|
|
|
|
SAVEIFS=$IFS
|
|
|
|
IFS=$'
|
|
|
|
'
|
|
|
|
local children=($(find "$1/" -maxdepth 1 -mindepth 1))
|
|
|
|
IFS=$SAVEIFS
|
|
|
|
for child in "${children[@]:-}"; do
|
2022-11-09 00:14:43 +00:00
|
|
|
symlink_to_dir "$child" "$target" "$replace_in_files"
|
2021-11-29 10:54:06 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function symlink_to_dir() {
|
|
|
|
if [[ -z "$1" ]]; then
|
|
|
|
echo "arg 1 to symlink_to_dir is unexpectedly empty"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
if [[ -z "$2" ]]; then
|
|
|
|
echo "arg 2 to symlink_to_dir is unexpectedly empty"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
local target="$2"
|
|
|
|
mkdir -p "$target"
|
2022-11-09 00:14:43 +00:00
|
|
|
local replace_in_files="${3:-}"
|
2021-11-29 10:54:06 +00:00
|
|
|
if [[ -f "$1" ]]; then
|
|
|
|
# In order to be able to use `replace_in_files`, we ensure that we create copies of specfieid
|
|
|
|
# files so updating them is possible.
|
|
|
|
if [[ "$1" == *.pc || "$1" == *.la || "$1" == *-config || "$1" == *.mk || "$1" == *.cmake ]]; then
|
2022-01-01 20:48:37 +00:00
|
|
|
dest="$target/$(basename "$1")"
|
2021-11-29 10:54:06 +00:00
|
|
|
cp "$1" "$dest" && chmod +w "$dest" && touch -r "$1" "$dest"
|
|
|
|
else
|
|
|
|
ln -s -f "$1" "$target"
|
|
|
|
fi
|
|
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
|
|
|
cp -pR "$1" "$2"
|
|
|
|
elif [[ -d "$1" ]]; then
|
2022-11-09 00:14:43 +00:00
|
|
|
|
|
|
|
# If not replacing in files, simply create a symbolic link rather than traversing tree of files, which can result in very slow builds
|
|
|
|
if [[ "$replace_in_files" = False ]]; then
|
|
|
|
ln -s -f "$1" "$target"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2021-11-29 10:54:06 +00:00
|
|
|
SAVEIFS=$IFS
|
|
|
|
IFS=$'
|
|
|
|
'
|
|
|
|
local children=($(find "$1/" -maxdepth 1 -mindepth 1))
|
|
|
|
IFS=$SAVEIFS
|
|
|
|
local dirname=$(basename "$1")
|
|
|
|
mkdir -p "$target/$dirname"
|
|
|
|
for child in "${children[@]:-}"; do
|
|
|
|
if [[ -n "$child" && "$dirname" != *.ext_build_deps ]]; then
|
2022-11-09 00:14:43 +00:00
|
|
|
symlink_to_dir "$child" "$target/$dirname" "$replace_in_files"
|
2021-11-29 10:54:06 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
|
|
|
echo "Can not copy $1"
|
|
|
|
fi
|
|
|
|
}
|
2022-11-09 00:14:43 +00:00
|
|
|
symlink_contents_to_dir $SOURCE_DIR $TARGET_DIR False
|