#  This is the GNUmakefile of the HPA Library.
#  Copyright (C)  2000    Daniel A. Atkinson
#  Copyright (C)  2004    Ivano Primi  <ivprimi@libero.it>    
#
#  Copying and distribution of this file, with or without modification,
#  are permitted in any medium without royalty provided the copyright
#  notice and this notice are preserved.

# Remark: This makefile requires the GNU version of make, also called
# 'gmake'. To obtain 'gmake' go to   http://directory.fsf.org   and start a
# search with the word 'gmake' or 'make'.

# Check for the presence of these programs on the system where you are going
# to build the library. If you can not find the GNU C compiler (gcc) you can
# use in place of it any other ANSI-compliant C compiler supporting the 
# options -c, -D, -g, -I, -O, -o, -L and -l.
# Remark: 'shtool' is shipped together with the source code. So, do not
# worry about its presence !
CC= gcc
AR= ar rcs
CP= ./shtool install -c -m 644
MKDIR= ./shtool install -d
INSTALL_BIN= ./shtool install -m 755
INSTALL_LIB= ./shtool install -m 644
ECHO= ./shtool echo 
RM= rm -f
RMDIR= rmdir

# If you want that the compiler puts the debug symbols into the object code,
# then define the following variable to -g.
DEBUG_MACRO=
#DEBUG_MACRO=  -Wall
#DEBUG_MACRO= -g 
#DEBUG_MACRO= -g -Wall

# If you want that the compiler produces an optimized object code, then
# define the following variable to something like -O (-O3 suggested for gcc).
#OPT_MACRO=
OPT_MACRO= -O3

# The value of MANTSIZE_MACRO defines the precision which the functions
# of the library will perform their computations with. The default
# value is 7, which guarantees a precision higher than the extended
# double one. However, you may increase the precision by setting a larger
# value for the size of the mantissa. Besides 7, you may use 11, 15, 19,
# 23, 27 and 31.
# Remark: The HPA library defines its own numeric type, called 'xpr'.
#         2 x (XMANTISSA_SIZE + 1) will be the size (in bytes) of
#         a variable of type 'xpr'. Then, if you choose an higher value
#         for MANTSIZE_MACRO, you will obtain not also an higher precision
#         in computations but also a bigger consumption of memory and 
#         more time needed to perform your computations. So, the next value
#         must be chosen carefully, according to your needs and to the
#         power of your machine.
MANTSIZE_MACRO = -DXMANTISSA_SIZE=7
#MANTSIZE_MACRO= -DXMANTISSA_SIZE=11 
#MANTSIZE_MACRO= -DXMANTISSA_SIZE=15
#MANTSIZE_MACRO= -DXMANTISSA_SIZE=19
#MANTSIZE_MACRO= -DXMANTISSA_SIZE=23
#MANTSIZE_MACRO= -DXMANTISSA_SIZE=27
#MANTSIZE_MACRO= -DXMANTISSA_SIZE=31

# Root directory of the installation
PREFIX=/usr/local
#PREFIX=/opt
#PREFIX=/usr
#PREFIX=$(HOME)

# BELOW THIS LINE YOU SHOULD NOT CHANGE ANYTHING

# BINDIR defines the (sub)directory of the system where the 'hpaconf'
# program (see README_3.0) will be installed; of course, you can change
# this value but you must know what you are doing.
# Moreover, if $(PREFIX)/bin is not present in the searching path of
# the executable files (i.e. it is not present in the list 
# specified by the PATH environment variable), then you will have to
# add $(PREFIX)/bin to the list of directories of the PATH environment
# variable.
BINDIR= $(PREFIX)/bin
# INCLUDEDIR defines the (sub)directory of the system where the include files
# provided with this library will be installed; of course, you can change
# this value but you must know what you are doing.
INCLUDEDIR= $(PREFIX)/include
# LIBDIR defines the (sub)directory where the file containing the object code
# of the library will be placed. The library will be created in a static
# form. You can change the location defined by LIBDIR but you must know
# what you are doing. 
LIBDIR= $(PREFIX)/lib
# DOCDIR defines the (sub)directory where will be placed the files
# containing the text of the license under which this library is distributed
# and the files of advertisement and help. Even this location can be redefined.
DOCDIR= $(PREFIX)/doc/hpalib

VERSION = 0.8.2

CFLAGS = -c $(DEBUG_MACRO) $(OPT_MACRO) $(MANTSIZE_MACRO)

# Include files
HEADERS		= ./src/xpre.h

# Source files
SRCS		= ./src/atox.c ./src/constant.c ./src/prxpr.c ./src/sfmod.c ./src/shift.c ./src/xadd.c ./src/xchcof.c ./src/xdiv.c ./src/xevtch.c ./src/xexp.c ./src/xfmod.c ./src/xfrac.c ./src/xhypb.c ./src/xivtrg.c ./src/xlog.c ./src/xmul.c ./src/xneg.c ./src/xprcmp.c ./src/xpwr.c ./src/xsqrt.c ./src/xtodbl.c ./src/xtoflt.c ./src/xtrig.c

#Doc files
DOCS		= BUGS Changelog INSTALL NOWARRANTY README ./doc/COPYING.LIB ./doc/manual

#Object files
OBJECTS		= $(SRCS:.c=.o)

# Byteord source file
BYTEORD_SRC	= byteord.c

# Byteord exec file
BYTEORD		= byteord 

#library file
LIBNAME		= libhpa.a

#hpaconf is the program that, once the library will have been installed,
#will help you to compile with and link against the HPA library (see 
#the file README_3.0 for its use).
HPACONF		= hpaconf

.PHONY :  all .depend install clean clobber uninstall

all : clobber .depend $(LIBNAME) $(HPACONF)

.depend:
	$(CC) $(BYTEORD_SRC) -o $(BYTEORD)
	./$(BYTEORD) 
	$(CC) -M $(CFLAGS) $(SRCS) > .depend

ifeq ($wildcard .depend,.depend)
include .depend
endif

$(LIBNAME) : $(OBJECTS)
	$(AR) $(LIBNAME) $^

$(HPACONF) :
	$(CC) -g -DVERSION="\"$(VERSION)\"" -DIPATH="\"-I$(PREFIX)/include\"" -DLPATH="\"-L$(LIBDIR)\"" ./hpaconf.c -o $(HPACONF)

install : all
	$(MKDIR) $(BINDIR)
	$(MKDIR) $(LIBDIR)
	$(MKDIR) $(INCLUDEDIR)
	$(MKDIR) $(DOCDIR)
	$(CP) $(DOCS)    $(DOCDIR)
	$(CP) ./GNUmakefile $(DOCDIR)
	$(CP) $(HEADERS) $(INCLUDEDIR)
	$(INSTALL_LIB)   $(LIBNAME) $(LIBDIR)
	$(INSTALL_BIN)   $(HPACONF) $(BINDIR)

clean :
	$(RM) $(OBJECTS)
	$(RM) $(BYTEORD)

clobber : clean
	$(RM) .depend
	$(RM) $(LIBNAME)
	$(RM) $(HPACONF)

uninstall :
	$(RM)    $(DOCDIR)/*
	$(RM)    $(INCLUDEDIR)/xpre.h
	$(RM)    $(LIBDIR)/$(LIBNAME)
	$(RM)    $(BINDIR)/$(HPACONF)
	$(RMDIR) $(DOCDIR)
	@$(ECHO) "I have not removed the directories $(PREFIX), $(BINDIR),"
	@$(ECHO) "$(LIBDIR), $(PREFIX)/include and $(PREFIX)/doc."
	@$(ECHO) "If you may and want to do it, do it yourself !"
