# Makefile for the MATH distribution
#--------------------------------------------------------------------
#
# COMMON DEFINITIONS
#
include Common
#
# GLOBAL MAKEFILE VARIABLES
#
MATHNAME = math-$(VERSION)

#-----------------------------------------------------------------------
# TARGETS
#-----------------------------------------------------------------------

all: doc lib

.PHONY: all lib doc floppy backup log rpm dist install uninstall

.PHONY: clean distclean

lib:
	$(MAKE) -s -C src

doc:
	$(MAKE) -s -C doc

log:
	$(TEX) logfile

#-----------------------------------------------------------------------
# RPM package
#-----------------------------------------------------------------------
# Create a bogus source file and do nothing with it in the spec file.
# In this way we can build the library from the original directory
# (using the rcfile accordingly) and the arguments passed to ./configure
# will be used to build the RPM package.
#-----------------------------------------------------------------------

rpm: clean math.spec math.rcfile
	touch $(MATHNAME).tar.gz
	rpm -ba --rcfile math.rcfile -v math.spec 
	$(RM) $(MATHNAME).tar.gz rpm/*.rpm

.PHONY: math.spec math.rcfile

math.spec:
	sed s%@INCLUDEDIR@%$(includedir)%g < math.spec.in > math.spec

math.rcfile:
	sed s%@BUILDDIR@%`pwd`%g < math.rcfile.in > math.rcfile

#-----------------------------------------------------------------------
# Install and uninstall
#-----------------------------------------------------------------------

install: lib
	$(MAKE) -s -C src install

install-doc: doc
	$(MAKE) -s -C doc install

uninstall:
	@echo "Uninstalling MATH...";
	@$(MAKE) -s -C src uninstall
	@$(RM) -r /usr/doc/$(MATHNAME)

#-----------------------------------------------------------------------
# Administratrivia
#-----------------------------------------------------------------------
floppy: backup
	mount /mnt/floppy
	( cd .. ; cp math.tgz /mnt/floppy )
	( cd .. ; $(RM) math.tgz )
	umount /mnt/floppy

backup: distclean
	( cd .. ; tar cvzf math.tgz math )

afloppy: abackup
	mount /mnt/floppy
	( cd .. ; cp math.afio /mnt/floppy )
	( cd .. ; $(RM) math.afio )
	umount /mnt/floppy

abackup: distclean
	( cd .. ; find math -name \* | afio -G 9 -Zvo math.afio )

clean:
	@echo "Cleaning base directory..."
	@$(RM) *~ *.aux *.log *.dvi rpm/*.rpm rpm/*/*.rpm $(MATHNAME).tar.gz
	@$(MAKE) -s -C src clean
	@$(MAKE) -s -C tests clean
	@$(MAKE) -s -C doc clean

distclean: clean
	$(RM) config.* math.rcfile math.spec

dist: distclean
	( cd .. ; tar cvzf $(MATHNAME).tar.gz math )