#!/bin/sh

ABORT=no

check_cmake() {
	(cmake --version) < /dev/null > /dev/null 2>&1 || {
		echo "error: cmake 2.8 or higher must be present to configure and install MADlib"
		ABORT=yes
	}
}

check_cmake
test "$ABORT" = yes && exit -1

cd `dirname $0`
mkdir -p build
cd build
rm -f CMakeCache.txt
cmake "$@" ..

# Create top-directory Makefile
cd ..

cat <<MAKEFILE >Makefile

all:

%:
	\$(MAKE) -C build \$@
clean:
	rm -f Makefile
	rm -rf build
MAKEFILE

if [ -e META.json ]; then
	cat <<MAKEFILE >>Makefile
install: extension-install
# keep a tab to do nothing for install

extension-install:
	\$(MAKE) -C build \$@
MAKEFILE
fi
