#-----------------------------------------------------------------------
# Copyright 1996-2016 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#-----------------------------------------------------------------------
#------------------------------------------------------------------------------
#
#  NSSDC/CDF						CDF tests makefile.
#
#  Version 1.5, 20-Feb-96, Hughes STX.
#
#  Modification history:
#
#   V1.0  26-Jan-94, J Love	Original version.
#   V1.0a 23-Feb-94, J Love	Added `CC='.
#   V1.0b  6-Apr-94, J Love	Finished `CC='.
#   V1.1  19-Dec-94, J Love	CDF V2.5.
#   V1.2   5-Jan-95, J Love	Updated dependencies, etc.
#   V1.2a 20-Jan-95, J Love	IRIX 6.x.
#   V1.3  16-Mar-95, J Love	Multi-compiler support, etc.
#   V1.4   3-Apr-95, J Love	POSIX.
#   V1.5  20-Feb-96, J Love	CDF V2.6.
#   V1.6  12-Feb-07, D Berger   Added existing LD_LIBRARY_PATH to temp 
#                               definition.
#   V1.7  22-Feb-16, M Liu      Modified to handle Mac's El Captain's not 
#                               (Mac OS 10.11) handling DYLD_LIBRARY_PATH
#
#------------------------------------------------------------------------------
#
# Notes:
#
# `make' on DECstations complains (prints an error message) if an if-then-else
# construct evaluates to FALSE but there is no `false' part.  To prevent this,
# the `NULL' command is executed as the `false' part.
#
#------------------------------------------------------------------------------

.SILENT:

SHELL=/bin/sh
NULL=true

FORTRAN=
FCx=
CCx=
SHARED=
FOPTIONS=
FOPTIONSld=
COPTIONS=
COPTIONSld=
SYSLIBS=
SHAREDEXT=
MAKE=
SRCDIR=
BUILDDIR=

INCLUDEcdf=$(SRCDIR)/../src/include

CC=$(CCx)
CFLAGS=$(COPTIONS) -I$(INCLUDEcdf)
CFLAGSld=$(COPTIONSld)

FC=$(FCx)
FEXTRA=
ifeq ("$(FC)","gfortran")
 FEXTRA=-std=legacy -w
endif
FFLAGS=$(FOPTIONS) $(FEXTRA)
FFLAGSld=$(FOPTIONSld)
MACos=Darwin

LIBCDFa=$(BUILDDIR)/../src/lib/libcdf.a
LIBCDFshare=$(BUILDDIR)/../src/lib/libcdf.$(SHAREDEXT)

LIBsARCHIVE=$(LIBCDFa) $(SYSLIBS)
#LIBsSHARE=$(LIBCDFshare) $(SYSLIBS)

CDFh=$(INCLUDEcdf)/cdf.h
CDFinc=$(INCLUDEcdf)/cdf.inc

BINsC=qst2c qst2ic qst2cutf8 qst2icEPOCH16 qst2cOrig qst2icTT2000
BINsF=qst2f qst2if qst2futf8 qst2ifEPOCH16 qst2fOrig qst2ifTT2000 qst2ifTT2000UnixTime
BINsCshare=qst2VersionS qst2cS qst2icS qst2icEPOCH16S qst2cOrigS qst2icTT2000S
BINsFshare=qst2fS qst2ifS qst2ifEPOCH16S qst2fOrigS qst2ifTT2000S qst2ifTT2000UnixTimeS

WHICHOS=$(shell uname)
ifeq ("$(WHICHOS)","Darwin")
  MACVERSION=$(shell uname -r | cut -f1 -d.)
  LIBsSHARE=-L../src/lib -Wl,-rpath,@loader_path/../src/lib -lcdf $(SYSLIBS)
else
  MACVERSION=0
  LIBsSHARE=-L../src/lib -lcdf $(SYSLIBS)
endif

#CURDIR=$(shell pwd)

#------------------------------------------------------------------------------
# Compile/link.
#------------------------------------------------------------------------------

all: c.yes cS.$(SHARED) f.$(FORTRAN) fS.$(FORTRAN).$(SHARED)

%.o : %.mod

c.yes: $(BINsC)

cS.yes: $(BINsCshare)
cS.no:

f.yes: $(BINsF)
f.no:

