# Makefile for UNIX wxBuilder
# Valid targets: xview, motif or nogui. These should produce
# the executables wxbuild_ol, wxbuild_motif and wxbuild_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

WXBUILDDIR = ..
DOCUTILSDIR = .
WXHELPDIR = $(WXDIR)/utils/wxhelp
OBJDIR = objects$(GUISUFFIX)
WXBUILDOBJ = $(OBJDIR)/wxbuild.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 = $(WXBUILDDIR)/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$(WXBUILDPDIR)/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) wxbuild$(GUISUFFIX)

.SUFFIXES:

nogui:
	make -f makefile.unx objects_nogui wxbuild_nogui GUI='-Dwx_nogui -Dwx_x -DNO_GUI' GUISUFFIX='_nogui' OPT='$(OPT)' LDLIBS='-lm -lg++' LDFLAGS='-L$(WXBUILDDIR)/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)

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

wxbuild_nogui:	$(WXBUILDOBJ) $(WXOBJ) $(TEX2ANYLIB)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o wxbuild_nogui $(WXBUILDOBJ) $(WXOBJ) $(TEX2ANYLIB) $(LDLIBS)

wxbuild$(GUISUFFIX):	$(WXBUILDOBJ) $(TEX2ANYLIB)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o wxbuild$(GUISUFFIX) $(XVIEW_LINK) $(WXBUILDOBJ) $(TEX2ANYLIB) $(LDLIBS)

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

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

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

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

docs:	ps xlp txt
ps:	$(WXBUILDDIR)/docs/wxbuild.ps
txt:	$(WXBUILDDIR)/docs/wxbuild.txt
xlp:	$(WXBUILDDIR)/docs/wxbuild.xlp
html:	wxbuildhtml wxbuildhtml
wxbuildhtml:	$(WXBUILDDIR)/docs/wxbuild_contents.html
wxbuildhtml:	$(WXBUILDDIR)/docs/wxbuild_contents.html

$(WXBUILDDIR)/docs/wxbuild.xlp:	$(WXBUILDDIR)/docs/wxbuild.tex
	cd ../docs; tex2rtf wxbuild.tex tmp.xlp -twice -xlp
	sed -e "s/WXHELPCONTENTS/wxBuilder Manual/g" < $(WXBUILDDIR)/docs/tmp.xlp > $(WXBUILDDIR)/docs/wxbuild.xlp
	/bin/rm -f $(WXBUILDDIR)/docs/tmp.xlp

$(WXBUILDDIR)/docs/wxbuild.dvi:	$(WXBUILDDIR)/docs/wxbuild.tex
	cd ../docs; latex wxbuild; latex wxbuild; makeindex wxbuild; latex wxbuild

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

$(WXBUILDDIR)/docs/wxbuild.txt:	$(WXBUILDDIR)/docs/wxbuild.dvi
	cd $(WXBUILDDIR)/docs; dvi2tty wxbuild.dvi > wxbuild.txt

$(WXBUILDDIR)/docs/wxbuild_contents.html:	$(WXBUILDDIR)/docs/wxbuild.tex
	cd ../docs; tex2rtf wxbuild.tex wxbuild.html -twice -html
	/bin/cp ../docs/*.html /user/11/jacs/html/wxbuild
	/bin/rm -f ../docs/*.html

cleaneach:
	rm -f $(OBJDIR)/*.o test$(GUISUFFIX) wxbuild$(GUISUFFIX) wxbuild$(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 


