#!/bin/csh -f
########################################################################
# This is a "makefile generator" for the doris software.  It creates
# a makefile for compilation of the Doris source code.  Follow the 
# on the screen please.
#
# For CYGWIN: change the first line to "tcsh -f". (Download tcsh from 
#     ------  redhat site, together with the develop package.)
#
#########################################################################
# based on interactive questions, and ls commands.
#%// BK 24-Aug-2000
# Added check for strptime
#%// BK 08-Mar-2001
# Changed name of script to "configure".
# Added big endian check.
#%// BK 19-Apr-2001
# Added large file support and -Wno-deprecated warnings
#%// PM 18-Aug-2004
# Added more path options for fftw.higher versions and different compilers
#%// PM 01-Sep-2004
# baseline.doris.sh and baseline.doris.csh
#%// PM 15-Feb-2007
# Added compilation and linking of Triangulate
#%// FvL 02-OKT-2007
# Added check .so for fftw and libsearch dir as /usr/lib64
#%// MA 02-Mar-2009
# Update testorbit build
#%// MA 22-May-2009
#

if ( -x /bin/clear ) /bin/clear
#set PRG    = `basename "$0"`
set PRG    = "configure"
set VER    = "v1.7, DEOS software"
set AUT    = "TUDelft, 19-May-2009"
set MAKEFILE = "Makefile"


echo "$PRG $VER, $AUT"
echo " "
echo " Welcome to the Makefile generator for the Doris insar software."
echo " I will ask you some questions on compilers, etc."
echo " The output of this program is a makefile named: $MAKEFILE"
echo " that you can use to compile Doris."
echo " More instructions will follow afterwards. (Please read them.)"
echo " "
echo "===> Press enter to continue."
set key = $<


# Declare variables.
set CC          = ""
set GppCOMPILER = n
set FFTW        = n
set VECLIB      = n
set LAPACK      = n
set X86         = n
set DEBUG       = n
set FFTWLIBDIR  = ""
set FFTWINCLDIR = ""
set VECLIBDIR   = ""
set LAPACKDIR   = ""
set LIBDIRS     = "../fftw-3.2.1/lib ../../fftw-3.2.1/lib /lib /lib64 /usr/lib /usr/lib64 /usr/lib32 /usr/local/lib"
### for fftw include dirs, assume they installed it with doris distributed.
### by doing what we said in install.
set INCLDIRS    = "../fftw-3.2.1/include ../../fftw-3.2.1/include /include /usr/include /usr/local/include"
set DEFINSTALLDIR  = "/home/dummy/bin"
if ( ! -d $DEFINSTALLDIR ) set DEFINSTALLDIR = "/usr/local/bin"
if ( ! -d $DEFINSTALLDIR ) set DEFINSTALLDIR = "../bin"

#
set TMPDIR = "/tmp"
if ( ! -w $TMPDIR ) set TMPDIR = .
echo "   Using temp dir: $TMPDIR"


# Get most likely compiler, first check g++
foreach TMPCC ( g++ g++-3.4 g++-4.0 g++-4.1 g++-4.2 g++-4.3 CC aCC icpc )
  echo Checking compiler: \"$TMPCC\"...
  $TMPCC -v > & /dev/null
  if ( ! $status ) then
    echo "   I found a working(?) compiler: $TMPCC"
    set CC = "$TMPCC"
    break
  endif
end


#
# Set flag for g++, this define enables some functions like sqr(int)
# that are not standard C++, but were provided with, e.g., HP aCC compiler.
#
if ( "$CC" == "g++" ) set GppCOMPILER = "y"


