#!/bin/sh
# -*- Makefile -*-

# This wrapper was written by Michael Olson <mwolson@gnu.org>.

# The purpose for doing this is to ensure that only the first argument
# is acted on.  There does not seem to be a feasible way of doing this
# using Make.

# The only inconveniences we suffer here are (1) an extra shell
# instance is loaded and (2) all `$' characters must be escaped.

[ "$1" = "emacs" ] && exit 0

make -f - $1 <<EOF
## Written by Gergely Nagy <algernon@debian.org>
## Adapted by Mario Lang <mlang@debian.org>
## Adapted by Michael Olson <mwolson@gnu.org>

PACKAGE	:= erc
ELDIR	:= /usr/share/emacs/site-lisp/\${PACKAGE}
ELFILES	:= \$(subst \${ELDIR}/,,\$(wildcard \${ELDIR}/erc*.el))
SITEFLAG = --no-site-file
FLAGS	= -q -batch -l path.el -f batch-byte-compile
FLAVOUR	= $1
ELCDIR	= /usr/share/\${FLAVOUR}/site-lisp/\${PACKAGE}
FILES   = \$(filter-out erc-bbdb.el erc-speedbar.el erc-speak.el \
	     erc-chess.el erc-ibuffer.el, \${ELFILES})

xemacs%: SITEFLAG = -no-site-file

emacs20:
	@echo install/erc: Handling install for emacsen flavor \$@
	@echo Sorry, ERC no longer works with emacs20.
	@echo We recommend that you install emacs21.

\${ELCDIR}/path.el:
	@install -m 755 -d \${ELCDIR}
	@cd \${ELCDIR} && \
	echo "(setq load-path (cons \".\" load-path) \
	            byte-compile-warnings nil)" > path.el

.PHONY: $1
$1: \${ELCDIR}/path.el
	@echo install/erc: Handling install for emacsen flavor \$(FLAVOUR)
	@cd \${ELCDIR} && \
	for i in \${ELFILES}; do ln -sf \${ELDIR}/\$\$i \${ELCDIR}; done && \
	\${FLAVOUR} \${SITEFLAG} \${FLAGS} \${FILES}
	@cd \${ELCDIR} && rm -f path.el

.SUFFIXES:
EOF
