# GNU Makefile
# to copy new files to staging directory
# and touch appropriate files 
#
# 01/26/98 C. Ludescher
#  
#
MARK=$(CODESYSDIR)/marker/sglib
SRC=$(CODESYSDIR)/sglib

ifeq ($(OPT),F)
# Fortran: copy as *.for
define update
@echo $*or
sed -e"/usr_dcl/s/usr_/sys$$/" $< > tmp 
sed -e"s/usr_/usr$$/g" -e"s/iag_/iag$$/g" -e"s/lib_/lib$$/g" tmp > tmp1
sed -e"/^c@vc/s/^c@vc/c/" tmp1 > tmp2
sed -e"/c@u/s/^/c@u/" -e"/^c@v/s/^c@v//" tmp2 > $(DEST)/tmp
@mv $(DEST)/tmp $(DEST)/$*or
@rm tmp*
@touch $@
endef
 
ffiles = $(shell echo $(SRC)/*.f)

else

# include files: copy as *.for
ifeq ($(OPT),I)
define update
@echo $*.for
sed -e"/^c@vc/s/^c@vc/c/" $< > tmp
sed -e"/c@u/s/^/c@u/" -e"/^c@v/s/^c@v//" tmp > $(DEST)/tmp
@mv $(DEST)/tmp $(DEST)/$*.for
@rm tmp
#@cp $< $(DEST)/$*.for
@touch $@
endef

ffiles = $(shell echo $(SRC)/*_inc $(SRC)/jcticcom)

else

# DCL files: copy as is
define update
@echo $*.for
@cp $< $(DEST)/$*
@touch $@
endef

ffiles = $(shell echo $(SRC)/*.com $(SRC)/*.mms)
endif
endif

files = $(notdir $(ffiles))

all: chkdir copy     
# create marker and vaxport directories
chkdir:
	@echo FILES : $(files)
	@if test ! -d $(MARK); then \
		mkdir $(MARK); fi
	@if test ! -d $(DEST); then \
		mkdir $(DEST); fi    

# copy / touch "newer" files
copy: $(foreach file,$(files),$(MARK)/$(file))
$(MARK)/%: $(SRC)/%
	$(update)



