# Makefile for the BLAS/LAPACK constants modules
# Requires a file etc/Makeinclude.arch for this architecture
# Some sample Makeinclude files are provided in the etc directory.
#
# Sample usage:
#    setenv ARCH gnu
#    make -f Makecongen
#    make -f Makecongen check
# The files la_constants.f90 and la_constants32.f90 are created
# in the ARCH directory. If acceptable, they can be moved or
# copied to the ../src directory.
#
# You should get the same values in these two files regardless of
# which compiler you use.
#
# Edward Anderson
# July 29, 2016
#

ARCHFILE = ../etc/Makeinclude.${ARCH}
include $(ARCHFILE)
EXEDIR  = $(ARCH)
OBJDIR  = $(ARCH)
OUTDIR  = $(ARCH)
SCONEXE = $(EXEDIR)/scongen
DCONEXE = $(EXEDIR)/dcongen

.SUFFIXES: .f .F .f90 .F90

SCONGEN = scongen.o
DCONGEN = dcongen.o

SOBJS=$(addprefix $(OBJDIR)/,$(SCONGEN))
DOBJS=$(addprefix $(OBJDIR)/,$(DCONGEN))

all: $(SCONEXE) $(DCONEXE)

$(SCONEXE): $(SOBJS)
	$(FC) -o $@ $(SOBJS)

$(DCONEXE): $(DOBJS)
	$(FC) -o $@ $(DOBJS)

check: $(SCONEXE) $(DCONEXE)
	$(SCONEXE) > $(OUTDIR)/la_constants32.f90
	$(DCONEXE) > $(OUTDIR)/la_constants.f90

clean:
	/bin/rm -rf $(SOBJS) $(DOBJS) $(SCONGEN) $(DCONGEN)

$(OBJDIR)/%.o:%.f90 $(ARCHFILE)
	$(FC) -c $(FFLAGS) -o $@ $<
$(OBJDIR)/%.o:%.f $(ARCHFILE)
	$(FC) -c $(FFLAGS) -o $@ $<
$(OBJDIR)/%.o:%.F $(ARCHFILE)
	$(FC) -c $(FFLAGS) -o $@ $<
$(OBJDIR)/%.o:%.F90 $(ARCHFILE)
	$(FC) -c $(FFLAGS) -o $@ $<
