
SHELL = /bin/sh

# ------------------------------------------------
#   DEFINITIONS
# ------------------------------------------------

#   installation tools
SHTOOL          = ./shtool
INSTALL_SCRIPT  = $(SHTOOL) install -c -m 755
INSTALL_DATA    = $(SHTOOL) install -c -m 644
MKDIR           = $(SHTOOL) mkdir -p -f -m 755
VERSION_TOOL    = $(SHTOOL) version

prefix          = /usr/local
bindir          = $(prefix)/bin
mandir          = $(prefix)/man

# ------------------------------------------------
#   STANDARD TARGETS
# ------------------------------------------------

all: tarcust tarcust.1

tarcust: tarcust.pl
	set -e; path_perl=`$(SHTOOL) path -m perl5 perl`; \
    sed -e "1s|@path_perl@|$${path_perl}|" \
        -e '/__END__/,$$d' tarcust.pl > $@ && chmod a+x $@

tarcust.1: tarcust.pl
	set -e; V=`$(VERSION_TOOL) -l perl -d long version.pl`; \
    pod2man --section=1 \
            --center="A tar Customizer" \
            --release="TarCust $$V" tarcust.pl > $@

install: all
	$(MKDIR) $(bindir)
	$(MKDIR) $(mandir)/man1
	$(INSTALL_SCRIPT) tarcust $(bindir)/tarcust
	$(INSTALL_DATA) tarcust.1 $(mandir)/man1/tarcust.1

clean:
	-rm -f tarcust tarcust.1

distclean: clean
	@:

# ------------------------------------------------
#   THE CONFIGURATION SUPPORT
# ------------------------------------------------

shtool:
	@shtoolize echo version install fixperm mkdir path

# ------------------------------------------------
#   THE RELEASE STUFF
# ------------------------------------------------

TAR    = tar       # where to find GNU Tar
FIND   = find      # where to find a good Find tool
GZIP   = gzip      # where to find GNU Zip
NAME   = barbier   # name of maintainer who rolls the tarball

NEWVERS = \
    $(VERSION_TOOL) -l perl -p TarCust $$OPT version.pl; \
    V=`$(VERSION_TOOL) -l perl -d long version.pl`;\
    sed -e "s/Version .*(.*)/Version $$V/g" <README >README.n && mv README.n README

UPDATEVERS = \
    V=`$(VERSION_TOOL) -l perl -d short version.pl`; \
    $(VERSION_TOOL) -l perl -p TarCust -s $$V version.pl; \
    V=`$(VERSION_TOOL) -l perl -d long version.pl`; \
    sed -e "s/Version .*(.*)/Version $$V/g" <README >README.n && mv README.n README; \
    sed -e "s/\\(TarCust_VersionStr.*\\)\"\\(.*\\)\"/\\1\"$$V\"/" <tarcust.pl >tarcust.n && mv tarcust.n tarcust.pl

_GETDISTINFO = \
    _version=`$(VERSION_TOOL) -l perl -d short version.pl`; \
    _date=`date '+%Y%m%d_%H%M'`;

_BUILDDIST = \
    echo "Creating tarball..."; \
    awk '{print $$1}'  MANIFEST | xargs $(TAR) cvf - |\
    ./tarcust --user-name=$(NAME) \
              --group-name=tarcust \
              --prefix="$${_distname}" - |\
    $(GZIP) --best - >$${_tarball}; \
    ls -l $${_tarball}; \
    echo "Done"

release: fixperm tarcust
	set -e; $(_GETDISTINFO) \
    _distname="tarcust-$${_version}"; \
    _tarball="$${_distname}.tar.gz"; \
    echo "Release Distribution: TarCust Version $$_version"; \
    $(_BUILDDIST)

snap: fixperm tarcust
	set -e; @$(_GETDISTINFO) \
    _distname="tarcust-$${_version}-SNAP"; \
    _tarball="$${_distname}.tar.gz"; \
    echo "Snap of whole source tree: TarCust Version $$_version as of $$_date"; \
    $(_BUILDDIST)

new-version:
	OPT=-iv; $(NEWVERS)

new-revision:
	OPT=-ir; $(NEWVERS)

new-patchlevel:
	OPT=-iP; $(NEWVERS)

new-release:
	OPT=-s$(R); $(NEWVERS)

update-version:
	$(UPDATEVERS)

fixperm:
	$(SHTOOL) fixperm *

##EOF##
