##############################################################################
##                                                                          ##
# This makefile builds Codewright or Fusion DLLs, 16- or 32-bit, under MSC.  #
#                                                                            #
# Targets:                                                                   #
#                                                                            #
#    all          Build the DLL.  This is the default target.                #
#    browse       Build the .BSC; call compiler to build .SBRs if needed.    #
#    clean        Delete .OBJs, .SBRs, and .MAPs.                            #
#    spotless     Same as above, and also delete .DLL and .BSC               #
#    <dllname>    Build the DLL (same as all).                               #
##                                                                          ##
# The makefile is in four sections.  The user configuration section lets     #
# you specify the primary build parameters and the locations for your        #
# Codewright/Fusion directories.  The project configuration section          #
# specifies the source file names and the basename  for miscellaneous        #
# files.  The compiler configuration section sets the actual compiler        #
# command lines.  The rules section defines the actual targets and           #
# dependencies.  If you add dependencies (as for include files), do so       #
# at the end of the rules section, at the very end of the makefile.          #
#                                                                            #
# The user configuration section is normally the only section that needs     #
# to be adjusted for a given installation.                                   #
##                                                                          ##
# The default settings give you a 16-bit Codewright DLL, no debugging info.  #
#                                                                            #
##############################################################################
##                       Begin user configuration section                   ##
##############################################################################
#
# Define DEBUG to build symbols, maps, and browser database.  If you want
# a browser database without the other debug stuff, build target "browse".
#
# DEBUG = 1

# Define FUSION to compile for Fusion; otherwise, a CW DLL will be built.
#
# FUSION = 1

# Define WIN32 to build a 32-bit DLL; otherwise, a 16-bit DLL gets built.
#
WIN32  = 1


# Point these macros to your relevant Codewright/Fusion home directories
#
CWDIR16       = c:\cwright
CWVDIR16      = c:\cwvc
CWDIR32       = d:\ed\cw32_60beta
CWVDIR32      = d:\ed\cw32_60beta

# Path to the directory in which to put the DLL when it's done.
#
DLLDIR = .

##############################################################################
##                      End user configuration section                      ##
##############################################################################
##                   Begin project configuration section                    ##
##############################################################################

# This is the basename for the project.
# .LIB, .MAP, and other files generated in the build will use this basename.
# It is also the default name for the .OBJ file; if you have multiple .C and
# .OBJ files, set .OBJLIST below.
#
PROJ          = lsp

# Here you can set the root names for the DLLs you want to build,
# for Codewright and Fusion, for 16- and 32- bit.  This root is
# also used for the .DEF filespec on the link command line.
#
CWROOT16      = $(PROJ)
CWVROOT16     = $(PROJ)v
CWROOT32      = $(PROJ)32
CWVROOT32     = $(PROJ)v32

# In most cases, nothing below this line will need to be changed.
# For multiple objects, use a list like this:
#  SRCLIST  = file1.c file2.c ...

SRCLIST  = $(PROJ).c

# Any special include directories (e.g. -I c:\myincl)
#
USERINCLUDE = 

# Any special libraries to link with (e.g, ddeml.lib)
#
USERLIBS =

##############################################################################
##                    End project configuration section                     ##
##############################################################################
##                   Begin compiler configuration section                   ##
##############################################################################
# This subsection sets locations for CW/CV libs and includes.
#
!ifdef WIN32
!ifdef FUSION

CWDIR      = $(CWVDIR32)
CWLIB      = ..\lib\win32\cwdll32.lib
CWSTARTLIB = ..\lib\win32\cwstart.lib
CWINCLUDE  = -I$(CWDIR)\include
DLLNAME    = $(CWVROOT32)

!else

CWDIR      = $(CWDIR32)
CWLIB      = cwdll32.lib
CWSTARTLIB = cwstart.lib
CWINCLUDE  = -I$(CWDIR)\cwstart -I$(CWDIR)\include
DLLNAME    = $(CWROOT32)

!endif

# 16-bit
!else
!ifdef FUSION

CWDIR      = $(CWVDIR16)
CWLIB      = cwvdll.lib
CWSTARTLIB = cwvstart.lib
CWINCLUDE  = -I$(CWDIR)\include
DLLNAME    = $(CWVROOT16)

!else

CWDIR      = $(CWDIR16)
CWLIB      = cwright.lib
CWSTARTLIB = cwstart.lib
CWINCLUDE  = -I$(CWDIR)\cwstart -I$(CWDIR)\include
DLLNAME    = $(CWROOT16)

!endif
!endif


# This subsection doesn't introduce any new information.
#
DLLFULLNAME = $(DLLDIR)\$(DLLNAME).dll
!ifdef WIN32
LIBDIR      = $(CWDIR)\lib\win32
!else
LIBDIR      = $(CWDIR)\lib\win16
!endif
CWLIBS      = $(LIBDIR)\$(CWLIB) $(LIBDIR)\$(CWSTARTLIB)
BSCNAME     = $(PROJ).bsc


