#
# File:		makefile.unx
# Author:	Julian Smart
# Created:	1993
# Updated:	
# Copyright:	(c) 1993, AIAI, University of Edinburgh
#
# "%W% %G%"
#
# Makefile for libprologio.a

GUISUFFIX=_ol
CC = gcc-2.1

# If your compiler cannnot understand both C++/C, it can be
# useful to have separate commands, since yy_tab.c is pure 'C',  not C++
# So, fixmake.sh can patch this line
# Typical: CC=g++ , CCLEX=gcc
#          CC=cl386 /Tp, CCLEX=cl386
#

CCLEX=$(CC)

# Replace X include/lib directories with your own, e.g. -I/usr/openwin/include ...
# XINCLUDE=-I/aiai/packages/prokappa2.0/X/usr/include -I/aiai/packages/X.V11R5/include
# XLIB=-L/aiai/packages/X.V11R5/lib -L/aiai/packages/prokappa2.0/X/usr/lib
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
DOCUTILSDIR = $(WXDIR)/utils/tex2rtf/src

PROLOGDIR = $(WXDIR)/utils/prologio
PROLOGINC = $(PROLOGDIR)/src
PROLOGLIB = $(PROLOGDIR)/lib/libproio$(GUISUFFIX).a

OBJDIR = objects$(GUISUFFIX)

OBJECTS = $(OBJDIR)/read.o $(OBJDIR)/prorpc.o $(OBJDIR)/y_tab.o

TESTOBJECTS = $(OBJDIR)/test.o
TESTPROGRAM = $(PROLOGDIR)/src/test$(GUISUFFIX)

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

# 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) -I$(PROLOGINC) $(GUI) $(DEBUG) $(WARN) $(HARDY_OPTIONS) $(OPT)
CFLAGS =
LDFLAGS =  $(XLIB) -L$(WXDIR)/lib -L$(PROLOGDIR)/lib
LDLIBS = -lproio_ol -lwx_ol -lxview -lolgx -lX11 -lm -lg++

all:	$(OBJDIR) $(PROLOGLIB)

demo:	$(TESTPROGRAM)

$(PROLOGLIB): $(OBJECTS)
	rm -f $@
	ar rv $@ $(OBJECTS)
	ranlib $@

.SUFFIXES:

$(OBJECTS):	$(PROLOGINC)/read.h $(PROLOGINC)/expr.h $(PROLOGINC)/prorpc.h

motif:
	make -f makefile.unx GUISUFFIX=_motif GUI=-Dwx_motif OPT='$(OPT)' GUISUFFIX=_motif LDLIBS='-lproio_motif -lwx_motif -lXm -lXt -lXmu -lX11 -lm -lg++' XVIEW_LINK=

xview:
	make -f makefile.unx GUI=-Dwx_xview OPT='$(OPT)' GUISUFFIX=_ol

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

hpdemo:
	make -f makefile.unx all demo GUI=-Dwx_motif GUISUFFIX=_hp CC=CC DEBUG='' WARN='' \
           XINCLUDE='-I/usr/include/Motif1.2 -I/usr/include/X11R5' \
           XLIB='-L/usr/lib/Motif1.2 -L/usr/lib/X11R5' \
           XVIEW_LINK='' \
           CCLEX='cc' \
           LDLIBS='-lwx_hp -lproio_hp -lXm -lXt -lX11 -lm'

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

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

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

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

$(OBJDIR)/y_tab.o:	y_tab.c lex_yy.c
	$(CCLEX) -c $(CPPFLAGS) -o $@ y_tab.c

lex_yy.c:	lexer.l
	lex lexer.l
	sed -e "s/BUFSIZ/5000/g" < lex.yy.c > lex_yy.c
	/bin/rm -f lex.yy.c

y_tab.c:	parser.y
	yacc parser.y
	mv y.tab.c y_tab.c

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

$(TESTPROGRAM): $(OBJDIR)/test.o $(WXLIB) $(PROLOGLIB)
	$(CC) $(CPPFLAGS) $(LDFLAGS) -o test$(GUISUFFIX) $(OBJDIR)/test.o $(XVIEW_LINK) $(LDLIBS)

docs:	ps xlp
ps:	$(PROLOGDIR)/docs/manual.ps
xlp:	$(PROLOGDIR)/docs/prologio.xlp
html:	$(PROLOGDIR)/docs/prologio_contents.html

$(PROLOGDIR)/docs/prologio.xlp:	$(PROLOGDIR)/docs/classes.tex $(PROLOGDIR)/docs/manual.tex
	cd ../docs; tex2rtf manual.tex tmp.xlp -twice -xlp
	sed -e "s/WXHELPCONTENTS/PROLOGIO Manual/g" < $(PROLOGDIR)/docs/tmp.xlp > $(PROLOGDIR)/docs/prologio.xlp
	/bin/rm -f $(PROLOGDIR)/docs/tmp.xlp

$(PROLOGDIR)/docs/prologio_contents.html:	$(PROLOGDIR)/docs/manual.tex $(PROLOGDIR)/docs/classes.tex
	cd ../docs; tex2rtf manual.tex prologio.html -twice -html
	/bin/cp ../docs/*.html /user/11/jacs/html/prologio
	/bin/rm -f ../docs/*.html

$(PROLOGDIR)/docs/manual.dvi:	$(PROLOGDIR)/docs/manual.tex $(PROLOGDIR)/docs/classes.tex $(PROLOGDIR)/docs/tutorial.tex
	cd $(PROLOGDIR)/docs; latex manual; latex manual; makeindex manual; latex manual

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

cleaneach:
	rm -f $(OBJECTS) $(TESTOBJECTS) test$(GUISUFFIX) $(PROLOGLIB) core

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

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

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

$(OBJDIR):
	mkdir $(OBJDIR)