#
# Check little Endian integers:
# Compile this program and run it.
#
set TSTPRG = "$TMPDIR/Doris_endian"
echo "Checking endianness for integers..."
echo "Creating test program: $TSTPRG.cc"
cat << __EOFDH > $TSTPRG.cc
/* *** Test program to find out if little endian           *** */
/* *   Generated by Doris software install script            * */
/* *   Exits with 0 if big, 1 if little endian integer.      * */
/* *** Bert Kampes, 19-Apr-2001                            *** */
// #include <ctime>
int main()
  {
  int i;
  int littleendian=0;// thus big assumed
  char test[64]={0};
  for (i=0;i<32;i++) test[i]=0;
  test[0]=0x01;
  if (0x0001==*(int *)(&test[0])) littleendian=1;
  return littleendian;
  }
__EOFDH
echo "Compiling test program: $TSTPRG"
$CC $TSTPRG.cc -o $TSTPRG > & /dev/null
if ( $status != 0 ) then
  echo "   ---------------------------------------------------------------"
  echo "   Sorry, could not compile test program, continuing."
  echo "   THIS WILL LIKELY CAUSE TROUBLE IF YOUR COMPILER DOESN'T WORK"
  echo "   Please change endianness interactively in a moment if required."
  echo "   ---------------------------------------------------------------"
  echo " "
  set X86 = "n"
endif
echo "Running test program: $TSTPRG"
if ( -x $TSTPRG ) then
  $TSTPRG > & /dev/null
  if ( $status != 0 ) then
    set X86 = "y"
    echo "   Your system seems Little Endian, using -D__X86PROCESSOR__"
    echo "   (or program failed to execute for another reason)"
  else
    echo "   Your system is Big Endian (not using a define)."
  endif
  rm -f $TSTPRG.cc $TSTPRG.o $TSTPRG
endif
echo " "


#
# Check library function strptime works:
#
echo "Checking whether library function strptime works ok..."
set STRPTIME = "1"
set TSTPRG = "$TMPDIR/Doris_strptime"
echo "Creating test program: $TSTPRG.cc"
cat << __EOFDH > $TSTPRG.cc
/* *** Test program to find out if function strptime works *** */
/* *   Generated by Doris software install script            * */
/* *** Bert Kampes, 14-Mar-2001                            *** */
//#include <iostream>
// #include <time.h>
#include <ctime>
int main()
  {
  struct tm tm_ref;
  char utc_ref[100] = "05-JAN-1985 01:02:03.000";
  strptime(utc_ref,"%d-%b-%Y %T",&tm_ref);
  int status = 0;
  if (tm_ref.tm_mday != 5) status=1;
  if (tm_ref.tm_mon  != 0) status=1;
  if (tm_ref.tm_year != 85) status=1;
  if (tm_ref.tm_hour != 1) status=1;
  if (tm_ref.tm_min  != 2) status=1;
  if (tm_ref.tm_sec  != 3) status=1;
  //cerr << "tm_ref.tm_mday: " << tm_ref.tm_mday << endl;
  return status;
  }
__EOFDH
echo "Compiling test program: $TSTPRG"
$CC $TSTPRG.cc -o $TSTPRG > & /dev/null
if ( $status != 0 ) then
  echo "   function strptime not found in library, using internal definition."
  echo "   by define -D__NO_STRPTIME (change by editing DEF8 in $MAKEFILE)"
  set STRPTIME = "0"
endif
echo "Running test program: $TSTPRG"
if ( -x $TSTPRG ) then
  $TSTPRG > & /dev/null
  if ( $status != 0 ) then
    echo "   strptime does not work properly, using internal definition."
    echo "   by define -D__NO_STRPTIME (change by editing DEF8 in $MAKEFILE)"
    echo "   (or program failed to execute for another reason)"
    set STRPTIME = "0"
  else
    rm -f $TSTPRG.cc $TSTPRG.o $TSTPRG
  endif
endif
if ( "$STRPTIME" == "1" ) then
  echo "   Library function strptime works fine, using it."
endif
echo " "




#
# Try to find veclib library
#
foreach DIR ( $LIBDIRS )
 echo Checking directory: \"$DIR\" for Veclib...
 if ( -e $DIR/libveclib.a ) then
   echo "   I found libveclib.a in $DIR"
   set VECLIBDIR = "$DIR"
   set VECLIB = "y"
   break
 endif
