#!/bin/bash
###############################################################################
# Copyright (C) Intel Corporation
#
# SPDX-License-Identifier: MIT
###############################################################################
# Build in typical fashion.
set -o errexit ; set -o nounset

if [ -z "$BASH_VERSION" ]; then
  echo "This script must be run under bash"
  exit 1
fi

script_dir="$( cd "$(dirname "${BASH_SOURCE[0]:-$0}")" >/dev/null 2>&1 ; pwd -P )"

source_dir="$(dirname "$script_dir")"
build_dir="$source_dir/_build"
staging_dir="$source_dir/_install"

cmake -B "$build_dir" -S "$source_dir" \
      -DBUILD_TESTS=ON \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_INSTALL_LIBDIR=lib \
      -DENABLE_DRI3=ON \
      -DENABLE_DRM=ON \
      -DENABLE_VA=ON \
      -DENABLE_WAYLAND=ON \
      -DENABLE_X11=ON \
      -DENABLE_WARNING_AS_ERROR=ON

cmake --build "$build_dir" --parallel $(nproc) --verbose

pushd "$build_dir"
  cpack .
popd

cmake --install "$build_dir" --prefix "$staging_dir" --config Release --strip
