# Makefile : Builds Tex2RTF for Windows 3.1
# For Windows version invoke with no target, or with target 'all'
# For DOS version, invoke makefile with NO_GUI=1
# To optimize and remove debugging information, add FINAL=1 to
# the command line.

!ifndef NO_GUI
# Change WXDIR to wherever wxWindows is found
WXDIR = $(WX)
WXLIB = $(WXDIR)\lib\wx.lib $(WXDIR)\contrib\fafa\fafa.lib
WXINC = $(WXDIR)\include
PRECOMP=/YuWX.H
WXFLAGS = /G2sw /Dwx_msw $(PRECOMP) /Fp$(WXDIR)\src\msw\wx.pch
TEX2RTFOBJ = tex2rtf.obj rtfutils.obj xlputils.obj htmlutil.obj
WXHELPDIR = $(WXDIR)\utils\wxhelp
LIBS=oldnames.lib $(WXLIB) libw llibcew commdlg ddeml shell $(WXDIR)\contrib\fafa\fafa.lib ctl3d
INC=/I$(WXINC) /I$(WXDIR)\include\base /I$(WXDIR)\include\msw /I$(WXHELPDIR)\src
TEX2RTFDIR = $(WXDIR)\utils\tex2rtf
!else
WXDIR = wxwin
WXLIB =
WXINC = $(WXDIR)
WXFLAGS = /Dwx_dos /DNO_GUI
TEX2RTFOBJ = tex2rtf.obj rtfutils.obj xlputils.obj htmlutil.obj \
  wb_list.obj wb_hash.obj wb_utils.obj wb_obj.obj
LIBS=oldnames.lib llibce
INC = /I$(WXINC)
TEX2RTFDIR = ..
!endif

DOCDIR = $(TEX2RTFDIR)\docs
TEX2ANYLIB = $(TEX2RTFDIR)\lib\tex2any.lib

!ifndef FINAL
FINAL=0
!endif

# Default is to output RTF for WinHelp
!ifndef WINHELP
WINHELP=-winhelp
!endif

!if "$(FINAL)" == "0"
OPT=/Od
CPPFLAGS= /AL /W3 /Zi $(OPT) $(WXFLAGS) $(INC) 
LINKFLAGS=/NOD /CO /ONERROR:NOEXE
!else
OPT=/Os
CPPFLAGS= /AL /W3 $(OPT) $(WXFLAGS) $(INC)
LINKFLAGS=/NOD /ONERROR:NOEXE
!endif

all:    tex2rtf.exe

compact:
        -wrun clean

!ifndef NO_GUI
wx:
        cd $(WXDIR)\src\msw
        nmake -f makefile.dos FINAL=$(FINAL) OPT=$(OPT) PRECOMP=$(PRECOMP)
        cd $(TEX2RTFDIR)\src
!endif

$(TEX2ANYLIB):      tex2any.obj texutils.obj
        erase $(TEX2ANYLIB)
        lib /PAGESIZE:128 @<<
$(TEX2ANYLIB)
y
tex2any.obj texutils.obj
nul
;
<<

tex2any.obj: tex2any.cc tex2any.h
	cl @<<
$(CPPFLAGS) /c /Tp $*.cc
<<

texutils.obj: texutils.cc tex2any.h
	cl @<<
$(CPPFLAGS) /c /Tp $*.cc
<<

tex2rtf.obj: tex2rtf.cc tex2rtf.h tex2any.h
	cl @<<
$(CPPFLAGS) /c /Tp $*.cc
<<

rtfutils.obj: rtfutils.cc tex2rtf.h bmputils.h tex2any.h
	cl @<<
$(CPPFLAGS) /c /Tp $*.cc
<<

xlputils.obj: xlputils.cc tex2rtf.h rtfutils.h tex2any.h
	cl @<<
$(CPPFLAGS) /c /Tp $*.cc
<<

htmlutil.obj: htmlutil.cc tex2rtf.h tex2any.h
	cl @<<
$(CPPFLAGS) /c /Tp $*.cc
<<

