#
# **************************************************************
# *                  SIMUSOL PROYECT                           *
# *                                                            *
# *         simpack o simusol-pack for SIMUSOL                                    *
# *                                                            *
# *                                                            *
# *   Developed by                                             *
# *   Diego.Saravia@gmail.com, 2016                            *
# *   and could be used with GPL                               *
# *   or every free license with copyleft needed.              *
# *   http://www.simusol.org                                   *
# **************************************************************

# This file is part of simusol-pack
#
#    simusol-pack is free software: you can redistribute it and/or modify
#    it under the terms of 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.
#
#    Table 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 Table.  If not, see <http://www.gnu.org/licenses/>.


#PREFIX=/usr/local

# para que no ejecute el primer objetivo de makefile.lib
all:

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)

# SI NO ESTA BAJAR DEL SITIO 
ifneq ($(shell $(shellpath) test -e  $(PREFIXMLIB) && echo -n yes),yes)
    $(info  ADVERTENCIA makefile.lib de summapack no esta instalada)
    ifeq ($(shell $(shellpath) test x"$(VEROID)" = x0 && echo -n yes),yes)
	   PREFIXMLIB=$(DESTDIR)/usr/local
          else
           PREFIXMLIB=$(DESTDIR)$(HOME)
	endif
	$(shell $(shellpath) wget --no-check-certificate -P http://summapack.org/downloads/makefile.lib  $(PREFIXMLIB)/share/summapack/data/makefile.lib); echo 0;
	$(shell $(shellpath) chmod a+r $(PREFIXMLIB)/share/summapack/data/makefile.lib); echo 0;
endif

$(info MAKELIB: ${PREFIXMLIB})
ifneq ("$(wildcard $(PREFIXMLIB)/share/summapack/data/makefile.lib)","")
  include $(PREFIXMLIB)/share/summapack/data/makefile.lib
endif
$(info MAKELIB: ${PREFIXMLIB})

#include share/summapack/data/makefile.lib
### otros que usen: poner el path de sumapack completo


#este paquete debe ser independiente de todo, si bien se  instala normalemente con el simusol-make

#NAME=simusol-summapack
#VERSION=0.1


#STABLE=last
#STABLE=UNSTABLE

#BASETMP := $(shell $(shellpath) mktemp -d |sed -e's/\n//'|sed -e's/^\/tmp\///')
# con := permanece cte
$(info BASETMP: ${BASETMP}) 


SERVERSUBIR=simusol.org
SERVERDIR=/var/www/simusol.org/public_html/downloads
SERVERUSER=www-data

$(info SERVERSUBIR: ${SERVERSUBIR})
$(info SERVERDIR: ${SERVERDIR})
$(info SERVERUSER: ${SERVERUSER})

$(info BINFILES $(BINFILES))
$(info IBINFILES $(IBINFILES))
$(info SHAREFILES $(SHAREFILES))
$(info ISHAREFILES $(ISHAREFILES))
$(info ISHAREDIRS $(ISHAREDIRS))
$(info ETCFILES $(ETCFILES))
$(info IETCFILES $(IETCFILES))
$(info IPKGFILES $(IPKGFILES))


#DISTRO=$(shell bin/distro.sh)   si no esta instalado no funcionara
#$(info DISTRO $(DISTO))

$(info DESTDIR $(DESTDIR) PREFIX $(PREFIX))


#$(SUDO) no ponemos sudo, que se instale normalmente usando sudo make o root o su o  falle
# esta comodidad la dejamos para make de mas nivel
# para que no protesten paquetes de otras distros


#$(SUDO) install makefile.lib  $(PREFIX)/share/simusol
#	$(call copytree,/tmp/dist/${NAME}-${VERSION}/,,$(SHAREDIRSRC),$(BINDIRSRC),$(PKGDIRSRC),$(ETCDIRSRC),/tmp/dist/${NAME}-${VERSION}/) 

#curdir es builtin

# DESTDIR=/tmp/$(BASETMP)
installdist: clean
	echo "PACKAGE DISTRIBUTION FILE ${PACKV}-${VERSION}-AI.tgz (architecture independent)"
	rm -rf /tmp/$(BASETMP) ; 
	mkdir -p /tmp/$(BASETMP) ;
	$(call copytree, /tmp/${BASETMP}$(PREFIX), /tmp/${BASETMP},,$(PREFIX)) 
	cd  /tmp/${BASETMP}; tar -c . | gzip -n> $(CURDIR)/../${PACKV}-${VERSION}-AI.tgz
	md5sum  ../${PACKV}-${VERSION}-AI.tgz>../${PACKV}-${VERSION}-AI.tgz.md5.


#if dist sudo=
# pkgfiles deben ser instaladas en share para que se las coloque en la pc objeto
# y en el raiz del paquete para poder usar el makefile y quiene lo use pueda ver las licencias e instrucciones

preparelocal:

# ojo ifeq para todo el make
#ifeq ($(UUU),0)
#                $(error No corrio como root, salir)
#endif
# esto solo funciona en paquete summapack, por eso va aca
# si no es root funciona dando errores, a menos que exista un DESDIR, entonces puede funcionar ok
install:
	echo install de exprtkpack
	$(call copytree,$(DESTDIR)$(PREFIX),$(DESTDIR),,$(DESTDIR)$(PREFIX))
	mandb >/dev/null
	echo fin instalacion exprtkpack

# create full documentantion, from that help routines to .sh y .pl and infofiles, and html pages, and pdf
# form help routines to man

#${DOWNLOAD}:
#	sudo mkdir -p ${DOWNLOAD}
#	sudo chmod -R a+w ${DOWNLOAD}
#	sudo chmod -R a+r ${DOWNLOAD}

# sera medio al pedo sin sudo???? el chmod, no se puede
# download si no esta instalado summapack va a HOME/var/cache/summapack
# aqui instalando summapack
# solo usar si el paquete es summapack




updateexprtk:  exprtkhpp
	cp $(DOWNLOAD)/exprtk.hpp share/exprtkpack/data