end
#
# Try to find lapack library (careful, most people have fortran version)
#
foreach DIR ( $LIBDIRS )
 echo Checking directory: \"$DIR\" for Lapack...
 if ( -e $DIR/liblapack.a ) then
   echo "   I found liblapack.a in $DIR"
   set LAPACKDIR = "$DIR"
   set LAPACK = "y"
   break
 endif
end
if ( "$VECLIB" == "n" ) echo "   I could not find libveclib.a"
if ( "$LAPACK" == "n" ) echo "   I could not find liblapack.a"
echo " "
#
# Try to find fftw library
#
foreach DIR ( $INCLDIRS )
 echo Checking directory: \"$DIR\" for fftw3.h...
 if ( -e $DIR/fftw3.h ) then
   echo "   I found fftw3.h in $DIR"
   set FFTWINCLDIR = "$DIR"
   #set FFTW = "y"
   break
 endif
end
foreach DIR ( $LIBDIRS )
 echo "Checking directory: $DIR for libfftw3f.[a|so]..."
 if ( -e $DIR/libfftw3f.a ) then
   echo "   I found libfftw3f.a in $DIR"
   set FFTWLIBDIR = "$DIR"
   set FFTW = "y"
   break
 else if ( -e $DIR/libfftw3f.so ) then
   echo "   I found libfftw3f.so in $DIR"
   set FFTWLIBDIR = "$DIR"
   set FFTW = "y"
   break
 endif
end
if ( "$FFTW" == "n" ) echo "   I could not find libfftw3f.a or libfftw3f.so"
if ( "$FFTW" == "y" ) if ( "$VECLIB" == "y" ) echo "   NOT POSSIBLE TO USE VECLIB AND FFTW"
echo " "



##########################################################################
#
# Interactive questions/check by user:
#
echo "===> What is your C++ compiler? [$CC] "
set key = $<
if ( "X$key" != "X" ) set CC = "$key"
if ( "$CC" == "g++" ) set GppCOMPILER = y

echo "===> Do you have the FFTW library (y/n)? [$FFTW] "
set key = $<
if ( "$key" == "y" || "$key" == "Y" ) then 
  set FFTW = "y"
else if ( "$key" == "n" || "$key" == "N" ) then
  set FFTW = "n"
else
  echo "     Using default: [$FFTW]"
endif
if ( "$FFTW" == "y" ) then
  echo "===> What is the path to the FFTW library (libfftw3f.a or libfftw3f.so)? [$FFTWLIBDIR] "
  set key = $<
  if ( "X$key" != "X" ) set FFTWLIBDIR = "$key"
  if ( "X$FFTWLIBDIR" == "X" || ! -d $FFTWLIBDIR ) then
    echo " you entered a non existing directory: $FFTWLIBDIR"
    echo "===> What is the path to the FFTW library? [$FFTWLIBDIR] "
    set key = $<
    if ( "X$key" != "X" ) set FFTWLIBDIR = "$key"
  endif
  echo "===> What is the path to the FFTW include file (fftw3.h)? [$FFTWINCLDIR] "
  set key = $<
  if ( "X$key" != "X" ) set FFTWINCLDIR = "$key"
  if ( "X$FFTWINCLDIR" == "X" || ! -d $FFTWINCLDIR ) then
    echo " you entered a non existing directory: $FFTWINCLDIR"
    echo "===> What is the path to the FFTW library? [$FFTWINCLDIR] "
    set key = $<
    if ( "X$key" != "X" ) set FFTWINCLDIR = "$key"
  endif
endif


echo "===> Do you have the VECLIB library (y/n)? [$VECLIB] "
set key = $<
if ( "$key" == "y" || "$key" == "Y" ) then 
  set VECLIB = "y"
else if ( "$key" == "n" || "$key" == "N" ) then
  set VECLIB = "n"
else
  echo "     Using default: [$VECLIB]"
