# Makefile for compiling Mathomatic under UNIX, GNU/Linux, and MacOS-X.

VERSION		= `cat VERSION`
CFLAGS		+= -O -DUNIX -DVERSION=\"$(VERSION)\"
LDFLAGS		+= -s
LIBS		+= -lm

CFLAGS		+= $(READLINE:1=-DREADLINE)
LIBS		+= $(READLINE:1=-lreadline -lncurses)

prefix		= /usr/local
bindir		= $(prefix)/bin
mandir		= $(prefix)/man
docdir		= $(prefix)/doc

AOUT	=mathomatic
OBJECTS	=main.o globals.o am.o help.o parse.o cmds.o simplify.o factor.o super.o \
	unfactor.o diff.o integrate.o complex.o list.o gcd.o

all: $(AOUT)
	@echo Make completed.

check: test

test: $(AOUT)
	cd tests; time ../$(AOUT) -t all.in >test.out; diff -u all.out test.out
	rm tests/test.out
	@echo All tests passed.

baseline: $(AOUT)
	cd tests; ../$(AOUT) -t all.in >all.out
	rm -f tests/test.out

$(OBJECTS): includes.h am.h externs.h proto.h VERSION makefile

$(AOUT): $(OBJECTS)
	$(CC) $(LDFLAGS) $(OBJECTS) $(LIBS) -o $(AOUT)

install: $(AOUT)
	install -d $(bindir)
	install -d $(mandir)/man1
	install -d $(docdir)/mathomatic
	install -m 0755 $(AOUT) $(bindir)
	install -m 0644 doc/mathomatic.1 $(mandir)/man1
	install -m 0644 changes.txt doc/*.htm doc/*.html $(docdir)/mathomatic
	@echo Install completed.

uninstall:
	rm -f $(bindir)/$(AOUT)
	rm -f $(mandir)/man1/mathomatic.1
	rm -rf $(docdir)/mathomatic
	@echo Uninstall completed.

clean:
	rm -f *.o
	rm -f $(AOUT)
