/*
// Local configuration file for ANL
*/

ADSOFT = /adsoft

/* if you want to turn on debug falgs, define here */
#define PassCDebugFlags

/* if you want cernlib fix for shared HBOOK, define here */
#define Add_CERNLIB_FIX		/* add cernlib-fix to libANL.a */

/* path to install binaries and libraries */
INSTALL_LIB_PATH = $(TOP)/$(EXT)
INSTALL_BIN_PATH = $(TOP)/$(EXT)/bin
INSTALL_INC_PATH = $(TOP)/include

/*
// ANL install directory
*/
ANL_DIR = ${ADSOFT}/aste_anl/$(ANL_ver)
ANL_INC = ${ANL_DIR}/include
ANL_LIB = ${ANL_DIR}/${EXT}
ANL_BIN = ${ANL_DIR}/${EXT}/bin
ANL_LNK = -L${ANL_LIB} -lANL -lBNK -lEVS
/* for ASCA_ANL compatibility */
ASCA_ANL_DIR = ${ANL_DIR}
ASCA_ANL_INC = ${ANL_INC}
ASCA_ANL_LIB = ${ANL_LIB}
ASCA_ANL_BIN = ${ANL_BIN}
ASCA_ANL_LNK = ${ANL_LNK}

/*
// ASTETOOL
*/
ASTETOOL_DIR = ${ADSOFT}/astetool/$(ASTETOOL_ver)
/*   where aste_*.h exists */
ASTETOOL_INC = ${ASTETOOL_DIR}/include
/*   ASCATOOL link option */
ASTETOOL_LNK = -L${ASTETOOL_DIR}/${EXT} -lastetool

/*
// ASCATOOL
*/
ASCATOOL_DIR = ${ADSOFT}/ascatool/$(ASCATOOL_ver)
/*   where ascatool.h exists */
ASCATOOL_INC = ${ASCATOOL_DIR}/include
/*   ASCATOOL link option */
ASCATOOL_LNK = -L${ASCATOOL_DIR}/${EXT} -lascatool

/*
// COM + CLI
*/
COM_CLI_DIR = ${ADSOFT}/com_cli/$(COM_CLI_ver)
READLINE_DIR = ${ADSOFT}/readline/$(READLINE_ver)
/*   where cli.h, com.h exists */
COM_CLI_INC = ${COM_CLI_DIR}/include
/*   COM + CLI [+ readline] link option */
/*   specify libreadline.a for MacOSX Tiger, which has system BSD readline */
COM_CLI_LNK = -L${COM_CLI_DIR}/${EXT} -lCOM -lCLI ${READLINE_DIR}/${EXT}/libreadline.a -ltermcap

/*
// atFunctions
*/
ATFUNCTIONS_DIR = ${ADSOFT}/atFunctions/$(ATFUNCTIONS_ver)
/*   where atFunctions.h and atError.h exists */
ATFUNCTIONS_INC = ${ATFUNCTIONS_DIR}/include
/*   atFunctions link option */
ATFUNCTIONS_LNK = -L${ATFUNCTIONS_DIR}/${EXT} -latFunctions

/*
// X-Window ProjectRoot
*/
X11_DIR = /usr/X11R6

/*
// CFORTRAN
*/
CFORTRAN_INC = ${ADSOFT}/cfortran/$(CFORTRAN_ver)

/*
// CERN
*/
CERN_DIR = ${ADSOFT}/cern/$(CERN_ver)
/*   where cfortran.h and hbook.h exists */
CERN_INC = ${CERN_DIR}/include
/*   CERN libraries link option */
/* CERN_LNK = \
-L${CERN_DIR}/${EXT} -lgraflib -lgrafX11 -lpacklib -lkernlib -lmathlib \
-L${X11_DIR}/lib -lX11 */
CERN_LNK = -L${CERN_DIR}/${EXT} -lcernlib-dummy

/*
// CFITSIO
*/
CFITSIO_DIR = ${ADSOFT}/cfitsio/$(CFITSIO_ver)
/*   where fitsio.h exists */
CFITSIO_INC = ${CFITSIO_DIR}/include
/*   CFITSIO link option */
CFITSIO_LNK = -L${CFITSIO_DIR}/${EXT} -lcfitsio

/*
// FITSIO
*/
CWFITSIO_DIR = ${ADSOFT}/cwfitsio/$(CWFITSIO_ver)
/*   where cwfitsio.h exists */
CWFITSIO_INC = ${CWFITSIO_DIR}/include
/*   CWFITSIO link option */
CWFITSIO_LNK = -L${CWFITSIO_DIR}/${EXT} -lcwfitsio
/*   FITSIO link option */
FITSIO_LNK = ${CWFITSIO_LNK} ${CFITSIO_LNK}

/*
// HEADAS
*/
HEADAS_DIR = ${ADSOFT}/headas/$(HEADAS_ver)
/*   where headas.h, etc exists */
HEADAS_INCLUDE = -I$(HEADAS_DIR)/heacore/heainit -I$(HEADAS_DIR)/heacore/heautils -I$(HEADAS_DIR)/heacore/heaio -I$(HEADAS_DIR)/heacore/pil
/*   HEADAS link option */
HEADAS_LNK = $(HEADAS_DIR)/$(EXT)/lib/libhdinit.a $(HEADAS_DIR)/$(EXT)/lib/libhdutils.a $(HEADAS_DIR)/$(EXT)/lib/libhdio.a $(HEADAS_DIR)/$(EXT)/lib/libpil.a

