#*******************************************************************************
# E.S.O. - VLT project
#
# "@(#) $Id: Makefile_HP-UX,v 1.38 2004/07/15 16:38:34 vltsccm Exp $"
#
# Makefile of fposs
#
# who       when        what
# --------  ----------  --------------------------------------------------------
# pbaksai   2014/07/22  CCB-000755: Support for 64 bits.
#                       - Fixed location of X11 lib.
#                       - Fixed location of Tcl include and lib.
#                       - Fixed detection of Tcl/Tk version.
# pbaksai   2014/07/15  CCB-000755: Support for 64 bits.
#                       - Change location of Tcl files in a non-VLT system.
# pbaksai   2014/07/10  CCB-000755: Support for 64 bits.
#                       - Detect Tcl/Tk version using tclsh. Falls back to 8.3
#                       - TK_VERSION must be equal to TCL_VERSION
# lsanzana  2004-06-11  Added pafchecksum & crc32.
# rschmutz  2004-05-22  Adapted to APR2004 (Tcl/Tk 8.4).
# rschmutz  28/01/03    Create configure_expert.
# rschmutz  23/11/02    This header created - previous history see below.
#
#*******************************************************************************
# REMARKS
#    None
#-------------------------------------------------------------------------------
#
#              C o n f i g u r e   M a k e f i l e   ( H P - U X )
#
#   This is a specialised makefile used to build those parts of the 
#   AAO fibre configuration program 'configure' that require system-dependent
#   treatment. This version is for use on an ESO HP-UX system. It has 
#   been developed on the OzPoz development workstation at AAO and
#   assumes the locations for the Tcl and Tk files that are on that machine.
#   If this is run on a different machine, the lines defining TCL_LIB
#   and TCL_DIR may have to be changed.
#
#   Note that this makefile builds a version of configure that only supports
#   ESO's FLAMES instrument.
#
#   Author(s): Keith Shortridge, AAO (KS)
#
#   History:
#
#   21st Sep 2000.  Original version, KS.
#   21st Jun 2001.  Added convertPAF.o and replaced MessDummy.o with the proper
#                   mess.o file. KS.
#   16th Aug 2001.  Changed location of TCL_DIR for new VLT software layout,
#                   changed to using GNU C, leaving HP-UX C settings in the
#                   file but commented out. KS.
#   20th Aug 2001.  Added -Wall flag. Merged the SDS makefile with
#                   this, so all of configure is held in one directory.
#                   Added the various .h file dependencies. KS.
#                   file but commented out. KS.
#   21st Aug 2001.  Now generates Tcl/Tk directories, and supports the
#                   'release' target. Added the various .h file 
#                   dependencies. Now at version 0.8. KS.
#   27th Aug 2001.  Added sdslist target. Now uses revised FLAMES model
#                   code - fpmdl.c etc replaced by fpcolMdl.c. KS.
#    4th Sep 2001.  Removed tdfxy.h - no longer used. KS.
#   17th Sep 2001.  RELEASE_FILES now includes MISC_FILES and TCL_FILES. 
#                   OzPosModel{n}.sds files no longer used. KS.
#    8th Oct 2001.  Modified list of documentation files. Version up to 1.0. KS.
#   30th Oct 2001.  -DDRAMA_BUILD had been missing from CFLAGS. Fixed. 
#                   Added fpcolMdl_err.h and tdfxy.h to list of include 
#                   files. KS.
#   24th Jan 2002.  Most Makefile targets now in the common Makefile, this
#                   file now only handles the system-dependent compilation
#                   and build targets.
#   11th Feb 2002.  fpDefines.h moved to fpcol sub-directory. tdfxy.h no longer
#                   needed (it had worked its way back in again in the last
#                   change).
#   10th Apr 2002.  Added fpcolMdlFit.c. KS.
#    1st Aug 2002.  Modified for MAR2002 release of VLT software. KS.
#    6th Aug 2002.  Added fpcolMdlCalModel.c. TCL directories now defined in
#                   terms of $VLTSW_RELEASE. KS.
#
#*******************************************************************************
#  location of additional sources
#
SDS_SRC = sds
SLA_SRC = sla
DRAMA_SRC = drama
FPCOL_SRC = fpcol
PAFCHK_MODULE = ../../pafchk

