#-------------------------------------------------------------------------#
#                                                                         #
#  COPYRIGHT[copyright mark] 2000, Raytheon System Company, its vendors,  #
#  and suppliers.  ALL RIGHTS RESERVED.                                   #
#                                                                         #
#-------------------------------------------------------------------------#
#----------------------------------------------------------------------------
# file:		makefile for HDF-EOS testdrivers Autotesting used by shell 
#               scripts in Commen directoery
# 	
# 
# author:  Abe Taaheri 
#
# history:
#	10-Jul-2014 AT Initial version
#----------------------------------------------------------------------------

# force make to use the 'sh' shell
SHELL = /bin/ksh

# name of remove utility
MAKE=$(MAKECMD)
RM= /bin/rm
RMFLAGS= -f 
CFLAGS_SUN= -DSUN5
FFLAGS_SUN= -DSUN5
CFLAGS_ALL= -D$(HDFSYS)
FFLAGS_ALL= -D$(HDFSYS)
CFLAGS_SGIn32= -n32 -mips3 -DIRIX -Dunix
FFLAGS_SGIn32= -n32 -mips3 -DIRIX -Dunix

CSUNLIB= -lnsl -lsocket
FSUNLIB= -lnsl -lsocket
CALLLIB=
FALLLIB=

INCDIR = -I$(HDFINC) -I$(HDFEOS_INC) -I$(SZIPINC) -I$(ZLIBINC) -I$(JPEGINC) 
LIBDIR = -L$(HDFLIB) -L$(HDFEOS_LIB) -L$(SZIPLIB) -L$(ZLIBLIB)  -L$(JPEGLIB) -lhdfeos -lGctp -lmfhdf -ldf -lz $(SZIPLIB)/libsz.a $(JPEGLIB)/libjpeg.a -lm -lc

all: select_brand testswath_c testswath77_f testgrid_c testgrid77_f testpoint_c testpoint_f testgrid77_szip_f testpoint77_szip_f

#all: select_brand 

select_brand:
	@if [ $(BRAND) = "sun5.10" ] ; then \
		CC="cc"; \
		F77="f77"; \
		CFLAGS="$(CFLAGS_SUN)"; \
		FFLAGS="$(FFLAGS_SUN)"; \
		CEXTRAL="$(CSUNLIB)"; \
		FEXTRAL="$(FSUNLIB)"; \
	elif [ $(BRAND) = "linux" ] ; then \
		CC="gcc"; \
		F77="gfortran -m32"; \
		CFLAGS="$(CFLAGS_ALL) -m32"; \
		FFLAGS="$(FFLAGS_ALL) -m32"; \
		CEXTRAL="$(CALLLIB)"; \
		FEXTRAL="$(FALLLIB)"; \
	elif [ $(BRAND) = "linux32" ] ; then \
		CC="gcc"; \
		F77="gfortran"; \
		CFLAGS="$(CFLAGS_ALL) -m32"; \
		FFLAGS="$(FFLAGS_ALL) -m32"; \
		CEXTRAL="$(CALLLIB)"; \
		FEXTRAL="$(FALLLIB)"; \
	elif [ $(BRAND) = "linux64" ] ; then \
		CC="gcc"; \
		F77="gfortran"; \
		CFLAGS="$(CFLAGS_ALL)"; \
		FFLAGS="$(FFLAGS_ALL)"; \
		CEXTRAL="$(CALLLIB)"; \
		FEXTRAL="$(FALLLIB)"; \
	elif [ $(BRAND) = "macintel" ] ; then \
		CC="gcc"; \
		F77="$(F77)"; \
		CFLAGS="$(CFLAGS_ALL)"; \
		FFLAGS="$(FFLAGS_ALL)"; \
		CEXTRAL="$(CALLLIB)"; \
		FEXTRAL="$(FALLLIB)"; \
	elif [ $(BRAND) = "macintel32" ] ; then \
		CC="gcc"; \
		F77="$(F77)"; \
		CFLAGS="$(CFLAGS_ALL)"; \
		FFLAGS="$(FFLAGS_ALL)"; \
		CEXTRAL="$(CALLLIB)"; \
		FEXTRAL="$(FALLLIB)"; \
	elif [ $(BRAND) = "macintel64" ] ; then \
		CC="gcc"; \
		F77="$(F77)"; \
		CFLAGS="$(CFLAGS_ALL)"; \
		FFLAGS="$(FFLAGS_ALL)"; \
		CEXTRAL="$(CALLLIB)"; \
		FEXTRAL="$(FALLLIB)"; \
	elif [ $(BRAND) = "cygwin" ] ; then \
		CC="gcc"; \
		F77="$(F77)"; \
		CFLAGS="$(CFLAGS_ALL)"; \
		FFLAGS="$(FFLAGS_ALL)"; \
		CEXTRAL="$(CALLLIB)"; \
		FEXTRAL="$(FALLLIB)"; \
	else \
		echo " The brand $(BRAND) is not supported. " ; \
		echo " Set the env. vriable BRAND to a supported one then make this makefile"; \
	fi ; \
	RM="$(RM)";\
	RMFLAGS="$(RMFLAGS)";\
	export CC F77 CFLAGS FFLAGS FEXTRAL;\
	export CEXTRAL RMFLAGS RM;\

