# This file is part of the MPFRCPP Library.
#
# Copyright (c) 2006-2007 Alexey V. Beshenov <bav.272304@gmail.com>.
#
# The MPFRCPP Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License as
# published by the Free Software Foundation; either version 2.1 of the
# License, or (at your option) any later version.
#
# The MPFRCPP Library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with the MPFRCPP Library; see the file COPYING.LIB. If
# not, write to the Free Software Foundation, Inc., 51 Franklin Street,
# Fifth Floor, Boston, MA 02110-1301, USA.

OPTIONS = -lmpfrcpp -lgmp -lmpfr --pedantic --std=c++98 -Wall
CC = g++

testdir = test/
exampledir = examples/

exampleprefix = example-
testprefix = test-

binpostfix = 

includedir = /usr/local/include
docdir = /usr/share/doc
libdir = /usr/local/lib

logfile = check.log

install :

	cd src/mpfrcpp; make; mv *.a $(libdir)

	rm -rf $(includedir)/mpfrcpp
	mkdir $(includedir)/mpfrcpp
	cp -r src/mpfrcpp/* $(includedir)/mpfrcpp

	rm -rf $(includedir)/nacre
	mkdir $(includedir)/nacre
	cp -r src/nacre/* $(includedir)/nacre

	rm -rf $(docdir)/mpfrcpp
	mkdir $(docdir)/mpfrcpp
	cp -r doc/* $(docdir)/mpfrcpp

check :

	$(CC) $(exampledir)fp_comparator.cpp -o $(exampleprefix)fp_comparator$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)native_complex.cpp -o $(testprefix)native_complex$(binpostfix) $(OPTIONS)
	$(CC) $(exampledir)quick_start.cpp -o $(exampleprefix)quick_start$(binpostfix) $(OPTIONS)
	$(CC) $(exampledir)round_modes.cpp -o $(exampleprefix)round_modes$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)std_complex.cpp -o $(testprefix)std_complex$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)constants.cpp -o $(testprefix)constants$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)initialization.cpp -o $(testprefix)initialization$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)special_functions.cpp -o $(testprefix)special_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)trigonometric_functions.cpp -o $(testprefix)trigonometric_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)hyperbolic_functions.cpp -o $(testprefix)hyperbolic_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)exponential_functions.cpp -o $(testprefix)exponential_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)logarithmic_functions.cpp -o $(testprefix)logarithmic_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)inverse_hyperbolic_functions.cpp -o $(testprefix)inverse_hyperbolic_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)inverse_trigonometric_functions.cpp -o $(testprefix)inverse_trigonometric_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)std_overloads.cpp -o $(testprefix)std_overloads$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)miscellaneous_functions.cpp -o $(testprefix)miscellaneous_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)integer_related_functions.cpp -o $(testprefix)integer_related_functions$(binpostfix) $(OPTIONS)
	$(CC) $(testdir)basic_arithmetic_functions.cpp -o $(testprefix)basic_arithmetic_functions$(binpostfix) $(OPTIONS)

	$(CC) $(exampledir)nacre_polynomial.cpp -o $(exampleprefix)nacre_polynomial$(binpostfix) $(OPTIONS)
	$(CC) $(exampledir)nacre_polynomial_roots.cpp -o $(exampleprefix)nacre_polynomial_roots$(binpostfix) $(OPTIONS)
	$(CC) $(exampledir)serialization.cpp -o $(exampleprefix)serialization$(binpostfix) $(OPTIONS)
	$(CC) $(exampledir)gauss-legendre.cpp -o $(exampleprefix)gauss-legendre$(binpostfix) $(OPTIONS)

	g++ -c $(testdir)separate_compilation_a.cpp > $(logfile)
	g++ -c $(testdir)separate_compilation_b.cpp >> $(logfile)
	g++ -c $(testdir)separate_compilation.cpp >> $(logfile)
	g++ -o $(testprefix)separate_compilation$(binpostfix) *.o -lmpfrcpp -lgmp -lgmpxx -lmpfr >> $(logfile)
	rm *.o

	./$(exampleprefix)fp_comparator$(binpostfix) >> $(logfile)
	./$(exampleprefix)quick_start$(binpostfix) >> $(logfile)
	./$(exampleprefix)round_modes$(binpostfix) >> $(logfile)
	./$(testprefix)native_complex$(binpostfix) >> $(logfile)
	./$(testprefix)std_complex$(binpostfix) >> $(logfile)
	./$(testprefix)constants$(binpostfix) >> $(logfile)
	./$(testprefix)initialization$(binpostfix) >> $(logfile)
	./$(testprefix)special_functions$(binpostfix) >> $(logfile)
	./$(testprefix)trigonometric_functions$(binpostfix) >> $(logfile)
	./$(testprefix)hyperbolic_functions$(binpostfix) >> $(logfile)
	./$(testprefix)exponential_functions$(binpostfix) >> $(logfile)
	./$(testprefix)logarithmic_functions$(binpostfix) >> $(logfile)
	./$(testprefix)std_overloads$(binpostfix) >> $(logfile)
	./$(testprefix)inverse_hyperbolic_functions$(binpostfix) >> $(logfile)
	./$(testprefix)inverse_trigonometric_functions$(binpostfix) >> $(logfile)
	./$(testprefix)miscellaneous_functions$(binpostfix) >> $(logfile)
	./$(testprefix)integer_related_functions$(binpostfix) >> $(logfile)
	./$(testprefix)basic_arithmetic_functions$(binpostfix) >> $(logfile)
	./$(exampleprefix)nacre_polynomial$(binpostfix) >> $(logfile)
	./$(exampleprefix)nacre_polynomial_roots$(binpostfix) >> $(logfile)
	./$(exampleprefix)serialization$(binpostfix) >> $(logfile)
	cd $(exampledir); ../$(exampleprefix)gauss-legendre$(binpostfix) >> $(logfile)
	./$(testprefix)separate_compilation$(binpostfix) >> $(logfile)

#	rm $(exampleprefix)*$(binpostfix) $(testprefix)*$(binpostfix)

clean :
	rm -f $(exampleprefix)*$(binpostfix) $(testprefix)*$(binpostfix)
	rm -f foobar.mpfr
	rm -f check.log
