# Makefile for UNIX Tex2RTF.
# Valid targets: xview, motif or nogui. These should produce
# the executables tex2rtf_ol, tex2rtf_motif and tex2rtf_nogui respectively.

CC = gcc-2.1
GUISUFFIX=_ol

# Replace X include/lib directories with your own, e.g. -I/usr/openwin/include ...
XINCLUDE=-I/aiai/packages/motif1.2.1/motif/include -I/aiai/packages/X.V11R5/include
XLIB=-L/aiai/packages/motif1.2.1/motif/sun4/lib -L/aiai/packages/X.V11R5/lib

WXDIR = ../../..
WXINC = $(WXDIR)/include
WXLIB = $(WXDIR)/lib/libwx$(GUISUFFIX).a

TEX2RTFDIR = ..
DOCUTILSDIR = .
WXHELPDIR = $(WXDIR)/utils/wxhelp
OBJDIR = objects$(GUISUFFIX)
TEX2RTFOBJ = $(OBJDIR)/tex2rtf.o $(OBJDIR)/rtfutils.o $(OBJDIR)/xlputils.o $(OBJDIR)/htmlutil.o
WXOBJ = $(OBJDIR)/wb_utils.o $(OBJDIR)/wb_list.o $(OBJDIR)/wb_hash.o $(OBJDIR)/wb_obj.o

TEX2ANYLIB = $(TEX2RTFDIR)/lib/libtex2any$(GUISUFFIX).a

INC = -I$(WXINC)/base -I$(WXINC)/x -I$(WXHELPDIR)/src

# Default is to use XView
DEBUG = -ggdb
WARN = -Wall
OPT = -O
GUI = -Dwx_xview
XVIEW_LINK = $(WXDIR)/src/x/objects_ol/sb_scrol.o

CPPFLAGS = $(XINCLUDE) $(INC) $(GUI) $(DEBUG) $(WALL)
LDFLAGS = $(XLIB) -L$(WXDIR)/lib -L$(TEX2RTFPDIR)/lib
LDLIBS = -lwx_ol -lxview -lolgx -lX11 -lm -lg++
# LDLIBS = -lwx_motif -lXm -lXt -lX11 -lm -lg++

# Make the utilities for converting Latex to other formats
utils:	$(OBJDIR) $(TEX2ANYLIB) tex2rtf$(GUISUFFIX)

.SUFFIXES:

nogui:
	make -f makefile.unx objects_nogui tex2rtf_nogui GUI='-Dwx_nogui -Dwx_x -DNO_GUI' GUISUFFIX='_nogui' OPT='$(OPT)' LDLIBS='-lm -lg++' LDFLAGS='-L$(TEX2RTFDIR)/lib' INC='-I./wxwin'  XVIEW_LINK='' XINCLUDE=''

motif:
	cd $(WXDIR)/src/x; make -f makefile.unx motif OPT='$(OPT)'
	make -f makefile.unx utils GUI=-Dwx_motif GUISUFFIX=_motif OPT='$(OPT)' LDLIBS='-lwx_motif -lXm -lXt -lX11 -lm -lg++' XVIEW_LINK=

xview:
	cd $(WXDIR)/src/x; make -f makefile.unx xview OPT='$(OPT)'
	make -f makefile.unx utils GUI=-Dwx_xview OPT='$(OPT)'

hp:
	make -f makefile.unx GUI=-Dwx_motif GUISUFFIX=_hp CC=CC DEBUG='' WARN='-w' \
           XINCLUDE='-I/usr/include/Motif1.2 -I/usr/include/X11R5' \
           XLIB='-L/usr/lib/Motif1.2 -L/usr/lib/X11R5' \
           XVIEW_LINK='' \
           LDLIBS='-lwx_hp -ltex2any_hp -lXm -lXt -lX11 -lm'

$(OBJDIR):
	mkdir $(OBJDIR)

# The LaTeX parsing library
$(OBJDIR)/tex2any:	$(TEX2ANYLIB)

$(TEX2ANYLIB):	$(OBJDIR)/tex2any.o $(OBJDIR)/texutils.o
	rm -f $@
	ar rv $@ $(OBJDIR)/tex2any.o $(OBJDIR)/texutils.o
	ranlib $@

$(OBJDIR)/tex2any.o:	tex2any.cc tex2any.h
	$(CC) -c $(CPPFLAGS) -o $@ tex2any.cc

$(OBJDIR)/texutils.o:	texutils.cc tex2any.h
	$(CC) -c $(CPPFLAGS) -o $@ texutils.cc

# wxWindows compatibility: in case you don't want the GUI.
$(OBJDIR)/wb_utils.o:	wxwin/wb_utils.cc wxwin/wx_utils.h
	$(CC) -c $(CPPFLAGS) -o $@ wxwin/wb_utils.cc