fS.yes.yes: $(BINsFshare)
fS.yes.no:
fS.no.yes:
fS.no.no:

qst2c:	qst2c.o $(LIBCDFa)
	@echo $(CC) $(CFLAGSld) -o $@ qst2c.o $(LIBsARCHIVE)
	      $(CC) $(CFLAGSld) -o $@ qst2c.o $(LIBsARCHIVE)

qst2cOrig:	qst2cOrig.o $(LIBCDFa)
	@echo $(CC) $(CFLAGSld) -o $@ qst2cOrig.o $(LIBsARCHIVE)
	      $(CC) $(CFLAGSld) -o $@ qst2cOrig.o $(LIBsARCHIVE)

qst2ic:	qst2ic.o $(LIBCDFa)
	@echo $(CC) $(CFLAGSld) -o $@ qst2ic.o $(LIBsARCHIVE)
	      $(CC) $(CFLAGSld) -o $@ qst2ic.o $(LIBsARCHIVE)

qst2cutf8: qst2cutf8.o $(LIBCDFa)
	@echo $(CC) $(CFLAGSld) -o $@ qst2cutf8.o $(LIBsARCHIVE)
	      $(CC) $(CFLAGSld) -o $@ qst2cutf8.o $(LIBsARCHIVE)

qst2icEPOCH16: qst2icEPOCH16.o $(LIBCDFa)
	@echo $(CC) $(CFLAGSld) -o $@ qst2icEPOCH16.o $(LIBsARCHIVE)
	      $(CC) $(CFLAGSld) -o $@ qst2icEPOCH16.o $(LIBsARCHIVE)

qst2icTT2000: qst2icTT2000.o $(LIBCDFa)
	@echo $(CC) $(CFLAGSld) -o $@ qst2icTT2000.o $(LIBsARCHIVE)
	      $(CC) $(CFLAGSld) -o $@ qst2icTT2000.o $(LIBsARCHIVE)

qst2VersionS: qst2Version.o $(LIBCDFshare)
	@echo $(CC) $(CFLAGSld) -o $@ qst2Version.o $(LIBsSHARE)
	      $(CC) $(CFLAGSld) -o $@ qst2Version.o $(LIBsSHARE)

qst2cS: qst2c.o $(LIBCDFshare)
	@echo $(CC) $(CFLAGSld) -o $@ qst2c.o $(LIBsSHARE)
	      $(CC) $(CFLAGSld) -o $@ qst2c.o $(LIBsSHARE)

qst2cOrigS: qst2cOrig.o $(LIBCDFshare)
	@echo $(CC) $(CFLAGSld) -o $@ qst2cOrig.o $(LIBsSHARE)
	      $(CC) $(CFLAGSld) -o $@ qst2cOrig.o $(LIBsSHARE)

qst2icS: qst2ic.o $(LIBCDFshare)
	@echo $(CC) $(CFLAGSld) -o $@ qst2ic.o $(LIBsSHARE)
	      $(CC) $(CFLAGSld) -o $@ qst2ic.o $(LIBsSHARE)

qst2icEPOCH16S: qst2icEPOCH16.o $(LIBCDFshare)
	@echo $(CC) $(CFLAGSld) -o $@ qst2icEPOCH16.o $(LIBsSHARE)
	      $(CC) $(CFLAGSld) -o $@ qst2icEPOCH16.o $(LIBsSHARE)

qst2icTT2000S: qst2icTT2000.o $(LIBCDFshare)
	@echo $(CC) $(CFLAGSld) -o $@ qst2icTT2000.o $(LIBsSHARE)
	      $(CC) $(CFLAGSld) -o $@ qst2icTT2000.o $(LIBsSHARE)

qst2f:	qst2f.o $(LIBCDFa)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsARCHIVE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsARCHIVE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsARCHIVE); \
	          $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsARCHIVE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsARCHIVE); \
	       $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsARCHIVE); \
	fi

qst2if:	qst2if.o $(LIBCDFa)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsARCHIVE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsARCHIVE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsARCHIVE); \
	          $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsARCHIVE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsARCHIVE); \
	       $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsARCHIVE); \
	fi

