# Emacs Makefile for TRAMP
# @configure_input@

# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.

# Author: kai.grossjohann@gmx.net
#         michael.albinus@gmx.de
# Keywords: comm, processes

# This file is part of GNU Emacs.

# GNU Emacs is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# GNU Emacs is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with GNU Emacs; see the file COPYING.  If not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.

# This Makefile requires GNU make and GNU tar.

# N.B.  Configuration of utilities for XEmacs packages is done in
# ../../Local.rules.  These have no effect on XEmacs's package build
# process (and thus live inside the conditional).

@SET_MAKE@
EMACS		= @EMACS@
EMACS_INFO	= @EMACS_INFO@
MAKEINFO	= @MAKEINFO@
RM		= -rm -f
AUTOCONF	= autoconf

DESTDIR		=
DIRS		= lisp texi

CONFIG_FILES	= @TRAMP_CONFIG_FILES@
CLEAN_FILES	= @TRAMP_CLEAN_FILES@

# To be used by maintainer only.
VERSION		= $(subst .,-,@PACKAGE_VERSION@)
TARNAME		= @PACKAGE_TARNAME@-@PACKAGE_VERSION@
EMACS_TARGET	= ../emacs
XEMACS_TARGET	= ../xemacs/packages/xemacs-packages/tramp

# Can't use wildcard tramp-*.el since that would catch tramp-efs.el,
# too, which isn't included in Emacs.
# lisp/trampver.el is not listed here since it is a generated file,
# but the files listed here are subjected to "cvs diff".  We just copy
# lisp/trampver.el.
EMACS_EL_FILES = lisp/tramp-cache.el lisp/tramp.el lisp/tramp-ftp.el	\
		lisp/tramp-smb.el lisp/tramp-util.el lisp/tramp-uu.el	\
		lisp/tramp-vc.el

# texi/trampver.texi is not listed here since it is a generated file,
# but the files listed here are subjected to "cvs diff".  We just copy
# texi/trampver.texi.
EMACS_TEXI_FILES = texi/tramp.texi

# XEmacs Tramp package has the same filesystem structure like Tramp
# itself.  Furthermore, it doesn't take *.el and *.texi only.  So one
# target is sufficient.  ChangeLog is copied to ChangeLog.upstream,
# lisp/trampver.el and texi/trampver.texi are copied, too.
XEMACS_FILES = CONTRIBUTORS						\
		lisp/ChangeLog lisp/tramp-cache.el lisp/tramp-efs.el	\
		lisp-tramp-ftp.el lisp/tramp-smb.el lisp/tramp-util.el	\
		lisp/tramp-uu.el lisp/tramp-vc.el lisp/tramp.el	\
		test/test-harness.el test/tramp-expr.el			\
		test/tramp-file-name.el test/tramp-path.el		\
		texi/ChangeLog texi/tramp.texi				\
		texi/tramp_ja.texi

TRAMP_EMACS_MERGE_VERSION = @TRAMP_EMACS_MERGE_VERSION@
TRAMP_EMACS_MERGE_TAG = $(subst .,-,V-@TRAMP_EMACS_MERGE_VERSION@)

# ftp upload program to be used.
ifeq (@FTP_UPLOAD@, yes)
  # Michaels flavor.
  FTP_UPLOAD = ftp-upload --host ftp-upload.gnu.org \
			  --dir /incoming/ftp
else
  # Kais flavor.
  FTP_UPLOAD = ftp -u ftp://ftp-upload.gnu.org/incoming/ftp
endif

# Decrease noise.
.SILENT: all lisp info install clean

.PHONY: all install lisp info clean distclean tags	\
	maintainer-clean cvstag MANIFEST tar emacs	\
	xemacs savannah cvs-update

all install: $(CONFIG_FILES)
	for a in ${DIRS}; do				\
	    $(MAKE) -C $$a				\
	    "EMACS=$(EMACS)" "EMACS_INFO=$(EMACS_INFO)"	\
	    "DESTDIR=$(DESTDIR)" $(MAKECMDGOALS);	\
	done

lisp: $(CONFIG_FILES)
	$(MAKE) -C lisp					\
	    "EMACS=$(EMACS)" "EMACS_INFO=$(EMACS_INFO)"	\
	    "DESTDIR=$(DESTDIR)" all

info: $(CONFIG_FILES)
	$(MAKE) -C texi					\
	    "EMACS=$(EMACS)" "EMACS_INFO=$(EMACS_INFO)"	\
	    "DESTDIR=$(DESTDIR)" all

clean:
	$(RM) $(CLEAN_FILES)				\
	      $(addprefix test/, $(CLEAN_FILES))
	for a in ${DIRS} contrib; do			\
	    $(MAKE) -C $$a clean;			\
	done

distclean: clean
	for a in ${DIRS} contrib; do			\
	    $(MAKE) -C $$a distclean;			\
	done
	$(RM) $(CONFIG_FILES) MANIFEST *.tar.gz*
	$(RM) -r autom4te.cache info

