VERSION := $(shell sed -n 's/$$version = "\(.*\)";/\1/p' common.inc)
BASEPATH ?= `pwd`
UID != id -u


default: suid

nosuid: setup
	chmod -R a+w cache

suid: setup
	@echo "Performing suid install--I hope you're not doing this as"
	@echo "root!  If this doesn't work, try"
	@echo "  make nosuid"
	chmod u+s convert

setup: convert
	[ -f config.inc ] || cp dfl_config.inc config.inc
	[ -f style.css ] || cp dfl_style.css style.css

convert: convert.c convert.h
	$(CC) $(CPPFLAGS) $(CFLAGS) $< -o $@

convert.h:
	echo "#define BASEPATH \"$(BASEPATH)\"" > convert.h

#
# Everything below here is stuff I use to make the distribution
#

clean:
	find . -name \*~ -exec rm -f {} \;
	rm -f convert

cache-clean:
	find cache -name \*__scaled\* -exec rm -f {} \;

dist: dist-clean stubs
	cd .. && tar czf $(HOME)/tmp/phpix-$(VERSION).tar.gz --group=0 --owner=0 --exclude=CVS phpix

zip:
	rm -f $(HOME)/tmp/phpix-$(VERSION).zip
	cd .. && zip -q -r $(HOME)/tmp/phpix-$(VERSION).zip phpix

dist-clean: clean cache-clean
	rm -f convert.h

stubs:
	([ -f config.inc ] && mv config.inc dfl_config.inc) || true
	([ -f style.css ] && mv style.css dfl_style.css) || true