qst2futf8: qst2futf8.o $(LIBCDFa)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2futf8.o $(LIBsARCHIVE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2futf8.o $(LIBsARCHIVE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2futf8.o $(LIBsARCHIVE); \
	          $(FC) $(FFLAGSld) -o $@ qst2futf8.o $(LIBsARCHIVE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2futf8.o $(LIBsARCHIVE); \
	       $(FC) $(FFLAGSld) -o $@ qst2futf8.o $(LIBsARCHIVE); \
	fi

qst2fOrig: qst2fOrig.o $(LIBCDFa)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsARCHIVE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsARCHIVE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsARCHIVE); \
	          $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsARCHIVE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsARCHIVE); \
	       $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsARCHIVE); \
	fi

qst2ifEPOCH16: qst2ifEPOCH16.o $(LIBCDFa)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsARCHIVE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsARCHIVE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsARCHIVE); \
	          $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsARCHIVE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsARCHIVE); \
	       $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsARCHIVE); \
	fi

qst2ifTT2000: qst2ifTT2000.o $(LIBCDFa)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsARCHIVE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsARCHIVE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsARCHIVE); \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsARCHIVE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsARCHIVE); \
	       $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsARCHIVE); \
	fi

qst2ifTT2000UnixTime: qst2ifTT2000UnixTime.o $(LIBCDFa)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsARCHIVE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsARCHIVE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsARCHIVE); \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsARCHIVE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsARCHIVE); \
	       $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsARCHIVE); \
	fi

qst2fS:	qst2f.o $(LIBCDFshare)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsSHARE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsSHARE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsSHARE); \
	          $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsSHARE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsSHARE); \
	       $(FC) $(FFLAGSld) -o $@ qst2f.o $(LIBsSHARE); \
	fi

qst2ifS: qst2if.o $(LIBCDFshare)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsSHARE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsSHARE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsSHARE); \
	          $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsSHARE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsSHARE); \
	       $(FC) $(FFLAGSld) -o $@ qst2if.o $(LIBsSHARE); \
	fi

qst2fOrigS: qst2fOrig.o $(LIBCDFshare)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsSHARE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsSHARE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsSHARE); \
	          $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsSHARE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsSHARE); \
	       $(FC) $(FFLAGSld) -o $@ qst2fOrig.o $(LIBsSHARE); \
	fi

qst2ifEPOCH16S: qst2ifEPOCH16.o $(LIBCDFshare)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsSHARE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsSHARE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsSHARE); \
	          $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsSHARE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsSHARE); \
	       $(FC) $(FFLAGSld) -o $@ qst2ifEPOCH16.o $(LIBsSHARE); \
	fi

qst2ifTT2000S: qst2ifTT2000.o $(LIBCDFshare)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsSHARE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsSHARE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsSHARE); \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsSHARE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsSHARE); \
	       $(FC) $(FFLAGSld) -o $@ qst2ifTT2000.o $(LIBsSHARE); \
	fi

qst2ifTT2000UnixTimeS: qst2ifTT2000UnixTime.o $(LIBCDFshare)
	@if [ $(MACos) =  `uname` ] ; then \
	   if [ `uname -r | cut -f1 -d.` = 8 ]; then \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsSHARE) -lSystemStubs; \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsSHARE) -lSystemStubs; \
	   else \
	     echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsSHARE); \
	          $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsSHARE); \
	   fi \
	else \
	  echo $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsSHARE); \
	       $(FC) $(FFLAGSld) -o $@ qst2ifTT2000UnixTime.o $(LIBsSHARE); \
	fi

.c.o:
	@echo $(CC) $(CFLAGS) -c $<
	      $(CC) $(CFLAGS) -c $<

.f.o:
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $<
	      $(FC) $(FFLAGS) -c $<
#	@rm $(SRCDIR)/CDF.INC

qst2Version.o: $(SRCDIR)/qst2Version.c $(CDFh)
	@echo $(CC) $(CFLAGS) -c $(SRCDIR)/qst2Version.c
	      $(CC) $(CFLAGS) -c $(SRCDIR)/qst2Version.c
qst2c.o: $(SRCDIR)/qst2c.c $(CDFh)
	@echo $(CC) $(CFLAGS) -c $(SRCDIR)/qst2c.c
	      $(CC) $(CFLAGS) -c $(SRCDIR)/qst2c.c
