# Rascal, the Advanced Scientific CALculator
# Copyright (C) 2001, Sebastian Ritterbusch (Rascal@Ritterbusch.de)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
PREFIX=/usr

VERSION=0.3.2

CC?=${CC}
CFLAGS+=${CPPFLAGS}  -DVERSION=\"$(VERSION)\"
# With the following options you may generate an optimized version of
# Rascal, but you will need a lot of time (takes 20min, that is 15* 
# longer, on my machine) and physical memory (256 MB physical memory 
# absolute minimum). The executable will be about twice as large.
# You have been warned... =:)
#CFLAGS=-O3 -g -DVERSION=\"$(VERSION)\" 
# for x86:
#CFLAGS=-O3 -g -fno-rtti -fstrict-aliasing -fomit-frame-pointer -march=i386 -mcpu=i686 -DVERSION=\"$(VERSION)\" 
# for Athlon: (contributed by Jochen)
#CFLAGS=-O3 -march=athlon -mcpu=athlon -fno-rtti -fstrict-aliasing -fomit-frame-pointer  -DVERSION=\"$(VERSION)\"

INSTALL=install -m 755
STRIP=strip -g
RM=rm -f
RMDIR=rm -rf
INSTDIR=install -d

LIBS+=${LDFLAGS} -lm -lreadline -lcurses
OBJS=y.tab.o lex.yy.o symtab.o value.o

-include value.mak

all: rascal 

rascal:	$(OBJS) rascal.1.gz
	${CC} -o rascal $(CFLAGS) $(OBJS) $(LIBS)
test: rascal
	./rascal TEST

doc: rascal.ps rascal.pdf
html: rascal_html/rascal.html

light:
	cp value.in.light value.in
	rm -f value.mak
	rm -f rascal.dvi
	rm -rf rascal_html

medium:
	cp value.in.medium value.in
	rm -f value.mak
	rm -f rascal.dvi
	rm -rf rascal_html

full:
	cp value.in.full value.in
	rm -f value.mak
	rm -f rascal.dvi
	rm -rf rascal_html

toolbox:
	cp value.in.toolbox value.in
	rm -f value.mak
	rm -f rascal.dvi
	rm -rf rascal_html

long:
	cp value.in.long value.in
	rm -f value.mak
	rm -f rascal.dvi
	rm -rf rascal_html

purenum:
	cp value.in.purenum value.in
	rm -f value.mak
	rm -f rascal.dvi
	rm -rf rascal_html

install:
	$(INSTALL) ./rascal $(PREFIX)/local/bin/
	$(INSTALL) ./rascal.rc $(PREFIX)/local/bin/
	$(INSTALL) ./grascal $(PREFIX)/local/bin/
	$(STRIP)   $(PREFIX)/local/bin/rascal
	$(INSTDIR) $(PREFIX)/local/share/doc/rascal
	$(INSTALL) rascal.ps $(PREFIX)/local/share/doc/rascal
	$(INSTALL) rascal.pdf $(PREFIX)/local/share/doc/rascal
	$(INSTALL) TOOLBOXTEST TEST $(PREFIX)/local/share/doc/rascal
	$(INSTALL) CHANGES $(PREFIX)/local/share/doc/rascal
	$(INSTALL) rascal.1.gz $(PREFIX)/local/man/man1
	-$(INSTALL) rascal-kde.desktop $(PREFIX)/share/applnk/Utilities
	-$(INSTALL) rascal-gnome.desktop $(PREFIX)/share/gnome/apps/Utilities
	-$(INSTDIR) $(PREFIX)/local/share/doc/rascal/html
	-$(INSTALL) rascal_html/index.html rascal_html/rascal.html rascal_html/*.gif rascal_html/*.css $(PREFIX)/local/share/doc/rascal/html

source-archive: clean rascal.1
	$(RMDIR) Rascal-$(VERSION)
	mkdir Rascal-$(VERSION)
	-cp -f --parents * modules/* rascal_html/*html rascal_html/*gif rascal_html/*css Rascal-$(VERSION)
	-$(RM) rascal-$(VERSION).tar.gz
	tar cvfz rascal-$(VERSION).tar.gz Rascal-$(VERSION)
	$(RMDIR) Rascal-$(VERSION)

rpm: source-archive
	rpm -ta --clean rascal-$(VERSION).tar.gz
	$(RMDIR) rascal-$(VERSION).tar.gz

uninstall:
	$(RM)      $(PREFIX)/local/bin/rascal
	$(RM)      $(PREFIX)/local/bin/rascal.rc
	$(RM)      $(PREFIX)/local/man/man1/rascal.1.gz
	$(RMDIR)   $(PREFIX)/local/share/doc/rascal

rascal.1.gz:
	gzip rascal.1

rascal.1:
	gzip -d rascal.1.gz

y.tab.c: hoc.y scan.l symtab.h value.out value.hpp modules/*.hpp 
	bison -v -y  -d hoc.y
y.tab.h: y.tab.c
lex.yy.c: scan.l y.tab.h symtab.h value.out value.hpp modules/*.hpp 
	flex scan.l
value.hpp: value.out modules/*.hpp 

value.mak: parsevalue
	-rm -rf parsevalue.log
	./parsevalue > parsevalue.log

value.out: parsevalue value.in modules/*.in modules/*.hlp
	-rm -rf parsevalue.log
	./parsevalue > parsevalue.log

symtab.o: symtab.h value.out
value.o: value.hpp value.out value.cpp modules/*.cpp modules/*.hpp
	${CC} $(CFLAGS) -c -o value.o value.cpp
parsevalue: parsevalue.cpp
	${CC} parsevalue.cpp  -o parsevalue
rascal.pdf: rascal.ps
	ps2pdf rascal.ps rascal.pdf
rascal.ps: rascal.dvi
	dvips rascal.dvi -o rascal.ps
rascal.dvi: rascal.tex value.tex modules/*.tex
	latex rascal.tex
	latex rascal.tex
rascal_html/rascal.html: rascal.tex value.tex modules/*.tex
	-latex2html -split 0 -nonavigation -transparent -math -math_parsing -dir rascal_html -mkdir -image_type gif rascal.tex

valexample: valexample.cpp
	cp value.in.valex value.in
	./parsevalue > parsevalue.log
	${CC} $(CFLAGS) valexample.cpp -o valexample

grascal: grascal.cpp calterm.hpp calterm.cpp
	$(CC) $(CFLAGS)  -DVERSION=\"$(VERSION)\" `${GNOME_CONFIG} --cflags gtk gnomeui zvt` grascal.cpp -o grascal `${GNOME_CONFIG} --libs gtk gnomeui zvt`

clean: rascal.1
	$(RMDIR) lex.yy.* core rascal grascal parsevalue.log valexample y.tab.* value.out value.cpp value.fn0 value.fn value.fn2 value.o y.output rascal.aux rascal.dvi rascal.log rascal.toc symtab.o parsevalue *~ modules/*~ rascal-*.tar.gz


syntax highlighted by Code2HTML, v. 0.9.1