# configure.wrf
#
# This file was automatically generated by the configure script in the
# top level directory. You may make changes to the settings in this
# file but be aware they will be overwritten each time you run configure.
# Ordinarily, it is necessary to run configure once, when the code is
# first installed.
#
# To permanently change options, change the settings for your platform
# in the file arch/configure.defaults then rerun configure.
#
SHELL           =       /bin/sh
DEVTOP          =       `pwd`
LIBINCLUDE      =       .
.SUFFIXES: .F .i .o .f90 .c

#### Get core settings from environment (set in compile script)
#### Note to add a core, this has to be added to.

COREDEFS = -DEM_CORE=$(WRF_EM_CORE) \
           -DNMM_CORE=$(WRF_NMM_CORE) -DNMM_MAX_DIM=2600 \
	   -DCOAMPS_CORE=$(WRF_COAMPS_CORE) \
           -DEXP_CORE=$(WRF_EXP_CORE)

#### Single location for defining total number of domains.  You need
#### at least 1 + 2*(number of total nests).  For example, 1 coarse
#### grid + three fine grids = 1 + 2(3) = 7, so MAX_DOMAINS=7.

MAX_DOMAINS	=	21

#### DM buffer length for the configuration flags.

CONFIG_BUF_LEN	=	16384


##############################################################################
#### The settings in this section are defaults that may be overridden by the 
#### architecture-specific settings in the next section.  
##############################################################################

##############################################################################
#### NOTE:  Do not modify these default values here.  To override these 
####        values, make changes after "Architecture specific settings".  
##############################################################################

#### Native size (in bytes) of Fortran REAL data type on this architecture ####
#### Note:  to change real wordsize (for example, to promote REALs from 
####        4-byte to 8-byte), modify the definition of RWORDSIZE in the 
####        section following "Architecture specific settings".  Do not 
####        change NATIVE_RWORDSIZE as is it architecture-specific.  
NATIVE_RWORDSIZE = 4

#### Default sed command and script for Fortran source files ####
SED_FTN = sed -f ../arch/standard.sed

# Hack to work around $(PWD) not changing during OSF1 build.  
# $(IO_GRIB_SHARE_DIR) is reset during the OSF1 build only.  
IO_GRIB_SHARE_DIR = 

#### ESMF switches                 ####
#### These are set up by Config.pl ####
# switch to use separately installed ESMF library for coupling:  1==true
ESMF_COUPLING       = 0
# select dependences on module_utility.o
ESMF_MOD_DEPENDENCE = ../external/esmf_time_f90/module_utility.o
# select -I options for separately installed ESMF library, if present
ESMF_MOD_INC        = 
# select -I options for external/io_esmf vs. external/esmf_time_f90
ESMF_IO_INC         = -I../external/esmf_time_f90
# select cpp token for external/io_esmf vs. external/esmf_time_f90
ESMF_IO_DEFS        = 
# select build target for external/io_esmf vs. external/esmf_time_f90
ESMF_TARGET         = esmf_time

##############################################################################

LIBWRFLIB = libwrflib.a


#### Architecture specific settings ####

# Settings for PC Linux i486 i586 i686, g95 compiler  DM-Parallel (RSL_LITE, MPICH, Allows nesting)
#
# Notes: for experimental implementation of moving nests, add -DMOVE_NESTS to ARCHFLAGS
#        for experimental implementation of vortex tracking nests, add -DMOVE_NESTS -DVORTEX_CENTER to ARCHFLAGS
#
DMPARALLEL      =       1
MAX_PROC        =       1024
FC              =       mpif90 -f90=g95
LD              =       mpif90 -f90=g95
CC              =       mpicc -cc=gcc -DMPI2_SUPPORT -DFSEEKO_OK 
SCC		=	gcc
SFC             =       g95
RWORDSIZE       =       $(NATIVE_RWORDSIZE)
# g95 does not like -r4. if you want promotion to -r8 add it to PROMOTION below
#PROMOTION      =       -r$(RWORDSIZE) -i4
PROMOTION       =       -i4
CFLAGS          =       -DDM_PARALLEL \
                        -DMAXDOM_MAKE=$(MAX_DOMAINS) -DMAXPROC_MAKE=$(MAX_PROC) -I../external/RSL_LITE
FCOPTIM		=	-O2 # -fast
FCDEBUG		=	#-g -O0
FCBASEOPTS      =       -Wno=101,139,155,158 -fno-second-underscore -fendian=big -ffree-form $(FCDEBUG) # -Mlfs
FCFLAGS         =       $(FCOPTIM) $(FCBASEOPTS)
ARCHFLAGS       =       $(COREDEFS) -DGRIB1  -DINTIO -DDM_PARALLEL \
                        -DIWORDSIZE=4 -DDWORDSIZE=8 -DRWORDSIZE=$(RWORDSIZE) -DLWORDSIZE=4 -DNETCDF \
			-DLIMIT_ARGS -DNMM_NEST=$(WRF_NMM_NEST) -DG95