endif
if ( "$VECLIB" == "y" ) then
  echo "===> What is the path to the VECLIB library? [$VECLIBDIR] "
  set key = $<
  if ( "X$key" != "X" ) set VECLIBDIR = "$key"
  if ( "X$VECLIBDIR" == "X" || ! -d $VECLIBDIR ) then
    echo " you entered a non existing directory: $VECLIBDIR"
    echo "===> What is the path to the VECLIB library? [$VECLIBDIR] "
    set key = $<
    if ( "X$key" != "X" ) set VECLIBDIR = "$key"
  endif
endif


echo "===> Do you have the LAPACK library (y/n)? [$LAPACK] "
set key = $<
if ( "$key" == "y" || "$key" == "Y" ) then
  set LAPACK = "y"
else if ( "$key" == "n" || "$key" == "N" ) then
  set LAPACK = "n"
else
  echo "     Using default: [$LAPACK]"
endif
if ( "$LAPACK" == "y" ) then
  echo "===> What is the path to the LAPACK library liblapack.a? [$LAPACKDIR] "
  set key = $<
  if ( "X$key" != "X" ) set LAPACKDIR = "$key"
  if ( ! -d $LAPACKDIR ) then
    echo " you entered a non existing directory: $LAPACKDIR"
    echo "===> What is the path to the LAPACK library? [$LAPACKDIR] "
    set key = $<
    if ( "X$key" != "X" ) set LAPACKDIR = "$key"
  endif
  ### Check LAPACK dir fortran version (underscore appended)
  echo " Checking whether you have FORTRAN LAPACK library:"
  nm $LAPACKDIR/liblapack.a | grep spotrf_ >& /dev/null
  if ( $status == 0 ) then
    echo "     FORTRAN"
  else
    echo "     C (or nm failed?)"
    echo "     If compilation fails, please do not use LAPACK"
    echo "     or change in the source code file matrixspecs.cc"
  endif
endif


echo "===> Are you working on a Little Endian (X86 PC, Intel) machine (y/n)? [$X86] "
set key = $<
if ( "$key" == "y" || "$key" == "Y" ) set X86 = "y"
if ( "$key" == "n" || "$key" == "N" ) set X86 = "n"


echo "===> Do you want to compile a more verbose DEBUG version (y/n)? [$DEBUG] "
echo "     (You can first compile an optimal version, then perform a make clean,"
echo "      and then compile a debug version, which you can use in case doris "
echo "      does not produce expected results)"
set key = $<
if ( "$key" == "y" || "$key" == "Y" ) set DEBUG = "y"


set INSTALLDIR = "dummy.$$.$$.$$"
while ( ! -d $INSTALLDIR )
  set INSTALLDIR = "$DEFINSTALLDIR"
  echo "===> Installation of Doris in directory: $INSTALLDIR (y/n)? [y]"
  set key = $<
  if ( "$key" == "n" || "$key" == "N" ) then
    echo "===> Enter installation directory (use absolute path): "
    set INSTALLDIR = $<
    if ( ! -d $INSTALLDIR ) then
      echo "===> Installation directory: $INSTALLDIR does not exist."
      echo "===> Should I create it (y/n)? [y]"
      set key = $<
      if ( "$key" != "n" && "$key" != "N" ) mkdir $INSTALLDIR
    endif
  endif
end



###################################################
echo " "
echo " Creating Makefile for:"
echo " compiler:       $CC"
echo " fftw:           $FFTW"
if ( "$FFTW" == "y" ) echo " FFTW LIB DIR:     $FFTWLIBDIR"
if ( "$FFTW" == "y" ) echo " FFTW INCLUDE DIR: $FFTWINCLDIR"
echo " veclib:         $VECLIB"
if ( "$VECLIB" == "y" ) echo " VECLIB dir:     $VECLIBDIR"
echo " lapack:         $LAPACK"
if ( "$LAPACK" == "y" ) echo " LAPACK dir:     $LAPACKDIR"
echo " Little endian:  $X86"
echo " DEBUG version:  $DEBUG"
echo " Install in dir: $INSTALLDIR"
echo " "
if ( -e $MAKEFILE ) then
  echo " file: $MAKEFILE will be OVERWRITTEN."