qst2cOrig.o: $(SRCDIR)/qst2cOrig.c $(CDFh)
	@echo $(CC) $(CFLAGS) -c $(SRCDIR)/qst2cOrig.c
	      $(CC) $(CFLAGS) -c $(SRCDIR)/qst2cOrig.c
qst2cutf8.o: $(SRCDIR)/qst2cutf8.c $(CDFh)
	@echo $(CC) $(CFLAGS) -c $(SRCDIR)/qst2cutf8.c
	      $(CC) $(CFLAGS) -c $(SRCDIR)/qst2cutf8.c
qst2ic.o: $(SRCDIR)/qst2ic.c $(CDFh)
	@echo $(CC) $(CFLAGS) -c $(SRCDIR)/qst2ic.c
	      $(CC) $(CFLAGS) -c $(SRCDIR)/qst2ic.c
qst2icEPOCH16.o: $(SRCDIR)/qst2icEPOCH16.c $(CDFh)
	@echo $(CC) $(CFLAGS) -c $(SRCDIR)/qst2icEPOCH16.c
	      $(CC) $(CFLAGS) -c $(SRCDIR)/qst2icEPOCH16.c
qst2icTT2000.o: $(SRCDIR)/qst2icTT2000.c $(CDFh)
	@echo $(CC) $(CFLAGS) -c $(SRCDIR)/qst2icTT2000.c
	      $(CC) $(CFLAGS) -c $(SRCDIR)/qst2icTT2000.c
qst2f.o: $(SRCDIR)/qst2f.f $(CDFh) $(CDFinc)
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $(SRCDIR)/qst2f.f
	      $(FC) $(FFLAGS) -c $(SRCDIR)/qst2f.f
#	@rm $(SRCDIR)/CDF.INC
qst2if.o: $(SRCDIR)/qst2if.f $(CDFh) $(CDFinc)
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $(SRCDIR)/qst2if.f
	      $(FC) $(FFLAGS) -c $(SRCDIR)/qst2if.f
qst2fOrig.o: $(SRCDIR)/qst2fOrig.f $(CDFh) $(CDFinc)
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $(SRCDIR)/qst2fOrig.f
	      $(FC) $(FFLAGS) -c $(SRCDIR)/qst2fOrig.f
#	@rm $(SRCDIR)/CDF.INC
qst2futf8.o: $(SRCDIR)/qst2futf8.f $(CDFh) $(CDFinc)
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $(SRCDIR)/qst2futf8.f
	      $(FC) $(FFLAGS) -c $(SRCDIR)/qst2futf8.f
#	@rm $(SRCDIR)/CDF.INC
qst2ifEPOCH16.o: $(SRCDIR)/qst2ifEPOCH16.f $(CDFh) $(CDFinc)
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $(SRCDIR)/qst2ifEPOCH16.f
	      $(FC) $(FFLAGS) -c $(SRCDIR)/qst2ifEPOCH16.f
#	@rm $(SRCDIR)/CDF.INC
qst2ifTT2000.o: $(SRCDIR)/qst2ifTT2000.f $(CDFh) $(CDFinc)
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $(SRCDIR)/qst2ifTT2000.f
	      $(FC) $(FFLAGS) -c $(SRCDIR)/qst2ifTT2000.f
#	@rm $(SRCDIR)/CDF.INC
qst2ifTT2000UnixTime.o: $(SRCDIR)/qst2ifTT2000UnixTime.f $(CDFh) $(CDFinc)
#	@cp -f $(CDFinc) $(SRCDIR)/CDF.INC
	@echo $(FC) $(FFLAGS) -c $(SRCDIR)/qst2ifTT2000UnixTime.f
	      $(FC) $(FFLAGS) -c $(SRCDIR)/qst2ifTT2000UnixTime.f
#	@rm $(SRCDIR)/CDF.INC

#------------------------------------------------------------------------------
# Tests.
#     Each executable name is preceeded by `./' in case the current directory
# is not in the path.
#------------------------------------------------------------------------------

