#
# ***************************************************************
# *                  Tabular - SIMUSOL PROYECT                  *
# *                                                             *
# *   Table extension for SIMUSOL PROYECT, for use with:        *                
# *       +  C++ Mathematical Expression Toolkit Library        *
# *          which is located in URL:                           *
# *          http://www.partow.net/programming/exprtk/index.html*
# *          used in Siru/Simusol                               *
# *       +  SCEPTRE (System for Circuit Evaluation             *
# *          and Prediction of Transient Radiation Effects)     *
# *          http://alpha.fh-friedberg.de/iem/84.html           *
# *          used in Simusol                                    *
# *   The extension was developed by                            *
# *   Diego.Saravia@ututo.org, 2016                             * 
# *   and could be used in the same terms of the toolkit        *
# *   or every free license with copyleft needed.               *
# *   http://www.simusol.org                                    *
# ***************************************************************#
# This file is part of Tabular
#
#    Tabular is free software: you can redistribute it and/or modify
#    it under the terms of
#
#     1)the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    2) Any other free licence with copyleft recognized by the FSF
#
#    Tabular 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 General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Tabular.  If not, see <http://www.gnu.org/licenses/>.


# For use with:
# **************************************************************
# *         C++ Mathematical Expression Toolkit Library        *
# *                                                            *
# * Author: Arash Partow (1999-2017)                           *
# * URL: http://www.partow.net/programming/exprtk/index.html   *
# *                                                            *
# * Copyright notice:                                          *
# * Free use of the Mathematical Expression Toolkit Library is *
# * permitted under the guidelines and in accordance with the  *
# * most current version of the MIT License.                   *
# * http://www.opensource.org/licenses/MIT                     *
# *                                                            *
# **************************************************************

# Este Makefile es autonomo. El de tabular incluia ../makefile.inc y enlazaba
# contra ../libs/tabular.o, pero en tabular2 no existe ninguno de los dos: la
# biblioteca esta partida en modulos bajo ../ y el build principal es autotools.
# mem.h, time_mem.h y pathconv.h los instala mem_util en siru/local/include,
# y libmem_util en siru/local/lib: de ahi salen open_file(), filetype() y
# datetime(), que usa manual_lexer.c.

CC       ?= gcc
CXX      ?= g++
CFLAGS   ?= -std=c99 -O1 -g -fPIC -Wno-long-long
CXXFLAGS ?= -std=gnu++14 -O1 -g
# mem_util y exprtk salen de pkg-config. Si mem_util esta en un prefijo
# propio hay que decirselo:
#   export PKG_CONFIG_PATH=$HOME/svn/siru/local/lib/pkgconfig
MEM_CFLAGS = $(shell pkg-config --cflags mem_util)
MEM_LIBS   = $(shell pkg-config --libs   mem_util)
MEM_LIBDIR = $(shell pkg-config --variable=libdir mem_util)
comma := ,
MEM_RPATH  = $(if $(MEM_LIBDIR),-Wl$(comma)-rpath$(comma)$(MEM_LIBDIR))

# exprtk ya no viene adentro del paquete: es el paquete libexprtk-dev, que
# instala la unica cabecera en /usr/include. Tener una copia aca significaba
# mantenerla al dia a mano en cada proyecto que la usa.
EXPRTK_CFLAGS = $(shell pkg-config --cflags exprtk)

CPPFLAGS_ALL = -D_GNU_SOURCE -I. -I.. $(MEM_CFLAGS) $(EXPRTK_CFLAGS)

LIBSRC = cell.c header.c lines.c sequence.c tables.c view.c gnuplot.c \
         interpola.c table.c manual_lexer.c
LIBOBJ = $(LIBSRC:.c=.o)

all: exprtk_table
compila: exprtk_table

install:

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

exprtk_table: exprtk_table.cpp $(LIBOBJ) Makefile
	@pkg-config --exists exprtk || { echo "Falta exprtk: instalar libexprtk-dev"; exit 1; }
	$(CXX) $(CXXFLAGS) $(CPPFLAGS_ALL) -o $@ exprtk_table.cpp $(LIBOBJ) \
	  $(MEM_LIBS) $(MEM_RPATH) -lm

clean::
	rm -f *~ *.o exprtk_table_static exprtk_table

.PHONY: all compila install clean
