2018-09-11 09:43:13 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# default placeholder value
|
|
|
|
REPLACE_VALUE='BAZEL_GEN_ROOT'
|
|
|
|
export BUILD_PWD=$(cygpath -m $(pwd))
|
|
|
|
|
|
|
|
# Append string to PATH variable
|
|
|
|
# $1 string to append
|
|
|
|
function path() {
|
|
|
|
export PATH="$1:$PATH"
|
|
|
|
}
|
|
|
|
|
2018-09-18 11:20:58 +00:00
|
|
|
# Replace string in *.pc and *.la files in directory
|
2018-09-11 09:43:13 +00:00
|
|
|
# $1 directory to search recursively, absolute path
|
|
|
|
# $2 string to replace
|
|
|
|
# $3 replace target
|
|
|
|
function replace_in_files() {
|
|
|
|
if [ -d "$1" ]; then
|
2018-09-21 08:57:02 +00:00
|
|
|
find -L $1 -type f \
|
2018-11-16 21:30:04 +00:00
|
|
|
\( -name "*.pc" -or -name "*.la" -or -name "*-config" -or -name "*.cmake" \) \
|
2018-09-20 18:19:38 +00:00
|
|
|
-exec sed -i 's@'"$2"'@'"$3"'@g' {} ';'
|
2018-09-11 09:43:13 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-09-20 18:19:38 +00:00
|
|
|
# copies contents of the directory to target directory
|
|
|
|
# (create the target directory if needed)
|
2018-09-11 09:43:13 +00:00
|
|
|
# $1 source directory, immediate children of which are copied
|
|
|
|
# $2 target directory
|
|
|
|
function copy_dir_contents_to_dir() {
|
2018-10-19 08:50:40 +00:00
|
|
|
cp -L -r --no-target-directory "$1" "$2"
|
2018-09-11 09:43:13 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 18:19:38 +00:00
|
|
|
# Symlink contents of the directory to target directory
|
|
|
|
# (create the target directory if needed).
|
2018-09-11 09:43:13 +00:00
|
|
|
# If file is passed, symlink it into the target directory.
|
2018-09-20 18:19:38 +00:00
|
|
|
# $1 source directory, immediate children of which are symlinked,
|
|
|
|
# or file to be symlinked.
|
2018-09-11 09:43:13 +00:00
|
|
|
# $2 target directory
|
|
|
|
function symlink_contents_to_dir() {
|
|
|
|
local target="$2"
|
|
|
|
mkdir -p ${target}
|
|
|
|
if [[ -f $1 ]]; then
|
|
|
|
symlink_to_dir $1 ${target}
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
local children=$(find $1 -maxdepth 1 -mindepth 1)
|
|
|
|
for child in $children; do
|
|
|
|
symlink_to_dir $child ${target}
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2018-09-20 18:19:38 +00:00
|
|
|
# COPIES all files from source directory to target directory
|
|
|
|
# (create the target directory if needed)
|
2018-09-11 09:43:13 +00:00
|
|
|
# (Windows complains about long filenames with symlink command, so copy them)
|
|
|
|
# NB symlinks from the source directory are copied
|
|
|
|
# $1 source directory
|
|
|
|
# $2 target directory
|
|
|
|
function symlink_to_dir() {
|
2018-10-19 08:50:40 +00:00
|
|
|
cp -r --no-target-directory $1 $2
|
2018-09-11 09:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# replace placeholder with absolute path in all files in a directory
|
|
|
|
# $1 directory
|
|
|
|
# $2 absolute path
|
|
|
|
function define_absolute_paths() {
|
|
|
|
replace_in_files $1 $REPLACE_VALUE $2
|
|
|
|
}
|
|
|
|
|
|
|
|
# replace the absolute path with a placeholder value in all files in a directory
|
|
|
|
# $1 directory
|
|
|
|
# $2 absolute path to replace
|
|
|
|
function replace_absolute_paths() {
|
|
|
|
replace_in_files $1 $2 $REPLACE_VALUE
|
|
|
|
}
|
|
|
|
|
|
|
|
# function for setting necessary environment variables for the platform
|
|
|
|
function set_platform_env_vars() {
|
|
|
|
export MSYS_NO_PATHCONV=1
|
|
|
|
export MSYS2_ARG_CONV_EXCL="*"
|
|
|
|
export SYSTEMDRIVE="C:"
|
2018-09-18 11:20:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function increment_pkg_config_path() {
|
2018-09-20 18:19:38 +00:00
|
|
|
local children=$(find $1 -mindepth 1 -name '*.pc')
|
2018-09-18 11:20:58 +00:00
|
|
|
# assume there is only one directory with pkg config
|
|
|
|
for child in $children; do
|
2018-09-20 18:19:38 +00:00
|
|
|
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(dirname $child)"
|
|
|
|
return
|
2018-09-18 11:20:58 +00:00
|
|
|
done
|
2018-11-16 21:30:04 +00:00
|
|
|
}
|