# Makefile for cdf

# To compile and test, type:
#    ./configure; make; make test

# To install lib/libcdf.*, bin/* and include/.h, under the source directory,
# type:
#    make install
# To install in other directory, as $HOME, use:
#    make install prefix=$HOME


.SILENT:

MAKE=
CC=
PIC=
COPTIONS=
COPTIONSld=
ZLIB=
ARCH1=
ARCH2=
ARCH3=
LD=
SYSLIBS=
SHAREDEXT=
LDOPTIONS=
AROPTIONS=
RANLIBcmd=
RANLIB=
CURSES=
CURSESINC=
CURSESLIB=
FC=
FOPTIONS=
FOPTIONSld=
INSTALLDIR=.

SHELL=/bin/bash
NULL=true
PART=all
VERSION=
JDK_HOME=
JNI=
JNIOS=
JNIEXT=
SRCDIR=.
BUILDDIR=
MACVERSION=
FORTRAN=

sname=$(shell uname -s)

#------------------------------------------------------------------------------
# Directory locations.
#------------------------------------------------------------------------------

DEFSsrcDIR=$(SRCDIR)/src/definitions
INCsrcDIR=$(SRCDIR)/src/include
LIBsrcDIR=src/lib
TOOLSsrcDIR=src/tools
TESTSsrcDIR=cdf_tests
HELPsrcDIR=$(SRCDIR)/src/help
LIBsrcZlibDIRorig=$(LIBsrcDIR)/zlib
LIBsrcZlibDIRng=$(LIBsrcDIR)/zlib-ng
JNIsrcDIR=cdfjava/jni
MYHOME=$(shell printenv HOME)

#------------------------------------------------------------------------------
# Macros specified on the `make' command line.
#------------------------------------------------------------------------------

SHARED=yes
INSTALLDIRx=$(abspath $(INSTALLDIR))
UCOPTIONS=

#------------------------------------------------------------------------------
# Other macros.
#------------------------------------------------------------------------------
LDLIB=
EXTRAMAKE=--no-print-directory
TOVERBOSE=
ifeq ($(ZLIB),zlib-ng)
  TOVERBOSE=
endif

#------------------------------------------------------------------------------
# Compile/link entire distribution.
#------------------------------------------------------------------------------

ifeq ($(JNI),yes)
  toBUILD=all.build build.jni
else
  toBUILD=all.build
endif

all: $(toBUILD)

all.build:
	@cd $(BUILDDIR)/$(LIBsrcDIR)/$(ZLIB); $(MAKE) $(TOVERBOSE) $(EXTRAMAKE) all
	@cd $(BUILDDIR)/$(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) all
	@cd $(BUILDDIR)/$(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) all
	@cd $(BUILDDIR)/$(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) all

