2022-04-07 19:22:21 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# Copyright 2022 The Tint Authors
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
|
|
|
set -e # Fail on any error.
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
|
|
|
|
ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )"
|
|
|
|
BUILD_SYSTEM=$(echo "$1" | tr '[:upper:]' '[:lower:]') # lowercase
|
|
|
|
BUILD_TYPE=$(echo "$2" | tr '[:upper:]' '[:lower:]') # lowercase
|
|
|
|
BUILD_DIR="${BUILD_SYSTEM}-${BUILD_TYPE}"
|
|
|
|
|
|
|
|
function show_usage() {
|
|
|
|
echo "setup-build [gn|cmake] [debug|release]"
|
|
|
|
echo
|
|
|
|
echo "creates a build directory in <dawn>/out using either GN or CMake, then"
|
|
|
|
echo "updates the '<dawn>/out/active' symlink to point to the build directory"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
function generate() {
|
|
|
|
CMD=$1
|
|
|
|
pushd "$ROOT_DIR" > /dev/null
|
2022-04-29 20:18:45 +00:00
|
|
|
mkdir -p "out/$BUILD_DIR"
|
|
|
|
rm -fr "out/active" || true
|
|
|
|
ln -s "$BUILD_DIR" "out/active"
|
|
|
|
${CMD}
|
2022-04-07 19:22:21 +00:00
|
|
|
popd > /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
case $BUILD_SYSTEM in
|
|
|
|
"gn")
|
|
|
|
case $BUILD_TYPE in
|
|
|
|
"debug")
|
2022-04-29 20:18:45 +00:00
|
|
|
generate "gn gen out/active --args=is_debug=true"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
"release")
|
2022-05-25 22:47:23 +00:00
|
|
|
generate "gn gen out/active --args=is_debug=false"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "invalid build type '${BUILD_TYPE}'"
|
|
|
|
show_usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
"cmake")
|
2022-04-29 20:18:45 +00:00
|
|
|
CMAKE_FLAGS=""
|
|
|
|
if [[ -x $(command -v ccache) ]]; then
|
|
|
|
CMAKE_FLAGS+="-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
|
|
|
|
fi
|
2022-04-07 19:22:21 +00:00
|
|
|
case $BUILD_TYPE in
|
|
|
|
"debug")
|
2022-04-29 20:18:45 +00:00
|
|
|
generate "cmake -S . -B out/active -GNinja -DCMAKE_BUILD_TYPE=Debug ${CMAKE_FLAGS}"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
"release")
|
2022-04-29 20:18:45 +00:00
|
|
|
generate "cmake -S . -B out/active -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo ${CMAKE_FLAGS}"
|
2022-04-07 19:22:21 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "invalid build type '${BUILD_TYPE}'"
|
|
|
|
show_usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
;;
|
|
|
|
"--help" | "-help" | "-h")
|
|
|
|
show_usage
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "invalid build system '${BUILD_SYSTEM}'"
|
|
|
|
show_usage
|
|
|
|
;;
|
|
|
|
esac
|