# -*- makefile -*-
# *_________________________________________________________________________*
# *      Minimal BLAS/LAPACK Library for use by other LAMMPS packages

SHELL = /bin/sh

# ------ FILES ------

SRC =	$(wildcard *.f)

FILES = $(SRC) Makefile.* README

# ------ DEFINITIONS ------

DIR = Obj_mingw64/
LIB = $(DIR)liblinalg.a
OBJ =   $(SRC:%.f=$(DIR)%.o)

# ------ SETTINGS ------

FC =    	x86_64-w64-mingw32-gfortran
FFLAGS =	-O3 -march=core2 -mtune=generic -msse2 -mpc64	\
		-ffast-math -funroll-loops -fstrict-aliasing -Wall -W	\
		-Wno-uninitialized -fno-second-underscore
FFLAGS0 =	-O0 -march=core2 -mtune=generic -msse2 -mpc64	\
		-Wall -W -Wno-uninitialized -fno-second-underscore
ARCHIVE =	x86_64-w64-mingw32-ar
AR =		x86_64-w64-mingw32-ar
ARCHFLAG =	-rcs
USRLIB =
SYSLIB =

.PHONY: default clean tar

.SUFFIXES:
.SUFFIXES: .F .f .o

# ------ MAKE PROCEDURE ------

default: $(DIR) $(LIB)

$(LIB): $(OBJ)
	$(ARCHIVE) $(ARFLAGS) $(LIB) $(OBJ)

$(DIR):
	mkdir $(DIR)

# ------ COMPILE RULES ------

$(DIR)%.o:%.F
	$(F90) $(F90FLAGS) -c $< -o $@

$(DIR)%.o:%.f
	$(FC) $(FFLAGS) -c $< -o $@

$(DIR)dlamch.o: dlamch.f
	$(FC) $(FFLAGS0) -c $< -o $@

# ------ CLEAN ------

clean:
	-rm $(DIR)*.o $(DIR)*.mod *~ $(LIB)
	-rmdir $(DIR)

tar:
	-tar -czvf ../linalg.tar.gz $(FILES)

