# Use MinGW Make to process this file
# make -f Makefile_mingwoct
#
#



include filedefs.mk
include ostools.mk

ifndef MATLABROOT
  $(warning MATLABROOT variable is undefined. Using default (probably wrong) MATLABROOT="c:\Octave\Octave3.6.4_gcc4.6.2")
  MATLABROOT=c:\Octave\Octave3.6.4_gcc4.6.2
endif
OCTAVELIBS=-lfftw3 -lfftw3f -lblas -llapack
OCTAVELINKFLAGS=-L$(MATLABROOT)\lib $(OCTAVELIBS)

#CC = i686-pc-mingw32-gcc 
CC=gcc

CFLAGS=-O3 -s -Wall -std=c99 -m32 -I../src/thirdparty -I./
DIRECTIVES=


DFILES = $(addprefix d,$(files)) $(addprefix d,$(files_blaslapack)) $(files_notypechange)
SFILES = $(addprefix s,$(files)) $(addprefix s,$(files_blaslapack))

all: static

static: double_static single_static

shared: double_shared single_shared

double_shared: $(DFILES) Makefile_mingwoct
	$(CC) -m32 -shared -Wl,--dll $(DFILES) \
	-o ../lib/ltfat.dll ltfat_notdllexport.def -static-libgcc $(OCTAVELINKFLAGS) 
	$(RM) *.o *.a
	$(CP) ..\lib\ltfat.dll ..\oct
  
single_shared: $(SFILES) Makefile_mingwoct  
	$(CC) -m32 -shared -Wl,--dll $(SFILES) \
	-o ../lib/ltfatf.dll -static-libgcc -L../oct -lltfat $(OCTAVELINKFLAGS)
	$(RM) *.o *.a
	$(CP) ..\lib\ltfatf.dll ..\oct

double_static: $(DFILES) Makefile_mingwoct
	ar rvu libltfat.a $(DFILES) 
	ranlib libltfat.a
	$(CP) libltfat.a ..\lib
	$(RM) *.o *.a	
	
single_static: $(SFILES) Makefile_mingwoct
	ar rvu libltfatf.a $(SFILES) 
	ranlib libltfatf.a
	$(CP) libltfatf.a ..\lib
	$(RM) *.o *.a	

s%.o: %.c config.h
	$(CC) $(CFLAGS) $(DIRECTIVES) -DLTFAT_SINGLE  -c $< -o s$*.o

d%.o: %.c config.h
	$(CC) $(CFLAGS) $(DIRECTIVES) -DLTFAT_DOUBLE  -c $< -o d$*.o

%.o: %.c
	$(CC) $(CFLAGS) $(DIRECTIVES) -c $<

clean:
	$(RM) ..\lib\ltfat.dll
	$(RM) ..\lib\ltfatf.dll
	$(RM) ..\lib\libltfat.a
	$(RM) ..\lib\libltfatf.a
	$(RM) *.o *.a

