# $Id: base,v 1.25 1998/04/26 01:02:43 balay Exp $ 
#
# MS VC++ Variables required
# Please point the following to the appropriate locations.
# If the variables are already set as enviornment variables, then you
# do not need to set them again.

#INCLUDE  = c:\Program Files\DevStudio\vc\include;c:\Program Files\DevStudio\vc\MFC\include;c:\Program Files\DevStudio\vc\ATL\include
#LIB      = c:\Program Files\DevStudio\vc\lib;c:\Program Files\DevStudio\vc\MFC\LIB
#
#  Sets the rule used to remove collections of libraries (different under NT and 95!)
#
!IF "$(OS)" == "Windows_NT"
NULL     =
#RM       = del /Q /F
!ELSE 
NULL     = nul
#RM       =  deltree /y
!endif
#
# Regular petsc-makefile variables
#
PARCH    = nt
CC       = cl /nologo 
FC       = df /iface:(cref,nomixed_str_len_arg) /nologo
AR       = lib /nologo
RM       = deltree /y
OMAKE    = nmake /nologo
RANLIB   = 
SHELL    = cmd
CP       = copy /y
CLINKER  = cl /nologo  $(COPTFLAGS)
FLINKER  = df /iface:(cref,mixed_str_len_arg) /nologo $(FOPTFLAGS)
SYS_LIB  = advapi32.lib

BOPT     = none

#
# Variables from base\common
#
LDIR	      = $(PETSC_DIR)\lib\lib$(BOPT)\nt
PDIR	      = $(PETSC_DIR)\lib\lib$(BOPT)\nt
PBDIR	      = $(PETSC_DIR)\lib\lib$(BBOPT)\nt
LIBNAME	      = $(PDIR)\$(LIBBASE).lib
SOURCE	      = $(SOURCEC) $(SOURCEF)
OBJS	      = $(OBJSC) $(OBJSF)
PETSC_INCLUDE = /I$(PETSC_DIR) /I$(PETSC_DIR)\include $(MPI_INCLUDE) \
                /I$(PETSC_DIR)/bmake/nt
CPPFLAGS      = $(PETSC_INCLUDE) $(PCONF) $(PETSCFLAGS) $(PETSC_PARCH)
PETSC_LIB     = libpetscts.lib libpetscsnes.lib  libpetscsles.lib \
		libpetscmat.lib libpetscvec.lib libpetscsys.lib \
		$(EXTERNAL_LIB) $(LAPACK_LIB) $(BLAS_LIB) \
		$(MPE_LIB) $(MPI_LIB) $(X11_LIB) $(FC_LIB) $(SYS_LIB) 
SLES_LIB      = libpetscsles.lib libpetscmat.lib libpetscvec.lib \
		libpetscsys.lib $(EXTERNAL_LIB) $(LAPACK_LIB) $(BLAS_LIB) \
		$(MPE_LIB) $(MPI_LIB) $(X11_LIB) $(FC_LIB) $(SYS_LIB) 


PETSC_FORTRAN_LIB = libpetscfortran.lib
PETSC_CONTRIB = libpetsccontrib.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);$(LDIR)

!include $(PETSC_DIR)\bmake\nt\base.site
!include $(PETSC_DIR)\bmake\nt\base.$(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) tree
	@cd ..
!ENDIF

#
# Targets for checking opts/libdir etc..
#
!IF "$(BOPT)" == "none"
chkpetsc_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:chkpetsc_dir
!ELSE
chkpetsc_dir: $(LDIR) 
$(LDIR) :
	@echo checking $(LDIR)
	@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)\nt\$(NULL)" \
	mkdir "$(PETSC_DIR)\lib\lib$(BOPT)\nt"
chkopts: 
#	@if not exist "$(LDIR)" \
#	echo Libraries not built for this BOPT: $(BOPT)
!ENDIF


#
#
# Targets required for libfast
#
libfast: chkpetsc_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 *.exe *.tmp *.pdb 2> %TEMP%\null
#
# Basic targets for compiling .c,.f, etc..
#
.SUFFIXES: .F $(SUFFIXES) .PETSc .C .cc .cpp .r .rm .so

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

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

.F.obj:
	$(RM) __$*.c $*.for 
	$(CP) $*.F __$*.c
	$(CC) /EP $(CPPFLAGS) __$*.c > $*.for
	$(FC) /c $(FOPTFLAGS) $(FFLAGS) $*.for
	$(RM) __$*.c $*.for 
.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