#*******************************************************************************
#   The following Tcl directories (needed to pick up tcl.h and the Tcl 
#   libraries) are for the location used on the AAO OzPoz system. These lines
#   may have to be changed for other systems. The version numbers for Tcl
#   and Tk have to be defined here as well, since there doesn't seem to be
#   a general libtk and libtcl provided. These will have to be modified if
#   the Tcl/Tk versions change.
#
X11_LIB := $(shell (test -f /usr/lib/libX11.so && echo /usr/lib) || \
                   (test -f /usr/lib/libX11.so.6 && echo /usr/lib) || \
                   (test -d /usr/X11R?/lib && echo /usr/X11R?/lib) || \
                   echo ../tcltk/lib)
TCL_LIB := $(shell (test -d /vlt/$$VLTSW_RELEASE/tcltk/lib && echo /vlt/$$VLTSW_RELEASE/tcltk/lib) || \
                   (test -n "$$TCLTK_LIB" && echo $$TCLTK_LIB) || \
                   echo "/usr/lib")
TCL_DIR := $(shell (test -d /vlt/$$VLTSW_RELEASE/tcltk/include && echo /vlt/$$VLTSW_RELEASE/tcltk/include) || \
                   echo "../tcltk/include" )
TCL_VERSION := $(shell echo "puts [info tclversion]" | tclsh 2>/dev/null)
ifeq "$(TCL_VERSION)" ""
TCL_VERSION := $(shell (test -n "$$TCLTK_VERSION" && echo $$TCLTK_VERSION) || echo 8.3)
endif
TK_VERSION = $(TCL_VERSION)

#  Standard C settings. We use gcc with optimise selected and with the maximum
#  warnings . The DFLAMES_ONLY flag prevents the inclusion of code to support
#  the AAO's 2dF and 6dF instruments, limiting support to ESO's FLAMES system.

COPT = -O
CWARNINGS = -Wall -ansi -DUSE_COMPAT_CONST
CINCLUDES = -I$(SDS_SRC) -I$(DRAMA_SRC) -I$(SLA_SRC) -I$(FPCOL_SRC) -I$(PAFCHK_MODULE)/include -I.
CFLAGS = -DFLAMES_ONLY -DDRAMA_BUILD $(CWARNINGS) $(COPT) $(CINCLUDES)
CC = gcc

#   The C flags used include standard -I flags. Two versions of CFLAGS and CC
#   are shown here, one for GNU C (gcc) and one (commented out) for the
#   standard HP-UX compiler.

COPT = -O
CINCLUDES = -I$(TCL_DIR) -I$(SDS_SRC) -I$(DRAMA_SRC) -I$(SLA_SRC) \
            -I$(FPCOL_SRC) -I$(PAFCHK_MODULE)/include -I.
            
#   For GNU C, only the standard flags are needed. Note that although we
#   include -Wall we do not include -ansi, since this causes the compiler to
#   leave _HPUX_SOURCE undefined, and we need that to allow the status.h
#   file to determine the system type.

CWARNINGS = -Wall -DUSE_COMPAT_CONST
CC = gcc
CFLAGS = -DFLAMES_ONLY -DDRAMA_BUILD $(CWARNINGS) $(CINCLUDES) $(COPT)

#   For the HP-UX compiler, the C flags used also include the -Ae flag used 
#   to invoke an ansi standard compilation with some extensions.

#CC = cc
#CFLAGS = -DFLAMES_ONLY -DDRAMA_BUILD -Ae  $(CINCLUDES) $(COPT)

#*******************************************************************************
#  'configure' - the default taget for this Makefile - builds the
#  main FPOSS configure program.
#   
TCL_FILES = configure.tcl mimic.tcl procs.tcl util.tcl

../bin/configure : ../lib/configure
	@echo "TCL_VERSION = >$(TCL_VERSION)<"
	@echo "TCL_DIR = >$(TCL_DIR)<"
	@echo "TCL_LIB = >$(TCL_LIB)<"
	@echo "X11_LIB = >$(X11_LIB)<"
	/bin/cp $(TCL_FILES) ../lib
	/bin/cp configure.sh ../bin/configure
	/usr/bin/chmod +x ../bin/configure
	/bin/cp configure_expert.sh ../bin/configure_expert
	/usr/bin/chmod +x ../bin/configure_expert
	/bin/rm -f ../lib/configure_expert
	/bin/ln -s configure ../lib/configure_expert