test:
	@if [ -f TEST.cdf ] ; then \rm TEST.* ; else $(NULL) ; fi
	@echo ""
	@echo "Testing CDF library..."
	@echo ""
	@./qst2c
	@./qst2cOrig
	@./qst2ic
	@if [ -f qst2cutf8 ] ; then $(MAKE) test.qst2cutf8 ; else $(NULL) ; fi
	@./qst2icEPOCH16
	@if [ -f qst2icTT2000 ] ; then $(MAKE) test.qst2icTT2000 ; else $(NULL) ; fi
	@if [ -f qst2f ] ; then $(MAKE) test.qst2f ; else $(NULL) ; fi
	@if [ -f qst2if ] ; then $(MAKE) test.qst2if ; else $(NULL) ; fi
	@if [ -f qst2fOrig ] ; then $(MAKE) test.qst2fOrig ; else $(NULL) ; fi
	@if [ -f qst2futf8 ] ; then $(MAKE) test.qst2futf8 ; else $(NULL) ; fi
	@if [ -f qst2ifEPOCH16 ] ; then $(MAKE) test.qst2ifEPOCH16 ; else $(NULL) ; fi
	@if [ -f qst2ifTT2000 ] ; then $(MAKE) test.qst2ifTT2000 ; else $(NULL) ; fi
	@if [ -f qst2ifTT2000UnixTime ] ; then $(MAKE) test.qst2ifTT2000UnixTime ; else $(NULL) ; fi
	@if [ -f qst2VersionS ] ; then \
	  echo ""; echo "Testing shareable CDF library..."; echo "" ; \
	 else $(NULL) ; \
	fi
# If Mac OX 10.11 (version 15) and later... use special handling
	@if [ $(MACVERSION) -lt 15 ] ; then \
	        $(MAKE) MAKE=$(MAKE) test.normalShare ; \
	else \
	        $(MAKE) MAKE=$(MAKE) test.Mac15Share ; \
	fi

test.normalShare:
	@if [ -f qst2VersionS ] ; then $(MAKE) test.qst2VersionS ; else $(NULL) ; fi
	@if [ -f qst2cS ] ; then $(MAKE) test.qst2cS ; else $(NULL) ; fi
	@if [ -f qst2cOrigS ] ; then $(MAKE) test.qst2cOrigS ; else $(NULL) ; fi
	@if [ -f qst2icS ] ; then $(MAKE) test.qst2icS ; else $(NULL) ; fi
	@if [ -f qst2icEPOCH16S ] ; then $(MAKE) test.qst2icEPOCH16S ; else $(NULL) ; fi
	@if [ -f qst2icTT2000S ] ; then $(MAKE) test.qst2icTT2000S ; else $(NULL) ; fi
	@if [ -f qst2fS ] ; then $(MAKE) test.qst2fS ; else $(NULL) ; fi
	@if [ -f qst2ifS ] ; then $(MAKE) test.qst2ifS ; else $(NULL) ; fi
	@if [ -f qst2fOrigS ] ; then $(MAKE) test.qst2fOrigS ; else $(NULL) ; fi
	@if [ -f qst2ifEPOCH16S ] ; then $(MAKE) test.qst2ifEPOCH16S ; else $(NULL) ; fi
	@if [ -f qst2ifTT2000S ] ; then $(MAKE) test.qst2ifTT2000S ; else $(NULL) ; fi
	@if [ -f qst2ifTT2000UnixTimeS ] ; then $(MAKE) test.qst2ifTT2000UnixTimeS ; else $(NULL) ; fi

test.Mac15Share:
	@if [ -f qst2VersionS ] ; then $(MAKE) test.qst2VersionS15 ; else $(NULL) ; fi
	@if [ -f qst2cS ] ; then $(MAKE) test.qst2cS15 ; else $(NULL) ; fi
	@if [ -f qst2cOrigS ] ; then $(MAKE) test.qst2cOrigS15 ; else $(NULL) ; fi
	@if [ -f qst2icS ] ; then $(MAKE) test.qst2icS15 ; else $(NULL) ; fi
	@if [ -f qst2icEPOCH16S ] ; then $(MAKE) test.qst2icEPOCH16S15 ; else $(NULL) ; fi
	@if [ -f qst2icTT2000S ] ; then $(MAKE) test.qst2icTT2000S15 ; else $(NULL) ; fi
	@if [ -f qst2fS ] ; then $(MAKE) test.qst2fS15 ; else $(NULL) ; fi
	@if [ -f qst2ifS ] ; then $(MAKE) test.qst2ifS15 ; else $(NULL) ; fi
	@if [ -f qst2fOrigS ] ; then $(MAKE) test.qst2fOrigS15 ; else $(NULL) ; fi
	@if [ -f qst2ifEPOCH16S ] ; then $(MAKE) test.qst2ifEPOCH16S15 ; else $(NULL) ; fi
	@if [ -f qst2ifTT2000S ] ; then $(MAKE) test.qst2ifTT2000S15 ; else $(NULL) ; fi
	@if [ -f qst2ifTT2000UnixTimeS ] ; then $(MAKE) test.qst2ifTT2000UnixTimeS15 ; else $(NULL) ; fi

