xref: /aosp_15_r20/external/libwebm/infra/common.sh (revision 103e46e4cd4b6efcf6001f23fa8665fb110abf8d)
1*103e46e4SHarish Mahendrakar# Copyright (c) 2021, Google Inc. All rights reserved.
2*103e46e4SHarish Mahendrakar#
3*103e46e4SHarish Mahendrakar# Redistribution and use in source and binary forms, with or without
4*103e46e4SHarish Mahendrakar# modification, are permitted provided that the following conditions are
5*103e46e4SHarish Mahendrakar# met:
6*103e46e4SHarish Mahendrakar#
7*103e46e4SHarish Mahendrakar#   * Redistributions of source code must retain the above copyright
8*103e46e4SHarish Mahendrakar#     notice, this list of conditions and the following disclaimer.
9*103e46e4SHarish Mahendrakar#
10*103e46e4SHarish Mahendrakar#   * Redistributions in binary form must reproduce the above copyright
11*103e46e4SHarish Mahendrakar#     notice, this list of conditions and the following disclaimer in
12*103e46e4SHarish Mahendrakar#     the documentation and/or other materials provided with the
13*103e46e4SHarish Mahendrakar#     distribution.
14*103e46e4SHarish Mahendrakar#
15*103e46e4SHarish Mahendrakar#   * Neither the name of Google nor the names of its contributors may
16*103e46e4SHarish Mahendrakar#     be used to endorse or promote products derived from this software
17*103e46e4SHarish Mahendrakar#     without specific prior written permission.
18*103e46e4SHarish Mahendrakar#
19*103e46e4SHarish Mahendrakar# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*103e46e4SHarish Mahendrakar# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*103e46e4SHarish Mahendrakar# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22*103e46e4SHarish Mahendrakar# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23*103e46e4SHarish Mahendrakar# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24*103e46e4SHarish Mahendrakar# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25*103e46e4SHarish Mahendrakar# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*103e46e4SHarish Mahendrakar# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*103e46e4SHarish Mahendrakar# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*103e46e4SHarish Mahendrakar# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29*103e46e4SHarish Mahendrakar# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*103e46e4SHarish Mahendrakar
31*103e46e4SHarish Mahendrakarlog_err() {
32*103e46e4SHarish Mahendrakar  echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
33*103e46e4SHarish Mahendrakar}
34*103e46e4SHarish Mahendrakar
35*103e46e4SHarish Mahendrakar#######################################
36*103e46e4SHarish Mahendrakar# Create build directory. Build directory will be deleted if it exists.
37*103e46e4SHarish Mahendrakar# Outputs:
38*103e46e4SHarish Mahendrakar#   build dir path
39*103e46e4SHarish Mahendrakar# Returns:
40*103e46e4SHarish Mahendrakar#   mkdir result
41*103e46e4SHarish Mahendrakar#######################################
42*103e46e4SHarish Mahendrakarmake_build_dir() {
43*103e46e4SHarish Mahendrakar  if [[ "$#" -ne 1 ]]; then
44*103e46e4SHarish Mahendrakar    return 1
45*103e46e4SHarish Mahendrakar  fi
46*103e46e4SHarish Mahendrakar
47*103e46e4SHarish Mahendrakar  local build_dir
48*103e46e4SHarish Mahendrakar  build_dir="$1"
49*103e46e4SHarish Mahendrakar  [[ -d "${build_dir}" ]] && rm -rf "${build_dir}"
50*103e46e4SHarish Mahendrakar  mkdir -p "${build_dir}"
51*103e46e4SHarish Mahendrakar}
52*103e46e4SHarish Mahendrakar
53*103e46e4SHarish Mahendrakar#######################################
54*103e46e4SHarish Mahendrakar# Cleanup files from the backup directory.
55*103e46e4SHarish Mahendrakar# Globals:
56*103e46e4SHarish Mahendrakar#   BUILD_DIR     build directory
57*103e46e4SHarish Mahendrakar#   LIBWEBM_ROOT  repository's root path
58*103e46e4SHarish Mahendrakar#######################################
59*103e46e4SHarish Mahendrakarcleanup() {
60*103e46e4SHarish Mahendrakar  # BUILD_DIR is not completely removed to allow for binary artifacts to be
61*103e46e4SHarish Mahendrakar  # extracted.
62*103e46e4SHarish Mahendrakar  find "${BUILD_DIR:?}" \( -name "*.[ao]" -o -name "*.l[ao]" \) -exec rm \
63*103e46e4SHarish Mahendrakar    -f {} +
64*103e46e4SHarish Mahendrakar  make -C "${LIBWEBM_ROOT:?}" -f Makefile.unix clean
65*103e46e4SHarish Mahendrakar}
66