$(OBJDIR)/wb_list.o:	wxwin/wb_list.cc wxwin/wx_list.h
	$(CC) -c $(CPPFLAGS) -o $@ wxwin/wb_list.cc

$(OBJDIR)/wb_hash.o:	wxwin/wb_hash.cc wxwin/wx_hash.h
	$(CC) -c $(CPPFLAGS) -o $@ wxwin/wb_hash.cc

$(OBJDIR)/wb_obj.o:	wxwin/wb_obj.cc wxwin/wx_obj.h
	$(CC) -c $(CPPFLAGS) -o $@ wxwin/wb_obj.cc

# Reads Latex manual and converts to RTF/Windows Help/HTML/wxHelp form
$(OBJDIR)/tex2rtf.o:     tex2rtf.cc rtfutils.h tex2rtf.h rtfutils.h
	$(CC) -c $(CPPFLAGS) -o $@ tex2rtf.cc

tex2rtf_nogui:	$(TEX2RTFOBJ) $(WXOBJ) $(TEX2ANYLIB)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o tex2rtf_nogui $(TEX2RTFOBJ) $(WXOBJ) $(TEX2ANYLIB) $(LDLIBS)

tex2rtf$(GUISUFFIX):	$(TEX2RTFOBJ) $(TEX2ANYLIB)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o tex2rtf$(GUISUFFIX) $(XVIEW_LINK) $(TEX2RTFOBJ) $(TEX2ANYLIB) $(LDLIBS)

$(OBJDIR)/rtfutils.o:     rtfutils.cc tex2rtf.h rtfutils.h
	$(CC) -c $(CPPFLAGS) -o $@ rtfutils.cc

$(OBJDIR)/htmlutil.o:     htmlutil.cc tex2rtf.h rtfutils.h
	$(CC) -c $(CPPFLAGS) -o $@ htmlutil.cc

$(OBJDIR)/xlputils.o:     xlputils.cc tex2rtf.h rtfutils.h
	$(CC) -c $(CPPFLAGS) -o $@ xlputils.cc

wx:
	cd $(WXDIR)/src/x; make -f makefile.unx

docs:	ps xlp txt
ps:	$(TEX2RTFDIR)/docs/tex2rtf.ps
txt:	$(TEX2RTFDIR)/docs/tex2rtf.txt
xlp:	$(TEX2RTFDIR)/docs/tex2rtf.xlp
html:	tex2rtfhtml tex2rtfhtml
tex2rtfhtml:	$(TEX2RTFDIR)/docs/tex2rtf_contents.html
tex2rtfhtml:	$(TEX2RTFDIR)/docs/tex2rtf_contents.html

$(TEX2RTFDIR)/docs/tex2rtf.xlp:	$(TEX2RTFDIR)/docs/tex2rtf.tex
	tex2rtf ../docs/tex2rtf.tex $(TEX2RTFDIR)/docs/tmp.xlp -twice -xlp
	sed -e "s/WXHELPCONTENTS/Tex2RTF Manual/g" < $(TEX2RTFDIR)/docs/tmp.xlp > $(TEX2RTFDIR)/docs/tex2rtf.xlp
	/bin/rm -f $(TEX2RTFDIR)/docs/tmp.xlp

$(TEX2RTFDIR)/docs/tex2rtf.dvi:	$(TEX2RTFDIR)/docs/tex2rtf.tex
	cd $(TEX2RTFDIR)/docs; latex tex2rtf; latex tex2rtf; makeindex tex2rtf; bibtex tex2rtf; latex tex2rtf

$(TEX2RTFDIR)/docs/tex2rtf.ps:	$(TEX2RTFDIR)/docs/tex2rtf.dvi
	cd $(TEX2RTFDIR)/docs; dvips -f -r < tex2rtf.dvi > tex2rtf.ps

$(TEX2RTFDIR)/docs/tex2rtf.txt:	$(TEX2RTFDIR)/docs/tex2rtf.dvi
	cd $(TEX2RTFDIR)/docs; dvi2tty tex2rtf.dvi > tex2rtf.txt

$(TEX2RTFDIR)/docs/tex2rtf_contents.html:	$(TEX2RTFDIR)/docs/tex2rtf.tex
	tex2rtf $(TEX2RTFDIR)/docs/tex2rtf.tex $(TEX2RTFDIR)/docs/tex2rtf.html -twice -html
	/bin/cp ../docs/*.html /user/11/jacs/html/tex2rtf
	/bin/rm -f ../docs/*.html

cleaneach:
	rm -f $(OBJDIR)/*.o test$(GUISUFFIX) tex2rtf$(GUISUFFIX) tex2rtf$(GUISUFFIX) $(TEX2ANYLIB) core

clean_motif:
	make -f makefile.unx GUISUFFIX=_motif cleaneach 

clean_ol:
	make -f makefile.unx GUISUFFIX=_ol cleaneach 

clean_hp:
	make -f makefile.unx GUISUFFIX=_hp cleaneach 


