VERSION := $(shell sed -n 's/\$$version = "\(.*\)";$$/\1/p' common.inc)

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 album.php ] && mv album.php index.php) || true
	[ -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:
ifdef BASEPATH
	echo "#define BASEPATH \"$(BASEPATH)\"" > convert.h
else
	echo "#define BASEPATH \"`pwd`\"" > convert.h
endif


#
# 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 album.php ] || mv index.php album.php
	([ -f config.inc ] && mv config.inc dfl_config.inc) || true
	([ -f style.css ] && mv style.css dfl_style.css) || true
	cp dfl_index.php index.php
