#*******************************************************************************
# E.S.O. - VLT project
#
# "@(#) $Id: Makefile 290518 2016-11-24 15:14:57Z pbaksai $"
#
# Makefile of fposs
#
# who       when      what
# --------  --------  ----------------------------------------------
# jpritcha  2016/10/01  Added 32bit target which will force 32bit compilation 
#                       on 64bit OS (Implemented for Linux ONLY)
# rschmutz  28/01/03  install configure in INTROOT.
# rschmutz  28/01/03  target expert_release added.
# rschmutz  15/01/03  Tcl *.s[lo] libraries added to release file.
# rschmutz  23/11/02  directories reorganized: more similar to standard module.
#                     create release tar so that in unpacks everything under
#                     a single directory (FPOSS).
# rschmutz  23/11/02  this header created - previous history see below.
#

#*******************************************************************************
# REMARKS
#    None
#------------------------------------------------------------------------

#
#              F P O S S  ( C o n f i g u r e )   M a k e f i l e  
#
#  This makefile is a system-independent makefile that is used to build
#  the fibre configuration program (FPOSS, also known as 'configure') used
#  by the ESO FLAMES instrument. It has a number of targets, but the only
#  ones expected to be specified explicitly are:
#
#  all       The default target. Builds the main FPOSS program - the
#            'configure' executable. Note that this only supports the
#            ESO FLAMES instrument.
#
#  release   Builds the tar file that is released by ESO to observers who
#            want to run FPOSS on their systems. This contains the executable
#            program and any necessary ancilliary files. Building this
#            target on different systems (eg HP-UX, Solaris, etc) produces
#            different tar files containing the executable specific to the 
#            system used for the build.
#
#  expert_release   As release above, but also distributes the configure_expert
#		    version of the configure utility.
#
#  clean     Cleans up the main source directory, leaving it suitable to be
#            archived under cmm, for example.
#
#
#  Author(s): Keith Shortridge, AAO (KS)
#
#  History:
#
#  22nd Jan 2002.  Original version. Previous versions of the Makefile were
#                  system-specific. This new version contains most of the
#                  common targets, but makes use of system-specific Makefiles
#                  to do the actual compilation and linking. KS.
#  11th Feb 2002.  System name now included in the tar file generated by the
#                  release target. KS.
#  12th Feb 2002.  Explicit version numbers for tcl and tk are no longer
#                  included in the tcl and tk directory names.
#  14th Sep 2002.  Default target now renamed fposs, ensuring the makefile works
#                  properly when source files are modified but the executable is
#                  unchanged. Added 'configure_full' target and improved some
#                  comments. KS.
#  26th Sep 2002.  Added release_full target. KS.
#   2nd Oct 2002.  No longer uses vlt1.fld. KS.
#  11th Nov 2002.  Now includes eso-logo.bmp. KS.

#*******************************************************************************
#  Version number. This rather messy line is used to extract the RCS
#  revision number for this Makefile - which at ESO will be the overall
#  revision number. Note: 1) The number in the string "$Revision n.m $"
#  is changed automatically by RCS when the file is retrieved from the
#  archive. 2) The first R in R$Revision is unnecessary, but makes the
#  command look nicer when printed, since the shell strips off the $R
#  and so R$Revision is echoed just as 'Revision', whereas $Revision
#  is echoed as 'evision'. 3) What actually goes into $VERSION is the string
#  with both the echo and the awk commands, so this is executed each time
#  $(VERSION) appears in a rule - it isn't done just once to set VERSION to
#  the actual version number, instead VERSION is a command that will output
#  the version number. 4) This isn't the best way to do it - normally one
#  would use the VERSION:sh construct provided by make, but gmake doesn't
#  seem to support this properly. This scheme works under make and gmake.

VERSION = `echo "R$Revision: 290518 $ " | awk '{print $$2}' -`

#*******************************************************************************
#  'all' - the default taget for this Makefile - builds the
#  main FPOSS configure program. Note that this is done through a
#  system-secific makefile. These system-specific Makefiles are given
#  names such as Makefile. Note: this target is called 'fposs' although
#  the executable that is built is called 'configure'. There is no file
#  used by the system called 'fposs', meaning that the system-specific 
#  make action is always executed.

32bit : 
	export MK32BIT=true ; \
	make -f Makefile_`uname` ../bin/configure

all : 
	make -f Makefile_`uname` ../bin/configure
           
man :
	@# no man pages

install :
	@# for simplicity, we assume that INTROOT is always available
	@/usr/bin/install -d "$(INTROOT)"/lib/fposs/bin
	@/usr/bin/install -d "$(INTROOT)"/lib/fposs/lib
	@/usr/bin/install -d "$(INTROOT)"/lib/fposs/config
	@/usr/bin/install -d "$(INTROOT)"/share/fposs
	@/bin/rm -f "$(INTROOT)"/lib/fposs/bin/configure
	@/usr/bin/install ../bin/configure "$(INTROOT)"/lib/fposs/bin/configure
	@/bin/rm -f "$(INTROOT)"/lib/fposs/bin/configure_expert
	@/usr/bin/install ../bin/configure_expert "$(INTROOT)"/lib/fposs/bin/configure_expert
	@/bin/rm -f "$(INTROOT)"/lib/fposs/lib/configure
	@/usr/bin/install ../lib/configure "$(INTROOT)"/lib/fposs/lib/configure
	@/bin/rm -f "$(INTROOT)"/lib/fposs/lib/configure_expert
	@/bin/ln -s configure "$(INTROOT)"/lib/fposs/lib/configure_expert
	@/bin/rm -f "$(INTROOT)"/lib/fposs/lib/configure.tcl
	@/usr/bin/install ../lib/configure.tcl "$(INTROOT)"/lib/fposs/lib/configure.tcl
	@/bin/rm -f "$(INTROOT)"/lib/fposs/lib/mimic.tcl
	@/usr/bin/install ../lib/mimic.tcl "$(INTROOT)"/lib/fposs/lib/mimic.tcl
	@/bin/rm -f "$(INTROOT)"/lib/fposs/lib/procs.tcl
	@/usr/bin/install ../lib/procs.tcl "$(INTROOT)"/lib/fposs/lib/procs.tcl
	@/bin/rm -f "$(INTROOT)"/lib/fposs/lib/util.tcl
	@/usr/bin/install ../lib/util.tcl "$(INTROOT)"/lib/fposs/lib/util.tcl
	@/bin/rm -f "$(INTROOT)"/lib/fposs/config/fpossInsStatus.sds
	@/usr/bin/install ../config/fpossInsStatus.sds "$(INTROOT)"/lib/fposs/config/fpossInsStatus.sds
	@/bin/rm -fr "$(INTROOT)"/share/fposs/test
	@/usr/bin/rsync -ax ../test "$(INTROOT)"/share/fposs
	@echo " . . . installation done."

