# Makefile for the Mathomatic symbolic math library and library test program.

CC		?= gcc
INSTALL		?= install

VERSION		= `cat ../VERSION`
OPTFLAGS	?= -O -Wall -Wshadow -Wno-char-subscripts # gcc specific flags; can be removed
CFLAGS		+= $(OPTFLAGS)
CFLAGS		+= -DLIBRARY -DVERSION=\"$(VERSION)\" # necessary C compiler flags
LDLIBS		+= -lm # libraries to link

# Install directories follow; installs everything in /usr/local by default:
prefix		?= /usr/local
libdir		?= $(prefix)/lib
includedir	?= $(prefix)/include

AOUT		= mathomatic # The name of the library test executable file to create.
LIB		= libmathomatic.a # The name of the symbolic math library file to create.
HEADERS		= mathomatic.h

OBJECTS		= globals.o am.o solve.o help.o parse.o cmds.o simplify.o \
		  factor.o super.o unfactor.o poly.o diff.o integrate.o \
		  complex.o complex_lib.o list.o gcd.o factor_int.o

all: $(AOUT)

lib $(LIB): lib.o $(OBJECTS)
	ar cr $(LIB) lib.o $(OBJECTS)
	ranlib $(LIB)

lib.o $(OBJECTS): $(HEADERS) ../includes.h ../license.h ../am.h ../externs.h ../complex.h ../proto.h ../altproto.h ../VERSION

$(OBJECTS): %.o: ../%.c
	$(CC) -c $(CFLAGS) $< -o $@

$(AOUT): test.o $(LIB)
	$(CC) $(LDFLAGS) test.o $(LIB) $(LDLIBS) -o $(AOUT)
	@echo ./$(AOUT) created.

install:
	$(INSTALL) -d $(libdir)
	$(INSTALL) -d $(includedir)
	$(INSTALL) -m 0644 $(LIB) $(libdir)
	$(INSTALL) -m 0644 $(HEADERS) $(includedir)
	@echo Mathomatic symbolic math library installed.

clean:
	rm -f *.o

flush: clean
	rm -f $(AOUT)
	rm -f *.a
