AC_INIT()

AC_ARG_ENABLE([debugging], 	 [  --enable-debugging            enable -g when compiling ])
AC_ARG_ENABLE([64bit_analysis],	 [  --enable-64bit-analysis       enable 64bit binary analysis ])
AC_ARG_ENABLE([64bit_build],	 [  --enable-64bit-build          enable 64bit build of stars, enabling more memory usage.])
AC_ARG_ENABLE([reducedanalysis], [  --enable-reducedanalysis      reduce the amount of in-depth analysis (useful for large programs that exhaust memory)])
AC_ARG_ENABLE([idapro],          [  --enable-idapro          	  build STARS as a plugin for IDA])
AC_ARG_ENABLE([idapro],          [  --enable-irdb          	  build STARS as a IRDB analysis])



AC_CANONICAL_HOST

EXTRA_CXXFLAGS=-O3 
CXX=g++
LD=g++
PLUGIN_NAME=SMPStaticAnalyzer.plx

if test "$enable_debugging" = yes; then 
	EXTRA_CXXFLAGS=-g
fi

if test "$enable_idapro" != no; then 
	BACKENDS=idapro
	if test "$enable_64bit_build" = yes; then
		echo Using 64-bit build mode is disabled with IDA -- exiting...
		exit 1
	fi
fi
if test "$enable_irdb" = yes; then 
	BACKENDS="$BACKENDS irdb"
fi




EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS}  \
                                   -std=c++0x \
	-I${SMPSA_HOME}/include  \
	-I${SMPSA_HOME}/include/base  \
	-I${SMPSA_HOME}/include/interfaces  \
	-I${SMPSA_HOME}/include/interfaces/abstract \
	-I${IDASDK}/include \
	-I${SMPSA_HOME}/include/interfaces/idapro \
	-D__LINUX__ -w   \
	" 

# select 32-bit or 64-bit build mode.
if test "$enable_64bit_build" = yes; then
	EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -m64"
else
	EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -m32"
fi

# set flags specific to each backend.
IDA_CXXFLAGS="-DSTARS_IDA_INTERFACE -D__PLUGIN__  -D__IDP__ --short-enums"
IRDB_CXXFLAGS="-DSTARS_IRDB_INTERFACE -I${SECURITY_TRANSFORMS_HOME}/include -I${SECURITY_TRANSFORMS_HOME}/libIRDB/include -I${SECURITY_TRANSFORMS_HOME}/beaengine/include"


if test "$enable_reducedanalysis" = yes; then 
	EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -DSMP_REDUCED_ANALYSIS"
fi

if test ! "$enable_64bit_analysis" = no; then
	echo Enabling 64-bit IDAPRO support.
   	EXTRA_CXXFLAGS="${EXTRA_CXXFLAGS} -D__EA64__"
   	PLUGIN_NAME=SMPStaticAnalyzer.plx64
fi

STARS_HOME=$SMPSA_HOME

AC_SUBST(EXTRA_CXXFLAGS)
AC_SUBST(CXX)
AC_SUBST(LD)
AC_SUBST(PLUGIN_NAME)
AC_SUBST(STARS_HOME)
AC_SUBST(IDA_CXXFLAGS)
AC_SUBST(IRDB_CXXFLAGS)
AC_SUBST(BACKENDS)

AC_OUTPUT(Makefile
	src/Makefile
	src/base/Makefile
	src/interfaces/Makefile
	src/interfaces/idapro/Makefile
	src/interfaces/irdb/Makefile
	src/interfaces/abstract/Makefile
	src/drivers/Makefile
	src/drivers/idapro/Makefile
	src/drivers/irdb/Makefile
	lib/irdb/Makefile
	lib/idapro/Makefile
	lib/Makefile
	scripts/Makefile
)
