SHELL = /bin/sh

binary:
	@if test -f .binary; then \
		echo "Humm... this is a binary version"; \
		config/findpath; \
		(cd scripts; make); \
		echo "Installation done"; \
	else \
		echo "***************************************"; \
		echo "Humm... this is a source version."; \
		echo "Please read the README_Unix file first."; \
		echo "***************************************"; \
	fi

#SCIDIR=.
include Path.incl
include Makefile.incl

all:: bin/scilex  

# Add the object files that are used to compile Scilex @JAVAC_PATH@ @JAVA_INCL@
include Makefile.OBJ

include config/@MAKEFILE_TARGET@

distclean::
	$(RM) bin/scilex

SUBDIRS = scripts macros imp intersci tcl examples

scilex-lib::
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \
	cd routines; echo "making all in routines..."; \
		$(MAKE) $(MFLAGS) all;

@PVMTARGET@::
	@cd pvm3; echo "making all in pvm3..."; $(MAKE) $(MFLAGS) "CC=$(CC)";

@OCAMLTARGET@::
	@cd ocaml; echo "making all in ocaml..."; $(MAKE) $(MFLAGS) ;

@JAVASCITARGET@::
	@cd routines/Javasci; echo "making all in routines/Javasci..."; $(MAKE) $(MFLAGS) ;

all::
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \
	for i in $(SUBDIRS) ;\
	do \
		(cd $$i ; echo "making all in $$i..."; \
			$(MAKE) $(MFLAGS) all); \
	done

all:: @MANTARGET@

distclean::
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \
	for i in routines $(SUBDIRS) @MANTARGET@;\
	do \
		(cd $$i ; echo "making distclean in $$i..."; \
			$(MAKE) $(MFLAGS)  distclean); \
	done

@PVMTARGET_DISTCLEAN@::
	@cd pvm3; echo "making distclean in pvm3..."; \
	$(MAKE) $(MFLAGS) super_distclean;

@OCAMLTARGET_DISTCLEAN@::
	@cd ocaml; echo "making distclean in ocaml..."; \
	$(MAKE) $(MFLAGS) super_distclean;

distclean::
	@cd maple; echo "making distclean in maple..."; \
	$(MAKE) $(MFLAGS) distclean;

@JAVASCITARGET_DISTCLEAN@::
	@cd routines/Javasci; echo "making distclean in routines/Javasci..."; \
	$(MAKE) $(MFLAGS) distclean;

clean::
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \
	for i in routines $(SUBDIRS) @MANTARGET@;\
	do \
		(cd $$i ; echo "making clean in $$i..."; \
			$(MAKE) $(MFLAGS)  clean); \
	done

man::
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \
	for i in man;\
	do \
		(cd $$i ; echo "making man in $$i..."; \
			$(MAKE) $(MFLAGS) man); \
	done


manclean:	
	@case '${MFLAGS}' in *[ik]*) set +e;; esac; \
	for i in man;\
	do \
		(cd $$i ; echo "making manclean in $$i..."; \
			$(MAKE) $(MFLAGS) manclean); \
	done

tests:
	@echo "Type \"make tests\" in $(SCIDIR)/tests directory "
	@echo "  to test the  distribution"

distclean::
	$(RM) config.cache config.log config.status .binary foo.f foo.o \
	conftest conftest.c so_locations

# SCIBASE for scilab binaries generation
SCIBASE = scilab-SE-BUILD_4-16044

