FORTRAN = gfortran
BIN = /usr/local/bin

.PHONY: all
all: smo

# kludge: cmd to retrieve the current def. unit path of fpc:
# fpc -h | head -n1 | cut -d \  -f 5,8
# may also be a way but the target is not consistent with the
# actual path: i386 instead of linux-i386 and so on...
unitpath: unitpath.pas
	fpc unitpath

gcvspl.o: gcvspl.f
	$(FORTRAN) -c gcvspl.f

.PHONY: gcv09
gcv09: gcv09.pas gcvspl.o
	fpc -gl gcv09.pas

# general smoothing and background substraction code using gcv
smo: gcv09 smo.pas smo.hlp ./s2pp
	./s2pp < smo.hlp > hlp.pas
	fpc -gl smo

.PHONY: clean
clean:
	rm -f *~ *.o *.ppu

.PHONY: distclean
distclean: clean
	rm -f smo unitpath hlp.pas smo.xy
	cd tst ; make distclean ; cd -

.PHONY: install
install: clean unitpath
	@cp -R $$PWD `./unitpath`;\
	cd `./unitpath`/`basename $$PWD`;\
	make;\
	ln -sf $$PWD/smo $(BIN);\
	echo "The current smo command is `which smo`";\
	cd -