#all: testswath_c testswath77_f testgrid_c testgrid77_f testpoint_c testpoint_f testgrid77_szip_f testpoint77_szip_f

testswath_c: select_brand
	@echo " "; echo " "; \
	echo " ---- Making *.c testdrivers in swath directory ----"; \
	$(CC) $(CFLAGS) -o testswath.o $(INCDIR) -c testswath.c; \
	$(CC) $(CFLAGS) -o testswath_c testswath.o $(LIBDIR) $(CEXTRAL); \
	$(RM) $(RMFLAGS) *.o; \
	cd .;
testswath77_f: select_brand
	@if [ "`basename ${F77}`" = "f77" -o "`basename ${F77}`" = "g77" -o "`basename ${F77}`" = "gfortran" ] ; then \
	echo " "; echo " "; \
	echo " ---- Making *.c testdrivers in swath directory ----"; \
	$(F77) $(FFLAGS) -o testswath.o $(INCDIR) -c testswath77.f; \
	$(F77) $(FFLAGS) -o testswath77_f testswath.o $(LIBDIR) $(FEXTRAL); \
	$(RM) $(RMFLAGS) *.o; echo " "; echo " "; \
	cd .;  \
	fi ;
testgrid_c: select_brand
	@echo " "; echo " "; \
	echo " ---- Making *.c testdrivers in grid directory  ----"; \
 	$(CC) $(CFLAGS) -o testgrid.o $(INCDIR) -c testgrid.c; \
	$(CC) $(CFLAGS) -o testgrid_c testgrid.o $(LIBDIR) $(CEXTRAL); \
	$(RM) $(RMFLAGS) *.o; \
	cd .;
testgrid77_f: select_brand
	@if [ "`basename ${F77}`" = "f77" -o "`basename ${F77}`" = "g77" -o "`basename ${F77}`" = "gfortran" ] ; then \
	echo " ---- Making *.f testdrivers in grid directory ----"; \
	$(F77) $(FFLAGS) -o testgrid.o $(INCDIR) -c testgrid77.f; \
	$(F77) $(FFLAGS) -o testgrid77_f testgrid.o $(LIBDIR) $(FEXTRAL); \
	$(RM) $(RMFLAGS) *.o; echo " "; echo " "; \
	cd .;  \
	fi ;
testpoint_c: select_brand
	@echo " "; echo " "; \
	echo " ---- Making *.c testdrivers in point directory ----"; \
	$(CC) $(CFLAGS) -o testpoint.o $(INCDIR) -c testpoint.c; \
	$(CC) $(CFLAGS) -o testpoint_c testpoint.o $(LIBDIR) $(CEXTRAL); \
	$(RM) $(RMFLAGS) *.o; \
	cd .;
testpoint77_f: select_brand
	@if [ "`basename ${F77}`" = "f77" -o "`basename ${F77}`" = "g77" -o "`basename ${F77}`" = "gfortran" ] ; then \
	echo " ---- Making *.f testdrivers in point directory ----"; \
	$(F77) $(FFLAGS) -o testpoint.o $(INCDIR) -c testpoint77.f; \
	$(F77) $(FFLAGS) -o testpoint77_f testpoint.o $(LIBDIR) $(FEXTRAL); \
	$(RM) $(RMFLAGS) *.o;echo " "; echo " "; \
	cd .;  \
	fi ;
testgrid77_szip_f: select_brand
	@if [ "`basename ${F77}`" = "f77" -o "`basename ${F77}`" = "g77" -o "`basename ${F77}`" = "gfortran" ] ; then \
	echo " ---- Making *.f testdrivers in grid directory ----"; \
	$(F77) $(FFLAGS) -o testgrid_szip77.o $(INCDIR) -c testgrid_szip77.f; \
	$(F77) $(FFLAGS) -o testgrid77_szip_f testgrid_szip77.o $(LIBDIR) $(FEXTRAL); \
	$(RM) $(RMFLAGS) *.o;echo " "; echo " "; \
	cd .;  \
	fi ;