test.qst2VersionS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2VersionS

test.qst2cS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2cS

test.qst2cOrigS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2cOrigS

test.qst2cutf8:
	./qst2cutf8

test.qst2icS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2icS

test.qst2icEPOCH16S:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2icEPOCH16S

test.qst2icTT2000:
	@export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2icTT2000

test.qst2icTT2000S:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2icTT2000S

test.qst2f:
	@export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2f

test.qst2fS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2fS

test.qst2if:
	@export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2if

test.qst2ifS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifS

test.qst2fOrigS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2fOrigS

test.qst2fOrig:
	@export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2fOrig

test.qst2futf8:
	./qst2futf8

test.qst2ifEPOCH16:
	@export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifEPOCH16

test.qst2ifEPOCH16S:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifEPOCH16S

test.qst2ifTT2000:
	@export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifTT2000

test.qst2ifTT2000S:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifTT2000S

test.qst2ifTT2000UnixTime:
	@export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifTT2000UnixTime

test.qst2ifTT2000UnixTimeS:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifTT2000UnixTimeS

test.qst2VersionS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2VersionS

test.qst2cS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2cS

test.qst2cOrigS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2cOrigS

test.qst2icS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2icS

test.qst2icEPOCH16S15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2icEPOCH16S

test.qst2icTT2000S15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2icTT2000S

test.qst2fS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2fS

test.qst2ifS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifS

test.qst2fOrigS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2fOrigS

test.qst2ifEPOCH16S15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifEPOCH16S

test.qst2ifTT2000S15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifTT2000S

test.qst2ifTT2000UnixTimeS15:
	@export LD_LIBRARY_PATH="`pwd`/../src/lib:$(LD_LIBRARY_PATH)" ; \
	export DYLD_LIBRARY_PATH="`pwd`/../src/lib:$(DYLD_LIBRARY_PATH)" ; \
	export PATH="`pwd`/../src/lib:$(PATH)" ; \
	export CDF_LEAPSECONDSTABLE="`pwd`/../CDFLeapSeconds.txt" ; \
	./qst2ifTT2000UnixTimeS

#------------------------------------------------------------------------------

#------------------------------------------------------------------------------

clean:
	@-rm -f *.o
	@-rm -f *.exe
	@-rm -f qst2c
	@-rm -f qst2cOrig
	@-rm -f qst2cutf8
	@-rm -f qst2ic
	@-rm -f qst2iEPOCH16c
	@-rm -f qst2f
	@-rm -f qst2if
	@-rm -f qst2fOrig
	@-rm -f qst2iEPOCH16f
	@-rm -f qst2VersionS
	@-rm -f qst2cS
	@-rm -f qst2cOrigS
	@-rm -f qst2icS
	@-rm -f qst2icEPOCH16
	@-rm -f qst2icEPOCH16S
	@-rm -f qst2icTT2000
	@-rm -f qst2icTT2000S
	@-rm -f qst2fS
	@-rm -f qst2ifS
	@-rm -f qst2fOrigS
	@-rm -f qst2futf8
	@-rm -f qst2ifEPOCH16
	@-rm -f qst2ifEPOCH16S
	@-rm -f qst2ifTT2000
	@-rm -f qst2ifTT2000S
	@-rm -f qst2ifTT2000UnixTime
	@-rm -f qst2ifTT2000UnixTimeS
	@-rm -f qstleapsecondsinfo
	@-rm -f *.trace
	@-rm -f core
	@-rm -f *.cdf

purge:
	@-rm -f *~
	@-rm -f *#