/****************************************************************************/
/************************* End of Includes.make *****************************/
/****************************************************************************/


/* Architecture dependent definitions */

#if defined(UltrixArchitecture)
FFLAGS = -g
CDEBUGFLAGS = -g
LIBSYS=-lUfor -lfor -lutil -li -lots
#endif

#if defined(AlphaArchitecture)
CC = cc
/* -mieee flag required for gcc/g++ for OSF1, to handle denormalized number */
CXX = g++ -mieee
CDEBUGFLAGS = -O -g3
CXXDEBUGFLAGS = -O3 -g3
FFLAGS = -O -g3
LIBSYS = -lUfor -lfor -lFutil -lots -lexc -lmld
#endif

#if defined(SunArchitecture)
#if (OSMajorVersion == 4)
#undef HasSharedLibraries
CC = gcc -munaligned-doubles
CDEBUGFLAGS = -O -g
FFLAGS = -O -g -Nl200
LIBSYS = -L`echo /usr/lang/SC?.0` -lF77
#else
CC = cc -D_XOPEN_SOURCE
CDEBUGFLAGS = -O -g
CXXDEBUGFLAGS = -O3 -g
FFLAGS = -O -g
/*LIBSYS = -L/opt/SUNWspro/lib -lM77 -lF77 -lsunmath*/
LIBSYS = -L/opt/SUNWspro/lib -lfsu -lfui -lf77compat -lsunmath

.SUFFIXES: .cc
.cc.o:
	$(CXX) $(CXXFLAGS) -c -o $@ $<

#endif
#endif

#if defined(LinuxArchitecture) && defined (i386Architecture)
CC = gcc
CXX = g++
CDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
CXXDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
DEFINES = -Dg77Fortran -fwritable-strings
FC = g77 -fno-second-underscore -fno-f2c
FFLAGS = -O3 -g
LIBSYS = -lstdc++ -lg2c
#endif

#if defined(LinuxArchitecture) && (defined (x86_64Architecture) || defined(AMD64Architecture))
CC = gcc
CXX = g++
CDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
CXXDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
DEFINES = -Dg77Fortran -fwritable-strings
FC = g77 -fno-second-underscore -fno-f2c
FFLAGS = -O3 -g
LIBSYS = -lstdc++ -lg2c
#endif

#if defined(PpcDarwinArchitecture)
CC = gcc
CXX = g++
CDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
CXXDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
INSTALLFLAGS = -c
DEFINES = -Dg77Fortran -fwritable-strings
FC = g77 -fno-second-underscore -fno-f2c
FFLAGS = -O3 -g
LIBSYS = -L/sw/lib -lstdc++ -lg2c
#endif

#if defined(i386DarwinArchitecture)
CC = gcc
CXX = g++
CDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
CXXDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
INSTALLFLAGS = -c
DEFINES = -Dg77Fortran -fwritable-strings
FC = gfortran -fno-second-underscore -fno-f2c
FFLAGS = -O -g
LIBSYS = -lstdc++ -lgfortran
#endif

#if defined(cygwinArchitecture)
CC = gcc
CDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
CXXDEBUGFLAGS = -O3 -g -Wall -Wno-long-long #--pedantic
DEFINES = -Wall -Dg77Fortran -fwritable-strings
FC = g77 -fno-second-underscore -fno-f2c
FFLAGS = -O -g
LIBSYS = -lstdc++ -lg2c
#endif

/* ANL definitions */

LINK_LIB = \
$(USR_LNK) $(ANL_LNK) $(COM_CLI_LNK) \
$(ASTETOOL_LNK) $(ASCATOOL_LNK) $(ATFUNCTIONS_LNK) \
$(CERN_LNK) $(CWFITSIO_LNK) $(HEADAS_LNK) $(CFITSIO_LNK) $(LIBSYS) -lm

ANLCFLAGS = \
$(USR_INCLUDE) -I$(ANL_INC) -I$(COM_CLI_INC) \
-I$(ASTETOOL_INC) -I$(ASCATOOL_INC) -I$(ATFUNCTIONS_INC) \
-I$(CFORTRAN_INC) -I$(CERN_INC) -I$(CWFITSIO_INC) -I$(CFITSIO_INC) \
$(HEADAS_INCLUDE)

ANLFFLAGS = -I$(ANL_INC)

MKANLINIT = $(ANL_BIN)/mkanlinit

.SUFFIXES: .def

.def.o:
	( cat $<; echo ""; echo $*.c; echo yes ) | $(MKANLINIT)
	$(CC) $(CFLAGS) -c -o $@ $*.c;

.f.o:
	$(FC) $(FFLAGS) $(ANLFFLAGS) -c -o $@ $<

.c.o:
	$(CC) $(CFLAGS) $(ANLCFLAGS) -c -o $@ $<

/* dummy entry for non-GNU Make */
all::

clean::
	-$(RM) `ls -1 *.def | sed 's/\.def$$/.c/g'`