../lib/configure : libsds.a configure.o config_method.o config.o FpilExtras.o \
           mess.o fpil.o fpilcons.o fpilmodel.o fpcolFpil.o fpcolBase.o \
           fpcolMdl.o fpcolMdlFit.o fpcolMdlCalModel.o \
           tdFparse.o tdFconvertSds.o \
           configversion.o convertPAF.o sla.o pafchkChecksum.o crc32.o
	$(CC) -o ../lib/configure configure.o config_method.o \
	   config.o FpilExtras.o mess.o fpil.o fpilcons.o fpilmodel.o \
	   fpcolFpil.o fpcolBase.o fpcolMdl.o fpcolMdlFit.o \
	   fpcolMdlCalModel.o tdFparse.o tdFconvertSds.o \
           configversion.o convertPAF.o sla.o pafchkChecksum.o crc32.o libsds.a \
           -L../lib -ltcl$(TCL_VERSION) -ltk$(TK_VERSION) \
           -L$(X11_LIB) -lX11 -lm
	/usr/bin/chatr +s enable ../lib/configure > /dev/null
              
#  These rules control the building of the SDS library, libsds.a
          
SDS_OBJECTS = arg.o ers_imp.o sds.o erssprintf.o ersvsprintf.o \
   sdsutil.o sdstclinit.o sdstcl.o
         
libsds.a : $(SDS_OBJECTS)
	ar -rv libsds.a $(SDS_OBJECTS)

#  sdslist is a utility program for examining SDS files. It isn't needed
#  by configure, but can be a useful diagnostic tool.
   
sdslist : $(SDS_SRC)/sdslist.c $(SDS_SRC)/sdsutil.c $(DRAMA_SRC)/status.h \
          $(SDS_SRC)/sds.h libsds.a
	$(CC) $(CFLAGS) $(SDS_SRC)/sdslist.c $(SDS_SRC)/sdsutil.c -o sdslist libsds.a

#  Include file dependencies
   
arg.o : $(SDS_SRC)/arg.c $(DRAMA_SRC)/status.h $(DRAMA_SRC)/Ers.h \
        $(SDS_SRC)/sds.h $(SDS_SRC)/arg.h
	$(CC) $(CFLAGS) -c $(SDS_SRC)/arg.c

config.o : config.c $(DRAMA_SRC)/drama.h $(SDS_SRC)/sds.h $(SDS_SRC)/arg.h \
           $(DRAMA_SRC)/Ers.h tdFconfig.h config_err.h

config_method.o : config_method.c $(DRAMA_SRC)/status.h tdFconfigMethod.h \
                  config_err.h

configure.o : configure.c $(DRAMA_SRC)/drama.h $(DRAMA_SRC)/status.h \
              $(SDS_SRC)/sds.h $(DRAMA_SRC)/Ers.h $(DRAMA_SRC)/mess.h \
              $(SDS_SRC)/sdstcl.h $(SDS_SRC)/arg.h $(SDS_SRC)/arg_err.h \
              tdFconvert.h convertPAF.h $(SDS_SRC)/sds_err_msgt.h \
              $(SDS_SRC)/arg_err_msgt.h conf_err_msgt.h config_err_msgt.h \
              fpil_err_msgt.h conf_err.h $(FPCOL_SRC)/fpcolFpil.h

convertPAF.o : convertPAF.c $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h \
               $(SLA_SRC)/slalib.h $(SLA_SRC)/slamac.h tdFconvert.h \
               $(DRAMA_SRC)/Ers.h convertPAF.h

ers_imp.o : $(DRAMA_SRC)/ers_imp.c $(DRAMA_SRC)/Ers.h
	$(CC) $(CFLAGS) -c $(DRAMA_SRC)/ers_imp.c

erssprintf.o : $(DRAMA_SRC)/erssprintf.c $(DRAMA_SRC)/Ers.h
	$(CC) $(CFLAGS) -c $(DRAMA_SRC)/erssprintf.c

ersvsprintf.o : $(DRAMA_SRC)/ersvsprintf.c $(DRAMA_SRC)/Ers.h
	$(CC) $(CFLAGS) -c $(DRAMA_SRC)/ersvsprintf.c

fpcolBase.o : $(FPCOL_SRC)/fpcolBase.c $(FPCOL_SRC)/fpcolBase.h \
              $(FPCOL_SRC)/fpcolInstDescr.h
	$(CC) $(CFLAGS) -c $(FPCOL_SRC)/fpcolBase.c

