#
# **************************************************************
# *                  SIMUSOL PROYECT                           *
# *                                                            *
# *         sceptre-simusol for SIMUSOL                        *
# *                                                            *
# *                                                            *
# *   Developed by                                             *
# *   Dolores Alia  and Diego.Saravia@gmail.com                *
# *   2017                                                     *
# *   and could be used with GPL                               *
# *   or every free license with copyleft needed.              *
# *   http://www.simusol.org                                   *
# **************************************************************
# Requiere la instalacion PREVIA de summapack
# This file is part of Simusol proyect
# 
#
#    dia-simusol 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/>.

# antes de lib
all: compile
#install  # mejor que install se especifique adrede



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

cpmakefilelib:
	cp ../summapack/share/summapack/data/makefile.lib ../tabular/share/summapack/data/makefile.lib 

PREFIXMLIB=$(call findfirstSB,share/summapack/data/makefile.lib)

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

#include /usr/local/share/summapack/data/makefile.lib
# buscar donde esta!!!


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

#################################################################33
# para hacer install sobre un directorio
#DBP=/tmp/BDsceptresimusol
#DBP=


# PACKV corrije, si el nombre tiene - lo pasa a _, no es conveniente nombres de paquetes con - en las tgz o tar.gz
# tgz se usa en paquetes AI o SRC/BIN/DOC/DEV, AI es de arquitectura independiente, si no lo es se divide en cuatro SRC BIN DEV y DOC
DIRICON=$(PACK)



# SIN DBP instala, con DBP crea arbol para distribucion 

# USO COMO TARGZ DESARROLLO (estandar) (make + sudo make install)
# compilacion instalacion a mano, uso como desarrollador
 DBP=
 PREFIX = ${DBP}/usr/local
 SRCDIR=src


# USO COMO TARGZ PARA DISTRIBUCION (otros lo instalen e instalen fuentes) (sudo make install)
# para instalar a mano completo desde make, sin paquete
# DBP=
# PREFIX = ${DBP}/usr/local
# SRCDIR=${PREFIX}/src


# USO COMO TARGZ PARA DISTRIBUCION (otros lo instalen e instalen con fuentes, en su HOME sin sudo ) (make, make install)
# para instalar a mano completo desde make, sin paquete
# DBP=
# PREFIX = /home/USER
# SRCDIR=${PREFIX}/src


# USO COMO TARGZ PARA DISTRIBUCION (otros lo instalen e instalen sin fuentes, en su HOME sin sudo ) (make, make install)
# para instalar a mano completo desde make, sin paquete
# DBP=
# PREFIX = /home/USER
# SRCDIR=src

# PAQUETE DISTRO QUE COMPILA AL INSTALAR (CON FUENTES), POSTINST (Recomendado) o sin ejecutar POSTINST como paquete fuente
# para crear paquete fuente  para distro no compilado 
# DBP=/tmp/BDsceptresimusol
# PREFIX = ${DBP}/usr
#  SRCDIR=${PREFIX}/src

# PAQUETE DISTRO CON BINARIOS (SIN FUENTES), PRECOMPILADO (forma estandar, pero inconveniente en eete caso, obliga a tener paquetes por arquitectura)
# Se debe hacer por separado PAQUETE DISTRO FUENTE
# para crear paquete para distro no precompilado, (no  paquete fuente, para compilar con postinst)
# DBP=/tmp/BDsceptresimusol
# PREFIX = ${DBP}/usr
# SRCDIR=src

# HACER INSTALA FUENTES Y NO COMPILADOS???

#Nota: el sudo make install solo compila, si SRCDIR != DIR y solo instala binarios si estan compilados en  SRCDIR




#include  share/sceptre-simusol/COMPILE.LIB
FC      = gfortran
FFLAGS  = -fno-automatic  -finit-local-zero -O -W -Wall -Wextra -g
# salvo etc en home