PVMBINDISTFILES = \
	$(SCIBASE)/pvm3/Readme \
	$(SCIBASE)/pvm3/lib/pvm \
	$(SCIBASE)/pvm3/lib/pvmd \
	$(SCIBASE)/pvm3/lib/pvmtmparch \
	$(SCIBASE)/pvm3/lib/pvmgetarch \
	$(SCIBASE)/pvm3/lib/@PVMARCH@/pvmd3 \
	$(SCIBASE)/pvm3/lib/@PVMARCH@/pvmgs \
	$(SCIBASE)/pvm3/lib/@PVMARCH@/pvm \
	$(SCIBASE)/pvm3/bin/@PVMARCH@/*

BINDISTFILES = \
	$(SCIBASE)/.binary \
	$(SCIBASE)/.pvmd.conf \
	$(SCIBASE)/ACKNOWLEDGEMENTS \
	$(SCIBASE)/CHANGES \
	$(SCIBASE)/Makefile \
	$(SCIBASE)/Makefile.OBJ \
	$(SCIBASE)/Makefile.incl \
	$(SCIBASE)/Makemex \
	$(SCIBASE)/Path.incl \
	$(SCIBASE)/README_Unix \
	$(SCIBASE)/RELEASE_NOTES \
	$(SCIBASE)/SVN_revision.incl \
	$(SCIBASE)/Version.incl \
	$(SCIBASE)/configure \
	$(SCIBASE)/libtool \
	$(SCIBASE)/license.txt \
	$(SCIBASE)/licence.txt \
	$(SCIBASE)/scilab.quit \
	$(SCIBASE)/scilab.star \
	$(SCIBASE)/X11_defaults \
	$(SCIBASE)/bin \
	$(SCIBASE)/config \
	$(SCIBASE)/contrib \
	$(SCIBASE)/demos \
	$(SCIBASE)/examples \
	$(SCIBASE)/imp/NperiPos.ps \
	$(SCIBASE)/imp/giffonts \
	$(SCIBASE)/macros \
	$(SCIBASE)/man/eng \
	$(SCIBASE)/man/fr \
	$(SCIBASE)/man/images \
	$(SCIBASE)/man/*.dtd \
	$(SCIBASE)/man/*/*.xsl \
	$(SCIBASE)/maple \
	$(SCIBASE)/routines/*.h \
	$(SCIBASE)/routines/Make.lib \
	$(SCIBASE)/routines/default/FCreate \
	$(SCIBASE)/routines/default/Flist \
	$(SCIBASE)/routines/default/README \
	$(SCIBASE)/routines/default/fundef \
	$(SCIBASE)/routines/default/*.c \
	$(SCIBASE)/routines/default/*.f \
	$(SCIBASE)/routines/default/*.h \
	$(SCIBASE)/routines/graphics/Math.h \
	$(SCIBASE)/routines/graphics/Graphics.h \
	$(SCIBASE)/routines/interf/*.h \
	$(SCIBASE)/routines/intersci/sparse.h \
	$(SCIBASE)/routines/menusX/*.h \
	$(SCIBASE)/routines/scicos/scicos.h \
	$(SCIBASE)/routines/scicos/scicos_block.h \
	$(SCIBASE)/routines/os_specific/*.h \
	$(SCIBASE)/routines/xsci/*.h \
	$(SCIBASE)/scripts \
	$(SCIBASE)/tcl \
	$(SCIBASE)/util

tarbindist:
	touch .binary
	@STRIP@ bin/scilex
	cd examples; make distclean
	cd .. ; tar cvf $(SCIBASE)/$(SCIBASE)-bin.tar $(BINDISTFILES) @PVMINST@ 
	$(RM) .binary

#-------------------------------------------------
# installation 
# Scilab is installed in $(PREFIX)/lib/SCIBASE
# with links in $(PREFIX)/bin/
# PREFIX is set by in configure --prefix= option 
# -----------------------------------------------


PREFIX=@prefix@

INSTPVMBINDISTFILES = \
	pvm3/Readme \
	pvm3/lib/pvm \
	pvm3/lib/pvmd \
	pvm3/lib/pvmtmparch \
	pvm3/lib/pvmgetarch \
	pvm3/lib/@PVMARCH@/pvmd3 \
	pvm3/lib/@PVMARCH@/pvmgs \
	pvm3/lib/@PVMARCH@/pvm \
	pvm3/bin/@PVMARCH@/*

INSTBINDISTFILES = \
	.pvmd.conf \
	ACKNOWLEDGEMENTS \
	CHANGES \
	Makefile \
        Makefile.OBJ \
	Makefile.incl \
	Makemex \
        Path.incl \
	README_Unix \
	Version.incl \
	configure \
	libtool \
	license.txt \
	licence.txt \
	scilab.quit \
	scilab.star \
	X11_defaults \
	bin \
	config \
	contrib \
	demos \
	examples \
	imp/NperiPos.ps \
	imp/giffonts \
	macros \
	man \
	maple \
	routines/*.h \
	routines/Make.lib \
	routines/default/FCreate \
	routines/default/Flist \
	routines/default/README \
	routines/default/fundef \
	routines/default/*.c \
	routines/default/*.f \
	routines/default/*.h \
	routines/graphics/Math.h \
	routines/graphics/Graphics.h \
	routines/interf/*.h \
	routines/intersci/sparse.h \
	routines/menusX/*.h \
	routines/scicos/scicos.h \
	routines/scicos/scicos_block.h \
	routines/os_specific/*.h \
	routines/xsci/*.h \
	scripts \
	tcl \
	util

DOCNAME=$(SCIBASE)

install:
	@if test `pwd`/..  != $(PREFIX)/lib ; then \
		install -d $(PREFIX)/lib/$(SCIBASE); \
		( for file in $(INSTBINDISTFILES) @PVMINST1@; do tar cf - $${file}  | (cd $(PREFIX)/lib/$(SCIBASE); tar xf -); done); \
		(cd $(PREFIX)/lib/$(SCIBASE);touch .binary; make postinstall PREFIX=$(PREFIX) ) \
	fi
	install -d $(PREFIX)/share/doc/$(DOCNAME)/
	install ACKNOWLEDGEMENTS CHANGES README_Unix Version.incl \
		licence.txt license.txt  $(PREFIX)/share/doc/$(DOCNAME)
	install -d $(PREFIX)/bin 
	$(RM)  $(PREFIX)/bin/scilab
	ln -fs $(PREFIX)/lib/$(SCIBASE)/bin/scilab $(PREFIX)/bin/scilab
	$(RM)  $(PREFIX)/bin/intersci
	ln -fs $(PREFIX)/lib/$(SCIBASE)/bin/intersci $(PREFIX)/bin/intersci
	$(RM)  $(PREFIX)/bin/intersci-n
	ln -fs $(PREFIX)/lib/$(SCIBASE)/bin/intersci-n $(PREFIX)/bin/intersci-n

# DESTDIR is the final destination of the file 
# it can be different from $(PREFIX)/lib
# when we use package builders for rpm or deb files 

DESTDIR=$(PREFIX)/lib

postinstall: 
	@echo "creating Path.incl SCIDIR=$(DESTDIR)/$(SCIBASE)"
	@echo "SCIDIR=$(DESTDIR)/$(SCIBASE)"  > Path.incl
	@cd scripts; make
	@cd examples ; make distclean > /dev/null
	@cp contrib/loader.sce contrib-loader.sce 
	@$(RM) -f -r contrib 
	@mkdir contrib 
	@mv contrib-loader.sce contrib/loader.sce
	@find man -name "*.xml" -print0 | xargs -0 $(RM)
	@@STRIP@ bin/scilex;

uninstall:
	$(RM) -r $(PREFIX)/$(SCIBASE)
	$(RM) $(PREFIX)/bin/scilab
	$(RM) $(PREFIX)/bin/intersci
	$(RM) $(PREFIX)/bin/intersci-n

cvsclean::
	@$(RM) -f -r geci xless wless xmetanet routines/comm routines/libcomm
	@cd man; $(RM) -f -r arma comm control dcd elementary fileio functions graphics gui identification linear metanet nonlinear polynomials programming pvm robust scicos signal sound strings tdcs time-date tclsci translation utilities

setversion : 
	echo "SCIVERSION=Scilab-4.1-SVN-`date --iso`" > Version.incl