#*******************************************************************************
#  'clean' is a standard target to get rid of object and other intermediate
#  files.
      
clean :
	-/bin/rm -rf ../bin/* ../lib/* ../tmp/* *.o *.a sdslist ../CheckFibreFail.sds

#*******************************************************************************
#  'release' builds the tar file used to release the system

#  The following sections define the various files needed for a release
#  of the system. That is, to generate the tar file that is released by ESO.
#
#  These are the files required for a release of the system. We
#  include these in the tar file generated by the 'release' target. 
#  This only includes those files needed to run FPOSS.
#TCL_FILES =        configure.tcl \
#		    mimic.tcl     \
#		    procs.tcl     \
#		    util.tcl
RELEASE_FILES = bin/configure 		  \
		lib			  \
		config/fpossInsStatus.sds \
		test/M67.fld		  \
		test/N3201-00.fld
   
release : all ../lib/tk
	-/bin/rm -rf ../tmp/FPOSS
	-/bin/rm -f ../lib/configure_expert
	mkdir ../tmp/FPOSS
	( cd .. ; tar -cf - $(RELEASE_FILES) | ( cd tmp/FPOSS ; tar xvf - ))
	( cd ../tmp ; tar -cvf ../bin/fposs-$(VERSION).`uname`.tar FPOSS )
	-/bin/rm -f ../bin/fposs-$(VERSION).`uname`.tar.gz
	gzip ../bin/fposs-$(VERSION).`uname`.tar
	-/bin/rm -rf ../tmp/FPOSS
	@echo Created release file: ../bin/fposs-$(VERSION).`uname`.tar.gz

EXPERT_RELEASE_FILES = bin/configure	  \
		bin/configure_expert	  \
		lib			  \
		config/fpossInsStatus.sds \
		test/M67.fld		  \
		test/N3201-00.fld
   
expert_release : all ../lib/tk
	-/bin/rm -rf ../tmp/FPOSS
	-/bin/rm -f ../lib/configure_expert
	/bin/ln -s configure ../lib/configure_expert
	mkdir ../tmp/FPOSS
	( cd .. ; tar -cf - $(EXPERT_RELEASE_FILES) | ( cd tmp/FPOSS ; tar xvf - ))
	( cd ../tmp ; tar -cvf ../bin/fposs_expert-$(VERSION).`uname`.tar FPOSS )
	-/bin/rm -f ../bin/fposs_expert-$(VERSION).`uname`.tar.gz
	gzip ../bin/fposs_expert-$(VERSION).`uname`.tar
	-/bin/rm -rf ../tmp/FPOSS
	@echo Created release file: ../bin/fposs_expert-$(VERSION).`uname`.tar.gz

#*******************************************************************************
#  Because of the way tcl/tk work, building the location of their ancilliary
#  files into the executable, and also because tcl/tk code is very sensitive
#  to having exactly the right ancilliary files, we include these in the
#  release. tcl_dir and tk_dir are directories containing the necessary
#  subset of ancilliary files. Note that these rules are coded in such a 
#  way that if the directories do not exist, they will pick up the files
#  released with the current build of tcl/tk. If they do exist, a copy is
#  made and renamed (this isn't ideal, but it means the rules work whether
#  the directories work or not).

../lib/tk : ../bin/configure
	/bin/rm -rf ../tmp/*
	/bin/rm -rf ../lib/tcl
	/bin/rm -rf ../lib/tk
	/bin/rm -f ../lib/lib*
	/bin/cp -r `../lib/configure -tcl_library` ../tmp/tcl
	/bin/cp `../lib/configure -tcl_library | sed 's/\/tcl8/\/libtcl8/'`.s[lo] ../tmp
	touch ../tmp/tcl/TCL_VERSION_`../lib/configure -tcl_version`
	/bin/cp -r `../lib/configure -tk_library` ../tmp/tk
	/bin/cp `../lib/configure -tk_library | sed 's/\/tk8/\/libtk8/'`.s[lo] ../tmp
	/bin/rm -rf ../tmp/tk/demos
	touch ../tmp/tk/TK_VERSION_`../lib/configure -tk_version`
	if [ X`uname` = XLinux ]; then \
	  ( cd ../tmp ; ln -s libtcl*.so libtcl.so ; ln -s libtk*.so libtk.so ) \
	fi
	/bin/mv ../tmp/tcl ../lib/tcl
	/bin/mv ../tmp/tk ../lib/tk
	/bin/mv ../tmp/lib* ../lib


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

