#!/bin/bash

bash --version

set -xe

basename="$(dirname "$0")"

if [[ ${CC} ]]; then
	JUDYCC="$CC"
else
	JUDYCC=gcc
fi

if [[ ! ${COPT} ]]; then
	COPT="-DJU_64BIT -O2 -fPIC -fno-strict-aliasing"
fi


if $JUDYCC -v 2>&1 >/dev/null | grep -E "clang|gcc version 4.6"; then
	COPT+=""
else
	COPT+=" -fno-aggressive-loop-optimizations"
fi


if [ ! -d "judy-1.0.5/src" ]; then
	(
		cd "$basename";
		gzip -dc Judy-1.0.5.tar.gz | tar -x
		cd judy-1.0.5/src
		CC="$JUDYCC" COPT="$COPT" sh ./sh_build
	)
fi
