include Makefile.config

SUBDIRS				=	doc/ gfx/ sfx/ maps/ src/
TARGETS				=	all info clean install install-strip uninstall
RECURSIVE_TARGETS	=	all-recursive clean-recursive distclean-recursive install-recursive \
						install-strip-recursive uninstall-recursive
CONFIGURE_SCRIPT	=	./configure

default: all

all: all-recursive

clean: clean-recursive

distclean: distclean-recursive clean
	$(CONFIGURE_SCRIPT) --clean
	$(DEL_FILE) Makefile.config config.h

install: install-dirs install-recursive

install-strip: install-dirs install-strip-recursive

uninstall: uninstall-recursive uninstall-local uninstall-dirs

snapshot:
	cd ..; \
	$(TBZ2) $(PRODUCT_ID)-$(PRODUCT_VERSION)-$(shell date +%Y%m%d | sed s/\ /\\\\\ /g).tar.bz2 $(PRODUCT_ID)/

stats:
	SOURCES="src/*.cpp src/*.hpp"; \
	echo -n "C chars/lines: "; \
	cat $$SOURCES | wc -cl; \
	echo -n "TODO marks: "; \
	cat $$SOURCES | grep "[^a-z]TODO[^a-z]" | wc -l; \
	echo -n "FIXME marks: "; \
	cat $$SOURCES | grep "[^a-z]FIXME[^a-z]" | wc -l; \
	echo -n "DEBUG marks: "; \
	cat $$SOURCES | grep "[^a-z]DEBUG[^a-z]" | wc -l; \
	echo -n "#ifdef DEBUG blocks: "; \
	cat $$SOURCES | grep "#ifdef DEBUG[^a-z]" | wc -l;

install-dirs:
	@if [ ! -d "$(PREFIX)" ]; \
	then \
		echo "creating directory $(PREFIX)"; \
		$(MK_DIR) "$(PREFIX)"; \
		$(SET_MOD) 755 "$(PREFIX)"; \
	fi
	@if [ ! -d "$(DATA_PREFIX)" ]; \
	then \
		echo "creating directory $(DATA_PREFIX)"; \
		$(MK_DIR) "$(DATA_PREFIX)"; \
		$(SET_MOD) 755 "$(DATA_PREFIX)"; \
	fi
	@if [ -n "$(SAVES_DIR)" ]; \
	then \
		if [ ! -d "$(DATA_PREFIX)$(SAVES_DIR)" ]; \
		then \
			echo "creating directory $(DATA_PREFIX)$(SAVES_DIR)"; \
			$(MK_DIR) "$(DATA_PREFIX)$(SAVES_DIR)"; \
			$(SET_MOD) 755 "$(DATA_PREFIX)$(SAVES_DIR)"; \
		fi; \
	fi

uninstall-dirs:
	@if [ -n "$(SAVES_DIR)" ]; \
	then \
		if [ -d "$(DATA_PREFIX)$(SAVES_DIR)" ]; \
		then \
			echo "removing directory $(DATA_PREFIX)$(SAVES_DIR)"; \
			$(DEL_DIR) "$(DATA_PREFIX)$(SAVES_DIR)"; \
		fi; \
	fi
	@if [ -d "$(DATA_PREFIX)" ]; \
	then \
		echo "removing directory $(DATA_PREFIX)"; \
		$(DEL_DIR) "$(DATA_PREFIX)"; \
	fi
	@if [ -d "$(PREFIX)" ]; \
	then \
		echo "removing directory $(PREFIX)"; \
		$(DEL_DIR) "$(PREFIX)"; \
	fi

uninstall-local:

$(RECURSIVE_TARGETS):
	@target=`echo $@ | sed s/-recursive//`; \
	for dir in $(SUBDIRS); \
	do \
		if [ -d $$dir -a -f $$dir/Makefile ]; \
		then \
			echo "making $$target in $$dir"; \
			$(MAKE) -C $$dir $$target; \
		fi; \
	done