# machine-specific flags needed to link in ESMF library (C++ run-time-library, etc.)
ESMF_LIB_FLAGS  =       
ESMF_IO_LIB     =       ../external/esmf_time_f90/libesmf_time.a
ESMF_IO_LIB_EXT =       -L../../external/esmf_time_f90/libesmf_time.a
INCLUDE_MODULES =       -fmod=../main -I../external/io_netcdf -I../external/io_int -I../external/esmf_time_f90 \
                        -I../external -I../frame -I../share -I../phys -I../chem -I../inc
PERL            =       perl
REGISTRY        =       Registry
LIB             =       ../external/io_netcdf/libwrfio_nf.a -L/users/michalak/netcdf-mac-pgi-64/lib -lnetcdf -L../external/RSL_LITE -lrsl_lite \
                        -L../external/io_grib1 -lio_grib1 \
                         \
                        -L../external/io_grib_share -lio_grib_share \
			-L../external/io_int -lwrfio_int \
			../frame/module_internal_header_util.o ../frame/pack_utils.o -L../external/esmf_time_f90 -lesmf_time 
LDFLAGS         =       $(FCFLAGS) 
ENVCOMPDEFS	=	
WRF_CHEM	=	0 
CPP             =       /lib/cpp -C -P -traditional
POUND_DEF	=	-DNO_RRTM_PHYSICS  -traditional $(COREDEFS) -DNONSTANDARD_SYSTEM -DCONFIG_BUF_LEN=$(CONFIG_BUF_LEN) -DMAX_DOMAINS_F=$(MAX_DOMAINS)
CPPFLAGS        =       -I$(LIBINCLUDE) -C -P $(ARCHFLAGS) -I../external/RSL_LITE -C -P `cat ../inc/dm_comm_cpp_flags` $(ENVCOMPDEFS) $(POUND_DEF)
AR              =       ar ru
M4              =       m4 -B 14000
RANLIB          =       ranlib
NETCDFPATH	=	/users/michalak/netcdf-mac-pgi-64
CC_TOOLS        =       cc

#### Override default sed command and script for Fortran source files         ####
#### This sed script does not pass __FILE__ and __LINE__ to wrf_error_fatal() ####
#### because the Fortran compiler complains about long source lines.          ####
SED_FTN = sed -f ../arch/no_file_line.sed

externals : wrf_ioapi_includes wrfio_nf wrfio_grib_share wrfio_grib1  ../external/RSL_LITE/librsl_lite.a wrfio_int gen_comms.c module_dm.F esmf_time

gen_comms.c : ../external/RSL_LITE/gen_comms.c
	( /bin/cp ../tools/gen_comms_warning ../tools/gen_comms.c ; \
          cat ../external/RSL_LITE/gen_comms.c >> ../tools/gen_comms.c )

module_dm.F : ../external/RSL_LITE/module_dm.F
	( /bin/cp module_dm_warning module_dm.F ; cat ../external/RSL_LITE/module_dm.F >> module_dm.F )

wrfio_nf : 
	( cd ../external/io_netcdf ; \
	  make NETCDFPATH=/users/michalak/netcdf-mac-pgi-64 RANLIB="$(RANLIB)" CPP="$(CPP)" FC="$(FC) $(PROMOTION) $(FCFLAGS) -w" TRADFLAG="-traditional" )

wrfio_grib_share :
	( cd ../external/io_grib_share ; \
          make CC="$(SCC)" CFLAGS="$(CFLAGS)" RM="$(RM)" RANLIB="$(RANLIB)" CPP="$(CPP)" FC="$(SFC) $(PROMOTION) -I. $(FCDEBUG) $(FCBASEOPTS) -w" TRADFLAG="-traditional" archive)

wrfio_grib1 :
	( cd ../external/io_grib1 ; \
          make CC="$(SCC)" CFLAGS="$(CFLAGS)" RANLIB="$(RANLIB)" CPP="$(CPP)" FC="$(SFC) $(PROMOTION) -I. $(FCDEBUG) $(FCBASEOPTS) -w" TRADFLAG="-traditional" archive)

wrfio_grib2 :
	( cd ../external/io_grib2 ; \
          make CC="$(SCC)" CFLAGS="$(CFLAGS) " RM="$(RM)" RANLIB="$(RANLIB)" CPP="$(CPP)" FC="$(SFC) $(PROMOTION) -I. $(FCDEBUG) $(FCBASEOPTS) -w" TRADFLAG="-traditional" FIXED="-ffixed-form" archive)

wrfio_int : 
	( cd ../external/io_int ; \
          make CC="$(CC)" RANLIB="$(RANLIB)" CPP="$(CPP)" SFC="$(SFC) $(PROMOTION) $(FCDEBUG) $(FCBASEOPTS)" FC="$(SFC) $(PROMOTION) $(FCDEBUG) $(FCBASEOPTS) -w" TRADFLAG="-traditional" all )

esmf_time : 
	( cd ../external/esmf_time_f90 ; \
	  make FC="$(FC) $(PROMOTION) $(FCDEBUG) $(FCBASEOPTS)" RANLIB="$(RANLIB)" CPP="$(CPP) -I../../inc -I. $(POUND_DEF)" )

