#

FPPFLAGS        = $(DEFAULT_FPPFLAGS) $(COREDEFS) $(DM_PPFLAGS) \
                     -DNATIVE_RWORDSIZE=$(NATIVE_RWORDSIZE) $(EXTRA_FPPFLAGS)
CPPFLAGS        = -C -P $(TRADFLAG) $(INCS)
REGFLAGS        = $(DEFAULT_FPPFLAGS) $(DM_PPFLAGS) $(COREDEFS) $(EXTRA_FPPFLAGS) 
 
CCFLAGS        = $(DEFAULT_CCFLAGS) $(COREDEFS) $(CCOPTIM) $(DM_PPFLAGS) $(WORDSIZE_DEF) $(EXTRA_CCFLAGS)
LDFLAGS         = -L. $(FCOPTIM) $(FCENDIAN) $(EXTRA_LDFLAGS)

FCFLAGS         = $(INCS) $(FCTYPE) $(FCFREE) $(FCENDIAN) $(FCDEBUG) $(FCOPTIM) $(FCWARN) $(EXTRA_FCFLAGS)
FCFLAGS_NOWARN  = $(INCS) $(FCTYPE) $(FCFREE) $(FCENDIAN) $(FCDEBUG) $(FCOPTIM) $(EXTRA_FCFLAGS)
FCFLAGS_SIMPLE  = $(INCS) $(FCTYPE) $(FCFREE) $(FCENDIAN) $(EXTRA_FCFLAGS) $(FCLOWOPT)
FIXEDFLAGS        = $(INCS) $(FCTYPE) $(FCFIXED) $(FCENDIAN) $(FCDEBUG) $(FCOPTIM) $(EXTRA_FCFLAGS)
FIXEDFLAGS_ENDIAN = $(FCTYPE) $(EXTRA_FCFLAGS)
                  

# compile these simply (no debug or optimisation) to speed compile

wrf_bdyout.o wrf_bdyin.o \
   wrf_restartout.o \
   wrf_restartin.o \
   wrf_inputin.o \
   wrf_inputout.o \
   wrf_histin.o \
   wrf_histout.o \
   module_si_io.o \
   module_io_wrf.o \
   module_configure.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_initialize_real.o \
   module_dm.o start_domain.o module_comm_dm.o \
   mediation_force_domain.o \
   mediation_integrate.o \
   mediation_interp_domain.o \
   mediation_feedback_domain.o \
   solve_interface.o \
   shift_domain_em.o \
   solve_em.o \
   solve_nmm.o \
   convert_nmm.o    :
	@ $(RM) $@
	@ $(SED_FTN) $*.F > $*.b 
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS_SIMPLE) $*.f

# compile these without warnings, as they generate too many

gamma1.o :
	@ $(RM) $@
	@ $(SED_FTN) $*.f90 > $*.b 
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS_NOWARN) $*.f

f_pack.o \
   f_xpose.o :
	@ $(RM) $@
	@ $(SED_FTN) $*.F90 > $*.b 
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS_NOWARN) $*.f

interp_fcn.o \
   init_modules.o \
   mediation_wrfmain.o \
   module_bc.o \
   set_timekeeping.o \
   wrf_fddaobs_in.o \
   module_get_file_names.o \
   module_io_quilt.o \
   module_integrate.o \
   module_nesting.o \
   module_machine.o \
   module_wrf_error.o \
   module_timing.o \
   io_grib_share.o \
   module_date_time.o \
   module_io.o \
   module_io_domain.o \
   module_tiles.o \
   wrf_debug.o \
   wrf_shutdown.o \
   input_wrf.o \
   output_wrf.o \
   module_bc_time_utilities.o \
   module_quilt_outbuf_ops.o \
   module_internal_header_util.o \
   wrf_ext_read_field.o \
   wrf_ext_write_field.o \
   nest_init_utils.o \
   wrf_auxhist1in.o wrf_auxhist2in.o wrf_auxhist3in.o \
   wrf_auxhist4in.o wrf_auxhist5in.o wrf_auxhist6in.o \
   wrf_auxhist7in.o wrf_auxhist8in.o wrf_auxhist9in.o \
   wrf_auxhist10in.o wrf_auxhist11in.o \
   wrf_auxhist1out.o wrf_auxhist2out.o wrf_auxhist3out.o \
   wrf_auxhist4out.o wrf_auxhist5out.o wrf_auxhist6out.o \
   wrf_auxhist7out.o wrf_auxhist8out.o wrf_auxhist9out.o \
   wrf_auxhist10out.o wrf_auxhist11out.o \
   wrf_auxinput1in.o wrf_auxinput2in.o wrf_auxinput3in.o \
   wrf_auxinput4in.o wrf_auxinput5in.o wrf_auxinput6in.o \
   wrf_auxinput7in.o wrf_auxinput8in.o wrf_auxinput9in.o \
   wrf_auxinput10in.o wrf_auxinput11in.o \
   wrf_auxinput1out.o wrf_auxinput2out.o wrf_auxinput3out.o \
   wrf_auxinput4out.o wrf_auxinput5out.o wrf_auxinput6out.o \
   wrf_auxinput7out.o wrf_auxinput8out.o wrf_auxinput9out.o \
   wrf_auxinput10out.o wrf_auxinput11out.o \
   couple_or_uncouple_em.o :
	@ $(RM) $@
	@ $(SED_FTN) $*.F > $*.b 
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS_NOWARN) $*.f

ESMF_Mod.o \
   ESMF_Calendar.o \
   ESMF_Stubs.o \
   ESMF_BaseTime.o \
   ESMF_Base.o \
   ESMF_TimeInterval.o \
   ESMF_Time.o \
   ESMF_Alarm.o \
   ESMF_Clock.o \
   ESMF_AlarmClock.o \
   Meat.o \
   module_utility.o \
   module_symbols_util.o :
	@ $(RM) $@
	@ $(SED_FTN) $*.F90 > $*.b 
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS_NOWARN) $*.f

module_ssmi.o \
   module_ffts.o \
   gsi_thinning.o \
   f_qv_from_rh.o \
   rad_bias.o \
   regress_one.o \
   tred2.o \
   tqli.o \
   da_bias_airmass.o :
	@ $(RM) $@
	@ $(SED_FTN) $*.f90 > $*.b 
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS_NOWARN) $*.f

# Remove implicit rules to ensure our multi-stage process works

.f90 : 
.F90 : 
.F : 

.f90.o : 
	@ $(RM) $@
	@ $(SED_FTN) $*.f90 > $*.b
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS) $*.f

.F90.o : 
	@ $(RM) $@
	@ $(SED_FTN) $*.F90 > $*.b
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS) $*.f

.F.o : 
	@ $(RM) $@
	@ $(SED_FTN) $*.F > $*.b
	@ $(CPP) $(CPPFLAGS) $(FPPFLAGS) $*.b  > $*.f
	@ $(RM) $*.b
	  $(FC) -c $(FCFLAGS) $*.f

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