fpcolFpil.o : $(FPCOL_SRC)/fpcolFpil.c $(FPCOL_SRC)/fpcolFpil.h \
              $(DRAMA_SRC)/drama.h $(SDS_SRC)/sds.h \
              $(DRAMA_SRC)/Ers.h $(FPCOL_SRC)/fpDefines.h \
              $(FPCOL_SRC)/fpcolBase.h $(FPCOL_SRC)/fpcolFpil.h \
              $(FPCOL_SRC)/fpcolMdl.h $(FPCOL_SRC)/fpcolInstDescr.h
	$(CC) $(CFLAGS) -c $(FPCOL_SRC)/fpcolFpil.c
    
fpil.o : fpil.c fpil.h fpil_err.h

fpilcons.o : fpilcons.c $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h fpil.h fpil_err.h

FpilExtras.o : FpilExtras.c fpil.h

fpilmodel.o : fpilmodel.c $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h fpil.h \
              fpil_err.h

fpcolMdl.o : $(FPCOL_SRC)/fpcolMdl.c $(FPCOL_SRC)/fpcolMdl.h \
             $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h \
             $(SLA_SRC)/slalib.h $(SLA_SRC)/slamac.h $(DRAMA_SRC)/Ers.h
	$(CC) $(CFLAGS) -c $(FPCOL_SRC)/fpcolMdl.c

fpcolMdlFit.o : $(FPCOL_SRC)/fpcolMdlFit.c $(FPCOL_SRC)/fpcolMdl.h
	$(CC) $(CFLAGS) -c $(FPCOL_SRC)/fpcolMdlFit.c

fpcolMdlCalModel.o : $(FPCOL_SRC)/fpcolMdlCalModel.c \
                     $(FPCOL_SRC)/fpcolMdlCalModel.h
	$(CC) $(CFLAGS) -c $(FPCOL_SRC)/fpcolMdlCalModel.c

mess.o : $(DRAMA_SRC)/mess.c $(DRAMA_SRC)/status.h $(DRAMA_SRC)/drama.h \
         $(DRAMA_SRC)/mess.h
	$(CC) $(CFLAGS) -c $(DRAMA_SRC)/mess.c

sds.o : $(SDS_SRC)/sds.c $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h
	$(CC) $(CFLAGS) -c $(SDS_SRC)/sds.c

sdslist.o : $(SDS_SRC)/sdslist.c $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h
	$(CC) $(CFLAGS) -c $(SDS_SRC)/arg.c

sdstcl.o : $(SDS_SRC)/sdstcl.c $(SDS_SRC)/sdstcl.h $(SDS_SRC)/arg.h \
           $(DRAMA_SRC)/Ers.h $(SDS_SRC)/sds_err.h
	$(CC) $(CFLAGS) -c $(SDS_SRC)/sdstcl.c

sdstclinit.o : $(SDS_SRC)/sdstclinit.c $(SDS_SRC)/sdstcl.h \
               $(SDS_SRC)/arg_err.h $(DRAMA_SRC)/Ers.h
	$(CC) $(CFLAGS) -c $(SDS_SRC)/sdstclinit.c

sdstest.o : $(SDS_SRC)/sdstest.c $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h
	$(CC) $(CFLAGS) -c $(SDS_SRC)/sdstest.c

sdsutil.o : $(SDS_SRC)/sdsutil.c $(DRAMA_SRC)/status.h $(SDS_SRC)/sds.h
	$(CC) $(CFLAGS) -c $(SDS_SRC)/sdsutil.c

sla.o : $(SLA_SRC)/sla.c $(SLA_SRC)/slalib.h $(SLA_SRC)/slamac.h
	$(CC) $(CFLAGS) -c $(SLA_SRC)/sla.c

tdFconvertSds.o : tdFconvertSds.c $(SDS_SRC)/sds.c $(DRAMA_SRC)/status.h \
                  $(SDS_SRC)/sds.h conf_err.h tdFconvert.h

tdFparse.o : tdFparse.c $(DRAMA_SRC)/status.h $(SLA_SRC)/slalib.h \
             $(DRAMA_SRC)/Ers.h \
             $(SDS_SRC)/sds.h tdFconvert.h conf_err.h

pafchkChecksum.o : $(PAFCHK_MODULE)/src/pafchkChecksum.c $(PAFCHK_MODULE)/include/pafchk.h 
	$(CC) $(CFLAGS) -c $(PAFCHK_MODULE)/src/pafchkChecksum.c

crc32.o :  $(PAFCHK_MODULE)/src/crc32.c $(PAFCHK_MODULE)/include/zconf.h $(PAFCHK_MODULE)/include/zlib.h
	$(CC) $(CFLAGS) -c $(PAFCHK_MODULE)/src/crc32.c

#*******************************************************************************
#___oOo___
