2019-12-19 06:26:51 +03:00
# This is a very basic `make` wrapper around the CMake build toolchain.
#
# Supported arguments:
# PREFIX: sets the installation prefix
# GENERATOR: explicitly specifies the CMake generator to use
# By default, bmake will try to cd into ./obj before anything else. Don't do that.
.OBJDIR : ./
CMAKE ?= cmake
# Before anything else, test for CMake, which is the only requirement to be able to run
# this Makefile CMake will perform the remaining dependency tests on its own.
.BEGIN :
@which $( CMAKE) >/dev/null 2>/dev/null || \
( echo 'Please install CMake and then re-run the `make` command!' 1>& 2 && false )
# Prefer to use ninja, if it is installed
_GENERATOR != which ninja 2>/dev/null >/dev/null && echo Ninja || echo "Unix Makefiles"
GENERATOR ?= $( _GENERATOR)
. i f $(GENERATOR) = = "Ninja"
2020-07-13 02:26:01 +03:00
BUILDFILE = build.ninja
2019-12-19 06:26:51 +03:00
. e l s e
2020-07-13 02:26:01 +03:00
BUILDFILE = Makefile
2019-12-19 06:26:51 +03:00
. e n d i f
PREFIX ?= /usr/local
2020-07-13 02:26:01 +03:00
.PHONY : build /fish
2019-12-19 06:26:51 +03:00
build/fish : build /$( BUILDFILE )
$( CMAKE) --build build
2020-07-13 02:26:01 +03:00
# Don't split the mkdir into its own rule because that would cause CMake to regenerate the build
# files after each build (because it adds the mdate of the build directory into the out-of-date
# calculation tree). GNUmake supports order-only dependencies, BSDmake does not seem to.
build/$(BUILDFILE) :
2019-12-19 06:26:51 +03:00
mkdir -p build
cd build; $( CMAKE) .. -G " $( GENERATOR) " -DCMAKE_INSTALL_PREFIX= " $( PREFIX) " -DCMAKE_EXPORT_COMPILE_COMMANDS= 1
.PHONY : install
install : build /fish
$( CMAKE) --build build --target install
.PHONY : clean
clean :
rm -rf build
.PHONY : test
test : build /fish
$( CMAKE) --build build --target test
.PHONY : run
run : build /fish
build/fish