#
# ***************************************************************
# *                  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/>.

INSTALL_PROGRAM=install
DESTDIR=
PREFIX=/usr/local




ifeq ($(MULTIARCH),)
  MULTIARCHMM=lib64/
 else
  MULTIARCHMM=lib/$(MULTIARCH)/
endif
$(info MULTIARCH $(MULTIARCHMM))
libdir=$(MULTIARCHMM)

includedir=include/
#PREFIX va en configure

all: all1


# ojo con ..
define findfirstSB
$(shell $(shellpath) if test -s ../$1 ; then \
                   echo ..;\
                 elif test -s ~/$1 ; then \
                    echo ~;\
                 elif test -s /usr/local/$1 ; then \
                   echo /usr/local;\
                 elif  test -s /usr/$1 ; then \
                    echo /usr;\
                 fi;)
endef
PREFIXMLIB=$(call findfirstSB,share/summapack/data/makefile.lib)
$(info MAKELIB: ${PREFIXMLIB}) 
include $(PREFIXMLIB)/share/summapack/data/makefile.lib
$(info MAKELIB FIN) 




$(info  DESTDIR ${DESTDIR} PREFIX ${PREFIX})

include ../makefile.inc



#	$(INSTALL_PROGRAM)  libtabular.so.$(LIBVER) $(DESTDIR)$(PREFIX)/$(libdir)/libtabular$(LIBMAYVER).so.$(LIBVER); test 0 = 0;
install:
	mkdir -p $(DESTDIR)$(PREFIX)/$(libdir); test 0 = 0;
	mkdir -p $(DESTDIR)$(PREFIX)/$(includedir); test 0 = 0;
	$(INSTALL_PROGRAM)  libtabular.so.$(LIBVER) $(DESTDIR)$(PREFIX)/$(libdir); test 0 = 0;
	$(INSTALL_PROGRAM)  simusol_table.h $(DESTDIR)$(PREFIX)/$(includedir)tabular$(LIBMAYVER).h; test 0 = 0;
	chmod a-x $(DESTDIR)$(PREFIX)/$(includedir)tabular$(LIBMAYVER).h; test 0 = 0;
	ln -fs  libtabular.so.$(LIBVER) $(DESTDIR)$(PREFIX)/$(libdir)libtabular.so ; test 0 = 0;
	ln -fs  libtabular.so.$(LIBVER) $(DESTDIR)$(PREFIX)/$(libdir)libtabular.so.$(LIBMAYVER); test 0 = 0;

#este anterio lo crea ldconfig, pq es el soname supongo, pero lo pongo pa que no proteste rpmlint que no lo ve
# y que debo indicarlo para que lo borre si lo pone ldconfig
#

#	ln -fs  libtabular.so.$(LIBVER)  $(DESTDIR)$(PREFIX)/$(libdir)libtabular$(LIBMAYVER).so; test 0 = 0;
#ldconfig  en rpmbuild se hace make install


installvie: /usr/local/lib/libtabular.so.1.0.1

############# ojo tabular.h cambiar

#/usr/local/lib/libtabular.so.1.0.1:  libtabular.so.1.0.1  # override target in makeile.inc
#	install  libtabular.so.1.0.1 /usr/local/lib
#	install  simusol_table.h /usr/local/include/tabular.h
#	ln -fs   libtabular.so.1.0.1  /usr/local/lib/libtabular.so
#	ln -fs   libtabular.so.1.0.1  /usr/local/lib/libtabular.so.1


#ldconfig  en rpmbuild se hace make install

abs2rel.o:
	$(COMPILERC) $(OPTIONS)  $(RPMFLAGS)  -c  -fPIC -g -o abs2rel.o abs2rel.c #$(LINKER_OPT)


rel2abs.o:
	$(COMPILERC) $(OPTIONS)  $(RPMFLAGS)  -c  -fPIC -g -o rel2abs.o rel2abs.c #$(LINKER_OPT)


simusol_table.o :simusol_table.c simusol_table.h  simusol_table_internal.h  Makefile
	$(COMPILERC) $(OPTIONS)  $(RPMFLAGS)    -c  -fPIC -g -o simusol_table.o simusol_table.c #$(LINKER_OPT)

libtabular.a : abs2rel.o rel2abs.o simusol_table.o 
	$(AR) rcs libtabular.a  simusol_table.o abs2rel.o  rel2abs.o


all1:  libtabular.so.$(LIBVER)

libtabular.so.$(LIBVER): simusol_table.o abs2rel.o rel2abs.o
	$(COMPILERC) $(OPTIONS) $(RPMFLAGS) -fPIC  -g -shared -Wl,-soname=libtabular.so.$(LIBMAYVER) -o  libtabular.so.$(LIBVER)  simusol_table.o abs2rel.o rel2abs.o



# poner libtabular


#strip_bin :
#	@for f in $(BUILD_LIST) $(BUILD_LIST_C); do if [ -f $$f ]; then strip -s $$f; echo $$f; fi done;

#valgrind :
#	@for f in $(BUILD_LIST) $(BUILD_LIST_C); do \
#		if [ -f $$f ]; then \
#			cmd="valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=$$f.log -v ./$$f"; \
#			echo $$cmd; \
#			$$cmd; \
#		fi done;

clean::
	rm -f core.* *~ *.o *.bak *stackdump gmon.out *.gcda *.gcno *.gcnor *.gch  libtabular.so.* libtabular.a
