# *
# *_________________________________________________________________________*
# *      Minimal BLAS/LAPACK Library for ATC and AWPMD

# To compile and link LAMMPS to the linalg library generated by this Makefile,
# adjust the corresponding definitions in the library's Makefile.lammps file.
#
# for lib/atc/Makefile.lammps use:
# user-atc_SYSINC =
# user-atc_SYSLIB = ../../lib/linalg/$(LIBOBJDIR)liblinalg.a -lgfortran
# user-atc_SYSPATH =
#
# for lib/awpmd/Makefile.lammps use:
# user-awpmd_SYSINC =
# user-awpmd_SYSLIB = ../../lib/linalg/$(LIBOBJDIR)liblinalg.a -lgfortran
# user-awpmd_SYSPATH =

SHELL = /bin/sh

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

SRC =	dasum.f daxpy.f dcopy.f ddot.f dgecon.f dgemm.f dgemv.f dger.f 	\
	dgetf2.f dgetrf.f dgetri.f disnan.f dlabad.f dlaisnan.f dlamch.f\
	dlacn2.f dlange.f dlassq.f dlaswp.f dlatrs.f drscl.f dscal.f	\
	dswap.f dtrmm.f dtrmv.f dtrsm.f dtrsv.f dtrti2.f dtrtri.f	\
	idamax.f ieeeck.f ilaenv.f iparmq.f lsame.f xerbla.f zdotc.f	\
	zdscal.f zhpr.f zpptrf.f zpptri.f zscal.f ztpmv.f ztpsv.f ztptri.f

FILES = $(SRC) Makefile.* README

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

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

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

FC =    	i686-w64-mingw32-gfortran
FFLAGS =	-O3 -march=i686 -mtune=generic -mfpmath=387 -mpc64	\
		-ffast-math -funroll-loops -fstrict-aliasing -Wall -W	\
		-Wno-uninitialized -fno-second-underscore
FFLAGS0 =	-O0 -march=i686 -mtune=generic -mfpmath=387 -mpc64	\
		-Wall -W -Wno-uninitialized -fno-second-underscore
ARCHIVE =	i686-w64-mingw32-ar
AR =		i686-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)

