################################################################################
#
# ninja.cygclass - functions for building Ninja-based packages
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2020 Cygport authors
# Provided by the Cygwin project <https://cygwin.com/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <https://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/ninja.cygclass
#  SYNOPSIS
#  inherit ninja
#  DESCRIPTION
#  Ninja is a build system with a focus on speed.  It is designed to have its
#  input files (named ninja.build) generated by a higher-level build system,
#  such as CMake or Meson.
#  INHERITED BY
#  meson.cygclass
#  REQUIRES
#  ninja
#****

#****C* ninja.cygclass/cygninja
#  SYNOPSIS
#  cygninja [OPTIONS]
#  DESCRIPTION
#  Runs 'ninja' with the given arguments.
#****
cygninja() {
	if ! inherited meson && [ ! -e build.ninja ]
	then
		error "cygninja: build.ninja: file not found"
	fi
	ninja ${_nproc} ${@} || error "cygninja: command failed: ${@:-all}"
}

#****T* ninja.cygclass/ninja_test
#  DESCRIPTION
#  Runs the package's test suite with 'ninja check'. Any arguments to
#  ninja_test are passed along.  ninja_test must be run from the directory
#  containing 'build.ninja'.
#****
ninja_test() {
	cygninja test ${@}
}

#****I* ninja.cygclass/ninja_install
#  DESCRIPTION
#  Installs the package into $D with 'ninja install'. Any arguments to
#  ninja_install are passed along. ninja_install must be run from the directory
#  containing 'build.ninja'.
#****
ninja_install() {
	DESTDIR=${D} cygninja install ${@}
}

readonly -f cygninja ninja_test ninja_install