!ifdef NO_GUI
wb_utils.obj:   wxwin\wb_utils.cc wxwin\wx_utils.h
	cl @<<
$(CPPFLAGS) /c /Tp wxwin\$*.cc
<<

wb_hash.obj:   wxwin\wb_hash.cc wxwin\wx_hash.h
	cl @<<
$(CPPFLAGS) /c /Tp wxwin\$*.cc
<<

wb_list.obj:   wxwin\wb_list.cc wxwin\wx_list.h
	cl @<<
$(CPPFLAGS) /c /Tp wxwin\$*.cc
<<

wb_obj.obj:   wxwin\wb_obj.cc wxwin\wx_obj.h
	cl @<<
$(CPPFLAGS) /c /Tp wxwin\$*.cc
<<
!endif

tex2rtf.res :      tex2rtf.rc $(WXDIR)\include\msw\wx.rc
    rc  /dFAFA_LIB /i$(WXDIR)\contrib\fafa /i$(WXDIR)\include\msw -r tex2rtf

!ifndef NO_GUI
tex2rtf.exe:      $(WXDIR)\src\msw\dummy.obj $(TEX2RTFOBJ) tex2rtf.def tex2rtf.res $(TEX2ANYLIB)
        link $(LINKFLAGS) @<<
$(WXDIR)\src\msw\dummy.obj $(TEX2RTFOBJ)
tex2rtf.exe,
nul,
$(LIBS) $(TEX2ANYLIB),
tex2rtf.def
<<
        rc -K tex2rtf.res
!else
tex2rtf.exe:      $(TEX2RTFOBJ) $(TEX2ANYLIB)
        link $(LINKFLAGS) @<<
$(TEX2RTFOBJ)
tex2rtf.exe,
nul,
$(LIBS) $(TEX2ANYLIB),
dos.def
<<
!endif

# No PostScript production on the PC: just check it goes through Latex
docs:	dvi hlp xlp html
dvi:	$(TEX2RTFDIR)/docs/tex2rtf.dvi
hlp:	$(TEX2RTFDIR)/docs/tex2rtf.hlp
rtf:	$(TEX2RTFDIR)/docs/tex2rtf.rtf
xlp:    $(TEX2RTFDIR)/docs/tex2rtf.xlp
html:    $(TEX2RTFDIR)/docs/tex2rtf.html

$(DOCDIR)/tex2rtf.dvi:	$(DOCDIR)/tex2rtf.tex
	cd $(DOCDIR)
        latex tex2rtf
        latex tex2rtf
        makeindx tex2rtf
        latex tex2rtf
#        dvips -f -r < tex2rtf.dvi > tex2rtf.ps

$(DOCDIR)/tex2rtf.rtf:
        cd $(DOCDIR)
        -wx tex2rtf $(DOCDIR)\tex2rtf.tex $(DOCDIR)\tex2rtf.rtf -twice $(WINHELP)
        cd $(TEX2RTFDIR)/src

$(DOCDIR)/tex2rtf.xlp:         $(DOCDIR)/tex2rtf.tex
        cd $(DOCDIR)
        -wx tex2rtf $(DOCDIR)\tex2rtf.tex $(DOCDIR)\tex2rtf.xlp -xlp -twice
        cd $(TEX2RTFDIR)/src

$(DOCDIR)/tex2rtf.html:         $(DOCDIR)/tex2rtf.tex
        cd $(DOCDIR)
        -wx tex2rtf $(DOCDIR)\tex2rtf.tex $(DOCDIR)\tex2rtf.htm -html -twice
        cd $(TEX2RTFDIR)/src

$(DOCDIR)/tex2rtf.hlp:         $(DOCDIR)/tex2rtf.rtf
        cd $(DOCDIR)
        hc tex2rtf
        cd $(TEX2RTFDIR)/src

test.rtf:   test.tex
        -wx $(TEX2RTFDIR)\src\tex2rtf $(TEX2RTFDIR)\src\test.tex $(TEX2RTFDIR)\src\test.rtf $(WINHELP)

clean:
        erase *.obj *.exe *.res $(TEX2ANYLIB)

cleanall:	clean
