# $Id: rules_win32,v 1.14 2001/04/19 15:39:39 balay Exp $ 
#
#  Sets the rule used to remove collections of libraries (different under NT and 95!)
#
!IF "$(OS)" == "Windows_NT"
NULL             =
RM               = del /Q /F
CP               = copy
!ELSE 
NULL             = nul
RM               = deltree /y
CP               = copy /y
!ENDIF
#
# Variables from base\common_variables
#
!IF "$(INSTALL_LIB_DIR)" == ""
INSTALL_LIB_DIR = $(PETSC_DIR)\lib\lib$(BOPT)\$(PETSC_ARCH)
!ENDIF

PETSC_LIB_DIR  = $(PETSC_DIR)\lib\lib$(BOPT)\$(PETSC_ARCH)
LIBNAME        = $(INSTALL_LIB_DIR)\$(LIBBASE).lib
SOURCE	       = $(SOURCEC) $(SOURCEF)
OBJS	       = $(OBJSC) $(OBJSF)
PETSC_INCLUDE  = /I$(PETSC_DIR) /I$(PETSC_DIR)\include $(MPI_INCLUDE) \
                 /I$(PETSC_DIR)\bmake\$(PETSC_ARCH) $(AMS_INCLUDE) $(PETSC_BLASLAPACK_FLAGS)
CCPPFLAGS      = $(PETSC_INCLUDE) $(PCONF) $(PETSCFLAGS) $(CPPFLAGS)
FCPPFLAGS      = $(PETSC_INCLUDE) $(PCONF) $(PETSCFLAGS) $(FPPFLAGS)
PETSC_SYS_LIB  = libpetsc.lib $(EXTERNAL_LIB) $(BLASLAPACK_LIB) \
                 $(MPE_LIB) $(MPI_LIB) $(X11_LIB) $(SYS_LIB)
PETSC_VEC_LIB  = libpetscvec.lib libpetsc.lib $(PETSC_SYS_LIB)
PETSC_MAT_LIB  = libpetscmat.lib $(PETSC_VEC_LIB)
PETSC_DM_LIB   = libpetscdm.lib $(PETSC_MAT_LIB)
PETSC_SLES_LIB = libpetscsles.lib $(PETSC_DM_LIB)
PETSC_SNES_LIB = libpetscsnes.lib $(PETSC_SLES_LIB)
PETSC_TS_LIB   = libpetscts.lib $(PETSC_SNES_LIB)
PETSC_LIB      = libpetsc.lib libpetscts.lib libpetscsnes.lib libpetscsles.lib \
		 libpetscdm.lib libpetscmat.lib libpetscvec.lib libpetsc.lib libpetscts.lib \
		 libpetscsnes.lib libpetscsles.lib libpetscdm.lib libpetscmat.lib \
		 libpetscvec.lib libpetsc.lib \
		 $(EXTERNAL_LIB) $(LAPACK_LIB) $(BLAS_LIB) \
		 $(MPE_LIB) $(MPI_LIB) $(X11_LIB) $(SYS_LIB)
PETSC_FORTRAN_LIB = libpetscfortran.lib
PETSC_CONTRIB     = libpetsccontrib.lib


PCONF         = $(PETSC_HAVE_MPE)  $(PETSC_HAVE_BLOCKSOLVE) $(PETSC_HAVE_PVODE) $(PETSC_HAVE_PARMETIS) \
                $(PETSC_HAVE_AMS)  $(PETSC_HAVE_SPAI)       $(PETSC_HAVE_X11)   $(PETSC_HAVE_MATLAB_ENGINE) \
                $(PETSC_HAVE_ADIC) $(PETSC_HAVE_JAVA)       $(PETSC_HAVE_LUSOL) $(PETSC_HAVE_RAMG) \
                                   $(PETSC_HAVE_DSCPACK)    $(PETSC_HAVE_MATLAB)
EXTERNAL_LIB  = $(MPE_LIB)         $(BLOCKSOLVE_LIB)      $(PVODE_LIB)        $(PARMETIS_LIB) \
                $(AMS_LIB)         $(SPAI_LIB)            $(X11_LIB)          $(MATLAB_LIB)   \
                $(ADIC_LIB)        $(LUSOL_LIB)           $(RAMG_LIB)                         \
                $(DSCPACK_LIB)

#
# The Microsoft linker uses this variable to determine the locations of libraries
# hence in the link line it does not indicate the directories where the libraries
# are located, just the library names (this is confusing!)
#
LIB           = $(LIB);$(PETSC_LIB_DIR)

!include $(PETSC_DIR)\bmake\$(PETSC_ARCH)\base.site
!include $(PETSC_DIR)\bmake\common_$(BOPT)

testexamples_1: $(TESTEXAMPLES_1)
testexamples_2: $(TESTEXAMPLES_2)
testexamples_3: $(TESTEXAMPLES_3)
testexamples_4: $(TESTEXAMPLES_4)
testexamples_5: $(TESTEXAMPLES_5)
testexamples_6: $(TESTEXAMPLES_6)
testexamples_7: $(TESTEXAMPLES_7)
testexamples_8: $(TESTEXAMPLES_8)
testexamples_9: $(TESTEXAMPLES_9)
testexamples_10: $(TESTEXAMPLES_10)
testexamples_11: $(TESTEXAMPLES_11)
buildexamples_1: $(BUILDEXAMPLES_1)
buildexamples_2: $(BUILDEXAMPLES_2)
buildexamples_3: $(BUILDEXAMPLES_3)
buildexamples_4: $(BUILDEXAMPLES_4)
buildexamples_5: $(BUILDEXAMPLES_5)
buildexamples_6: $(BUILDEXAMPLES_6)
buildexamples_7: $(BUILDEXAMPLES_7)
buildexamples_8: $(BUILDEXAMPLES_8)
buildexamples_9: $(BUILDEXAMPLES_9)
buildexamples_10: $(BUILDEXAMPLES_10)
buildexamples_11: $(BUILDEXAMPLES_11)

