2019-12-18 21:26:51 -06: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
CMAKE ?= cmake
GENERATOR ?= $( shell ( which ninja > /dev/null 2> /dev/null && echo Ninja) || \
echo 'Unix Makefiles' )
prefix ?= /usr/local
PREFIX ?= $( prefix)
i f e q ( $( GENERATOR ) , N i n j a )
BUILDFILE = build.ninja
e l s e
BUILDFILE = Makefile
e n d i f
2019-12-18 21:28:56 -06:00
# If CMake has generated an in-tree Makefile, use that instead (issue #6264)
MAKE_DIR := $( shell dirname $( realpath $( firstword $( MAKEFILE_LIST) ) ) )
i f e q ( $( shell test -f $ ( MAKE_DIR ) /Makefile && echo 1) , 1 )
2019-12-18 22:13:41 -06:00
all :
@+$( MAKE) -f $( MAKE_DIR) /Makefile $( MAKECMDGOALS) --no-print-directory
2019-12-18 22:11:02 -06:00
% :
2019-12-18 21:28:56 -06:00
@+$( MAKE) -f $( MAKE_DIR) /Makefile $( MAKECMDGOALS) --no-print-directory
e l s e
2019-12-18 21:26:51 -06:00
all : .begin build /fish
2020-07-12 18:26:01 -05:00
.PHONY : .begin
2019-12-18 21:26:51 -06:00
.begin :
@which $( CMAKE) > /dev/null 2> /dev/null || \
( echo 'Please install CMake and then re-run the `make` command!' 1>& 2 && false )
2020-07-12 18:26:01 -05:00
.PHONY : build /fish
2019-12-18 21:26:51 -06:00
build/fish : build /$( BUILDFILE )
$( CMAKE) --build build
2020-07-12 18:26:01 -05:00
# Use build as an order-only dependency. This prevents the target from always being outdated
# after a make run, and more importantly, doesn't clobber manually specified CMake options.
build/$(BUILDFILE) : | build
2019-12-18 21:28:56 -06:00
cd build; $( CMAKE) .. -DCMAKE_EXPORT_COMPILE_COMMANDS= 1 -G " $( GENERATOR) " \
2020-07-05 22:09:53 -05:00
-DCMAKE_INSTALL_PREFIX= " $( PREFIX) " -DCMAKE_EXPORT_COMPILE_COMMANDS= 1 \
-DCMAKE_BUILD_TYPE= RelWithDebInfo
2019-12-18 21:26:51 -06:00
build :
mkdir -p build
.PHONY : clean
clean :
rm -rf build
.PHONY : test
test : build /fish
$( CMAKE) --build build --target test
.PHONY : install
install : build /fish
$( CMAKE) --build build --target install
.PHONY : run
run : build /fish
./build/fish || true
.PHONY : exec
exec : build /fish
exec ./build/fish
2019-12-18 21:28:56 -06:00
e n d i f # CMake in-tree build check