Ben Clayton | feb42e5 | 2022-04-07 19:22:21 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2022 The Tint Authors |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -e # Fail on any error. |
| 17 | |
| 18 | SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )" |
| 19 | ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )" |
| 20 | BUILD_SYSTEM=$(echo "$1" | tr '[:upper:]' '[:lower:]') # lowercase |
| 21 | BUILD_TYPE=$(echo "$2" | tr '[:upper:]' '[:lower:]') # lowercase |
| 22 | BUILD_DIR="${BUILD_SYSTEM}-${BUILD_TYPE}" |
| 23 | |
| 24 | function show_usage() { |
| 25 | echo "setup-build [gn|cmake] [debug|release]" |
| 26 | echo |
| 27 | echo "creates a build directory in <dawn>/out using either GN or CMake, then" |
| 28 | echo "updates the '<dawn>/out/active' symlink to point to the build directory" |
| 29 | exit 1 |
| 30 | } |
| 31 | |
| 32 | function generate() { |
| 33 | CMD=$1 |
| 34 | pushd "$ROOT_DIR" > /dev/null |
Ben Clayton | 446166c | 2022-04-29 20:18:45 +0000 | [diff] [blame] | 35 | mkdir -p "out/$BUILD_DIR" |
| 36 | rm -fr "out/active" || true |
| 37 | ln -s "$BUILD_DIR" "out/active" |
| 38 | ${CMD} |
Ben Clayton | feb42e5 | 2022-04-07 19:22:21 +0000 | [diff] [blame] | 39 | popd > /dev/null |
| 40 | } |
| 41 | |
| 42 | case $BUILD_SYSTEM in |
| 43 | "gn") |
| 44 | case $BUILD_TYPE in |
| 45 | "debug") |
Ben Clayton | 446166c | 2022-04-29 20:18:45 +0000 | [diff] [blame] | 46 | generate "gn gen out/active --args=is_debug=true" |
Ben Clayton | feb42e5 | 2022-04-07 19:22:21 +0000 | [diff] [blame] | 47 | ;; |
| 48 | "release") |
Ben Clayton | 3e6bf1a | 2022-05-25 22:47:23 +0000 | [diff] [blame] | 49 | generate "gn gen out/active --args=is_debug=false" |
Ben Clayton | feb42e5 | 2022-04-07 19:22:21 +0000 | [diff] [blame] | 50 | ;; |
| 51 | *) |
| 52 | echo "invalid build type '${BUILD_TYPE}'" |
| 53 | show_usage |
| 54 | ;; |
| 55 | esac |
| 56 | ;; |
| 57 | "cmake") |
Ben Clayton | 446166c | 2022-04-29 20:18:45 +0000 | [diff] [blame] | 58 | CMAKE_FLAGS="" |
| 59 | if [[ -x $(command -v ccache) ]]; then |
| 60 | CMAKE_FLAGS+="-DCMAKE_CXX_COMPILER_LAUNCHER=ccache" |
| 61 | fi |
Ben Clayton | feb42e5 | 2022-04-07 19:22:21 +0000 | [diff] [blame] | 62 | case $BUILD_TYPE in |
| 63 | "debug") |
Ben Clayton | 446166c | 2022-04-29 20:18:45 +0000 | [diff] [blame] | 64 | generate "cmake -S . -B out/active -GNinja -DCMAKE_BUILD_TYPE=Debug ${CMAKE_FLAGS}" |
Ben Clayton | feb42e5 | 2022-04-07 19:22:21 +0000 | [diff] [blame] | 65 | ;; |
| 66 | "release") |
Ben Clayton | 446166c | 2022-04-29 20:18:45 +0000 | [diff] [blame] | 67 | generate "cmake -S . -B out/active -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo ${CMAKE_FLAGS}" |
Ben Clayton | feb42e5 | 2022-04-07 19:22:21 +0000 | [diff] [blame] | 68 | ;; |
| 69 | *) |
| 70 | echo "invalid build type '${BUILD_TYPE}'" |
| 71 | show_usage |
| 72 | ;; |
| 73 | esac |
| 74 | ;; |
| 75 | "--help" | "-help" | "-h") |
| 76 | show_usage |
| 77 | ;; |
| 78 | *) |
| 79 | echo "invalid build system '${BUILD_SYSTEM}'" |
| 80 | show_usage |
| 81 | ;; |
| 82 | esac |