else
  echo " file: $MAKEFILE will be created."
endif
echo "===> Press enter to continue (CTRL-C to exit)."
set key = $<



#
# Set variable for LFLAGS, IFLAGS, DEFINES
#
# +++ At 17:49, August 29th, Robert J. Mellors wrote:
#<RJM:   I had a few minor problems compiling v3.16 with gcc on my intel linux
#<RJM:  redhat system -
#<RJM: [...]
#<RJM:  Next, the linker complained about a variety of missing functions,
#<RJM:  c_sqrt and a plethora of others; I added
#<RJM:  -lg2c   (before -lm) to LFLAGS in the Makefile (being too lazy to do it
#<RJM:  right and change configure).
#<RJM:  This seemed to fix that.

set CFLAGS = " "
set LFLAGS = " "
#set LFLAGS = "-lg2c"
set IFLAGS = " "
if ( "$FFTW" == "y" ) then                           # MA moved back to top due to searchpath issues: ../fftw/lib vs /usr/lib
  set CFLAGS = "$CFLAGS -D__USE_FFTW_LIBRARY__"
  ### last one must be fftw lib and math lib         # to be tested again
  ### for Cygwin, the slash after "-L$FFTWLIBDIR/" is maybe required?!
  echo "Adding extra lib flag for fftw: -lm (must be at end)"
  set LFLAGS = "$LFLAGS -L$FFTWLIBDIR -lfftw3f -lm"
  set IFLAGS = "$IFLAGS -I$FFTWINCLDIR"
endif
###########################
if ( "$LAPACK" == "y" ) then 
  set CFLAGS = "$CFLAGS -D__USE_LAPACK_LIBRARY__"
  # Set the location of liblapack.a (DEF4)
  echo "Adding lib for lapack"
  set LFLAGS = "$LFLAGS -L$LAPACKDIR -llapack"
endif
###########################
if ( "$VECLIB" == "y" ) then 
  set CFLAGS = "$CFLAGS -D__USE_VECLIB_LIBRARY__"
  # Set the location of libveclib.a (DEF4)
  echo "Adding extra flag for veclib: -lcl"
  set LFLAGS = "$LFLAGS -L$VECLIBDIR -lveclib -lcl"
endif
###########################
if ( "$X86" == "y" ) then
  set CFLAGS = "$CFLAGS -D__X86PROCESSOR__"
endif
###########################
if ( "$STRPTIME" == "0" ) then
  set CFLAGS = "$CFLAGS -D__NO_STRPTIME"
endif
###########################
#DEF9     = -D__NO_IOS_BINARY__ # -9- comment out if you ios::binary (most will)
### include dir for fftw
set CFLAGS = "$CFLAGS $IFLAGS"




#
# Create the Makefile:
#

cat << __EOFHD > $MAKEFILE
#########################################################################
# Makefile for the Doris software.					#
# Created by: $PRG						#
# 04-Dec-1998                                                           #
#                                                                       #
# Delft University of Technology                                        #
# Delft Institute of Earth Observation and Space Systems                #
# http://doris.tudelft.nl               				#
# See also the user manual, annex installation.				#
#									#
### Usage ### 								#
# The command: "make" creates and optimized version of doris.		#
# The command: "make install" installs it andcleans up.			#
# If this does not work, try a more controlled approach by:		#
#									#
# 0. inspect set up of this Makefile					#
# 1. set CC DEFS LIBS etc., first set these to debug values		#
#    (read NOTE there if problems)					#
# 2. compile software sources to *.o:     "make swobjs"			#
# 3. link object together to executable:  "make doris"			#
# 4. install executable:                  "make install"		#
# 5. remove object files:                 "make clean"			#
#									#
# BTW. "make" does "swobjs doris" by default.				#
#									#
###        								#
# Successfully tested for compilers/platforms:				#
#  GNU g++ version 2.7.2.2 on HP-UX B.10.20 A 9000/785			#
#  GNU g++ version 2.95.2  on HP-UX B.10.20 A 9000/785			#
#  HP  aCC version A.01.07 on HP-UX B.10.20 A 9000/785			#
#  GNU g++ version ?       on Linux X86					#
#  SGI ?								#
#  Sun Studion 9,10,11     on Solaris Sparc and X86/AMD64		#
#  GNU g++ versions v3.4, v4.0, v4.1, v4.2, v4.3 on Linux X86 and AMD64 # 
#  Sun Sudion v11          on Linux AMD64				#
#  Intel Compilers v9, v10, v11 on Linux AMD64				#
#########################################################################
###################################################################
###################################################################
# Please change if required: DEF[1-6], CC, CFLAGS, LIBDIR,      ###
###################################################################
### The shell used by this makefile ###
SHELL   = /bin/sh