compile:	
	cd ${SRCDIR}/$(PACK)/auxpro;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}" 
	cd ${SRCDIR}/$(PACK)/phase1;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}" 
	cd ${SRCDIR}/$(PACK)/phase2;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}"
	cd ${SRCDIR}/$(PACK)/extras;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}" 

IDIRS   = ${BINDIR} ${SHAREDIRSCEPTRE}  ${ETCDIR} ${SHAREDIRSCEPTRE}/examples  ${SHAREDIRSCEPTRE}/data ${SHAREDIRSCEPTRE}/launchers ${SHAREDIRSCEPTRE}/pkgroot

ISRCDIRS = ${SRCDIR}/auxpro ${SRCDIR}/phase1 ${SRCDIR}/phase2 ${SRCDIR}/extras

#ILIBDIRS =  ${LIBDIR}



ISCRIPTFILES = scripts/*


# install -d o -D ?   -D hace todos los dirs? RTA:   con -d los hace
#  sacado de muchos installecho 0;

tests:
	rm -f /tmp/sceptretest/LOG
	EF=`ls share/sceptre-simusol/examples/*.d`;\
	mkdir -p /tmp/sceptretest;\
	cd /tmp/sceptretest; \
	for FILE in $${EF} ; do \
	echo $${FILE};\
	        echo                                                  >> LOG ;\
	        echo ======================================= $${FILE} >> LOG ;\
		sceptre  $(CURDIR)/$${FILE} | tee -a LOG | grep -P "(ended|aborted|deleted|error)";\
	done;

#Fortran runtime error
# nota el caso 3 se arregla con sudo




BINDIRSRC=bin/
ETCDIRSRC=etc/
SHAREDIRSRC=share/
SRCDIRSRC=src/
LIBDIRSRC=lib/


IBINFILES=$(shell $(shellpath) find  -type f -not -wholename '*.svn*'| grep ^\./$(BINDIRSRC) | grep -v '^\#' | grep -v '~$$')

ISHAREFILES=$(shell $(shellpath) find  -type f -not -wholename '*.svn*'| grep ^\./$(SHAREDIRSRC) | grep -v '^\#' | grep -v '~$$')

ILIBFILES=$(shell $(shellpath) find  -type f -not -wholename '*.svn*'| grep ^\./$(LIBDIRSRC) | grep -v '^\#' | grep -v '~$$')

IETCFILES=$(shell $(shellpath) find  -type f -not -wholename '*.svn*'| grep ^\./$(ETCDIRSRC) | grep -v '^\#' | grep -v '~$$')

IPKGFILES =$(shell /bin/ls -l $(PKGDIRSRC) 2>/dev/null | grep '^-' |  awk -F' ' '{print $$9}' | grep -v '^\#' | grep -v '~$$'| grep -v 'listado.ls')



ISHAREDIRS=$(shell $(shellpath) find  -type d -not -wholename '*.svn*'| grep ^\./$(SHAREDIRSRC) )
ILIBIRS=$(shell $(shellpath) find  -type d -not -wholename '*.svn*'| grep ^\./$(LIBDIRSRC) )

IFILDESKTOP=$(shell find  -type f -not -wholename '*.svn*'| grep  ".desktop" )   # launchers/

ISRCFILES=$(shell $(shellpath) find  -type f -not -wholename '*.svn*'| grep ^\./$(SRCDIRSRC) | grep -v '^\#' | grep -v '~$$')
ISRCDIRS=$(shell $(shellpath) find  -type d -not -wholename '*.svn*'| grep ^\./$(SRCDIRSRC) )

$(info IBINFILES $(IBINFILES))
$(info ISHAREFILES $(ISHAREFILES))
$(info ISHAREDIRS $(ISHAREDIRS))
$(info ILIBFILES $(ILIBFILES))
$(info ILIBDIRS $(ILIBDIRS))
$(info IETCFILES $(IETCFILES))
$(info IPKGFILES $(IPKGFILES))
$(info ISRCFILES $(ISRCFILES))
$(info ISRCDIRS $(ISRCDIRS))





define installdirs
	@echo D Ultimoarg============= $1 == $2 == $3 == $4 == $5
	@for FILE in $1  ; do \
	   if test x"$$FILE" != x"." ; then \
	    FILEP=`echo -n $$FILE|sed -e  's/\.\/$3//' ` ;\
	    install  -d $2/$$FILEP;\
	    echo "D:$5/$$FILEP" >> listado.ls ;\
	    echo "D:$5/$$FILEP"  ;\
	   fi;\
	done;
endef


define installfiles
	@echo F Ultimoarg=========== $1 == $2 == $3 == $4 == $5 == $6
	@for FILE in $1 ; do \
	   if test x"$$FILE" != x"." ; then \
	    FILEP=`echo -n $$FILE|sed -e  's/\.\/$3//' ` ;\
	    if test x"$5" = x ; then \
	       FILEC=$$FILE; \
	      else \
               FILEC=`echo $$FILE|  sed -e  's/^\./\.\/$5/'`; \
	    fi; \
	    install $$FILEC  $2/$$FILEP;\
	    echo "A:$6/$$FILEP" >> listado.ls ;\
	    echo "A:$6/$$FILEP"  ;\
	   fi;\
	done;
endef


ETCROOT=/
BINDIR=bin
ETCRES=etc
ETCDIR=$(ETCROOT)etc
SHAREDIR=share
PKGDIR=share/sceptre-simusol/pkg-data



#	$(call copytree,$(PREFIXDIA),$(ETCDIR),$(SUDO), prefixsintmp)
define copytree
	echo copytree $1 - $2 - $3 - $4
	echo SHARE $(SHAREDIRSRC)
	$3 mkdir -p $1/${SHAREDIR}
	$(call installdirs,${ISHAREDIRS},$1,,$3,$4)
	$(call installfiles,${ISHAREFILES},$1,,$3,,$4)
	echo LIB $(LIBDIRSRC)
	$3 mkdir -p $1/${LIBDIR}
	$(call installdirs,${ILIBDIRS},$1,,$3,$4)
	$(call installfiles,${ILIBFILES},$1,,$3,,$4)
	echo BIN $(BINDIRSRC)
	$3 mkdir -p $1/${BINDIR}
	$(call installfiles,${IBINFILES},$1,,$3,,$4)
	echo PKG $(PKGDIRSRC)
	$3 mkdir -p $1/${PKGDIR}
	$(call installfiles,${IPKGFILES},$1/${PKGDIR},,$3,,$4/${PKGDIR})
	echo ETC $(ETCDIRSRC)
	if test x"${IETCFILES}" != x ; then \
	        $3 mkdir -p $2/etc ;\
	fi;
	$(call installfiles,${IETCFILES},$2,,$3,,)
endef

#	$(call installdirs,${ISRCDIRS},$1,,$3,$4)
#	$(call installfiles,${ISRCFILES},$1,,$3,,$4)



BINFILES=${SRCDIR}/$(PACK)/phase1/sceptre1 ${SRCDIR}/$(PACK)/auxpro/ngp_gnu

# VERE postinstall
LIBFILES=${SRCDIR}/$(PACK)/phase2/libsceptre.a ${SRCDIR}/$(PACK)/phase2/sceptre2.o ${SRCDIR}/$(PACK)/auxpro/libsceptreaux.a  ${SRCDIR}/$(PACK)/extras/simusoltable.o ${SRCDIR}/$(PACK)/extras/radiacion.o



# si SCRDIR=src se entiende que no se quiere instalar, dado que no tiene sentido instalrse sobre si misma

install:
	$(call copytree,$(PREFIX),$(ETCDIR),$(SUDO),$(PREFIX))
ifneq (${SRCDIR},src)
	 $(call installdirs,${ISRCDIRS},$(PREFIX),,$(SUDO))
	 $(call installfiles,${ISRCFILES},$(PREFIX),,$(SUDO),)
endif
	$(call listado,)
	$(call mexec,)
	$(PREFIX)/bin/postinst ${PREFIX} NOMAKE
	@echo "installation finished"



#for FILE in ${BINFILES} ; do \
#		FILEP=`basename  $${FILE}`;\
#		install -m 755  $${FILE} ${PREFIX}/${BINDIR}/$${FILEP}  ;\
#		echo "A:${PREFIX}/${BINDIR}/$${FILEP}" >> listado.ls ; \
#		echo "A:${PREFIX}/${BINDIR}/$${FILEP}" ; \
#		done;
#	for FILE in ${LIBFILES} ; do \
#		FILEP=`basename  $${FILE}`;\
#		install -m 644  $${FILE} ${PREFIX}/${LIBDIR}/$${FILEP}  ;\
#		echo "A:${PREFIX}/${LIBDIR}/$${FILEP}" >> listado.ls ; \
#		echo "A:${PREFIX}/${LIBDIR}/$${FILEP}"  ; \
#		done;


#NOMAKE para que no compile como sudo
#si debe compilar en postinst de un paquete, del tipo de simusol, Arquitectura independiente pero con binarios.
# usuarios compilan# se hace esto para no distribuir binaris, para simusol dond eusa el fortran no tiene sentido distriburio binarios


#	chown ${USERBASE}:${USERBASE} listado.ls 
#	install -d ${PREFIX}/${PACK}/ls
#	mv  ${PREFIX}/${PACK}/ls/${PACK}.ls ${PREFIX}/${PACK}/ls/${PACK}.ls.viejo 2>/dev/null; exit 0;
#	install listado.ls ${PREFIX}/${PACK}/ls/${PACK}.ls



# no se puede hacer clean pq compila

installdist:
	echo "PACKAGE DISTRIBUTION FILE ${PACKV}-${VERSION}-AI.tgz (architecture independent)";
	rm -rf /tmp/$(BASETMP) ; 
	mkdir -p /tmp/$(BASETMP) ;
	mkdir -p /tmp/$(BASETMP)/etc ;
	mkdir -p /tmp/$(BASETMP)$(PREFIX) ;
	mkdir -p /tmp/$(BASETMP)$(PREFIX)/share/sceptre-simusol/ls;
	$(call copytree,/tmp/${BASETMP}$(PREFIX),/tmp/${BASETMP}$(ETCRES),,$(PREFIX))
	$(call listado,/tmp/${BASETMP})
	$(call mexec,/tmp/${BASETMP})
	cd  /tmp/${BASETMP}; tar -c . | gzip -n> $(CURDIR)/../${PACKV}-${VERSION}-AI.tgz
	md5sum  ../${PACKV}-${VERSION}-AI.tgz>../${PACKV}-${VERSION}-AI.tgz.md5.


#	for FILE in ${BINFILES} ; do \
#		FILEP=`basename  $${FILE}`;\
#		install -m 644  $${FILE}  /tmp/${BASETMP}${PREFIX}/${BINDIR}/$${FILEP}  ;\
#		echo "A:${PREFIX}/${BINDIR}/$${FILEP}" >> listado.ls ; \
#		echo "A:${PREFIX}/${BINDIR}/$${FILEP}" ; \
#		done;
#	for FILE in ${LIBFILES} ; do \
#		FILEP=`basename  $${FILE}`;\
#		install -m 644  $${FILE}  /tmp/${BASETMP}${PREFIX}/${LIBDIR}/$${FILEP}  ;\
#		echo "A:${PREFIX}/${LIBDIR}/$${FILEP}" >> listado.ls ; \
#		echo "A:${PREFIX}/${LIBDIR}/$${FILEP}"  ; \
#		done;


#if test x${DBP} != x ; then \
#fi
#	 install -s -m 755 src/auxpro/asa            ${BINDIR}
#        no se lo crea en el momento de la instalacion sino en la ejecucion
#        install -m 644    ${SRCDIR}/phase2/sceptre2.o        ${LIBDIR};\
#	   echo "A:${LIBDIR}/sceptre2.o" >> listado.ls ; \


#usar listado
uninstallXXXXXX:
	@rm -fv ${BINDIR}/sceptre1 
	@rm -fv ${BINDIR}/ngp_gnu
#	@rm -fv ${BINDIR}/asa
	@rm -fv ${BINDIR}/sceptre
	@rm -fv ${BINDIR}/sceptre-simusol-install
	@rm -fv ${BINDIR}/ngp
	@rm -fv ${LIBDIR}/sceptre2.o
	@rm -fv ${LIBDIR}/libsceptre.a
	@rm -fv ${LIBDIR}/libsceptreaux.a
	@rm -rf ${PREFIX}/share/sceptre-simusol  ##### REGLA, nunca rm -rf con solo variables
	@rm -fv ${ETCDIR}/ngp.rc
	@if test ${SRCDIR} != src ; then \
	    rm -rf  ${SRCDIR}/auxpro; \
	    rm -rf  ${SRCDIR}/phase1; \
	    rm -rf  ${SRCDIR}/phase2; \
	    rm -rf  ${SRCDIR}/extras; \
	fi 
	@rmdir ${SRCDIR}
	@echo "UN-installation finished"

clean::
	rm -f listado.ls
	rm -rf *~
	cd ${SRCDIR}/$(PACK)/auxpro; ${MAKE} $@ 
	cd ${SRCDIR}/$(PACK)/phase1; ${MAKE} $@
	cd ${SRCDIR}/$(PACK)/phase2; ${MAKE} $@
	cd ${SRCDIR}/$(PACK)/extras; ${MAKE} $@

nonbinclean:
	rm -f listado.ls
	rm -rf *~
	cd ${SRCDIR}/$(PACK)/auxpro; ${MAKE} $@ 
	cd ${SRCDIR}/$(PACK)/phase1; ${MAKE} $@
	cd ${SRCDIR}/$(PACK)/phase2; ${MAKE} $@
	cd ${SRCDIR}/$(PACK)/extras; ${MAKE} $@

#dist: ../$(DISTDIR).tar.gz
#../$(DISTDIR).tar.gz: clean $(FILES)
#	mkdir -p /tmp/basura
#	rm -rf /tmp/basura/*
#	mkdir -p /tmp/basura/$(DISTDIR)
#	for FILE in ${DIRS} ; do \
#	  mkdir  /tmp/basura/$(DISTDIR)/$${FILE};\
#	done;
#	for FILE in ${FILES} ; do \
#	  cp $${FILE} /tmp/basura/$(DISTDIR)/$${FILE};\
#	done;
#	ACTDIR=`pwd`;\
#	cd /tmp/basura; tar cvzf $${ACTDIR}/../${DISTDIR}.tar.gz $(DISTDIR); 
#	md5sum ../$(DISTDIR).tar.gz > ../$(DISTDIR).tar.gz.md5; \
#       ls -l ../$(DISTDIR).tar.gz*;  \
#
## no necesariamente binaria, es la distribucion ya ubicada en el arbol del host
#bindist: install
#	if test x${DBP} = x ; then \
#	   echo "Defina DBP par poder usar, preponderantemente en \tmp"; \
#	   exit 1; \
#	fi
#	echo "CUIDADO BORRA todo ${DBP}"
#	rm -r ${DBP};  ########## CUIDADO NO SACAR PREGUNTA ANTERIOR
#	$(MAKE) install
#	if test ${SRCDIR} != src ; then \
#	   NAME=$(DISTDIR)-DistroS; \
#	 else \
 #          NAME=$(DISTDIR)-DistroB; \
#	fi ;\
#	DIRO=`pwd`;\
#	echo "ARCHIVO TAR.GZ CREADO $${DIRO}/$${NAME}.tar.gz";\
#	cd ${DBP}; tar -zcvf $${DIRO}/../$${NAME}.tar.gz .
#

#upload: dist
#	scp  ../$(DISTDIR).tar.gz  ../$(DISTDIR).tar.gz.md5 www-data@simusol.org:/var/www/simusol.org/public_html/downloads ;\
#	ssh www-data@simusol.org "cd /var/www/simusol.org/public_html/downloads; rm -f sceptre-simusol-last.tar.gz;  rm -f sceptre-simusol-last.tar.gz.md5; ln -s $(DISTDIR).tar.gz sceptre-simusol-last.tar.gz; ln -s $(DISTDIR).tar.gz.md5 sceptre-simusol-last.tar.gz.md5;"







yyy:
	if test x${SRCDIR} != xsrc ; then \
	   echo ">>>> SRCDIR != src";\
	   for DIR in ${ISRCDIRS} ; do \
		install -d                          $${DIR} ;\
		echo "D:$${DIR}" >> listado.ls ;\
	        done; \
	   for FILE in ${SRCF} ; do \
		FILEP=`echo -n $$FILE|sed -e  's/src\///'` ;\
		echo $${FILE} $${FILEP};\
	        install -m 644  $${FILE} ${SRCDIR}  ;\
	        echo "A:${SRCDIR}/$${FILEP}" >> listado.ls ; \
		done;\
	   fi ;




installx:
	if test x${DBP} != x ; then \
	   mkdir -p ${DBP} ;\
	fi
	for DIR in ${IDIRS} ; do \
		install -d             $${DIR} ;\
		echo "D:$${DIR}" >> listado.ls ;\
	done;
	for FILE in ${ISCRIPTFILES} ; do \
		install -m 755   $${FILE}           ${BINDIR}  ;\
		FILEP=`echo -n $$FILE|sed -e  's/scripts\///'` ;\
		echo "A:${BINDIR}/$${FILEP}" >> listado.ls     ;\
	done;
	ROOTFILES=`ls -F | grep -v '[/@=|~]$$' | sed -e 's/\*//' `;\
	SHAREFILES=`find share -type f `;\
	for FILE in $${SHAREFILES}   ; do \
		FILEP=`echo -n $$FILE|sed -e  's/share\///'` ;\
		install -m 755   $${FILE}           ${SHAREDIRSCEPTRE}  ;\
		echo "A:${SHAREDIRSCEPTRE}/$${FILEP}" >> listado.ls ; \
	done;
	for FILE in $${ROOTFILES} ; do \
		install -m 644    $${FILE}     ${SHAREDIRSCEPTRE}/pkgroot ;  \
		echo "A:${SHAREDIRSCEPTRE}/pkgroot/$${FILE}" >> listado.ls ; \
	done;
	install -m 644    etc/ngp.rc       ${ETCDIR}
	echo "A:${ETCDIR}/ngp.rc" >> listado.ls ;
	for FILE in ${EXAMPLEFILES} ; do \
	  install -m 644  $${FILE} ${SHAREDIRSCEPTRE}/examples  ;\
	  echo "A:${SHAREDIRSCEPTRE}/$${FILE}" >> listado.ls ; \
	done;
	if test x${SRCDIR} != xsrc ; then \
	   echo ">>>> SRCDIR != src";\
	   for DIR in ${ISRCDIRS} ; do \
		install -d                          $${DIR} ;\
		echo "D:$${DIR}" >> listado.ls ;\
	        done; \
	   for FILE in ${SRCF} ; do \
		FILEP=`echo -n $$FILE|sed -e  's/src\///'` ;\
		echo $${FILE} $${FILEP};\
	        install -m 644  $${FILE} ${SRCDIR}  ;\
	        echo "A:${SRCDIR}/$${FILEP}" >> listado.ls ; \
		done;\
	   fi ;
	if test x${SRCDIR} != xsrc ; then \
	   cd ${SRCDIR}/auxpro;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}" ; \
	   cd ${SRCDIR}/phase1;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}" ; \
	   cd ${SRCDIR}/phase2;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}" ; \
	   cd ${SRCDIR}/extras;  ${MAKE} "FC=${FC}" "FFLAGS=${FFLAGS}" ; \
	   if test x${DBP} = x ; then \
	        install -d                          ${LIBDIR} ;\
	        echo "D:${LIBDIR}" >> listado.ls ;\
	   install -s -m 755 ${SRCDIR}/phase1/sceptre1       ${BINDIR} ; \
	   echo "A:${BINDIR}/sceptre1" >> listado.ls ;\
	   install -s -m 755 ${SRCDIR}/auxpro/ngp_gnu        ${BINDIR} ;\
	   echo "A:${BINDIR}/ngp_gnu" >> listado.ls ; \
	   install -m 644    ${SRCDIR}/phase2/libsceptre.a      ${LIBDIR};\
	   echo "A:${LIBDIR}/linsceptre.a" >> listado.ls ; \
	   install -m 644    ${SRCDIR}/phase2/sceptre2.o      ${LIBDIR};\
	   echo "A:${LIBDIR}/sceptre2.o" >> listado.ls ; \
	   install -m 644    ${SRCDIR}/auxpro/libsceptreaux.a   ${LIBDIR};\
	   echo "A:${LIBDIR}/libsceptreaux.a" >> listado.ls ;\
	   cd ${SRCDIR}/auxpro; ${MAKE} clean ;\
	   cd ../phase1; ${MAKE} clean ;\
	   cd ../phase2; ${MAKE} clean ;\
	  fi ;\
	 else \
	  echo ">>>> SRCDIR=src";\
	  if test ! -e src/phase1/sceptre1 ; then \
	     echo "Ejecute make (sin install)  como usuario normal"; \
	     exit 1 ; \
	    else \
	      echo ">>>>Instalo binarios";\
	      install -d                          ${LIBDIR} ;\
	      echo "D:${LIBDIR}" >> listado.ls ; \
	      install -s -m 755 src/phase1/sceptre1       ${BINDIR} ; \
	      echo install -s -m 755 src/phase1/sceptre1       ${BINDIR} ; \
	      echo "A:${BINDIR}/sceptre1" >> listado.ls ;\
	      install -s -m 755 src/auxpro/ngp_gnu        ${BINDIR} ;\
	      echo "A:${BINDIR}/ngp_gnu" >> listado.ls ; \
	      install -m 644    src/phase2/libsceptre.a      ${LIBDIR};\
	      echo "A:${LIBDIR}/libsceptre.a" >> listado.ls ; \
	      install -m 644    ${SRCDIR}/phase2/sceptre2.o      ${LIBDIR};\
	      echo "A:${LIBDIR}/sceptre2.o" >> listado.ls ; \
	      install -m 644    src/auxpro/libsceptreaux.a   ${LIBDIR};\
	      echo "A:${LIBDIR}/libsceptreaux.a" >> listado.ls ;\
	  fi \
	fi

