#-------------------------------------------------------------------------------
#  (C) Altran Praxis Limited
#===============================================================================

################################################################################
# PURPOSE
#-------------------------------------------------------------------------------
# Makefile for Victor
# For Linux, Windows, Solaris or Mac OS X (aka Darwin).
################################################################################

################################################################################
# BUILD CONFIGURATION
################################################################################

OUTPUT_NAME:=vct

ALT_ERGO:=alt-ergo
VICTOR:=vct

# Location of root.
ROOT:=..

# Location of common.
COMMON:=${ROOT}/common

include ${COMMON}/Makefile.inc

################################################################################
# PLATFORM SPECIFIC CONFIGURATION
################################################################################

CPPFLAGS=
LDFLAGS=

# Windows.
ifeq (${TARGET},Windows)
    ifeq (${GCC_TARGET},i686-pc-mingw32)
        # on windows, let the compiler know the gmplib location
        CPPFLAGS="-I /gmp/include"
        LDFLAGS="-L /gmp/lib"
    endif
endif

################################################################################
# TARGETS
################################################################################

ALT_ERGO_DIR=$(shell ${TAR} ztf ${ALT_ERGO}-*.tar.gz | head -1)

# Target to build vct and alt-ergo
ifeq (${BUILD_VICTOR},true)
all: ${VICTOR}-target ${ALT_ERGO}-target
else
all:
endif

${VICTOR}-target:
	# Don't build Victor in parallel (-j). Missing dependencies in the Makefile.
ifeq (${TARGET},Darwin)
	$(MAKE) -C ${VICTOR}/src CPPFLAGS=${CPPFLAGS} LDFLAGS=${LDFLAGS} STATIC_GMP_MAC=1
else
	$(MAKE) -C ${VICTOR}/src CPPFLAGS=${CPPFLAGS} LDFLAGS=${LDFLAGS} STATIC_GMP=1
endif

${ALT_ERGO}-target: ${ALT_ERGO}
ifeq (${GCC_TARGET},i686-pc-mingw32)
	# on windows we mimick the build by copying the mingw binary provided
	# by the Alt-Ergo team to where a source built binary would have
	# appeared
	cp alt-ergo-*-mingw.exe ${ALT_ERGO}/alt-ergo.opt
else
	# by default, we build Alt-Ergo from the sources
	# Don't build Alt-Ergo in parallel (-j). Missing dependencies in the Makefile.
	cd ${ALT_ERGO} && ./configure
	$(MAKE) -C ${ALT_ERGO}
endif

${ALT_ERGO}:
	${TAR} zxvf ${ALT_ERGO}-*.tar.gz
	mv ${ALT_ERGO_DIR} ${ALT_ERGO}

# Cleaning code base
# ==================

clean:
	rm -Rf ${ALT_ERGO}
	-$(MAKE) -C ${VICTOR}/src clean
	rm -f ${VICTOR}/bin/${OUTPUT_NAME}${EXE_EXTN}

reallyclean: clean

################################################################################
# END-OF-FILE
