#
# Makefile for iztaci-gar-packages
#


PREFIX ?= /usr

# Not FHS compliant but oh well...
gardir = $(PREFIX)/gar

DIRS = $(gardir)

VERSION  = $(shell cat VERSION)
DISTBASE = iztaci-gar-packages-$(VERSION)
DISTFILE = $(DISTBASE).tar.xz

all: install

install:
	install -v -d $(addprefix $(DESTDIR), $(DIRS))
	find -name level.mk | cut -f2 -d/ | sed 's|/level.mk||g' | sort -u | xargs -i cp -vdR {} $(DESTDIR)$(gardir)
	@echo
	@echo ---------------------------------------------------------------------------
	@echo                The Iztaci GAR packages have been installed.
	@echo ---------------------------------------------------------------------------

dist:
	@mkdir -pv distfiles/$(DISTBASE)
	if test -f distfiles/$(DISTFILE); then                             \
	   echo; echo distfiles/$(DISTFILE) exists already.; echo;         \
	   exit 1;                                                         \
	else                                                               \
	   tar c --exclude .git --exclude distfiles -f- . | tar x -f- -C distfiles/$(DISTBASE); \
	   cd distfiles; tar cvJ $(DISTBASE) -f $(DISTFILE);               \
	fi
	rm -rf distfiles/$(DISTBASE)
	@echo
	@echo distfiles/$(DISTFILE) has been successfully created.
	@echo
