#
# Makefile for Vim on Win32 (Windows NT and Windows 95), using the Borland C++
# 4.5 and later  32-bit compiler.  Contributed by Ben Singer.
# It builds on Windows 95 and NT-Intel, producing the same binary in either
# case.  To build using Microsoft Visual C++, use Makefile.w32.
#
# Updated 4/1997 by Ron Aaron

# let the make utility do the hard work:
.AUTODEPEND
.CACHEAUTODEPEND

#
# VARIABLES LIST:
#
#   BOR	    -	path to root of Borland C install, typ: \BC5
#   DEBUG   -	define if you wish a DEBUGging build
#   CODEGUARD -	define (for BORLAND only) if you want to use CODEGUARD
#   GUI	    -	define if you want the GUI version
#   CPU	    -	one of 3,4,5 or 6 - select CPU to compile for
#   USEDLL  -	use the Runtime library DLL
#   VIMDLL  -	create vim32.dll, and stub (g)vim.exe
#   INTEL   -	use the Intel backend compiler (faster EXE)
#   ALIGN   -	Alignment to use (1,2,4)
#   FASTCALL -	Use register-based function protocol
#   OS	    -	DOS, WIN16 or WIN32 (only WIN32 supported just now...)	

# Change this to point to the root of *your* BC installation:
BOR = \bc5

# Can be DOS, WIN16 or WIN32
OS = WIN32
!if ($(OS)!=WIN32)
!error Check the OS variable again: $(OS) is not supported!
!endif

# Uncomment to make an executable for debugging:
#DEBUG = -v

# Comment out to make a console-mode only version:
GUI = 1

# Uncomment to use the CODEGUARD stuff (BC 5.0 or later):
#CODEGUARD = -vG

# Uncomment to use FASTCALL calling convention:
FASTCALL = 1

# Optimize for space or speed?
OPTIMIZE = SPEED

# Change as appropriate for your target processor (3 to 6):
CPU = 3
!ifndef CPU
CPU = 3
!endif

# Uncomment to use DLL version of run-time:
#USEDLL = 1

# Uncomment to make a DLL version of VIM:
VIMDLL = 1

# Uncomment to use the Intel back-end compiler (BC 5.0 or later):
#INTEL = 1

# Change to alignment you desire: (1,2 or 4)
ALIGN = 4

# warning:
!if $d(INTEL) && $d(FASTCALL)
!error INTEL and FASTCALL dont work together!
!endif
!if $d(INTEL) && $d(USEDLL)
!error INTEL and USEDLL dont work together!
!endif

# Optimizations: change as desired:
!ifdef DEBUG
OPT = -Od -N
!else
!if ($(OPTIMIZE)==SPACE)
OPT = -O1 -ff -N- -d 
!else
OPT = -O2 -ff -N- 
!endif
!ifdef FASTCALL
OPT = $(OPT) -pr
!endif
!ifdef INTEL
OPT = $(OPT) -OM -OI
!endif
!ifndef CODEGUARD
OPT = $(OPT) -vi-
!endif
!endif

# shouldn't have to change:
LIB = $(BOR)\lib
INCLUDE = $(BOR)\include
DEFINES = -DWIN32;PC

# don't change below:
CPU = -$(CPU)
ALIGN = -a$(ALIGN)

!if ($(GUI)==1)
DEFINES = $(DEFINES);USE_GUI_WIN32;USE_CLIPBOARD
!ifdef DEBUG
TARGET = gvimd.exe
!else
TARGET = gvim.exe
!endif
!ifdef VIMDLL
EXETYPE=-WD
DEFINES = $(DEFINES);VIMDLL
!else
EXETYPE=-WE
!endif
STARTUPOBJ = c0w32.obj
LINK2 = -aa
RESFILE = vim.res
!else
!ifdef DEBUG
TARGET = vimd.exe
!else
# for now, anyway: VIMDLL is only for the GUI version
!undef VIMDLL
TARGET = vim.exe
!endif
EXETYPE=-WC
STARTUPOBJ = c0x32.obj
LINK2 = -ap
RESFILE = 
!endif

!ifdef USEDLL
DEFINES = $(DEFINES);_RTLDLL
!endif

!ifdef DEBUG
OBJDIR	= objdbg
!else
OBJDIR	= obj
!endif

