blob: 76ec76c5b96c7f05ef792479c87234990b4a460d [file] [log] [blame]
Ben Claytonfeb42e52022-04-07 19:22:21 +00001#!/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
16set -e # Fail on any error.
17
18SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd )"
19ROOT_DIR="$( cd "${SCRIPT_DIR}/.." >/dev/null 2>&1 && pwd )"
20BUILD_SYSTEM=$(echo "$1" | tr '[:upper:]' '[:lower:]') # lowercase
21BUILD_TYPE=$(echo "$2" | tr '[:upper:]' '[:lower:]') # lowercase
22BUILD_DIR="${BUILD_SYSTEM}-${BUILD_TYPE}"
23
24function 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
32function generate() {
33 CMD=$1
34 pushd "$ROOT_DIR" > /dev/null
Ben Clayton446166c2022-04-29 20:18:45 +000035 mkdir -p "out/$BUILD_DIR"
36 rm -fr "out/active" || true
37 ln -s "$BUILD_DIR" "out/active"
38 ${CMD}
Ben Claytonfeb42e52022-04-07 19:22:21 +000039 popd > /dev/null
40}
41
42case $BUILD_SYSTEM in
43 "gn")
44 case $BUILD_TYPE in
45 "debug")
Ben Clayton446166c2022-04-29 20:18:45 +000046 generate "gn gen out/active --args=is_debug=true"
Ben Claytonfeb42e52022-04-07 19:22:21 +000047 ;;
48 "release")
Ben Clayton3e6bf1a2022-05-25 22:47:23 +000049 generate "gn gen out/active --args=is_debug=false"
Ben Claytonfeb42e52022-04-07 19:22:21 +000050 ;;
51 *)
52 echo "invalid build type '${BUILD_TYPE}'"
53 show_usage
54 ;;
55 esac
56 ;;
57 "cmake")
Ben Clayton446166c2022-04-29 20:18:45 +000058 CMAKE_FLAGS=""
59 if [[ -x $(command -v ccache) ]]; then
60 CMAKE_FLAGS+="-DCMAKE_CXX_COMPILER_LAUNCHER=ccache"
61 fi
Ben Claytonfeb42e52022-04-07 19:22:21 +000062 case $BUILD_TYPE in
63 "debug")
Ben Clayton446166c2022-04-29 20:18:45 +000064 generate "cmake -S . -B out/active -GNinja -DCMAKE_BUILD_TYPE=Debug ${CMAKE_FLAGS}"
Ben Claytonfeb42e52022-04-07 19:22:21 +000065 ;;
66 "release")
Ben Clayton446166c2022-04-29 20:18:45 +000067 generate "cmake -S . -B out/active -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo ${CMAKE_FLAGS}"
Ben Claytonfeb42e52022-04-07 19:22:21 +000068 ;;
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 ;;
82esac