DIRS =  src src/phase1 src/phase2 src/auxpro data scripts examples doc

FILES	= sceptre-simusol.lsm \
	sceptre-simusol.summa \
	Makefile \
	src/phase1/Makefile \
	src/phase2/Makefile \
	src/auxpro/Makefile \
	src/phase1/*.f \
        src/phase1/*.for \
	src/phase1/*.inc \
	src/phase2/*.f \
        src/phase2/*.for \
	src/phase2/*.inc \
	src/auxpro/*.[cf] \
        src/auxpro/*.for \
	src/auxpro/*.inc \
	share/ngp.rc \
	share/usrlib.a \
	share/modellib.dat \
	share/data/Manual.png \
	share/launchers/Simusol-Sceptre-Manual.desktop \
	scripts/sceptre \
	scripts/postinst \
	scripts/ngp \
	scripts/sceptre-simusol-install \
	share/sceptre-simusol/data/Manual.png \
	examples/*.d \
	doc/help/en/manual_pdf/doc_en.pdf \
	doc/help/de/manual_pdf/doc_ger.pdf \
	COPYING \
	SCEPTRE \
	README \
	NEWS \
	DISTRIBUTION_PACKAGES \
	ETime.bug \
	CHANGE.log





SRC1 = src/phase1/Makefile src/phase1/*.f src/phase1/*.for src/phase1/*.inc
SRC2 = src/phase1/Makefile src/phase2/*.f src/phase2/*.for src/phase2/*.inc
SRCA = src/auxpro/Makefile src/auxpro/*.f src/auxpro/*.for src/auxpro/*.inc

SRCF= src/*/Makefile src/*/*.f src/*/*.for src/*/*.inc
# revisar inc cuantos son fuentes y cuantos producidos




#       install -d 			    ${BINDIR}
#	echo "D:${BINDIR}" >> listado.ls ;
#       install -d 			    ${ETCDIR}
#	echo "D:${SHAREDIRSCEPTRE}" >> listado.ls ;
#	install -d 			    ${SHAREDIRSCEPTRE}/examples
#	echo "D:${SHAREDIRSCEPTRE}/examples" >> listado.ls ;
#	install -d 			    ${SHAREDIRSCEPTRE}/data
#	echo "D:${SHAREDIRSCEPTRE}/data" >> listado.ls ;
#	install -d 			    ${SHAREDIRSCEPTRE}/launchers
#	echo "D:${SHAREDIRSCEPTRE}/launchers" >> listado.ls ;
#	 install -d                          ${SRCDIR};\
#	 echo "D:${SRCDIR}" >> listado.ls ; \
#	 install -d                          ${SRCDIR}/auxpro;\
#	 echo "D:${SRCDIR}/auxpro" >> listado.ls ; \
#	 install -d                          ${SRCDIR}/phase1;\
#	 echo "D:${SRCDIR}/phase1" >> listado.ls ; \
#	 install -d                          ${SRCDIR}/phase2 ;\
#	 echo "D:${SRCDIR}/phase2" >> listado.ls ; \
#	install -m 755    scripts/sceptre           ${BINDIR}
#	echo "A:${BINDIR}/sceptre" >> listado.ls ;
#	install -m 755    scripts/sceptre-simusol-install      ${BINDIR}
#	echo "A:${BINDIR}/sceptre-simusol-install" >> listado.ls ;
#	install -m 755    scripts/postinst           ${BINDIR}
#	echo "A:${BINDIR}/postinst" >> listado.ls ;
#	install -m 755    scripts/ngp               ${BINDIR}
#	echo "A:${BINDIR}/ngp" >> listado.ls ;
#	install -d                          ${SHAREDIRSCEPTRE}
#       install -m 644    share/modellib.dat ${SHAREDIRSCEPTRE}
#	echo "A:${SHAREDIRSCEPTRE}/modellib.dat" >> listado.ls ;	
#	install -m 644  share/data/Manual.png ${SHAREDIRSCEPTRE}/data  ;\
#	echo "A:${SHAREDIRSCEPTRE}/data/Manual.png" >> listado.ls ; \
#	install -m 644  share/launchers/Simusol-Sceptre-Manual.desktop ${SHAREDIRSCEPTRE}/launchers; \
#	echo "A:${SHAREDIRSCEPTRE}/launchers/Simusol-Sceptre-Manual.png" >> listado.ls ; \
#	install -m 644    share/usrlib.a     ${SHAREDIRSCEPTRE} ; echo 0;   ### esto es fuente????
#	   for FILE in ${SRCA} ; do \
#	        install -m 644  $${FILE} ${SRCDIR}/auxpro;\
#	        echo "A:${SRCDIR}/auxpro/$${FILE}" >> listado.ls ; \
#	        done;\
#	   for FILE in ${SRC1} ; do \
#	        install -m 644  $${FILE} ${SRCDIR}/phase1;\
#	        echo "A:${SRCDIR}/phase1/$${FILE}" >> listado.ls ; \
#	        done;\
#	   for FILE in ${SRCA} ; do \
#	        install -m 644  $${FILE} ${SRCDIR}/phase2;\
#	        echo "A:${SRCDIR}/phase2/$${FILE}" >> listado.ls ; \
#	        done; \
