diff options
author | Matt Turner <mattst88@gmail.com> | 2020-05-06 15:57:25 -0700 |
---|---|---|
committer | Matt Turner <mattst88@gmail.com> | 2020-05-06 15:57:25 -0700 |
commit | 3313f001b48b40c8f5543271cd679f3bbb118b97 (patch) | |
tree | 655c73d9f629efbb6396ce6aaf2e3d1dfba6019a /nj |
Initial import
Diffstat (limited to 'nj')
-rwxr-xr-x | nj | 77 |
1 files changed, 77 insertions, 0 deletions
@@ -0,0 +1,77 @@ +#! /bin/bash +# +# Copyright 2017 Kenneth Graunke <kenneth@whitecape.org> +# +# This program 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. +# +# This program 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 this program. If not, see <http://www.gnu.org/licenses/>. +# _____________________________________________________________________ +# +# The "nj" ninja builder +# +# From any directory in a Git worktree, 'nj' will jump to the build +# directory, build, and optionally install your project. +# +# It supports in-tree builds, a single out-of-tree build (in build/), +# or multiple out-of-tree builds (in build/*/). +# +# Usage: +# $ nj [<build>] [<targets>] # if using multiple out-of-tree builds. +# $ nj [<targets>] # if using an in-tree or single out-of-tree build +# +# By default, <build> defaults to "debug". +# +# Setup: +# +# You can create multiple out-of-tree builds, named whatever you like. +# An example build called 'debug' would look like: +# +# - build/debug +# - build/debug/extratargets (optional) +# - build/debug/install (optional) +# +# If no targets are specified, nj defaults to 'all'. It appends the contents +# of the 'extratargets' file, if it exists, allowing you to build additional +# targets that aren't enabled by default in your project's build system, such +# as 'check'. +# +# Additionally, if 'install' exists, it runs 'ninja install'. This can be +# a directory which you've set as Meson/CMake's install prefix, or just a +# blank file if you want it to install elsewhere. +# _____________________________________________________________________ + +topdir=$(git rev-parse --show-toplevel) +if [ -f "$topdir/build.ninja" ]; then + # In-tree build exists, use that. + builddir="${topdir}" +elif [ -f "$topdir/build/build.ninja" ]; then + # Single out-of-tree build, use that. + builddir="${topdir}/build" +else + # Select an out of tree build from the first command line argument, + # defaulting to build-debug if no directory was given. + builddir="${topdir}/build-${1:-debug}" + shift + + if [ ! -f "$builddir/build.ninja" ]; then + echo "No build directory in \"$builddir\"...aborting." + exit + fi +fi + +cd "$builddir" + +extratargets="$(cat extratargets 2>/dev/null)" +targets="${@:-all $extratargets}" + +ninja $targets +[[ "$targets" == all* ]] && [ -e install ] && ninja install > /dev/null |