#
# ${R_HOME}/src/modules/lapack/Makefile

VPATH = @srcdir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@

top_builddir = ../../..
subdir = src/modules/lapack
R_HOME = $(top_builddir)

include $(top_builddir)/Makeconf

SOURCES_C = Lapack.c
SOURCES_F = @USE_EXTERNAL_LAPACK_FALSE@ rgeev.f rsyev.f

DEPENDS = $(SOURCES_C:.c=.d)
SOURCES = $(SOURCES_C) $(SOURCES_F) @USE_EXTERNAL_BLAS_FALSE@ $(SOURCES_BLAS)
OBJECTS = $(SOURCES_C:.c=.lo) $(SOURCES_F:.f=.lo)
HEADERS = Lapack.h

LIBSOURCES = dlamc.f dlapack0.f dlapack1.f dlapack2.f dlapack3.f \
  @COMPILE_DOUBLE_COMPLEX_FALSE@ cmplx.f @USE_EXTERNAL_BLAS_FALSE@ cmplxblas.f
LIBOBJECTS = $(LIBSOURCES:.f=.lo)

distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir)
DISTFILES = \
	README Makefile.in Makefile.win \
	Rlapackrc.rc dllversion.rc \
	$(HEADERS) $(SOURCES_C) \
	cmplx.f cmplxblas.f \
	dlamc.f dlapack0.f dlapack1.f dlapack2.f dlapack3.f \
	rgeev.f rsyev.f

## <FIXME>
## Change to 'lapack.la' when using libtool for shlibs.
## Remove when using automake ... also fix target 'install' then.
lapack_la = lapack$(SHLIB_EXT)
Rlapack_la = libRlapack$(DYLIB_EXT)
## </FIXME>
Rexecmodulesdir_LTLIBRARIES = $(lapack_la)
lapack_la_SOURCES = $(SOURCES)
lapack_la_OBJECTS = $(OBJECTS)
@USE_LIBTOOL_TRUE@lapack_la_LDFLAGS = -avoid-version -rpath "$(Rexecmodulesdir)" -module
## Used for passing '+s' to SHLIB_LINK on HP-UX.
@USE_LIBTOOL_FALSE@lapack_la_LDFLAGS = @LAPACK_LDFLAGS@
lapack_la_LIBADD = $(LIBR)

Rlapack_la_SOURCES = $(LIBSOURCES)
Rlapack_la_OBJECTS = $(LIBOBJECTS)

all: Makefile Makedeps R

Makefile: $(srcdir)/Makefile.in \
  $(top_builddir)/config.status \
  $(SOURCES)
	@cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@

Makedeps: Makefile $(DEPENDS)
	@cat $(DEPENDS) >> Makefile
	@touch $@

## we need to force stores with gcc 3.4.0 on i686
DLAMC_FFLAGS=$(FPICFLAGS) $(SHLIB_FFLAGS) $(FFLAGS) -ffloat-store
@USING_G77_TRUE@dlamc.lo: dlamc.f
@USING_G77_TRUE@	$(F77) $(DLAMC_FFLAGS) -c $< -o $@

R: Makefile
	@$(MAKE) Makedeps
@USE_EXTERNAL_LAPACK_FALSE@	@$(MAKE) $(Rlapack_la) Rlapack_install
	@$(MAKE) $(Rexecmodulesdir_LTLIBRARIES)

$(lapack_la): $(lapack_la_OBJECTS) $(lapack_la_DEPENDENCIES)
	$(SHLIB_LINK) -o $@ $(lapack_la_LDFLAGS) $(lapack_la_OBJECTS) $(lapack_la_LIBADD) @LAPACK_LIBS@ @BLAS_LIBS@ $(FLIBS) $(LIBS)
## <FIXME>
## Not sure if we want to do this ...
	@$(MAKE) rhome="$(abs_top_builddir)" install
## </FIXME>

## Include BLAS here, as with (static) ATLAS that pulls all the
## BLAS routines into one place.
## <FIXME>
## This is not yet right.  Prefer not to include FLIBS, but MacOSX seems
## to require it.
## AIX support is untested
## </FIXME>
$(Rlapack_la): $(Rlapack_la_OBJECTS) @USE_EXPORTFILES_TRUE@ $(top_builddir)/etc/Rlapack.exp
	$(DYLIB_LINK) @RLAPACK_LDFLAGS@ -o $@ $(Rlapack_la_OBJECTS) @BLAS_LIBS@ $(FLIBS)

$(top_builddir)/etc/Rlapack.exp: $(Rlapack_la_OBJECTS)
	@$(SHELL) $(top_srcdir)/tools/ldAIX4 -o $@ $(Rlapack_la_OBJECTS)

Rlapack_install: $(Rlapack_la) 
	@$(MKINSTALLDIRS) $(R_HOME)/lib/
	@$(SHELL) $(top_srcdir)/tools/copy-if-change $(Rlapack_la) \
	  $(R_HOME)/lib/$(Rlapack_la)

install: installdirs
@USE_LIBTOOL_FALSE@	@$(SHELL) $(top_srcdir)/tools/copy-if-change $(lapack_la) "$(Rexecmodulesdir)/lapack$(SHLIB_EXT)"
@USE_LIBTOOL_TRUE@	@$(LIBTOOL) --mode=install $(INSTALL) $(lapack_la) "$(Rexecmodulesdir)"
@USE_EXTERNAL_LAPACK_FALSE@	@$(SHELL) $(top_srcdir)/tools/copy-if-change $(Rlapack_la) "$(Rexeclibdir)/libRlapack$(DYLIB_EXT)"
installdirs:
	@$(MKINSTALLDIRS) "$(Rexecmodulesdir)"
install-strip:
	$(MAKE) INSTALL_PROGRAM="${INSTALL_PROGRAM} -s" install
uninstall:
	@rm -f "$(Rexecmodulesdir)/lapack$(SHLIB_EXT)"

mostlyclean: clean
clean:
	@-rm -rf .libs _libs
	@-rm -f Makedeps *.d *.o *.a *.lo *.la \
	  lapack$(SHLIB_EXT) @USE_EXTERNAL_LAPACK_FALSE@ libRlapack$(DYLIB_EXT)
distclean: clean
	@-rm -f Makefile
maintainer-clean: distclean

TAGS info dvi check:

distdir: $(DISTFILES)
	@for f in $(DISTFILES); do \
	  test -f $(distdir)/$${f} \
	    || ln $(srcdir)/$${f} $(distdir)/$${f} 2>/dev/null \
	    || cp -p $(srcdir)/$${f} $(distdir)/$${f}; \
	done

## Automagically generated dependencies:

