!IF "$(VERBOSE)" != "YES"
!CMDSWITCHES +S
!ELSE
!CMDSWITCHES -S
!ENDIF

TARGET           = WINNT
OS_MAJOR         = 4
OS_MINOR         = 0
OS_VERSION_DEF   = /D "_OS_MAJOR_=$(OS_MAJOR)" /D "_OS_MINOR_=$(OS_MINOR)"

!IF "$(DEBUG)" == ""
TARGETDIR        = $(TARGET)-$(OS_MAJOR).$(OS_MINOR)
!ELSE
TARGETDIR        = $(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG
!ENDIF

CDEVVERSION      = 1.7.2
CDEVINCLUDES     = /I $(CDEV)\include
CDEVLIB          = $(CDEV)\lib\$(TARGETDIR)
CDEVBIN          = $(CDEV)\bin\$(TARGETDIR)
CREATE_LINK      = copy $** $@ > nul

BASEDIR          = $(CDEV)\extensions\cdevGenericServer
BASEINCLUDES     = /I $(BASEDIR)\include

!IF "$(BASELIB)" == ""
BASELIB          = $(BASEDIR)\lib\$(TARGETDIR)
!ENDIF 

!IF "$(BASEBIN)" == ""
BASEBIN          = $(BASEDIR)\bin\$(TARGETDIR)
!ENDIF

!IF "$(CDEVSHOBJ)" == ""
CDEVSHOBJ        = $(CDEVLIB)
!ENDIF

!IF "$(SHOBJ)"  == "NO"
OBJDIR           = .obj\$(TARGETDIR)
!ELSE
SHOBJ            = YES
OBJDIR           = .shobj\$(TARGETDIR)
!ENDIF

CC               = cl
CXX              = cl
LIB32            = link
LINK             = link

CC_ALL_EXE       = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /Fo".exec\$(TARGETDIR)/"\
                   $(CXXEXTRA) $(CXXEXTRA_EXE) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TC /c
CXX_ALL_EXE      = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /Fo".exec\$(TARGETDIR)/"\
                   $(CXXEXTRA) $(CXXEXTRA_EXE) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TP /c
CXX_DEBUG_EXE    = /MDd /Z7 /Od /D "_DEBUG" /GZ 
CXX_RELEASE_EXE  = /MD /O2 /D "NDEBUG" 
LINK_ALL_EXE     = kernel32.lib user32.lib gdi32.lib winspool.lib \
                   comdlg32.lib advapi32.lib shell32.lib ole32.lib \
                   oleaut32.lib uuid.lib odbc32.lib odbccp32.lib \
                   ws2_32.lib /nologo /subsystem:console /pdb:NONE 
LINK_DEBUG_EXE   = /debug
LINK_RELEASE_EXE =

CC_ALL_LIB       = /nologo /D "WIN32" /D "_MBCS" /D "_LIB" /Fo"$(OBJDIR)/"\
                   $(CXXEXTRA) $(CXXEXTRA_LIB) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TC /c
CXX_ALL_LIB      = /nologo /D "WIN32" /D "_MBCS" /D "_LIB" /Fo"$(OBJDIR)/"\
                   $(CXXEXTRA) $(CXXEXTRA_LIB) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TP /c
CXX_DEBUG_LIB    = /MDd /Z7 /Od /D "_DEBUG" /GZ
CXX_RELEASE_LIB  = /MD /O2 /D "NDEBUG"
LINK_ALL_LIB     = -lib /nologo
LINK_DEBUG_LIB   = 
LINK_RELEASE_LIB =

CC_ALL_DLL       = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Fo"$(OBJDIR)/"\
                   $(CXXEXTRA) $(CXXEXTRA_DLL) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TC /c
CXX_ALL_DLL      = /nologo /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /Fo"$(OBJDIR)/"\
                   $(CXXEXTRA) $(CXXEXTRA_DLL) $(CXXINCLUDES) $(CDEVINCLUDES) $(BASEINCLUDES) $(OS_VERSION_DEF) /TP /c
CXX_DEBUG_DLL    = /MDd /Z7 /Od /D "_DEBUG" /GZ
CXX_RELEASE_DLL  = /MD /O2 /D "NDEBUG"
LINK_ALL_DLL     =  kernel32.lib user32.lib gdi32.lib winspool.lib \
                    comdlg32.lib advapi32.lib shell32.lib ole32.lib \
                    oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib \
                    /nologo /dll /pdb:NONE
LINK_DEBUG_DLL   = /debug
LINK_RELEASE_DLL =

!IF "$(DEBUG)" != ""
CC_EXE_FLAGS     = $(CC_ALL_EXE)  $(CXX_DEBUG_EXE)
CC_LIB_FLAGS     = $(CC_ALL_LIB)  $(CXX_DEBUG_LIB)
CC_DLL_FLAGS     = $(CC_ALL_DLL)  $(CXX_DEBUG_DLL)
CXX_EXE_FLAGS    = $(CXX_ALL_EXE) $(CXX_DEBUG_EXE)
CXX_LIB_FLAGS    = $(CXX_ALL_LIB) $(CXX_DEBUG_LIB)
CXX_DLL_FLAGS    = $(CXX_ALL_DLL) $(CXX_DEBUG_DLL)
LINK_EXE_FLAGS   = $(LINK_ALL_EXE) $(LINK_DEBUG_EXE)
LINK_LIB_FLAGS   = $(LINK_ALL_LIB) $(LINK_DEBUG_LIB)
LINK_DLL_FLAGS   = $(LINK_ALL_DLL) $(LINK_DEBUG_DLL)
!ELSE 
CC_EXE_FLAGS     = $(CC_ALL_EXE)  $(CXX_RELEASE_EXE)
CC_LIB_FLAGS     = $(CC_ALL_LIB)  $(CXX_RELEASE_LIB)
CC_DLL_FLAGS     = $(CC_ALL_DLL)  $(CXX_RELEASE_DLL)
CXX_EXE_FLAGS    = $(CXX_ALL_EXE) $(CXX_RELEASE_EXE)
CXX_LIB_FLAGS    = $(CXX_ALL_LIB) $(CXX_RELEASE_LIB)
CXX_DLL_FLAGS    = $(CXX_ALL_DLL) $(CXX_RELEASE_DLL)
LINK_EXE_FLAGS   = $(LINK_ALL_EXE) $(LINK_RELEASE_EXE)
LINK_LIB_FLAGS   = $(LINK_ALL_LIB) $(LINK_RELEASE_LIB)
LINK_DLL_FLAGS   = $(LINK_ALL_DLL) $(LINK_RELEASE_DLL)
!ENDIF

!IF "$(HAIL)" != "NO"
HAILTARGET = hail
!ENDIF

!IF "$(FAIRWELL)" != "NO"
BYETARGET  = fairwell
!ENDIF

# ******************************************************************************
# * Master rules for building cdevGenericServer objects
# ******************************************************************************
all : $(HAILTARGET) targets $(BYETARGET)

hail:
	@echo ^ ^ ^ =^> Building $(APPNAME) for Target: $(TARGETDIR)

fairwell:
	@echo ^ ^ ^ ^ ^ ^ Done...
	
clean:
!IF "$(HAIL)" != "NO"
	@echo ^ ^ ^ =^> Cleaning $(APPNAME) for Target: $(TARGETDIR)
!ENDIF
	-@for %x in (.obj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG \
	             .obj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR) \
	             .shobj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG \
	             .shobj\$(TARGET)-$(OS_MAJOR).$(OS_MINOR) \
	             .exec\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)-DEBUG \
	             .exec\$(TARGET)-$(OS_MAJOR).$(OS_MINOR)) DO \
	             @if exist %x rmdir /s /q %x	 
	-@for %x in ($(BINARIES) $(TARGETS)) DO @if exist %x erase %x
!IF "$(FAIRWELL)" != "NO"
	@echo ^ ^ ^ ^ ^ ^ Done...
!ENDIF
	
purge:
!IF "$(HAIL)" != "NO"
	@echo ^ ^ ^ =^> Purging $(APPNAME) for Target: $(TARGETDIR)
!ENDIF
	-@for %x in (.shobj .obj .exec) DO @if exist %x rmdir /s /q %x
	-@for %x in ($(BINARIES) $(TARGETS) $(TEMPLINKS)) DO @if exist %x erase %x
!IF "$(FAIRWELL)" != "NO"
	@echo ^ ^ ^ ^ ^ ^ Done...
!ENDIF
	

.cc{.obj\$(TARGETDIR)}.obj::
	@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
	-@if not exist .obj\$(TARGETDIR) mkdir .obj\$(TARGETDIR) 
	-@if not exist $(BASEBIN) mkdir $(BASEBIN)
	-@if not exist $(BASELIB) mkdir $(BASELIB)
	$(CXX) $(CXX_LIB_FLAGS) $< 

.cc{.shobj\$(TARGETDIR)}.obj::
	@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
	-@if not exist .shobj\$(TARGETDIR) mkdir .shobj\$(TARGETDIR) 
	-@if not exist $(BASEBIN) mkdir $(BASEBIN)
	-@if not exist $(BASELIB) mkdir $(BASELIB)
	$(CXX) $(CXX_DLL_FLAGS) $< 
	
.cc{.exec\$(TARGETDIR)}.obj::
	@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
	-@if not exist .exec\$(TARGETDIR) mkdir .exec\$(TARGETDIR) 
	-@if not exist $(BASEBIN) mkdir $(BASEBIN)
	-@if not exist $(BASELIB) mkdir $(BASELIB)
	$(CXX) $(CXX_EXE_FLAGS) $< 

.c{.obj\$(TARGETDIR)}.obj::
	@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
	-@if not exist .obj\$(TARGETDIR) mkdir .obj\$(TARGETDIR) 
	-@if not exist $(BASEBIN) mkdir $(BASEBIN)
	-@if not exist $(BASELIB) mkdir $(BASELIB)
	$(CC) $(CC_LIB_FLAGS) $< 

.c{.shobj\$(TARGETDIR)}.obj::
	@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
	-@if not exist .shobj\$(TARGETDIR) mkdir .shobj\$(TARGETDIR) 
	-@if not exist $(BASEBIN) mkdir $(BASEBIN)
	-@if not exist $(BASELIB) mkdir $(BASELIB)
	$(CC) $(CC_DLL_FLAGS) $< 
	
.c{.exec\$(TARGETDIR)}.obj::
	@echo ^ ^ ^ ^ ^ ^ =^> Compiling $<
	-@if not exist .exec\$(TARGETDIR) mkdir .exec\$(TARGETDIR) 
	-@if not exist $(BASEBIN) mkdir $(BASEBIN)
	-@if not exist $(BASELIB) mkdir $(BASELIB)
	$(CC) $(CC_EXE_FLAGS) $< 