### Specify compiler/installation directory ###
INSTALLDIR = $INSTALLDIR
CC	   = $CC
SCRIPTSDIR = ../bin

### Define statements controlling compilation ###
# Comment out DEF[1-8] statements when appropriate.
DEF1    = -D__DEBUGMAT1	# 		-1- range checking in matrix class
DEF2    = -D__DEBUGMAT2	# 		-2- info matrix class (debug only)
DEF3    = -D__DEBUG #			-3- debug for other files
DEF4    = -Wno-deprecated            #  -4- do not display warnings due to depricated entries 
DEF5    = -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE #  -5- support for large files
#DEF6    = -DNO_FASTTRIG              #  -6-  extra functional switches
#DEF9     = -D__NO_IOS_BINARY__ # -9- comment out if you ios::binary (most will)
#
### Do not change following 2, simply comment DEF1-8 above
DEFSDEBUG 	= \$(DEF1) \$(DEF2) \$(DEF3)
DEFS		= \$(DEF4) \$(DEF5) \$(DEF6) $CFLAGS

### NOTE ###
# If you get warnings like the following (I got them with g++, not with aCC)
# then use define __GNUC__ to define these functions
#%// BK 15-Aug-2000
#In file included from matrixbk.h:38,
#		 from processor.cc:23:
#constants.h: In method \`real8 cn::dist(cn) const':
#constants.h:106: implicit declaration of function \`int sqr(...)'
### END NOTE ###


# LOCAL dir
LOCAL_INSTALLDIR = ../bin

### CFLAGS ###
# Compiler options flag ###
# Specify compiler flags (I selected these for g++)
CFLAGSDEBUG 	= -g -O \$(DEFS) \$(DEFSDEBUG)
CFLAGSOPT 	= -O \$(DEFS)
#CFLAGSOPT 	= -O2 \$(DEFS)   # this crashed doris! (?)
#CFLAGSOPT 	= -O3 \$(DEFS)   # this crashed doris! (?)

__EOFHD



#
# See if you want a DEBUG version
#
if ( "$DEBUG" == "n" ) then
cat << __EOFHD >> $MAKEFILE
### CCNOTE ###
### Change here ###
### set CFLAGS depending on if you compile debug version or working version ###
#CFLAGS 	= \$(CFLAGSDEBUG)
CFLAGS 	= \$(CFLAGSOPT)
### END CCNOTE ###
__EOFHD
else
cat << __EOFHD >> $MAKEFILE
### CCNOTE ###
### Change here ###
### set CFLAGS depending on if you compile debug version or working version ###
CFLAGS 	= \$(CFLAGSDEBUG)
#CFLAGS 	= \$(CFLAGSOPT)
### END CCNOTE ###
__EOFHD
endif



#
# Add LFLAGS to Makefile 
#
cat << __EOFHD >> $MAKEFILE

### Library locations flag ###
### -lcl : used for veclib 
### -lm  : used for fftw
LFLAGS  = $LFLAGS


#####################################################
### No need to change anything below here... ####
#####################################################
EXECUTABLE = 	doris

