# "My name is OZYMANDIAS, King of Kings:
#  Look on my Makefiles, ye Mighty, and despair!"
# No thing beside remains. Round the decay
# Of that collossal wreck, boundless and bare
# The lone and level sands stretch far away.

# Jokes aside: If you're looking to add emoticons, you're probably looking for
# the file named SMILEYS.

STAGEDIR  :=	out
EMOTEDIR  :=	$(STAGEDIR)/Smileys/f9
SRCDIR    :=	src
PKGDIR    :=	$(PWD)

GIFNAMES  :=	$(shell sed '/^\(#\|$$\)/d' SMILEYS | awk '{print $$2}')
OUTGIFS   :=	$(patsubst %,$(EMOTEDIR)/%.gif,$(GIFNAMES))
COMMA     := ,
EMOTELIST :=	$(patsubst %,"%"$(COMMA)\n,$(GIFNAMES))

MISC_SRCS :=	$(wildcard $(SRCDIR)/*)
MISC_OUT  :=	$(patsubst $(SRCDIR)/%,$(STAGEDIR)/%,$(MISC_SRCS))

PROJECT := f9_emotes

include ../plugin.mk

pre-package: $(OUTGIFS) $(MISC_OUT)

$(STAGEDIR)/%.php: $(SRCDIR)/%.php
	@echo $< '=>' $@
	@sed 's/@@SMILEYS@@/\n $(EMOTELIST)/' $< > $@

$(STAGEDIR)/%: $(SRCDIR)/%
	@echo $< '=>' $@
	@cp $< $@

$(EMOTEDIR)/%.gif : SRC = $(shell grep -E '\b$*$$' SMILEYS | awk '{print $$1}').gif
$(EMOTEDIR)/%.gif: out/Smileys/f9
	@echo ' +' $(SRC)
	@cp $(SRC) $@


$(EMOTEDIR):
	mkdir -p $@

.PHONY: clean
clean:
	rm -fr $(STAGEDIR)
	rm -f f9_emotes.tar.gz
