#-*- Makefile -*-
include ../../gnuwin32/MkRules

MODULE = lapack
all: 
	@$(MAKE) --no-print-directory -f Makefile.win -s makeMakedeps 
	@$(MAKE) --no-print-directory -f Makefile.win ../../../$(BINDIR)/Rlapack.dll 
ifdef USE_IMPLIBS
	@$(MAKE) --no-print-directory -f Makefile.win implib
endif
	@$(MAKE) --no-print-directory -f Makefile.win install

CSOURCES = Lapack.c
# flexiblas not supported on Windows
OBJS=$(CSOURCES:.c=.o) dllversion.o
LIBSOURCES = dlamch.f dlapack.f cmplx.f
LIBSOURCES90 = dlartg.f90 dlassq.f90 la_constants.f90 la_xisnan.f90 \
  zlartg.f90 zlassq.f90
LIBOBJECTS = $(LIBSOURCES:.f=.o) $(LIBSOURCES90:.f90=.o) init_win.o Rlapackrc.o

CPPFLAGS = -I../../include -DHAVE_CONFIG_H
ifndef USE_LLVM
  dlamch-FFLAGS = -ffloat-store
endif

la_constants.mod: la_constants.o
la_xisnan.mod: la_xisnan.o
dlartg.o dlassq.o zlartg.o zlassq.o la_xisnan.o: la_constants.o
dlassq.o zlassq.o: la_xisnan.o

install: $(MODULE).dll
	@$(MKDIR) -p ../../../modules$(R_ARCH)
	$(CP) $< ../../../modules$(R_ARCH)/$(MODULE).dll

lapack-DLLLIBS = -L../../../$(IMPDIR) -lRlapack -lRblas -lR

implib: libRlapack.dll.a
	@$(CP) libRlapack.dll.a ../../../lib

libRlapack.dll.a: Rlapack.def

Rlapack.def: $(LIBOBJECTS)
	@$(ECHO) EXPORTS > $@
	@$(NM) $^ | $(SED) -n $(SYMPAT) | $(SORT) | uniq >> $@


$(MODULE).dll: $(OBJS)

../../../$(BINDIR)/Rlapack.dll: $(LIBOBJECTS) Rlapack.def
	$(DLL) -shared -s -o $@ $^ -L../../../$(IMPDIR) -lR -lRblas $(FLIBS)

clean:
	@$(RM) Makedeps *.d *.o $(MODULE).def $(MODULE).dll Rlapack.def \
	  Rlapack.dll *.a *.mod


# Dependencies
dllversion.o: ../../include/Rversion.h
Rlapackrc.o: ../../include/Rversion.h

DEPS = $(CSOURCES:.c=.d)

makeMakedeps: $(DEPS)
	@$(RM) Makedeps
	@cat $(DEPS) >> Makedeps

-include Makedeps
