#!/usr/bin/env sh
#
# mk -- build minxlib
#
# Convenience script for building minxlib without having to switch to
# the out-of-source build directory and other such hassles.
#

#
# Copyright (C) 2012 The Minx Project Developers
#
# See wiki/copyright.wiki for the full list of authors who have
# contributed to this project.
#

#
# This file is part of Minx.
#
# Minx 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.
#
# Minx 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 Minx. If not, see <http://www.gnu.org/licenses/>.
#

#------------------------------- MAIN ----------------------------------

# Restrict executable search path
PATH="/usr/local/bin:/usr/bin:/bin"

# Decide whether we want release or debug builds
BUILD=release # default
[ "$1" = "-d" -o "$1" = "--debug" ] && { BUILD=debug ; shift ; }

# Switch to the correct directory, i.e., the one containing this script
ABS_NAME=`readlink -f "$0"`
cd `dirname "$ABS_NAME"`

# Okay, now let's build the dang thing
[ -s build/$BUILD/Makefile ] || { # no Makefile ==> need to run cmake first
    rm -rf build/$BUILD
    mkdir -p build/$BUILD
    cd build/$BUILD
    cmake -DCMAKE_BUILD_TYPE=$BUILD ../.. || exit 1
    cd -
}
make -j4 -C build/$BUILD $@

#-----------------------------------------------------------------------

# Editor config:
#
# Local Variables:
# indent-tabs-mode: nil
# sh-basic-offset: 4
# End:
#
# vim: expandtab shiftwidth=4 tabstop=4