../external/RSL_LITE/librsl_lite.a :
	( cd ../external/RSL_LITE ; make CC="$(CC)" FC="$(FC) $(FCFLAGS) $(PROMOTION)" MAX_DOMAINS=$(MAX_DOMAINS) MAX_PROC=$(MAX_PROC) LEARN_BCAST=-DLEARN_BCAST )

# compile these without high optimization to speed compile
solve_interface.o : solve_interface.F
shift_domain_em.o : shift_domain_em.F
module_io_mm5.o : module_io_mm5.F
module_si_io.o : module_si_io.F
module_io_wrf.o : module_io_wrf.F
module_domain.o : module_domain.F
module_start.o : module_start.F
module_initialize.o : module_initialize.F
module_initialize_b_wave.o : module_initialize_b_wave.F
module_initialize_hill2d_x.o : module_initialize_hill2d_x.F
module_initialize_quarter_ss.o : module_initialize_quarter_ss.F
module_initialize_squall2d_x.o : module_initialize_squall2d_x.F
module_initialize_squall2d_y.o : module_initialize_squall2d_y.F
module_initialize_real.o : module_initialize_real.F
module_dm.o : module_dm.F
module_comm_dm.o : module_comm_dm.F
start_domain.o : start_domain.F
mediation_integrate.o : mediation_integrate.F
module_configure.o : module_configure.F

solve_interface.o                                              \
shift_domain_em.o                                              \
module_io_mm5.o module_si_io.o module_io_wrf.o module_domain.o \
module_start.o module_initialize.o module_initialize_b_wave.o  \
module_initialize_hill2d_x.o module_initialize_quarter_ss.o    \
module_initialize_squall2d_x.o module_initialize_squall2d_y.o  \
module_configure.o                                             \
mediation_integrate.o \
module_initialize_real.o module_dm.o module_comm_dm.o start_domain.o :
	$(RM) $@
	$(SED_FTN) $*.F > $*.b 
	$(CPP) -I../inc $(CPPFLAGS) $*.b  > $*.f90
	$(RM) $*.b
	$(FC) -c $(PROMOTION) $(FCBASEOPTS) $(MODULE_DIRS) $*.f90


###########################################################

# These sub-directory builds are identical across all architectures
wrfio_esmf :
	( cd ../external/io_esmf ; \
	make FC="$(FC) $(PROMOTION) $(FCDEBUG) $(FCBASEOPTS) $(ESMF_MOD_INC)" RANLIB="$(RANLIB)" CPP="$(CPP) $(POUND_DEF) " )


#
#	Macros, these should be generic for all machines

LN	=	ln -sf
MAKE	=	make -i -r
RM	= 	rm -f

#	There is probably no reason to modify these rules

wrf_ioapi_includes :
	( cd ../external/ioapi_share ; \
	$(MAKE) NATIVE_RWORDSIZE="$(NATIVE_RWORDSIZE)" RWORDSIZE="$(RWORDSIZE)" )

.F.i:
	$(RM) $@
	$(CPP) -I../inc $(CPPFLAGS) $*.F > $@
	mv $*.i $(DEVTOP)/pick/$*.f90
	cp $*.F $(DEVTOP)/pick

.F.o:
	$(RM) $@
	$(SED_FTN) $*.F > $*.b 
	$(CPP) -I../inc $(CPPFLAGS) $*.b  > $*.f90
	$(RM) $*.b
	$(FC) -o $@ -c $(FCFLAGS) $(MODULE_DIRS) $(PROMOTION) $(FCSUFFIX) $*.f90
#PGI	if [ ! -e $@ ] ; then \
#PGI	sleep 10 ; $(FC) -c $(FCFLAGS) $(MODULE_DIRS) $(PROMOTION) $(FCSUFFIX) $*.f90 ; \
#PGI	fi
#PGI	if [ ! -e $@ ] ; then \
#PGI	sleep 10 ; $(FC) -c $(FCFLAGS) $(MODULE_DIRS) $(PROMOTION) $(FCSUFFIX) $*.f90 ; \
#PGI	fi

.F.f90:
	$(RM) $@
	$(SED_FTN) $*.F > $*.b 
	$(CPP) -I../inc $(CPPFLAGS) $*.b  > $@
	$(RM) $*.b

.f90.o:
	$(RM) $@
	$(FC) -o $@ -c $(FCFLAGS) $(PROMOTION) $(FCSUFFIX) $*.f90
#PGI	if [ ! -e $@ ] ; then \
#PGI	sleep 10 ; $(FC) -c $(FCFLAGS) $(PROMOTION) $(FCSUFFIX) $*.f90 ; \
#PGI	fi
#PGI	if [ ! -e $@ ] ; then \
#PGI	sleep 10 ; $(FC) -c $(FCFLAGS) $(PROMOTION) $(FCSUFFIX) $*.f90 ; \
#PGI	fi

.c.o:
	$(RM) $@
	$(CC) -o $@ -c $(CFLAGS) $*.c

