##############################################################################
# $Id: makefile,v 1.23 2001/05/16 14:54:15 amodigli Exp $
##############################################################################
#+++ MAKEFILE +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
#.COPYRIGHT     (C) 1998  European Southern Observatory
#
#.IDENT         makefile
#
#.KEYWORDS      Installation of the UVES pipeline
#
#.USAGE         make
#
#.INPUT         LINK	Create the links of the procedures.
#		COMPILE	Compile the source codes to create the executables.
#
#.OUTPUT        
#
#.RETURN        
#
#.DEFAULT
#
#.PURPOSE       Establish a proper installation of the UVES pipeline.
#
#.ALGORITHM     
#
#.ENVIRON       
#   
#.LANGUAGE      make
#
#.AUTHOR        Sebastian Wolf, ESO-DMO
#
#.VERSION       1.0 1999/07/09  Created.
#		1.1 1999/08/30	make of echelle and spec sources were missing!
#		1.2 1999/09/07	make update implemented
#		1.3 1999/09/23	make patch implemented
#		1.4 1999/09/28	remove links and *.exe using 'make clean_exec'!
#				USE gzipped tar files from now on (>0.8.1 rel)!
#       1.5 2000/03/02 AM: check: creates /context /exec /proc dir only if 
#                                 are not present and do on them chmod g+wr
#
#.COMMENT	After the archive file has been unpacked you just have to type
#		make at the system prompt.
##############################################################################
# $Name:  $
# $Revision: 1.23 $
# $Log: makefile,v $
# Revision 1.23  2001/05/16 14:54:15  amodigli
# Check for error and in case exit 1
#
# Revision 1.22  2001/03/10 10:31:41  amodigli
# Simplified.
# Now no more extra link under
# $PIPE_HOME/uves-<rel>
#
# Revision 1.21  2001/03/08 07:29:41  amodigli
# Updated version number to 1.1.0
#
# Revision 1.20  2001/02/28 16:31:45  amodigli
# Updated release number
#
# Revision 1.19  2001/02/16 13:21:19  amodigli
# Some cleaning in preparation to release to SEG
#
# Revision 1.18  2001/02/15 17:42:50  amodigli
# Small change to not create the links
# to uves-<rel> in the deployment dir
# and to allow for normal users no
# deployment.
#
# Revision 1.17  2001/02/12 10:59:45  amodigli
# Added setup and updated makefile to be
# compliant with ipip and new dir structure
# for 01FEB
#
# Revision 1.16  2001/02/01 09:11:37  amodigli
# Updated to 1.0.8
#
# Revision 1.15  2001/01/04 13:07:20  amodigli
# Added Id, Name, Revision, Log conf. control info
#
##############################################################################
PIPELINE = .
UVESPIPE = $(PIPELINE)/uves
#
# MIDAS pipeline tree:
#
EDIR     = $(PIPELINE)/exec
PDIR     = $(PIPELINE)/proc
CDIR     = $(PIPELINE)/context
LDIR     = $(UVESPIPE)/lib
HDIR     = $(UVESPIPE)/help
#
PPDIR    = $(UVESPIPE)/pipe/proc
PSDIR    = $(UVESPIPE)/pipe/src
PLDIR    = $(UVESPIPE)/pipe/libsrc
POBJ     = $(PSDIR)/*.o
#
EPDIR    = $(UVESPIPE)/echelle/proc
ESDIR    = $(UVESPIPE)/echelle/src
#
SPDIR    = $(UVESPIPE)/spec/proc
SSDIR    = $(UVESPIPE)/spec/src
#
UPDIR    = $(UVESPIPE)/uves/proc
UCDIR    = $(UVESPIPE)/uves/etc
#
RPDIR    = $(UVESPIPE)/rec/proc
#
UPRGS    = $(PDIR)/uves*.prg
EPRGS    = $(PDIR)/nec*.prg
#
LIBS     = $(LDIR)/libphysmod.a
#
# HELPC    = $(HDIR)/*.hlc
#
# control files (may be deleted after installation)
#
LINKED   = .LINKED
COMPILED = .COMPILED
PIPEVERS = UVES-PIPEVERSION
TARFILE  =

EOL      = "\\n"
CINFO    = "$(EOL) Compiling "
LINFO    = "$(EOL) Linking "
DOTS     = "...$(EOL)"
#
# COMPILE *has to* be done at first because it installs all directories needed!
all: COMPILE LINK helpc  links

pall: COMPILE LINK helpc

clean:
	@\rm -f $(PIPEVERS) $(LINKED) $(COMPILED) ReadMe ReleaseNotes $(CDIR)/echelle.ctx
	@\rm -rf $(LDIR) 

update: clean all
#
# Patches are never complete releases of the UVES context only a selection
# of single procedures or C-files. Additionally, each patch should include
# a $PIPEVERSION file which updates the so far actual one! Usually, this file
# will automatically created by the update: label when a full UVES context
# is released!
#
patch: clean all

#
# Create directories needed for the installation
#
$(EDIR):
	@if [ ! -d $(EDIR) ]; \
		then \
		echo "$(EOL) creating $(EDIR) $(DOTS)"; \
		mkdir $(EDIR); \
		chmod g+wr $(EDIR); \
	fi

$(PDIR):
	@if [ ! -d $(PDIR) ]; \
		then \
		echo "$(EOL) creating $(PDIR) $(DOTS)"; \
		mkdir $(PDIR); \
		chmod g+wr $(PDIR); \
	fi

$(LDIR):
	@mkdir $(LDIR)
#
# Create the links to the context files:
#
$(CDIR):
	@if [ ! -d $(CDIR) ]; \
		then \
		echo "$(EOL) creating $(CDIR) $(DOTS)"; \
		mkdir $(CDIR); \
		chmod g+wr $(CDIR); \
	fi
#
# Compile the libraries
#
$(LIBS):  $(COMPILED)

#
# Compile the pipeline executables
#
COMPILE: $(COMPILED)

#
# Create the links of the MIDAS procedures
#
LINK: $(LINKED)

#
# Control the version
#
VERSION: $(PIPEVERS)

#
# Create the auxiliary help files
#
helpc:
	@cd $(HDIR); echo "$(EOL) making $(HDIR) $(DOTS)" ; \
	make || exit 1; make make_alll

#
# Create the links ($(CDIR) $(EDIR) $(LDIR) $(PDIR) already created!)
#
$(LINKED):
	@cd $(PPDIR); make clean ; echo "$(LINFO) $(PPDIR) $(DOTS)" ; \
	make || exit 1

	@cd $(RPDIR); make clean ; echo "$(LINFO) $(RPDIR) $(DOTS)" ; \
	make || exit 1

	@cd $(UPDIR); make clean ; echo "$(LINFO) $(UPDIR) $(DOTS)" ; \
	make || exit 1

	@cd $(UCDIR); make clean ; echo "$(LINFO) $(UCDIR) $(DOTS)" ; \
	make || exit 1

	@cd $(EPDIR); make clean ; echo "$(LINFO) $(EPDIR) $(DOTS)" ; \
	make || exit 1

	@cd $(SPDIR); make clean ; echo "$(LINFO) $(SPDIR) $(DOTS)" ; \
	make || exit 1

	@echo "$(LINFO) echelle context $(DOTS)"
	@ln -sf $(MIDASHOME)/$(MIDVERS)/context/echelle.ctx $(CDIR) || exit 1
	@touch $(LINKED)

#
# Do the compilations
#
$(COMPILED): $(CDIR) $(EDIR) $(LDIR) $(PDIR)
	@ln -sf $(MIDASHOME)/$(MIDVERS)/stdred/lib/libspec.a $(LDIR)

	@cd $(PLDIR) ; make clean_exec ; echo "$(CINFO) $(PLDIR) $(DOTS)" ; \
	make || exit 1; make clean 

	@cd $(PSDIR) ; make clean_exec ; echo "$(CINFO) $(PSDIR) $(DOTS)" ; \
	make || exit 1; make clean

	@cd $(ESDIR) ; make clean_exec ; echo "$(CINFO) $(ESDIR) $(DOTS)" ; \
	make || exit 1; make clean

	@cd $(SSDIR) ; make clean_exec ; echo "$(CINFO) $(SSDIR) $(DOTS)" ; \
	make || exit 1; make clean

	@touch $(COMPILED)

links:
	@\rm -f $(PIPEVERS)
#	@cat uves/Install/ReadMe
#	@cat $(PIPEVERS)

#leading @ suppresses printing of the command

install:
	@echo "copying proc dir to $(INSTDIR) ..."; \
	/bin/cp -r proc $(INSTDIR) || exit 1

	@echo "copying exec dir to $(INSTDIR) ..."; \
	/bin/cp -r exec $(INSTDIR) || exit 1

	@echo "copying context dir to $(INSTDIR) ..."; \
	/bin/cp -r context $(INSTDIR) || exit 1

	@echo "copying uves dir to $(INSTDIR) ..."; \
	/bin/cp -r uves $(INSTDIR) || exit 1

	@echo "copying makefile file to $(INSTDIR) ..."; \
	/bin/cp -r makefile $(INSTDIR) || exit 1	

	@echo "copying ReleaseNotes file to $(INSTDIR) ..."; \
	/bin/cp -r ReleaseNotes $(INSTDIR) || exit 1

	@echo "copying ReadMe file to $(INSTDIR) ..."; \
	/bin/cp -r ReadMe $(INSTDIR) || exit 1

	@echo "copying Disclaimer.txt file to $(INSTDIR) ..."; \
	/bin/cp -r Disclaimer.txt $(INSTDIR) || exit 1

