#-----------------------------------------------------------------
# This file can be used to produce a shared libary instead 
# a standard .a library 
# for examples: replace the line ``include ../Make.lib'' by 
# ``include ../../config/Makeso.incl in file 
# routines/calelm/Makefile to produce a calelm.so shared libary 
# Copyright Enpc (Jean-Philippe Chancelier)
#-----------------------------------------------------------------

top_builddir = $(SCIDIR)

SHELL = @SHELL@
DLLTOOL = @DLLTOOL@
LIBM = @LIBM@
LIBTOOL = @LIBTOOL@
OBJDUMP = @OBJDUMP@
STATIC = @STATIC@
LN_S = @LN_S@
NM = @NM@
LDFLAGS = @LDFLAGS@ $(EXTRA_LDFLAGS) 
LIBS = @LIBS@
FLIBS = @FLIBS@
#******************************************************************* 
INCLUDES=  $(XFLAGS) $(TK_INC_PATH) $(TCL_INC_PATH) -I$(SCIDIR)/routines 

# we do not set CFLAGS and FFLAGS here 
#CFLAGS = $(CC_OPTIONS) 
#FFLAGS = $(FC_OPTIONS) 

QUIET=--quiet
 
COMPILE = $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
FCOMPILE = $(FC) $(INCLUDES) $(FFLAGS)
CXXCOMPILE = $(CXX) $(INCLUDES) $(CXXFLAGS) $(CFLAGS)

LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(QUIET) $(CC) $(INCLUDES) $(CPPFLAGS) $(CFLAGS)
CXXLTCOMPILE = $(LIBTOOL) --tag=CXX --mode=compile $(QUIET) $(CXX) $(INCLUDES) $(CXXFLAGS) $(CFLAGS)
FLTCOMPILE = $(LIBTOOL) --tag=F77 --mode=compile $(QUIET) $(FC) $(INCLUDES) $(FFLAGS)

LINK = $(LIBTOOL) --tag=CC --mode=link $(QUIET) $(CC) $(CFLAGS) $(LDFLAGS)  $(FLIBS) $(OTHERLIBS) -o $@

OBJECTS = $(OBJS:.o=.lo)
LIBRARY_NAME = $(LIBRARY:.a=)
#******************************************************************* 

all:: $(LIBRARY_NAME).la 

.SUFFIXES:
.SUFFIXES: .c .lo .o .F .f .F90 .f90 .cc .cpp

$(LIBRARY_NAME).la : $(OBJECTS) 
	@echo linking 
	@$(LINK) -rpath `pwd` -module -avoid-version -export-dynamic $(OBJECTS) 
	@$(LIBTOOL) --mode=install $(QUIET) cp -f $(LIBRARY_NAME).la `pwd`/$(LIBRARY_NAME).la > /dev/null

clean	::
	@$(RM) *.o *.lo
	@$(RM) $(LIBRARY_NAME).la
	@$(RM) $(LIBRARY_NAME).so
	@$(RM) $(LIBRARY_NAME).a
	@$(RM) -r .libs
	@$(RM) $(LIBRARY_NAME)_gateway.c 

distclean:: clean 
	@$(RM) $(LIBRARY_NAME).dia

tests	: $(LIBRARY_NAME).dia

$(LIBRARY_NAME).dia	: $(LIBRARY_NAME).la $(LIBRARY_NAME).tst
	@$(SCIDIR)/bin/scilab -nw -e "scitest(\"$(LIBRARY_NAME).tst\");quit;"


.c.o:
	@echo "compiling $<"
	@$(COMPILE)  -c $<

.c.lo :
	@echo "Compiling $<"
	@$(LTCOMPILE) -c $<

.cc.o:
	@echo "compiling $<"
	@$(COMPILE)  -c $<

.cc.lo :
	@echo "Compiling $<"
	@$(LTCOMPILE) -c $<

.cpp.o:
	@echo "compiling $<"
	@$(CXXCOMPILE)  -c $<

.cpp.lo :
	@echo "Compiling $<"
	@$(CXXLTCOMPILE) -c $<

.F.o:
	@echo "compiling $<"
	@$(FCOMPILE)  -c $<

.F.lo :
	@echo "Compiling $<"
	@$(FLTCOMPILE)  -c $<

.f.o:
	@echo "compiling $<"
	@$(FCOMPILE)  -c $<

.f.lo :
	@echo "Compiling $<"
	@$(FLTCOMPILE)  -c $<

.F90.o:
	@echo "compiling $<"
	@$(FCOMPILE)  -c $<

.F90.lo :
	@echo "Compiling $<"
	@$(FLTCOMPILE)  -c $<

.f90.o:
	@echo "compiling $<"
	@$(FCOMPILE)  -c $<

.f90.lo :
	@echo "Compiling $<"
	@$(FLTCOMPILE)  -c $<