build.jni:
	@cd $(BUILDDIR)/$(JNIsrcDIR); $(MAKE) $(EXTRAMAKE) all
	@rm -f $(BUILDDIR)/*.exe

#------------------------------------------------------------------------------
# Test distribution.
#------------------------------------------------------------------------------

test:
	@cd $(BUILDDIR)/$(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) test 

#------------------------------------------------------------------------------
# Install files.
#------------------------------------------------------------------------------

install: install.$(PART)

install.all: install.definitions install.include install.lib \
	     install.tools install.help_ copy.leapseconds copy.txt \
	     install.jars notify.user  

install.definitions: copy.definitions change.definitions
install.include: copy.include
install.tools: copy.tools
install.jars: copy.jars
install.help_: copy.help

install.lib: copy.lib.a
	@if [ -f $(LIBsrcDIR)/libcdf.so ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.so ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(LIBsrcDIR)/libcdf.sl ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.sl ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(LIBsrcDIR)/libcdf.dylib ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.dylib ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.so ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.jnilib ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.jnilib ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.jnilib ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.dll ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.jnilib ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.sl ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.jnilib ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(LIBsrcDIR)/libcdf.o ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.o ; \
	 else \
	   $(NULL) ; \
	 fi
	@if [ -f $(LIBsrcDIR)/libcdf.dll ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) "INSTALLDIR=$(INSTALLDIRx)" install.lib.dll ; \
	 else \
	   $(NULL) ; \
	 fi

install.lib.so: copy.lib.so
install.lib.sl: copy.lib.sl
install.lib.dylib: copy.lib.dylib
install.lib.jnilib: copy.lib.jnilib
install.lib.o: copy.lib.o
install.lib.dll: copy.lib.dll

change.definitions:
	@if [ $(INSTALLDIRx) == $(SRCDIR) ] ; then \
	   $(SHELL) $(SRCDIR)/modify_definition_files.sh $(SRCDIR) ; \
	else \
	   $(SHELL) $(SRCDIR)/modify_definition_files.sh $(INSTALLDIRx) ; \
	fi

copy.leapseconds:
	@if [ ! $(INSTALLDIRx) == $(SRCDIR) ] ; then \
	      cp $(SRCDIR)/CDFLeapSeconds.txt $(INSTALLDIRx) ; \
	fi

copy.txt:
	@if [ ! $(INSTALLDIRx) == $(SRCDIR) ] ; then \
	      cp $(SRCDIR)/CDF_copyright.txt $(INSTALLDIRx) ; \
	      cp $(SRCDIR)/CHANGES.txt $(INSTALLDIRx) ; \
	      cp $(SRCDIR)/Release_notes.txt $(INSTALLDIRx) ; \
	      cp $(SRCDIR)/Welcome.txt $(INSTALLDIRx) ; \
	      cp $(SRCDIR)/README_cdf_tools.txt $(INSTALLDIRx) ; \
	fi

copy.definitions:
	@mkdir -p $(INSTALLDIRx)/bin
	@echo cp $(DEFSsrcDIR)/definitions.C $(INSTALLDIRx)/bin
	      cp $(DEFSsrcDIR)/definitions.C $(INSTALLDIRx)/bin
	@echo cp $(DEFSsrcDIR)/definitions.K $(INSTALLDIRx)/bin
	      cp $(DEFSsrcDIR)/definitions.K $(INSTALLDIRx)/bin
	@echo cp $(DEFSsrcDIR)/definitions.B $(INSTALLDIRx)/bin
	      cp $(DEFSsrcDIR)/definitions.B $(INSTALLDIRx)/bin

copy.include:
	@mkdir -p $(INSTALLDIRx)/include
	@echo cp $(INCsrcDIR)/cdf.h $(INSTALLDIRx)/include
	      cp $(INCsrcDIR)/cdf.h $(INSTALLDIRx)/include
	@echo cp $(INCsrcDIR)/cdf.inc $(INSTALLDIRx)/include
	      cp $(INCsrcDIR)/cdf.inc $(INSTALLDIRx)/include
	@echo cp $(INCsrcDIR)/cdflib.h $(INSTALLDIRx)/include
	      cp $(INCsrcDIR)/cdflib.h $(INSTALLDIRx)/include
	@echo cp $(INCsrcDIR)/cdflib64.h $(INSTALLDIRx)/include
	      cp $(INCsrcDIR)/cdflib64.h $(INSTALLDIRx)/include
	@echo cp $(INCsrcDIR)/cdfdist.h $(INSTALLDIRx)/include
	      cp $(INCsrcDIR)/cdfdist.h $(INSTALLDIRx)/include
	@echo cp $(INCsrcDIR)/cdfconfig.h $(INSTALLDIRx)/include
	      cp $(INCsrcDIR)/cdfconfig.h $(INSTALLDIRx)/include
	@echo cp $(INCsrcDIR)/cdftools.h $(INSTALLDIRx)/include
	      cp $(INCsrcDIR)/cdftools.h $(INSTALLDIRx)/include

copy.lib.so:
	@mkdir -p $(INSTALLDIRx)/lib
	@echo cp $(LIBsrcDIR)/libcdf.so $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.so $(INSTALLDIRx)/lib/libcdf.$(VERSION).so
	      rm -f $(INSTALLDIRx)/lib/libcdf.so
	      cd $(INSTALLDIRx)/lib && ln -s libcdf.$(VERSION).so libcdf.so

copy.lib.sl:
	@mkdir -p $(INSTALLDIRx)/lib
	@echo cp $(LIBsrcDIR)/libcdf.sl $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.sl $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.sl $(INSTALLDIRx)/lib/libcdf.$(VERSION).sl
	      rm -f $(INSTALLDIRx)/lib/libcdf.sl
	      cd $(INSTALLDIRx)/lib && ln -s libcdf.$(VERSION).sl libcdf.sl

copy.lib.dylib:
	@mkdir -p $(INSTALLDIRx)/lib
	@echo cp $(LIBsrcDIR)/libcdf.dylib $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.dylib $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.dylib $(INSTALLDIRx)/lib/libcdf.$(VERSION).dylib
	      rm -f $(INSTALLDIRx)/lib/libcdf.dylib
	      cd $(INSTALLDIRx)/lib && ln -s libcdf.$(VERSION).dylib libcdf.dylib
	@if [ $(MACVERSION) -gt 0 ] ; then \
	  mkdir -p ${MYHOME}/lib ; \
	  cp $(LIBsrcDIR)/libcdf.dylib $(MYHOME)/lib/libcdf.$(VERSION).dylib ; \
	  rm -f $(MYHOME)/lib/libcdf.dylib ; \
	  cd $(MYHOME)/lib && ln -s libcdf.$(VERSION).dylib libcdf.dylib ; \
	fi

copy.lib.jnilib:
	@mkdir -p $(INSTALLDIRx)/lib
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.so ] ; then \
	  echo cp $(JNIsrcDIR)/libcdfNativeLibrary.so $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).so ; \
	  cp $(JNIsrcDIR)/libcdfNativeLibrary.so $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).so ; \
	  rm -f $(INSTALLDIRx)/lib/libcdfNativeLibrary.so ; \
	  cd $(INSTALLDIRx)/lib && ln -s libcdfNativeLibrary.$(VERSION).so libcdfNativeLibrary.so ; \
	fi
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.dll ] ; then \
	  echo cp $(JNIsrcDIR)/libcdfNativeLibrary.dll $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).dll ; \
	  cp $(JNIsrcDIR)/libcdfNativeLibrary.dll $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).dll ; \
	  rm -f $(INSTALLDIRx)/lib/libcdfNativeLibrary.dll ; \
	  cd $(INSTALLDIRx)/lib && ln -s libcdfNativeLibrary.$(VERSION).dll libcdfNativeLibrary.dll ; \
	fi
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.jnilib ] ; then \
	  echo cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \
	  cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \
	  mkdir -p $(MYHOME)/lib ; \
	  echo cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \
	  cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/lib/libcdfNativeLibrary.$(VERSION).jnilib ; \
	  mkdir -p $(MYHOME)/Library/Java/Extensions ; \
	  echo cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/Library/Java/Extensions/libcdfNativeLibrary.$(VERSION).jnilib ; \
	  cp $(JNIsrcDIR)/libcdfNativeLibrary.jnilib $(MYHOME)/Library/Java/Extensions/libcdfNativeLibrary.$(VERSION).jnilib ; \
	  rm -f $(INSTALLDIRx)/lib/libcdfNativeLibrary.jnilib ; \
	  cd $(INSTALLDIRx)/lib && ln -s libcdfNativeLibrary.$(VERSION).jnilib libcdfNativeLibrary.jnilib ; \
	  rm -f $(MYHOME)/lib/libcdfNativeLibrary.jnilib ; \
	  cd $(MYHOME)/lib && ln -s libcdfNativeLibrary.$(VERSION).jnilib libcdfNativeLibrary.jnilib ; \
	  rm -f $(MYHOME)/Library/Java/Extensions/libcdfNativeLibrary.jnilib ; \
	  cd $(MYHOME)/Library/Java/Extensions && ln -s libcdfNativeLibrary.$(VERSION).jnilib libcdfNativeLibrary.jnilib ; \
	fi
	@if [ -f $(JNIsrcDIR)/libcdfNativeLibrary.sl ] ; then \
	  echo cp $(JNIsrcDIR)/libcdfNativeLibrary.sl $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).sl ; \
	  cp $(JNIsrcDIR)/libcdfNativeLibrary.sl $(INSTALLDIRx)/lib/libcdfNativeLibrary.$(VERSION).sl ; \
	  rm -f $(INSTALLDIRx)/lib/libcdfNativeLibrary.sl ; \
	  cd $(INSTALLDIRx)/lib && ln -s libcdfNativeLibrary.$(VERSION).sl libcdfNativeLibrary.sl ; \
	fi

copy.lib.o:
	@mkdir -p $(INSTALLDIRx)/lib
	@echo cp $(LIBsrcDIR)/libcdf.o $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.o $(INSTALLDIRx)/lib

copy.lib.dll:
	@mkdir -p $(INSTALLDIRx)/lib
	@echo cp $(LIBsrcDIR)/libcdf.dll $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.dll $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.dll $(INSTALLDIRx)/lib/libcdf.$(VERSION).dll
	      rm -f $(INSTALLDIRx)/lib/libcdf.dll
	      cd $(INSTALLDIRx)/lib && ln -s libcdf.$(VERSION).dll libcdf.dll

copy.lib.a:
	@mkdir -p $(INSTALLDIRx)/lib
	@echo cp $(LIBsrcDIR)/libcdf.a $(INSTALLDIRx)/lib
	      cp $(LIBsrcDIR)/libcdf.a $(INSTALLDIRx)/lib
	@if [ $(MACVERSION) -gt 0 ] ; then \
	  mkdir -p ${MYHOME}/lib ; \
	  cp $(LIBsrcDIR)/libcdf.a $(MYHOME)/lib ; \
	fi


copy.tools:
	@if [ -f $(TOOLSsrcDIR)/cdfedit.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfedit.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfedit.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfedit ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfedit" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfedit" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfxp.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfxp.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfexport.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfxp ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfxp" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfexport" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfcvt.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfcvt.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfconvert.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfcvt ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfcvt" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfconvert" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/skt2cdf.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/skt2cdf.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/skeletoncdf.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/skt2cdf ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/skt2cdf" \
	        "DESTINATION=$(INSTALLDIRx)/bin/skeletoncdf" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdf2skt.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdf2skt.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/skeletontable.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdf2skt ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdf2skt" \
	        "DESTINATION=$(INSTALLDIRx)/bin/skeletontable" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfinq.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfinq.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfinquire.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfinq ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfinq" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfinquire" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfstats.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfstats.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfstats.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfstats ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfstats" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfstats" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfcmp.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfcmp.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfcompare.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfcmp ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfcmp" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfcompare" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfdump.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfdump.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfdump.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfdump ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfdump" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfdump" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfirsdump.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfirsdump.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfirsdump.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfirsdump ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfirsdump" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfirsdump" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfmerge.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfmerge.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfmerge.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfmerge ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfmerge" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfmerge" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfvalidate.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfvalidate.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfvalidate.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfvalidate ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfvalidate" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfvalidate" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@if [ -f $(TOOLSsrcDIR)/cdfleapsecondsinfo.exe ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
		"SOURCE=$(TOOLSsrcDIR)/cdfleapsecondsinfo.exe" \
		"DESTINATION=$(INSTALLDIRx)/bin/cdfleapsecondsinfo.exe" \
		copy.file ; \
	elif [ -f $(TOOLSsrcDIR)/cdfleapsecondsinfo ] ; then \
	   $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) \
	        "SOURCE=$(TOOLSsrcDIR)/cdfleapsecondsinfo" \
	        "DESTINATION=$(INSTALLDIRx)/bin/cdfleapsecondsinfo" \
	        copy.file ; \
	else \
	   $(NULL) ; \
	fi
	@echo cp $(SRCDIR)/src/tools/cdfdir.unix $(INSTALLDIRx)/bin/cdfdir
	      cp $(SRCDIR)/src/tools/cdfdir.unix $(INSTALLDIRx)/bin/cdfdir

copy.help:
	@mkdir -p $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfedit.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfedit.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfeditj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfeditj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfedit.ilh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfedit.ilh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfbrow.ilh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfbrow.ilh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfxp.ilh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfxp.ilh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfcvt.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfcvt.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfcvtj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfcvtj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfcmp.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfcmp.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfcmpj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfcmpj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdf2skt.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdf2skt.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdf2sktj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdf2sktj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/skt2cdf.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/skt2cdf.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/skt2cdfj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/skt2cdfj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfstats.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfstats.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfstatsj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfstatsj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfdump.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfdump.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfdumpj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfdumpj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfirsdump.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfirsdump.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfirsdumpj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfirsdumpj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfinq.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfinq.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfinqj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfinqj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfdirj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfdirj.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfmerge.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfmerge.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfmergej.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfmergej.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfvalidate.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfvalidate.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfvalidatej.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfvalidatej.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfleaptableinfo.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfleaptableinfo.olh $(INSTALLDIRx)/lib/cdf/help
	@echo cp $(HELPsrcDIR)/cdfleaptableinfoj.olh $(INSTALLDIRx)/lib/cdf/help
	      cp $(HELPsrcDIR)/cdfleaptableinfoj.olh $(INSTALLDIRx)/lib/cdf/help

copy.jars:
	@mkdir -p $(INSTALLDIRx)/lib
	@if [ -f $(JNIsrcDIR)/cdfNativeLibrary.o ] ; then \
	  echo cp -f $(SRCDIR)/cdfjava/classes/cdfjava.jar $(INSTALLDIRx)/lib ; \
	       cp -f $(SRCDIR)/cdfjava/classes/cdfjava.jar $(INSTALLDIRx)/lib ; \
	  echo cp -f $(SRCDIR)/cdfjava/classes/cdfjson.jar $(INSTALLDIRx)/lib ; \
	       cp -f $(SRCDIR)/cdfjava/classes/cdfjson.jar $(INSTALLDIRx)/lib ; \
	  echo cp -f $(SRCDIR)/cdfjava/classes/cdfml.jar $(INSTALLDIRx)/lib ; \
	       cp -f $(SRCDIR)/cdfjava/classes/cdfml.jar $(INSTALLDIRx)/lib ; \
	  echo cp -f $(SRCDIR)/cdfjava/classes/gson-2.8.6.jar $(INSTALLDIRx)/lib ; \
	       cp -f $(SRCDIR)/cdfjava/classes/gson-2.8.6.jar $(INSTALLDIRx)/lib ; \
	  echo cp -f $(SRCDIR)/cdfjava/classes/javax.json-1.0.4.jar $(INSTALLDIRx)/lib ; \
	       cp -f $(SRCDIR)/cdfjava/classes/javax.json-1.0.4.jar $(INSTALLDIRx)/lib ; \
	  echo cp -f $(SRCDIR)/cdfjava/cdftools/CDFToolsDriver.jar $(INSTALLDIRx)/lib ; \
	       cp -f $(SRCDIR)/cdfjava/cdftools/CDFToolsDriver.jar $(INSTALLDIRx)/lib ; \
	  cp -f $(SRCDIR)/HOWTO_run-CDF-Java-tools.txt $(INSTALLDIRx) ; \
	  cp -f $(SRCDIR)/HOWTO_run-CDF-Json-tools.txt $(INSTALLDIRx) ; \
	  cp -f $(SRCDIR)/HOWTO_run-CDF-XML-tools.txt $(INSTALLDIRx) ; \
	else \
	  $(NULL) ; \
	fi

copy.file:
	@echo cp $(SOURCE) $(DESTINATION)
	      cp $(SOURCE) $(DESTINATION)
	      chmod +x $(DESTINATION)

notify.user:
	@echo
	@echo Installation completed!
	@echo
	@echo "**********"
	@echo "*  NOTE  *"
	@echo "**********"
	@echo "If you want to use any of the CDF command-line utilitites (e.g. cdfedit, "
	@echo "cdfexport, etc.), we strongly encourage you to set the CDF environment "
	@echo "variables defined in the CDF definition files.  Once the environment variables"
	@echo "defined, you can invoke the CDF utility of interest just by typing the utility"
	@echo "name. Otherwise, you'll have to specify the full path of the utility."
	@echo
	@echo If you use TCSH or CSH, run the following command:
	@echo
	@if [ $(INSTALLDIRx) = $(BUILDDIR) ] ; then \
	   echo "    source `pwd`/bin/definitions.C" ; \
	else \
	   echo "    source $(INSTALLDIRx)/bin/definitions.C" ; \
	fi
	@echo
	@echo
	@echo If you use BASH/BSH and ZSH, run the following command: 
	@echo
	@if [ $(INSTALLDIRx) = $(BUILDDIR) ] ; then \
	   echo "    . `pwd`/bin/definitions.B" ; \
	else \
	   echo "    . $(INSTALLDIRx)/bin/definitions.B" ; \
	fi
	@echo
	@echo
	@echo If you use KSH, run the following command: 
	@echo
	@if [ $(INSTALLDIRx) = $(BUILDDIR) ] ; then \
	   echo "    . `pwd`/bin/definitions.K" ; \
	else \
	   echo "    . $(INSTALLDIRx)/bin/definitions.K" ; \
	fi
	@echo
	@echo

ranlib.file:
	@echo $(RANLIBcmd) $(TARGET)
	      $(RANLIBcmd) $(TARGET)

#------------------------------------------------------------------------------
# Clean/purge.
#------------------------------------------------------------------------------

clean:
	@-rm -f core
	@-rm -f samples/core
	@if [ -f $(BUILDDIR)/$(LIBsrcZlibDIRorig)/Makefile ] ; then \
	  cd $(BUILDDIR)/$(LIBsrcZlibDIRorig); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean ; \
	fi
	@if [ -f $(BUILDDIR)/$(LIBsrcZlibDIRng)/Makefile ] ; then \
	  cd $(BUILDDIR)/$(LIBsrcZlibDIRng); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean ; \
	fi
	@cd $(BUILDDIR)/$(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean
	@cd $(BUILDDIR)/$(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean
	@cd $(BUILDDIR)/$(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean
	@if [ -f $(JNIsrcDIR)/Makefile ] ; then \
	  cd $(BUILDDIR)/$(JNIsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean ; \
	fi

purge:
	@-rm -f *~
	@-rm -f *#
	@-rm -f samples/*~
	@-rm -f samples/*#
	@-rm -f $(HELPsrcDIR)/*~
	@-rm -f $(HELPsrcDIR)/*#
	@-rm -f $(DEFSsrcDIR)/*~
	@-rm -f $(DEFSsrcDIR)/*#
	@-rm -f $(INCsrcDIR)/*~
	@-rm -f $(INCsrcDIR)/*#
	@if [ -f $(BUILDDIR)/$(LIBsrcZlibDIRorig)/Makefile ] ; then \
	 cd $(BUILDDIR)/$(LIBsrcZlibDIRorig); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge
	fi
	@if [ -f $(BUILDDIR)/$(LIBsrcZlibDIRng)/Makefile ] ; then \
	 cd $(BUILDDIR)/$(LIBsrcZlibDIRng); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) clean ; \
	fi
	@cd $(BUILDDIR)/$(LIBsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge
	@cd $(BUILDDIR)/$(TOOLSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge
	@cd $(BUILDDIR)/$(TESTSsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge
	@if [ -f $(JNIsrcDIR)/Makefile ] ; then \
	  cd $(BUILDDIR)/$(JNIsrcDIR); $(MAKE) $(EXTRAMAKE) MAKE=$(MAKE) purge ; \
	fi

#------------------------------------------------------------------------------
# Help.
#------------------------------------------------------------------------------

help:
	@echo 
	@echo "The defaults setup in Makefile"
	@echo '  [To make a change(s), e.g., run "make CC=.. ... all"]'
	@echo '  [                               "make INSTALLDIR=... install"]'
	@echo "  CC=$(CC)"
	@echo "  LD=$(LD)"
	@echo "  PIC=$(PIC)"
	@echo "  COPTIONS=$(COPTIONS)"
	@echo "  COPTIONSld=$(COPTIONSld)"
	@echo "  SHARED=$(SHARED)"
	@echo "  SHAREDEXT=$(SHAREDEXT)"
	@echo "  LDOPTIONS=$(LDOPTIONS)"
	@echo "  FORTRAN=$(FORTRAN)"
	@echo "  FC=$(FC)"
	@echo "  FOPTIONS=$(FOPTIONS)"
	@echo "  FOPTIONSld=$(FOPTIONSld)"
	@echo "  CURSES=$(CURSES)"
	@echo "  CURSESINC=$(CURSESINC)"
	@echo "  CURSESLIB=$(CURSESLIB)"
	@echo "  SYSLIBSexe=$(SYSLIBSexe)"
	@echo "  SYSLIBSshr=$(SYSLIBSshr)"
	@echo "  ZLIB=$(ZLIB)"
	@echo "  JNI=$(JNI)"
	@echo "  JNIOS=$(JNIOS)"
	@echo "  JNIEXT=$(JNIEXT)"
	@echo "  JDK_HOME=$(JDK_HOME)"
	@echo "  AROPTIONS=$(AROPTIONS)"
	@echo "  RANLIB=$(RANLIB)"
	@echo "  RANLIBcmd=$(RANLIBcmd)"
	@echo "  INSTALLDIR=$(INSTALLDIRx)"
	@echo 
	
#------------------------------------------------------------------------------
# Warning messages.
#------------------------------------------------------------------------------

note1.1st:
	@cat Note.1st

note1.noCC:
	@cat Note.noCC

note1.solaris:
	@cat Note.solaris

note1.intel:
	@cat Note.intel

note1.macx.no:
	@cat Note.MacX

note1.macx.yes:
	@$(NOOP)

note1.macx.i386:
	@echo 
	@echo Xcode version: $(XCODEVERSION) no longer supports i386 build...
	@echo
