#
# makefile for vile filters on WIN32 using Microsoft Visual C++
#
# $Header: /usr/build/vile/vile/filters/RCS/makefile.wnt,v 1.36 2010/08/15 22:05:30 tom Exp $
#
#
!include <ntwin32.mak>

# set DBG=yes to get debugging info (and a larger executable)
!if "$(DBG)" != ""
CC_DEBUG     = $(cdebug)
LD_DEBUG     = $(ldebug)
!endif

LEX_OUTPUT_ROOT = lex.yy

x	= .exe
o	= .obj

# Other vars
CON_LDFLAGS  = $(LD_DEBUG) $(conlflags) $(conlibsmt) user32.lib comdlg32.lib ole32.lib shell32.lib -nologo -pdb:none

UTILS	= \
	atr2ansi$x \
	atr2html$x \
	atr2text$x \
	vile-crypt$x \
	vile-manfilt$x

SCRIPTS = \
	filters.rc

CFLAGS   = $(cvarsmt) $(CC_DEBUG) -nologo -DWIN32_LEAN_AND_MEAN -G4 -I. -I..

# special definition for spell-filter
!if "$(SCREEN)" == "ntconio"
CFLAGS   = $(CFLAGS) -DHAVE_POPEN
!elseif "$(FLT)" == ""
CFLAGS   = $(CFLAGS) -DHAVE_POPEN
!endif

!if "$(FLT)" != ""
CFLAGS   = $(CFLAGS) -DOPT_FILTER
!endif

CFLAGS   = $(CFLAGS) -DOPT_LOCALE

TMPINCS	= \
	genmake.exe \
	mk-1st.tmp \
	mk-2nd.tmp

MAKEDEPS = $(TMPINCS) makefile.wnt
GENDEPS = makefile.wnt genmake.exe genmake.mak

!if "$(RECUR_FILTERS)" == ""
# list these on separate lines, otherwise nmake does the last only.
all :: $(TMPINCS)
dist :: $(TMPINCS)
install :: $(TMPINCS)
uninstall :: $(TMPINCS)

!if "$(FLT)" == ""
mk-1st.tmp : $(GENDEPS) mk-1st.bat
	mk-1st.bat genmake.mak extern $@
mk-2nd.tmp : $(GENDEPS) mk-2nd.bat
	mk-2nd.bat genmake.mak extern $@
!else
mk-1st.tmp : $(GENDEPS) mk-1st.bat
	mk-1st.bat genmake.mak intern $@
mk-2nd.tmp : $(GENDEPS) mk-2nd.bat
	mk-2nd.bat genmake.mak intern $@
!endif

RECUR_OPTS = RECUR_FILTERS=yes FLT=$(FLT) LEX=$(LEX) SCREEN=$(SCREEN) -f makefile.wnt $@ -$(MAKEFLAGS)

all ::
	$(MAKE) $(RECUR_OPTS)
dist ::
	$(MAKE) $(RECUR_OPTS)
install ::
	$(MAKE) $(RECUR_OPTS)
uninstall ::
	$(MAKE) $(RECUR_OPTS)

!else

!include mk-1st.tmp

!if "$(FLT)" == ""
UTILS = $(UTILS) $(ALL_C) $(ALL_LEX)
!else

FLTLIB = builtflt.lib
FLTOBJ = $(OBJ_C) filters$o
!if "$(LEX)" != ""
FLTOBJ = $(FLTOBJ) $(OBJ_LEX)
!endif

all ::	genmake.exe

genmake.exe:  genmake.c
	$(cc) $(CFLAGS) genmake.c -Fogenmake -link $(CON_LDFLAGS)

all :: $(FLTOBJ) $(FLTLIB)

$(FLTLIB) : $(MAKEDEPS) $(FLTOBJ)
	lib -out:$@ @<<
	$(FLTOBJ)
<<
!endif

all :: $(UTILS)

dist :: $(UTILS) $(SCRIPTS)
	- del *.zip
	zip filters.zip $(UTILS) $(SCRIPTS)

dist :: $(KEYS)
	!copy $** $**words && zip filters.zip $**words && del $**words

!if "$(VILE_LIBDIR_PATH)" == ""
install ::
	@ echo Sorry, you have not set VILE_LIBDIR_PATH
!else if !exist("$(VILE_LIBDIR_PATH)")
install :: $(UTILS)
	@echo Sorry, these are installed only if VILE_LIBDIR_PATH is a single directory
	!@echo "      $**"
!else
install :: $(UTILS)
	echo installing $(UTILS) in $(VILE_LIBDIR_PATH)
	!copy $** "$(VILE_LIBDIR_PATH)"\$**
uninstall :: $(UTILS)
	echo uninstalling $(UTILS) in $(VILE_LIBDIR_PATH)
	!erase "$(VILE_LIBDIR_PATH)"\$**
!endif

!if "$(VILE_STARTUP_PATH)" == ""
install ::
	@echo Sorry, you have not set VILE_STARTUP_PATH
!else if !exist("$(VILE_STARTUP_PATH)")
install :: $(SCRIPTS) $(KEYS)
	@echo Sorry, these are installed only if VILE_STARTUP_PATH is a single directory
	!@echo "      $**"
!else
install :: $(SCRIPTS)
	echo installing $(SCRIPTS) in $(VILE_STARTUP_PATH)
	!copy $** "$(VILE_STARTUP_PATH)"\$**
uninstall :: $(SCRIPTS)
	echo uninstalling $(SCRIPTS) in $(VILE_STARTUP_PATH)
	!erase "$(VILE_STARTUP_PATH)"\$**
install :: $(KEYS)
	echo installing $(KEYS) in $(VILE_STARTUP_PATH)
	!copy $** "$(VILE_STARTUP_PATH)"\$**words
uninstall :: $(KEYS)
	echo uninstalling $(KEYS) in $(VILE_STARTUP_PATH)
	!erase "$(VILE_STARTUP_PATH)"\$**words
!endif

.SUFFIXES: .c .l $o

.l$o:
	$(LEX) $<
	$(CC) -c $(CPPFLAGS) $(CFLAGS) $(LEX_OUTPUT_ROOT).c -Fo$@
	- erase $(LEX_OUTPUT_ROOT).c

.c$o:
	$(cc) $(CFLAGS) -c $< -Fo$@


LF_DEPS = filterio$o filters$o
LF_ARGS = $(LF_DEPS) $(LEXLIB)

CF_DEPS	= filterio$o filters$o
CF_ARGS	= $(CF_DEPS)

!include mk-2nd.tmp

atr2ansi$x : atr2ansi$o unfilter$o
	$(link) -out:$@ $(CON_LDFLAGS) atr2ansi$o unfilter$o

atr2html$x : atr2html$o unfilter$o
	$(link) -out:$@ $(CON_LDFLAGS) atr2html$o unfilter$o

atr2text$x : atr2text$o unfilter$o
	$(link) -out:$@ $(CON_LDFLAGS) atr2text$o unfilter$o

vile-crypt$x : ecrypt$o encrypt$o
	$(link) -out:$@ $(CON_LDFLAGS) ecrypt$o encrypt$o

vile-manfilt$x : manfilt$o
	$(link) -out:$@ $(CON_LDFLAGS) manfilt$o

encrypt$o : ..\encrypt.c
	$(cc) $(CFLAGS) -c ..\encrypt.c -Fo$@

!endif # "$(RECUR_FILTERS)" == ""

clean:
	- del lex.*.c
	- del *.bak
	- del *.tmp
	- del *.pdb
	- del *$x
	- del *$o
	- del *.lib
	- del *.map

distclean: clean
	- del *.zip