tags:
	etags lisp/*.el texi/*.texi

# Maintainer targets.

maintainer-clean: distclean
	$(RM) configure config.status

cvstag:
	cvs tag V-$(VERSION)

# Depends on configure in order to run autoconf.  All files
# which shall be produced on customer host, should be removed.
MANIFEST: configure distclean
	find . \( -name CVS    -prune \)		\
	    -o \( -name info   -prune \)		\
	    -o \( -name tmp    -prune \)		\
	    -o \( -name tramp2 -prune \)		\
	    -o \( -type f \!   -name *,v		\
			  \!   -name .cvsignore \)	\
	    -print > MANIFEST
	./config.status

tar: MANIFEST
	mkdir $(TARNAME)
	tar cpfT - MANIFEST | ( cd $(TARNAME) ; tar xpf - )
	chmod -R a+r $(TARNAME)
	tar cvpfz $(TARNAME).tar.gz $(TARNAME)
	$(RM) -r $(TARNAME)
	gpg --detach-sign $(TARNAME).tar.gz
	echo "directory: tramp" >$(TARNAME).tar.gz.directive
	gpg --clearsign $(TARNAME).tar.gz.directive
	$(RM) $(TARNAME).tar.gz.directive
	chmod a+r $(TARNAME).tar.gz*

emacs:
	./configure --with-contrib --with-packaging --with-emacs;	     \
	cvs -f diff -u -r$(TRAMP_EMACS_MERGE_TAG) -rV-$(VERSION)	     \
		$(EMACS_EL_FILES) > tramp-emacs-merge.diff || true;	     \
	( cd $(EMACS_TARGET)/lisp/net; patch -p1 ) < tramp-emacs-merge.diff; \
	cp lisp/trampver.el $(EMACS_TARGET)/lisp/net;			     \
	cvs -f diff -u -r$(TRAMP_EMACS_MERGE_TAG) -rV-$(VERSION)	     \
		$(EMACS_TEXI_FILES) > tramp-emacs-merge2.diff || true;	     \
	( cd $(EMACS_TARGET)/man; patch -p1 ) < tramp-emacs-merge2.diff;     \
	cp texi/trampver.texi $(EMACS_TARGET)/man;			     \
	ls $(EMACS_TARGET)/lisp/net/*.rej >/dev/null 2>/dev/null &&	     \
		echo "WARNING!  Patch in lisp/net didn't apply cleanly.";    \
	ls $(EMACS_TARGET)/man/*.rej >/dev/null 2>/dev/null &&		     \
		echo "WARNING!  Patch in man didn't apply cleanly.";	     \
	echo "Don't forget to update the ChangeLog for Emacs.";		     \
	echo "Also remember to update Emacs merge revision in configure.ac."

xemacs:
	./configure --with-contrib --with-packaging --with-xemacs;	     \
	cvs -f diff -u -r$(TRAMP_EMACS_MERGE_TAG) -rV-$(VERSION)	     \
		$(XEMACS_FILES) > tramp-xemacs-merge.diff || true;	     \
	patch -p0 -d $(XEMACS_TARGET) < tramp-xemacs-merge.diff;	     \
	find $(XEMACS_TARGET) -name "*.rej" >/dev/null 2>/dev/null &&	     \
		echo "WARNING!  Patch didn't apply cleanly.";		     \
	cp lisp/trampver.el $(XEMACS_TARGET)/lisp;			     \
	cp texi/trampver.texi $(XEMACS_TARGET)/texi;			     \
	cp ChangeLog $(XEMACS_TARGET)/ChangeLog.upstream;		     \
	echo "Don't forget to update AUTHOR_VERSION in Makefile.";	     \
	echo "Don't forget to update the ChangeLog for XEmacs.";	     \
	echo "Announce patch in xemacs-patches mailing list.";		     \
	echo "Also remember to update Emacs merge revision in configure.ac."

savannah: tar cvstag
	$(FTP_UPLOAD) $(TARNAME).tar.gz*
	./configure --with-japanese-manual
	$(MAKE) -C texi savannah

cvs-update:
	cvs update -dP

# Targets updating files generated by autoconf and configure.

$(CONFIG_FILES): $(CONFIG_FILES:=.in) config.status
	./config.status

config.status: configure
	./config.status --recheck

configure: aclocal.m4 configure.ac
	$(AUTOCONF)

# Experimental stuff.

# Make "Version foo released." ChangeLog entries.
cl-release:
	for cl in ChangeLog */ChangeLog; do \
	    emacs -nw $$cl --eval \
	    "(progn (add-change-log-entry nil nil nil t) \
	    (backward-delete-char 2) \
	    (insert \"Version @PACKAGE_VERSION@ released.\") \
	    (save-buffer) (kill-emacs))" ; \
	done


syntax highlighted by Code2HTML, v. 0.9.1