
# arch-tag: 8b57b532-bc60-49dc-8fc0-77605d0a646f

VERSION:= $(shell tla logs -r | head -1 | sed -e 's/^patch-//')
NAME:=hsregex-0.$(VERSION)
 
CFLAGS:= -DHAVE_PCRE_H -DHAVE_REGEX_H $(shell pcre-config  --cflags)
LDFLAGS:= $(shell pcre-config --libs)

%.hs : %.hsc
	hsc2hs $(CFLAGS) $<

LIBFILES:=  RRegex.hs RRegex/PCRE.hs RRegex/Syntax.hs RRegex/Posix.hs  RRegex/TH.hs

hsgrep: Main.hs $(LIBFILES) 
	ghc $(CFLAGS) --make Main.hs -o $@ $(LDFLAGS)

clean:
	rm -f *.hi RRegex/*.hi *.o RRegex/*.o hsgrep RRegex/Posix.hs RRegex/PCRE.hs
	rm -f *.hsp *.hspp RRegex/*.hsp RRegex/*.hspp 

%.hsp : %.hspp
	sed -e '/^#/d' $< > $@

%.hspp : %.hs
	ghc -cpp $(CFLAGS) -D__HADDOCK__=1 -E $<  

LF:=   $(addsuffix p, $(LIBFILES))

docs: $(LF)  
	mkdir docs || true
	haddock -h $(LF) -o docs
ALL:= $(shell tla inventory -s)
$(NAME).tar.gz: $(ALL)
	tla inventory -s | tar c  -T - | (mkdir $(NAME) &&  cd $(NAME) && tar x && make && make docs && make clean) 
	tar zcvf $@ $(NAME)
	rm -rf $(NAME)

publish: $(NAME).tar.gz
	rm -rf ~/public_html/computer/haskell/hsregex/hsregex-*
	cp $< ~/public_html/computer/haskell/hsregex
	cd  ~/public_html/computer/haskell/hsregex && tar zxvf $<
	#mkdir ~/public_html/computer/haskell/hsregex/hsregex
	#cp -rv . ~/public_html/computer/haskell/hsregex/hsregex 
	make -C ~/public_html/
	

realclean:
	rm -rf docs
	rm -f hsregex-*.tar.gz

.PHONY: docs clean publish  realclean