#
# Targets from bmake\common file 
#

#
# Target for tree
#
!IF  "$(DIRS)" == ""
tree : $(ACTION)
!ELSE
tree : $(DIRS)
$(DIRS): $(ACTION)
	-@cd $*
	-@echo  $(ACTION) in: $(MAKEDIR)\$*
	-@$(OMAKE) /nologo /f makefile BOPT=$(BOPT) ACTION=$(ACTION) BLAS_FC=$(BLAS_FC) tree
	-@cd ..
!ENDIF

#
# Targets for checking opts/libdir etc..
#
!IF "$(BOPT)" == "none"
chklib_dir:
	@echo You must set the variable BOPT=[g,O,Opg,O_c++,O_complex,...]
	@echo Remove all .obj files and rerun make with appropriate BOPT
	@return
chkopts:chklib_dir
!ELSE
chklib_dir: $(INSTALL_LIB_DIR) 
$(INSTALL_LIB_DIR) :
	@echo checking $(INSTALL_LIB_DIR)
	@if not exist "$(PETSC_DIR)\lib\$(NULL)" \
	mkdir "$(PETSC_DIR)\lib"
	@if not exist "$(PETSC_DIR)\lib\lib$(BOPT)\$(NULL)" \
	mkdir "$(PETSC_DIR)\lib\lib$(BOPT)"
	@if not exist "$(PETSC_DIR)\lib\lib$(BOPT)\$(PETSC_ARCH)\$(NULL)" \
	mkdir "$(PETSC_DIR)\lib\lib$(BOPT)\$(PETSC_ARCH)"
chkopts: 
#	@if not exist "$(INSTALL_LIB_DIR)" \
#	echo Libraries not built for this BOPT: $(BOPT)
!ENDIF


#
#
# Targets required for libfast
#
libfast: chklib_dir libfast_c libfast_f libfast_lib
!IF "$(SOURCEC)" == ""
libfast_c:
!ELSE
libfast_c: $(OBJSC)
libfast_c_old: $(SOURCEC)
	@$(CC) @<<
/c $(CFLAGS) 
$(COPTFLAGS) 
$(SOURCEC) 
<<
!ENDIF
!IF "$(SOURCEF)" == ""
libfast_f:
!ELSE
libfast_f: $(OBJSF)
!ENDIF
!IF "$(OBJS)" == " "  # The extra space is introduced as $(OBJS) = $(OBJSC) $(OBJSF)
libfast_lib:
!ELSE
libfast_lib:
	@if exist $(LIBNAME) $(AR) @<<
$(LIBNAME)
$(OBJS)
$(SOBJS)
<<
	@if not exist $(LIBNAME) $(AR) @<<
/out:$(LIBNAME) 
$(OBJS) 
$(SOBJS) 
<<
	@$(RM)  $(OBJS) $(SOBJS)
!ENDIF

#
# Since lib is not much different from libfast,
# the same target is used
#
lib: libfast
clean:
	@$(RM) *.obj ex*.exe *.tmp *.pdb *.ilk 2> %TEMP%\null
#
# Basic targets for compiling .c,.f, etc..
#
.SUFFIXES: .F $(SUFFIXES) .PETSc .C .cc .cpp .r .rm .so

.c.lib:
	$(CC) /c $(COPTFLAGS) $(CFLAGS) $(CCPPFLAGS) $(MAKEDIR)\$<
	$(AR) @<<
$(LIBNAME) 
$*.obj
<<
	$(RM) $*.obj

.F.lib:
	$(FC) /c $(FOPTFLAGS) $(FFLAGS) $(FCPPFLAGS) $(MAKEDIR)\$<
	$(AR) @<<
$(LIBNAME) 
$*.obj
<<
	$(RM) $*.obj

.c.obj: 
	$(CC) /c $(COPTFLAGS) $(CFLAGS) $(CCPPFLAGS) $(MAKEDIR)\$<

.F.obj:
	$(FC) /c $(FOPTFLAGS) $(FFLAGS) $(FCPPFLAGS) $(MAKEDIR)\$<

.F90.obj:
	$(FC) /c $(FOPTFLAGS) $(FFLAGS) $(FCPPFLAGS) $(MAKEDIR)\$<

.c.PETSc :
	-@$(OMAKE) /f makefile BOPT=$(BOPT) $* > trashz
	@<<x.bat
	@echo off
	egrep -i "(Error|Warning|Unresoved)" trashz > %TEMP%\null
	if NOT ERRORLEVEL 1 type trashz 
<<

.F.PETSc:
	-@$(OMAKE) /f makefile BOPT=$(BOPT) $*
.cpp.rm:
	-@$(RM) $*.exe *.obj trashz 2> %temp%\null
.cc.rm:
	-@$(RM) $*.exe *.obj trashz 2> %temp%\null
.C.rm:
	-@$(RM) $*.exe *.obj trashz 2> %temp%\null
.F.rm:
	-@$(RM) $*.exe *.obj trashz 2> %temp%\null
.f.rm:
	-@$(RM) $*.exe *.obj trashz 2> %temp%\null
.c.rm:
	-@$(RM) $*.exe *.obj trashz 2> %temp%\null

################################################################
# If using complex version of PETSc, use the fortran compiler for CLINKER
#
!IF "$(BOPT)" == "g_complex" || "$(BOPT)" == "O_complex"
CLINKER = $(FLINKER)
!ENDIF
