# There are plans to switch to auto tools, this Makefile will work for now.

prefix = /usr/local
bindir = $(prefix)/bin
datadir = $(prefix)/share
AXP_DATADIR = $(datadir)/axp

INSTALL = install -c

all: check-dependencies
	@echo ""
	@echo "Please run one of the following commands:"
	@echo ""
	@echo "	make install                 # use the default prefix $(prefix)"
	@echo "	make install prefix=~/axp                        # or prefix=/opt"
	@echo "	make install bindir=/opt/bin datadir=/opt/share  # unsupported yet"
	@echo ""
	@echo "If you don't change the prefix, then axp executable is installed"
	@echo "into $(bindir) and axp data (perl library) into $(datadir)/axp."
	@echo ""

install: check-dependencies
	$(INSTALL) -d -m 755 $(bindir)
	$(INSTALL) bin/axp $(bindir)
	@for dir in perllib; do \
		for file in `find $$dir -follow -type f -print | grep -v .arch-ids`; do \
			echo install: $(AXP_DATADIR)/$$file; \
			$(INSTALL) -d -m 755 `dirname $(AXP_DATADIR)/$$file`; \
			$(INSTALL) -m 644 $$file $(AXP_DATADIR)/$$file; \
		done; \
	done

check-dependencies: 
	@perl -M5.005 -e '' \
		|| echo "WARNING: You don't seem to have perl >= 5.005 installed"

# needed for development only; released tarballs include perllib/Arch inline
../arch-perl/perllib/Arch:
	@echo "No arch-perl found in the parent directory, needed for this project."
	@echo "Please execute the following command:"
	@echo "	tla get migo@homemail.com--Perl-GPL/arch-perl--devel--0 ../arch-perl"
	@exit 1

# needed for development only; released tarballs include the required revision
check-required-arch-perl-revision:
	@revision=`cat ./.required-arch-perl-revision`; \
	if [ ! -f ../arch-perl/\{arch\}/arch-perl/arch-perl--devel/arch-perl--devel--0/migo@homemail.com--Perl-GPL/patch-log/$$revision ]; then \
		echo "Your arch-perl tree is not up to date, at least $$revision is required"; \
		echo "Please execute the following command:"; \
		echo "	tla update -d ../arch-perl"; \
		exit 1; \
	fi