SWSRCS	=	processor.cc \
		utilities.cc \
		ioroutines.cc \
		readinput.cc \
		readdata.cc \
		coregistration.cc \
		filtering.cc \
		referencephase.cc \
		products.cc \
		geocode.cc \
		unwrap.cc \
		matrixspecs.cc \
		exceptions.cc \
		estorbit.cc
SWOBJS	=	\$(SWSRCS:.cc=.o)

### scripts of doris.tar in SCRIPTSDIR, used at make install
SCRIPTS	=	helpdoris \
		baseline.doris.sh \
		baseline.doris.csh \
                construct_dem.sh \
		coregpm.doris \
		doris* \
		heightamb \
		phasefilt.doris \
		plotcpm* \
		plotoffsets* \
		run \
		viewanddel \
		cpx2ps \
		lonlathei2ascii \
		ascii2ascii_UTM \
		ascii2ps* \
                tsx* \
                rs2* \
                csk* \
                gammaReadfiles.csh \
                hhmmss2sec.py \
                sec2hhmmss.py




#####################################################
### And no need to change anything below here... ####
#####################################################
### what to do if make w/o arguments ###
# first make all object files, then link them together
default:        \$(EXECUTABLE)


### how to compile object code .o from C++ source files .cc (general rule) ###
# space between -o and filename for SUN make (BK 7 july 2000)
.cc.o:		
		\$(CC) \$(CFLAGS) -c -o \$(@) \$<

#####################################################
### Make object code from source ###
swobjs:		\$(SWOBJS)


### Load objects to executable ###
### The added .cc files contain class definitions
### matrixclass is explicitly included
### in the source code since we had some problems finding out how to do that
### here, since compilers treat the template class differently than normal classes.
### BK 07-Feb-2002
\$(EXECUTABLE):	\$(SWOBJS) tmp_strptime.cc slcimage.cc productinfo.cc orbitbk.cc
		\$(CC) \$(CFLAGS) -c -o triangle.o -DTRILIBRARY -DANSI_DECLARATORS triangle.c
		\$(CC) \$(CFLAGS)\
		tmp_strptime.cc \$(SWOBJS) triangle.o\
		slcimage.cc productinfo.cc orbitbk.cc\
		\$(LFLAGS) -o \$@
		@echo " "
		@echo "*******************************"
		@echo "* ...Compilation finished...  *"
		@echo "*******************************"
		@echo " "


### Install executable in installdir ###
install:	\$(EXECUTABLE)
		@echo "* Installing \$(EXECUTABLE) in: \$(INSTALLDIR)"
		@cp -f \$(EXECUTABLE) \$(INSTALLDIR)/.
		( cd \$(SCRIPTSDIR); cp -f \$(SCRIPTS) \$(INSTALLDIR)/. )
		\$(MAKE) cleaner
		@echo " "
		@echo "*******************************"
		@echo "* ...Installation finished... *"
		@echo "*******************************"
		@echo " "
		@echo "* Check that \$(INSTALLDIR) is in your path search: echo \\\$\$PATH ."
		@echo " "


installcb:	\$(EXECUTABLE)
		@echo "* Installing \$(EXECUTABLE) in: \$(LOCAL_INSTALLDIR)"
		@cp -f \$(EXECUTABLE) \$(LOCAL_INSTALLDIR)/.
		\$(MAKE) cleaner
		@echo " "
		@echo "*******************************"
		@echo "* ...Installation finished... *"
		@echo "*******************************"
		@echo " "
		@echo "* Check that \$(LOCAL_INSTALLDIR) is in your path search: echo \\\$\$PATH ."
		@echo " "


#####################################################
### Testers ###
test:		testdoris
testdoris:	\$(EXECUTABLE)
		@echo " "
		@echo "* Executing command: \$(EXECUTABLE) -v"
		\$(EXECUTABLE) -v
		@echo " "