##### BASE COMPILER/TOOLS RULES #####
BRC = brc32
LINK	= $(BOR)\BIN\TLink32
!ifdef INTEL
CC   = $(BOR)\BIN\Bcc32i
!else
CC   = $(BOR)\BIN\Bcc32
!endif

LFLAGS	= -Tpe -c -m -L$(LIB) $(DEBUG) $(LINK2)
LFLAGSDLL  = -B:40000000 -Tpd -c -m -L$(LIB) $(DEBUG) $(LINK2)

CFLAGS = -w -waus- -wpar- -I$(INCLUDE) -H -H=$(OBJDIR)\vim.csm -P-
CC1 = -c
CC2 = -o
CC = $(CC) +bcc.cfg
LINK	= TLink32

# implicit rules:
.c.obj:
	$(CC) $(CC1) $(CC2)$@ $*.c
	
vimmain = \
	$(OBJDIR)\os_w32exe.obj
!ifdef VIMDLL
vimwinmain = \
	$(OBJDIR)\os_w32dll.obj
!else
vimwinmain = \
	$(OBJDIR)\os_w32exe.obj
!endif
	
vimobj = $(vimwinmain)\
	$(OBJDIR)\buffer.obj\
	$(OBJDIR)\charset.obj\
	$(OBJDIR)\digraph.obj\
	$(OBJDIR)\edit.obj\
	$(OBJDIR)\eval.obj\
	$(OBJDIR)\ex_cmds.obj\
	$(OBJDIR)\ex_docmd.obj\
	$(OBJDIR)\ex_getln.obj\
	$(OBJDIR)\fileio.obj\
	$(OBJDIR)\getchar.obj\
	$(OBJDIR)\main.obj\
	$(OBJDIR)\mark.obj\
	$(OBJDIR)\memfile.obj\
	$(OBJDIR)\memline.obj\
	$(OBJDIR)\message.obj\
	$(OBJDIR)\misc1.obj\
	$(OBJDIR)\misc2.obj\
	$(OBJDIR)\normal.obj\
	$(OBJDIR)\ops.obj\
	$(OBJDIR)\option.obj\
	$(OBJDIR)\os_win32.obj\
	$(OBJDIR)\quickfix.obj\
	$(OBJDIR)\regexp.obj\
	$(OBJDIR)\screen.obj\
	$(OBJDIR)\search.obj\
	$(OBJDIR)\syntax.obj\
	$(OBJDIR)\tag.obj\
	$(OBJDIR)\term.obj\
	$(OBJDIR)\ui.obj\
	$(OBJDIR)\undo.obj\
	$(OBJDIR)\version.obj\
	$(OBJDIR)\window.obj

!ifdef VIMDLL
vimdllobj = $(vimobj)
DLLTARGET = vim32.dll
!endif

!if ($(GUI)==1)
vimobj = $(vimobj) \
	$(OBJDIR)\gui.obj\
	$(OBJDIR)\gui_w32.obj
!endif

# Blab what we are going to do:
MSG = Compiling $(TARGET), with: 
!ifdef GUI
MSG = $(MSG) GUI
!endif
!ifdef USEDLL
MSG = $(MSG) USEDLL
!endif
!ifdef VIMDLL
MSG = $(MSG) VIMDLL
!endif
!ifdef DEBUG
MSG = $(MSG) DEBUG
!endif
!ifdef CODEGUARD
MSG = $(MSG) CODEGUARD
!endif
!ifdef INTEL
MSG = $(MSG) INTEL
!endif
MSG = $(MSG) cpu=$(CPU)
MSG = $(MSG) Align=$(ALIGN)

!message $(MSG)

# Targets:
vim: bcc.cfg mkcmdtab.exe $(DLLTARGET) $(TARGET)
	@del $(OBJDIR)\version.obj

all:	vim ctags\ctags.exe

ctags\ctags.exe:
    cd ctags
    make -f makefile.bcc
    cd ..

clean:
    @del /y $(OBJDIR)\*.*

vim32.dll: $(OBJDIR) $(vimdllobj)
!message Making DLL 
  $(LINK) @&&|
	$(LFLAGSDLL) +
	c0d32.obj +
	$(vimdllobj)
	$<,$*
!ifdef CODEGUARD
	cg32.lib+
