SHELL=/bin/sh

# makefile for MSC program and module
#
# the MSC source code is not included in the public distribution.
# please obtain the MSC code from the original author,
# and copy it to this directory before compilation.
#
# see the top-level makefile for additional information.

.SUFFIXES:
.SUFFIXES: .c .cpp .cxx .exe .f .h .i .o .py .pyf .so
.PHONY: all clean edac msc mufpot

FC?=gfortran
FCCOPTS?=
F2PY?=f2py
F2PYOPTS?=
CC?=gcc
CCOPTS?=
SWIG?=swig
SWIGOPTS?=
PYTHON?=python
PYTHONOPTS?=
PYTHONINC?=

all: msc

msc: msc.exe msc.so

msc.exe: msc.f param.f common.f phases.f angles.f revision.f
	$(FC) $(FCOPTS) -o msc.exe msc.f phases.f angles.f

#msc.pyf currently needs a manual edit before compiling.
#this target should execute only if it doesn't exist.
msc.pyf: | msc.f phases.f angles.f
	$(F2PY) -h msc.pyf -m msc msc.f phases.f angles.f only: mscmain anglesarray anglesfile ps
	$(error msc.pyf auto-generated - must be edited manually before build can continue!)

msc.so: msc.f param.f common.f phases.f angles.f revision.f msc.pyf
	$(F2PY) -c $(F2PYOPTS) msc.pyf msc.f phases.f angles.f -m msc

revision.f: msc.f
	echo "      character*50 coderev" > revision.f
	echo "      parameter(coderev=" >> revision.f
	git log --pretty=format:"     ='Code revision %h, %ad')" --date=iso -1 $< >> $@ || echo "     ='Code revision unknown, "`date +"%F %T %z"`"')" >> $@

clean:
	rm -f *.so *.o *.exe
	rm -f revision.f
