# Makefile for upload

TARGET=wiki.txt
FETCHDIR=/Users/hylom/otptools/sfmag2wiki/fetch
OUTDIR=/Users/hylom/otptools/sfmag2wiki/converted
UPLOAD=/Users/hylom/otptools/sfmag2wiki/s2wupload.pl
ATTACH=/Users/hylom/otptools/sfmag2wiki/s2wattach.pl
CONV=/Users/hylom/otptools/sfmag2wiki/sfmag_html2wiki.py
DIRNAME:=$(shell basename $$PWD)

attachments=$(wildcard *.png *jpg *.gif)
targets=wiki.txt.cache $(patsubst %,%.cache, $(attachments))

test:
	@pwd

all:
	for i in *;do [ -d $$i ] && cd $$i && $(MAKE) upload && cd ..; done
#	for i in *;do [ -d $$i ] && cd $$i && $(MAKE) test && cd ..; done


all-all:
	for i in *;do [ -d $$i ] && cd $$i && $(MAKE) upload && cd ..; done

upload: $(targets)

wiki.txt.cache: wiki.txt
	$(UPLOAD) $<
	touch $@

%.jpg.cache: %.jpg
	$(ATTACH) $<
	touch $@

%.png.cache: %.png
	$(ATTACH) $<
	touch $@

%.gif.cache: %.gif
	$(ATTACH) $<
	touch $@

clean-all:
	for i in *;do [ -d $$i ] && cd $$i && $(MAKE) clean && cd ..; done

clean:
	rm -f *.cache

prep:
	for i in *;do [ -d $$i ] && ln -sf ../Makefile $$i/Makefile; done

update:
	@echo $(CONV) $(FETCHDIR)/$(subst -,/,$(DIRNAME)).body.html $(FETCHDIR) $(OUTDIR)
