#*******************************************************************************
# E.S.O. - VLT project
#
# "@(#) $Id: Makefile_Linux,v 1.43 2009/06/26 14:05:53 vltsccm Exp $"
#
# Makefile of fposs
#
# who       when        what
# --------  ----------  --------------------------------------------------------
# jpritcha  2016/10/01  Added support for Linux_x86_64
#                       - Compile and link in 64bit on 64bit OS
#                       - Force 32bit compilation on 64bit OS with variable MK32BIT = true
# 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.
#                       - Compile and link in 32 bits.
# 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-31  Make sure that the VLTSW Tcl/Tk is used.
# 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   ( L i n 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 a Linux system. It has been 
#   developed on a Red Hat 6.0 system with Tcl/Tk 8.0 installed in the
#   standard locations, so the relevant include files and libraries are found
#   in the default paths. 
#
#   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.
#   14th May 2001.  Added convertPAF. KS.
#    6th Jun 2001.  Included proper mess.o file, introduced COPT. KS.
#   20th Aug 2001.  Added -Wall -ansi flags. Merged the SDS makefile with
#                   this, so all of configure is held in one directory.
#   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.
#    5th Jun 2002.  Added rules for 6dF and 2dF targets. KS.
#    6th Aug 2002.  Added fpcolMdlCalModel.c. 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.
#   20140710: CCB-000755
#   - Now the current Tcl version number is detected and Tk version
#     is assumed to be the same.
#   - To compile in a non-VLT system, directories are changed assuming it
#     compiles from inside the FPOSS package.
#   - Ubuntu puts TCL inlcude files in /usr/include/tcl<VERSION>
#     direcctories and i386 libraries in /usr/lib/i386-linux-gnu on
#     x86_64 OSs
#     
#     
#
X11_LIB := $(shell (test -f /usr/lib/libX11.so && echo /usr/lib) || \
                   (test -f /usr/lib/libX11.so.6 && echo /usr/lib) || \
                   (test -n "$$MK32BIT" && test -f /usr/lib/i386-linux-gnu/libX11.so.6 && echo /usr/lib/i386-linux-gnu) || \
                   (test -d /usr/X11R?/lib && eval echo /usr/X11R?/lib) || \
                   echo "/usr/lib")

## TCL version
## -----------
## to control manually use:
# export TCL_VERSION=8.5
ifeq "$(TCL_VERSION)" ""
  TCL_VERSION := $(shell echo "puts [info tclversion]" | tclsh 2>/dev/null)
endif
ifeq "$(TCL_VERSION)" ""
  TCL_VERSION := $(shell (test -n "$$TCLTK_VERSION" && echo $$TCLTK_VERSION) || echo 8.3)
endif
TK_VERSION = $(TCL_VERSION)

TCL_LIB := $(shell (test -d /vlt/$$VLTSW_RELEASE/tcltk/lib && echo /vlt/$$VLTSW_RELEASE/tcltk/lib) || \
                   (test -n "$$TCLTK_LIB" && echo $$TCLTK_LIB) || \
                   (test -n "$$MK32BIT" && test -f /usr/lib/i386-linux-gnu/libtcl$(TCL_VERSION).so && echo /usr/lib/i386-linux-gnu) || \
                   echo ../tcltk/lib)
TCL_DIR := $(shell (test -d /vlt/$$VLTSW_RELEASE/tcltk/include && echo /vlt/$$VLTSW_RELEASE/tcltk/include) || \
                   (test -f /usr/include/tcl$$TCL_VERSION/tcl.h && echo /usr/include/tcl$$TCL_VERSION ) || \
                   (test -n "$$TCLTK_DIR" && echo $$TCLTK_DIR) || \
                   echo "../tcltk/include" )

#*******************************************************************************
#  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 -m32
#LOPT = -m32
ifndef MK32BIT
  ifeq ($(shell uname -i),x86_64)
    COPT = -O3 -D__linux_x86_64__
    LOPT =
  endif
endif
## [JPR] 2023-12-20: Force 64bit (for now)
COPT = -O3 -D__linux_x86_64__
LOPT =
CWARNINGS = -Wall -ansi -DUSE_COMPAT_CONST -DUSE_INTERP_RESULT
## The following is useful for debugging...
#CWARNINGS = -Wall -ansi -DUSE_COMPAT_CONST -DUSE_INTERP_RESULT -Wno-unused -Wno-deprecated-declarations -Wno-format-security
CINCLUDES = -I$(TCL_DIR) -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

#*******************************************************************************
#  '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
	/bin/chmod +x ../bin/configure
	/bin/cp configure_expert.sh ../bin/configure_expert
	/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 \
           $(LOPT) \
           -L$(TCL_LIB) -ltk$(TK_VERSION) -ltcl$(TCL_VERSION) \
           -L$(X11_LIB) -lX11 -lm -ldl
              
#  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) -I$(VLTROOT)/include -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___