### Orbit test program for debugging ###
test-orbit:	ioroutines.o matrixspecs.o utilities.o exceptions.cc slcimage.cc orbitbk.cc matrixbk.cc bk_messages.hh
		\$(CC) \$(CFLAGS) -D__TESTMAIN__ \
		ioroutines.o matrixspecs.o utilities.o exceptions.cc slcimage.cc orbitbk.cc \
		\$(LFLAGS) \
		-o \$@
### Matrix test program for debugging ###
### fast_sin defined in utilities.cc, which requires ioroutines, which, etc.
test-matrix:  matrix_test.cc matrixspecs.o utilities.o utilities.o ioroutines.o matrixbk.cc
		\$(CC) \$(CFLAGS) matrix_test.cc matrixspecs.o \
		utilities.o ioroutines.o exceptions.cc orbitbk.cc \
		\$(LFLAGS) \
		-o \$@
		@echo " "


#####################################################
### Cleaners ###
clean:		cleanswobjs 

cleaner:	clean cleanprog
cleanest:	clean cleanprog uninstall
cleanprog:
		@rm -f \$(EXECUTABLE) \$(EXECUTABLE.debug) \
		matrixbk_test testorbit
		@echo "* Removed executables in current dir."
cleanswobjs:
		@rm -f \$(SWOBJS) matrixbk_test.o orbitbk.o slcimage.o triangle.o
		@echo "* Removed object files."
uninstall:	
		@rm -f \$(INSTALLDIR)/\$(EXECUTABLE)
		@echo "* Removed executables in install dir: \$(INSTALLDIR)."

### BK 12-Dec-2000 ###

__EOFHD




### Finish with some hints.
set LINE = `grep -n CFLAGSOPT $MAKEFILE | cut -f1 -d":"`
cat << __EOFHD

  $PRG has finished creating: $MAKEFILE
  -------------------------------------------------
  To compile the Doris software do the following:
   1. Inspect the created Makefile named: $MAKEFILE
       *TIP* If you like to use other compiler flags (CFLAGS),
             change them in file: $MAKEFILE
             change them at line: $LINE[1] in file: $MAKEFILE
       *TIP* the command: make -f $MAKEFILE -n 
             will show what happens without executing.

   2. At the prompt, enter the command:
        make -f $MAKEFILE
      to compile an version of Doris.
       *TIP* if compilation FAILS due to strptime, try uncommenting DEF8
       *TIP* if compilation FAILS due to something else, please report the
             problem to the mailing list, after checking the user manual
	     and the FAQ.

   3. Enter the command: make -f $MAKEFILE install
      to install the executable in directory: $INSTALLDIR
      This will also install the scripts residing in directory ../bin
      and it will clean up this directory (remove the object files).

   4. After installation, the command:
        doris -v         [should now give the version number]
        doris -h         [should give help]
        doris -c         [should give the copyright notice]
        doris -q         [should give help also]

       *TIP* Make sure the installation directory is in your path.
             (do a rehash or login again)
 
   5. You are adviced to create a (slower, much more verbose) debug 
      version of Doris.  If you get an error during running the normal 
      version of Doris, you can repeat the processing with this debug
      executable.  In order to compile a debug version, make sure the
      normal version is installed.  next, run the configure script again
      (or set appropriate CFLAGS in file $MAKEFILE at line $LINE[2]),
      and indicate that you do want a debug version.  Then give the commands:
        make clean
	make -f $MAKEFILE 
      This compiles a debug version, named "doris".  Do not use make install,
      instead move this executable to "doris.debug" in the installation
      directory by hand.

  ----------------------------------------------------------------------
  DO NOT FORGET to go to directory SARtools and do a make install,
  and also in directory ENVISAT_TOOLS.  The programs in these directories
  are used in doris.
  Before compiling doris, create the fftw library if you want to use it.
  ----------------------------------------------------------------------
  
  
  MORE INFORMATION
  ----------------
   - See the README file, the $MAKEFILE, or the users manual
     (at: http://doris.tudelft.nl/)
   - Consider installing the Matlab InSAR toolbox.

__EOFHD

### EOF.

