2020-04-30 09:24:25 +00:00
|
|
|
function symlink_contents_to_dir() {
|
2021-06-01 20:59:16 +00:00
|
|
|
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
|
2020-04-30 09:24:25 +00:00
|
|
|
local target="$2"
|
2020-05-08 09:43:40 +00:00
|
|
|
mkdir -p "$target"
|
|
|
|
if [[ -f "$1" ]]; then
|
2021-01-31 15:43:03 +00:00
|
|
|
symlink_to_dir "$1" "$target"
|
|
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
2020-05-08 09:43:40 +00:00
|
|
|
local actual=$(readlink "$1")
|
2021-01-31 15:43:03 +00:00
|
|
|
symlink_contents_to_dir "$actual" "$target"
|
2020-05-08 09:43:40 +00:00
|
|
|
elif [[ -d "$1" ]]; then
|
2021-01-31 15:43:03 +00:00
|
|
|
SAVEIFS=$IFS
|
|
|
|
IFS=$'
|
|
|
|
'
|
2021-05-06 00:47:25 +00:00
|
|
|
local children=($(find "$1/" -maxdepth 1 -mindepth 1))
|
2021-01-31 15:43:03 +00:00
|
|
|
IFS=$SAVEIFS
|
2021-02-22 20:28:41 +00:00
|
|
|
for child in "${children[@]:-}"; do
|
2021-01-31 15:43:03 +00:00
|
|
|
symlink_to_dir "$child" "$target"
|
2020-04-30 09:24:25 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
function symlink_to_dir() {
|
2021-06-01 20:59:16 +00:00
|
|
|
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
|
2020-04-30 09:24:25 +00:00
|
|
|
local target="$2"
|
2020-05-08 09:43:40 +00:00
|
|
|
mkdir -p "$target"
|
|
|
|
if [[ -f "$1" ]]; then
|
2021-05-09 05:18:25 +00:00
|
|
|
# In order to be able to use `replace_in_files`, we ensure that we create copies of specfieid
|
|
|
|
# files so updating them is possible.
|
2021-05-16 21:53:04 +00:00
|
|
|
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-05-09 05:18:25 +00:00
|
|
|
cp "$1" "$dest" && chmod +w "$dest" && touch -r "$1" "$dest"
|
|
|
|
else
|
2020-05-08 09:43:40 +00:00
|
|
|
ln -s -f "$1" "$target"
|
2021-05-09 05:18:25 +00:00
|
|
|
fi
|
2021-01-31 15:43:03 +00:00
|
|
|
elif [[ -L "$1" && ! -d "$1" ]]; then
|
2021-06-01 20:59:16 +00:00
|
|
|
cp -pR "$1" "$2"
|
2020-05-08 09:43:40 +00:00
|
|
|
elif [[ -d "$1" ]]; then
|
2021-01-31 15:43:03 +00:00
|
|
|
SAVEIFS=$IFS
|
|
|
|
IFS=$'
|
|
|
|
'
|
2021-05-06 00:47:25 +00:00
|
|
|
local children=($(find "$1/" -maxdepth 1 -mindepth 1))
|
2021-01-31 15:43:03 +00:00
|
|
|
IFS=$SAVEIFS
|
2020-05-08 09:43:40 +00:00
|
|
|
local dirname=$(basename "$1")
|
|
|
|
mkdir -p "$target/$dirname"
|
2021-02-22 20:28:41 +00:00
|
|
|
for child in "${children[@]:-}"; do
|
2021-06-01 20:59:16 +00:00
|
|
|
if [[ -n "$child" && "$dirname" != *.ext_build_deps ]]; then
|
2021-01-31 15:43:03 +00:00
|
|
|
symlink_to_dir "$child" "$target/$dirname"
|
2021-02-22 20:28:41 +00:00
|
|
|
fi
|
2020-05-08 09:43:40 +00:00
|
|
|
done
|
2020-04-30 09:24:25 +00:00
|
|
|
else
|
|
|
|
echo "Can not copy $1"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
symlink_contents_to_dir $SOURCE_DIR $TARGET_DIR
|