!endif
	import32.lib+
!if ($(USEDLL)==1)
	cw32mti.lib
!else
	cw32mt.lib
!endif
	vim.def
|
    implib vim32.lib vim32.dll

!ifdef VIMDLL
$(TARGET): $(OBJDIR) ex_cmds.h vim32.dll $(vimmain) $(RESFILE)
!else
$(TARGET): $(OBJDIR) ex_cmds.h $(vimobj) $(RESFILE)
!endif
!message Making EXE
  $(LINK) @&&|
	$(LFLAGS) +
	$(STARTUPOBJ) +
!ifdef VIMDLL
	$(vimmain)
!else
	$(vimobj)
!endif
	$<,$*
!ifdef CODEGUARD
	cg32.lib+
!endif
	import32.lib+
!ifdef VIMDLL
	vim32.lib+
!endif
!if ($(USEDLL)==1)
	cw32mti.lib
!else
	cw32mt.lib
!endif
|
!if ($(GUI)==1)
	$(BRC) -i $(BOR)\include $(RESFILE) $(TARGET)
!endif

$(OBJDIR)\buffer.obj:  buffer.c

$(OBJDIR)\charset.obj:	charset.c

$(OBJDIR)\digraph.obj:	digraph.c

$(OBJDIR)\edit.obj:  edit.c

$(OBJDIR)\eval.obj:  eval.c

$(OBJDIR)\ex_cmds.obj:	ex_cmds.c ex_cmds.h

$(OBJDIR)\ex_docmd.obj:  ex_docmd.c ex_cmds.h

$(OBJDIR)\ex_getln.obj:  ex_getln.c

$(OBJDIR)\fileio.obj:  fileio.c

$(OBJDIR)\getchar.obj:	getchar.c

$(OBJDIR)\main.obj:  main.c

$(OBJDIR)\mark.obj:  mark.c

$(OBJDIR)\memfile.obj:	memfile.c

$(OBJDIR)\memline.obj:	memline.c

$(OBJDIR)\message.obj:	message.c

$(OBJDIR)\misc1.obj:  misc1.c

$(OBJDIR)\misc2.obj:  misc2.c

$(OBJDIR)\normal.obj:  normal.c

$(OBJDIR)\ops.obj:  ops.c

$(OBJDIR)\option.obj:  option.c

$(OBJDIR)\quickfix.obj:  quickfix.c

$(OBJDIR)\regexp.obj:  regexp.c

$(OBJDIR)\screen.obj:  screen.c

$(OBJDIR)\search.obj:  search.c

$(OBJDIR)\syntax.obj:  syntax.c

$(OBJDIR)\tag.obj:  tag.c

$(OBJDIR)\term.obj:  term.c

$(OBJDIR)\ui.obj:  ui.c

$(OBJDIR)\undo.obj:  undo.c

$(OBJDIR)\version.obj:	version.c 

$(OBJDIR)\os_win32.obj:  os_win32.c

$(OBJDIR)\window.obj:  window.c

$(OBJDIR)\gui.obj: gui.c

$(OBJDIR)\gui_w32.obj: gui_w32.c

$(OBJDIR)\os_w32dll.obj: os_w32dll.c

$(OBJDIR)\os_w32exe.obj: os_w32exe.c
	$(CC) $(CC1) -WE $(CC2)$@ os_w32exe.c

$(OBJDIR):
	@if not exist $(OBJDIR)\nul mkdir $(OBJDIR)

ex_cmds.h: ex_docmd.h mkcmdtab.exe
	mkcmdtab.exe ex_docmd.h ex_cmds.h

mkcmdtab.exe: mkcmdtab.c
    $(CC) -WC mkcmdtab.c
    $(LINK) @&&|
	$(LFLAGS) -ap +
	c0x32.obj +
	mkcmdtab.obj
	$<,$*
	import32.lib+
	cw32.lib
|

vim.res: vim.rc
    $(BRC) -i $(BOR)\include -32 -r $*.rc

bcc.cfg: Makefile.b32
  copy &&|
	$(CFLAGS)
	$(DEFINES)
	$(EXETYPE)
	$(DEBUG)
	$(OPT)
	$(CODEGUARD)
	$(CPU)
	$(ALIGN)
| $@

# vi:set sts=4 sw=4:
