#correct CALCHEP (CalcHEP directory) if it needs

#if (CALCHEP = $(CURDIR)/..
# define full paths to SPHENO ,SOFTSUSY, ISAJET if you are going to use these 
#  packages.  For example: ISAJET =  $(HOME)/isajet
SPHENO =
SOFTSUSY = 
ISAJET = /home/pukhov/Packages/Isajet
CERNLIB=  /home/pukhov/Packages/cern/pro/lib
#======================
SUSPECT=$(CURDIR)

ifneq ($(MAKECMDGOALS),clean)

ifeq (,$(wildcard $(CALCHEP)/FlagsForMake))
$(error "Can not find FlagsForMake file.  It should be disposed in the\
 CalcHEP directory. Check variable CALCHEP in Makefile and   FlagsForMake\
 in CALCHEP directory. FlagsForMake appears in result of CalcHEP installation") 
endif

#read compiler options ..
include $(CALCHEP)/FlagsForMake

endif

.PHONY: all clean extlib

VPATH = SuSpect

SuSpectOBJ = $(subst .f,.o,$(wildcard SuSpect/*.f))

extlibfile = $(subst vars,extlib,$(wildcard models/vars*.mdl))

mLibOBJ =  $(subst .c,.o,$(wildcard *.c))  

all:  suspect.exe mLib.a extlib

suspect.exe: $(SuSpectOBJ) 
	$(FC) -o suspect.exe $(SuSpectOBJ)

mLib.a(suspect_call.o):suspect_path.h
mLib.a(isasugra_call.o):isajet_path.h suspect_path.h
mLib.a(ssusy_call.o): ssusy_path.h
mLib.a(spheno_call.o):spheno_path.h

ssusy_path.h: Makefile
	echo static char \* SOFTSUSY =\"$(SOFTSUSY)\"\;  > ssusy_path.h
spheno_path.h: Makefile
	echo static char \* SPHENO  = \"$(SPHENO)\"\;  > spheno_path.h
isajet_path.h: Makefile
	echo static char \* ISAJET  = \"$(ISAJET)\"\;  > isajet_path.h
suspect_path.h: Makefile
	echo static char \* SUSPECT = \"$(SUSPECT)\"\;  > suspect_path.h

mLib.a:mLib.a($(mLibOBJ))
	echo $(0)
	$(RANLIB) mLib.a
	rm -f $(mLibOBJ)

# for Isajet before 7.79 add  flag  -Dlt779 for FC
isajet_slha: isajet_SLHA/isasugra_slha.F isajet_SLHA/lesHouches.c
	$(CC) $(CFLAGS)   -c  isajet_SLHA/lesHouches.c
	$(FC) $(FFLAGS) -o isajet_slha  isajet_SLHA/isasugra_slha.F lesHouches.o \
    -L$(ISAJET) -L$(CERNLIB) -lisajet -lmathlib
                   


extlib: 
	./updateExtLib
	
	

clean: 
	rm -f *.o *.a *_path.h   suspect.exe isajet_slha SuSpect/*.o  
	./updateExtLib 0