# This subsection defines the actual compile and link command lines.
#
# Note: $(DLLNAME) varies according to dll type (mydll, mydllv, mydll32...)
# while $(PROJ) is always the same for a given project (mydll)
#
# Set *_EXE to the full paths of the appropriate tools, as needed.
#
!ifdef WIN32
CC_EXE        = cl
LINK_EXE      = link
RC_EXE        = rc
BSCMAKE_EXE   = bscmake

CFLAGS        = -W3 -c $(CWINCLUDE) $(USERINCLUDE) -DSTRICT -Zp1 -YX -DNDEBUG -D_X86_ \
	-DWIN32 -Fp$(PROJ).PCH -FR

CNODEBUG      = -Ow -G3

CDEBUG        = -Od -Zi -Fd$(DLLNAME).PDB -FR

LFLAGS        = -DLL -DEF:win32\$(DLLNAME).def -ENTRY:DLLEntry@12  \
	-SUBSYSTEM:windows -implib:$(DLLNAME).lib -OUT:win32\$(DLLFULLNAME)

LDEBUG        = -DEBUG -DEBUGTYPE:cv -MAP:$(PROJ).map

LLIBS         = libc.lib oldnames.lib user32.lib gdi32.lib winspool.lib \
	comdlg32.lib advapi32.lib shell32.lib $(CWLIBS)

LARGS         = @$(PROJ).CRF $(LLIBS)

RC            =

OBJLIST = $(SRCLIST:.c=.obj)
OBJARG  = $(OBJLIST)

# Compiling for 16-bit
#
!else
CC_EXE        = cl
LINK_EXE      = link
RC_EXE        = rc
BSCMAKE_EXE   = bscmake

CFLAGS        = -Ow -W3 -c $(CWINCLUDE) $(USERINCLUDE) -DSTRICT -DMT -Alfw -Zp2 -FR

CNODEBUG      = -G3s

CDEBUG        = -G2 -Zi -Fd$(DLLNAME).PDB -FR

LFLAGS        = /NOD/NOE

LDEBUG        = /MAP/CO/LI

LLIBS         = libw.lib ldllcew.lib $(USERLIBS) oldnames $(CWLIBS)

LARGS         = @$(PROJ).CRF, $(DLLFULLNAME),$(PROJ).map, $(LLIBS), $(DLLNAME).def

RC            = $(RC_EXE) $(DLLFULLNAME)

OBJLIST = $(SRCLIST:.c=.obj)
OBJARG  = $(OBJLIST: = +^
)

!endif

!ifdef DEBUG
CC          = $(CC_EXE) $(CFLAGS) $(CDEBUG)
LINK        = $(LINK_EXE) $(LFLAGS) $(LDEBUG) $(LARGS)
!else
CC          = $(CC_EXE) $(CFLAGS) $(CNODEBUG)
LINK        = $(LINK_EXE) $(LFLAGS) $(LARGS)
!endif

SBRLIST     = $(SRCLIST:.c=.sbr)

BSCFLAGS    = -n
BSCARGS     = -o $(BSCNAME) $(SBRLIST)
BSCMAKE     = $(BSCMAKE_EXE) $(BSCFLAGS) $(BSCARGS)

##############################################################################
##                    End compiler configuration section                    ##
##############################################################################
##############################################################################
##                     Begin rules configuration section                    ##
##############################################################################


# Don't modify the rules here.  Better to modify the individual macros
# defined above.  Everything from here down should really be
# constant across platforms and products.
# nmake
.c.obj:
	$(CC) $<
.c.sbr:
	$(CC) -FR $<

# Add any special targets here
#

all:    $(DLLNAME)
!ifdef DEBUG
	$(BSCMAKE)
!endif

clean:
	del $(OBJLIST)
	del $(SBRLIST)
	del $(PROJ).bsc
	del $(PROJ).map
	del $(DLLNAME).pdb

spotless:   clean
	del $(DLLFULLNAME)
	del $(DLLNAME).lib
	del $(DLLNAME).exp
	del $(DLLNAME).pch

browse: $(BSCNAME)
$(BSCNAME): $(SBRLIST)
	$(BSCMAKE)

$(DLLNAME):  $(DLLFULLNAME)
$(DLLFULLNAME): $(OBJLIST) 
	echo >NUL @<<$(PROJ).CRF
		$(OBJARG)
<<
	$(LINK)
	$(RC)


# User-defined dependencies.  These have to be specified individually,
# because nmake won't allow dependencies in inference rules.
#
# $(PROJ).c: $(PROJ).h

##############################################################################
##                      End rules configuration section                     ##
##############################################################################
##############################################################################
##                                End makefile                              ##
##############################################################################
