# Rules for compiling the FORTAN code

.SUFFIXES:	.for

.for.o:
		@echo "---" $<; \
		dir=$(<D); if [ $${dir} = "." ]; then dir=$(PWD) ; fi ; \
		mkdir -p $(<D)/TMP; file=$${dir}/$<; \
		TEST2=$(filter 0,$(shell grep -c '&' $< )); \
		if [ "x$${TEST2}" != "x0" ]; then \
		   file=$${dir}/TMP/$(<F)_amp.f; sed "s/&/*/g" $< > $${file};\
		fi; \
		echo $${file}; \
		ln -sf $${file} $(<D)/TMP/$(<F)_for.f ; \
		$(FC) $(FFLAGS) -o $@ -c $(<D)/TMP/$(<F)_for.f

.f.o:
		@echo "---" $<; file=$<; \
		TEST2=$(filter 0,$(shell grep -c '&' $< )); \
		if [ "x$${TEST2}" != "x0" ]; then \
		   mkdir -p $(<D)/TMP; file=$(<D)/TMP/$(<F)_amp.f; sed "s/&/*/g" $< > $${file};\
		fi; \
		$(FC) $(FFLAGS) -o $@ -c $${file}

.F.o:
		@echo "---" $<; file=$<;\
	 	TEST1=$(filter 0,$(shell grep -c '^     #' $< )) ;\
		TEST2=$(filter 0,$(shell grep -c '&' $< )) ;\
		mkdir -p $(<D)/TMP; \
		if [ "x$${TEST1}" != "x0" ]; then \
		   file=$(<D)/TMP/$(<F)_cont.F; sed "s/^     #/     +/" $< > $${file};\
		fi ; \
		if [ "x$${TEST2}" != "x0" ]; then \
		   if [ "x$${TEST1}" != "x0" ]; then \
		      sed "s/&/*/g" $${file} > $${file}_amp.F ;\
		      file=$${file}_amp.F; \
		   else \
		      file=$(<D)/TMP/$(<F)_amp.f; sed "s/&/*/g" $< > $${file};\
		   fi; \
		fi; \
	       	$(CPP) $(CPPFLAGS) $${file} $(<D)/TMP/$(<F)_cpp.f;\
	       	$(FC) $(FFLAGS) -o $@ -c $(<D)/TMP/$(<F)_cpp.f
# The End
