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

MODULE=lapack
all: 
	@$(MAKE) --no-print-directory -f Makefile.win -s makeMakedeps 
	@$(MAKE) --no-print-directory -f Makefile.win ../../../bin/Rlapack.dll 
	@$(MAKE) --no-print-directory -f Makefile.win ../../../lib/libRlapack.a
	@$(MAKE) --no-print-directory -f Makefile.win ../../../modules/$(MODULE).dll

CSOURCES = Lapack.c
FSOURCES = rgeev.f rsyev.f

CFLAGS=$(OPTFLAGS) -I../../include -DHAVE_CONFIG_H
FFLAGS=$(FOPTFLAGS)
dlamc-FFLAGS=-ffloat-store
OBJS=$(CSOURCES:.c=.o) $(FSOURCES:.f=.o) dllversion.o

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

lapack-DLLLIBS=-L../../../lib -lRlapack
DLLLIBS=-L../../gnuwin32 -lR -lRblas -lg2c

$(MODULE).dll: $(OBJS)

dllversion.o: ../../include/Rversion.h

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


# Rlapack.* section
Rlapack.dll: dlamc.o dlapack0.o dlapack1.o dlapack2.o dlapack3.o cmplx.o Rlapackrc.o
	@$(ECHO) LIBRARY Rlapack > Rlapack.def
	@$(ECHO) EXPORTS >> Rlapack.def
	@$(NM) $^ > Defs
	@$(SED) -n '/^........ [BCDRT] _/s/^........ [BCDRT] _/ /p' Defs >> $*.def
	@$(RM) Defs
	$(DLL) --shared $(DLLFLAGS) -o $@ Rlapack.def $^ $(DLLLIBS)

libRlapack.a: Rlapack.def

../../../bin/Rlapack.dll: Rlapack.dll
	@$(MKDIR) -p ../../../bin
	@$(CP) $< $@

../../../lib/libRlapack.a: libRlapack.a
	@$(MKDIR) -p ../../../lib
	@$(CP) $< $@

Rlapackrc.o: ../../include/Rversion.h

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

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

-include Makedeps
