#	Top-level Makefile for MM5toGrADS conversion program

#	Macros, these should be generic for all machines

.IGNORE:

AR	=	ar ru
CD	=	cd
LN	=	ln -s
MAKE	=	make -i -f Makefile
RM	=	/bin/rm -f
RM_LIST	=	*.o *.f core .tmpfile grads.exe ../grads.exe
RM_LIST2=	*.o *.f core .tmpfile make.grads.out grads.namelist grads.print.out

#	Targets for supported architectures

default:
	uname -a > .tmpfile
	grep CRAY .tmpfile ; \
	if [ $$? = 0 ]; then echo "Compiling for CRAY" ; 		\
		( $(CD) src ; $(MAKE) all				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= linux"		\
		"MAKE		= $(MAKE)"	"CPP		= /opt/ctl/bin/cpp" \
		"CPPFLAGS	= -I. -C -P -DRECLENBYTE"	\
		"FC		= f90" 		"FCFLAGS	= -I. -f free"		\
		"LDOPTIONS      = " 		"CFLAGS         = "		\
		"LOCAL_LIBRARIES= " ) ; \
	else \
		grep OSF .tmpfile ; \
	if [ $$? = 0 ]; then echo "Compiling for Compaq" ; 		\
		( $(CD) src ; $(MAKE) all 				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= DEC"		\
		"MAKE		= $(MAKE)"	"CPP		= /usr/bin/cpp" \
		"CPPFLAGS	= -I. -C -P "			\
		"FC		= f90"		"FCFLAGS	= -I. -free -convert big_endian -fpe"	\
		"LDOPTIONS      = "		"CFLAGS         = "		\
		"LOCAL_LIBRARIES= " ) ; \
	else \
		grep IRIX .tmpfile ; \
	if [ $$? = 0 ]; then echo "Compiling for SGI" ; 		\
		( $(CD) src ; $(MAKE) all				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= linux" 		\
		"MAKE		= $(MAKE)"	"CPP		= /lib/cpp"	\
	 	"CPPFLAGS	= -I. -C -P "			\
		"FC		= f90" 		"FCFLAGS	= -I. -n32 -freeform"	\
		"LDOPTIONS      = -n32"		"CFLAGS         = -I. -n32"	\
		"LOCAL_LIBRARIES= " ) ; \
	else \
		grep HP .tmpfile ; \
	if [ $$? = 0 ]; then echo "Compiling for HP" ; 			\
		( $(CD) src ; $(MAKE) all				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= linux"		\
		"MAKE		= $(MAKE)"	"CPP		= /opt/langtools/lbin/cpp" \
		"CPPFLAGS= -I. -C -P -DRECLENBYTE"		\
		"FC		= f90" 		"FCFLAGS	= -I. -O +langlvl=90 +source=free"	\
		"LDOPTIONS	= " 		"CFLAGS		= -Aa"		\
		"LOCAL_LIBRARIES= " ) ; \
	else \
		grep SUN .tmpfile ; \
	if [ $$? = 0 ]; then echo "Compiling for SUN" ; 		\
		( $(CD) src ; $(MAKE) all				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= linux"		\
		"MAKE		= $(MAKE)"	"CPP		= /usr/ccs/lib/cpp" \
		"CPPFLAGS=-I. -C -P -DRECLENBYTE"		\
		"FC		= f90" 		"FCFLAGS	= -I. -free"		\
		"LDOPTIONS	= "    		"CFLAGS		= -I."		\
		"LOCAL_LIBRARIES= " ) ; \
	else \
		grep AIX .tmpfile ; \
	if [ $$? = 0 ]; then echo "Compiling for IBM" ;			\
		( $(CD) src ; $(MAKE) all				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= linux"		\
		"MAKE		= $(MAKE)"	"CPP		= /usr/lib/cpp" \
		"CPPFLAGS	= -I. -C -P -DRECLENBYTE"	\
		"FC		= xlf"		"FCFLAGS	= -I. -O -qmaxmem=-1 -qfree=f90"\
		"LDOPTIONS	= " 		"CFLAGS		= -I."		\
		"LOCAL_LIBRARIES= " ) ; \
	else \
		grep Linux .tmpfile ; \
	if [ $$? = 0 ]; then echo "Compiling for Linux" ;		\
		( $(CD) src ; $(MAKE) all				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= linux"		\
		"MAKE		= $(MAKE)"	"CPP		= /lib/cpp"	\
		"CPPFLAGS	= -I. -C -traditional -DRECLENBYTE"	\
		"FC		= pgf90"	"FCFLAGS	= -I. -Mfree -O2 -tp p6 -pc 32 -byteswapio"\
		"LDOPTIONS	= " 		"CFLAGS		= -I."		\
		"LOCAL_LIBRARIES= " ) ; \
	else echo "Do not know how to compile for the `cat .tmpfile` machine." \
		fi ; \
		fi ; \
		fi ; \
		fi ; \
		fi ; \
		fi ; \
		fi ; \
	fi ; \
		( $(RM) grads.exe ; $(LN) src/grads.exe . ) ;

intel:
	"Compiling for Linux with INTEL compiler" ;		\
		( $(CD) src ; $(MAKE) all				\
		"RM		= $(RM)" 	"RM_LIST	= $(RM_LIST)"	\
		"LN		= $(LN)" 	"MACH		= linux"		\
		"MAKE		= $(MAKE)"	"CPP		= /lib/cpp"	\
		"CPPFLAGS	= -I. -C -traditional -DRECLENBYTE -Drecl"	\
		"FC		= ifort"	"FCFLAGS	= -I. -FR -pc 32 -convert big_endian"\
		"LDOPTIONS	= " 		"CFLAGS		= -I."		\
		"LOCAL_LIBRARIES= " ) ; \
		( $(RM) grads.exe ; $(LN) src/grads.exe . ) ;

code:
	( $(CD) src ; $(MAKE) code					\
	"MAKE			=	$(MAKE)"			\
	"CPP			=	/usr/bin/cpp"			\
	"CPPFLAGS		=	-I. -C -P -DDEC"		)

clean:
	( $(CD) src   ; $(MAKE) clean "CD = $(CD)" "RM = $(RM)" "RM_LIST = $(RM_LIST)" )
	$(RM) $(RM_LIST2)
