# Makefile for inetutils
#
# Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
#
# Written by Miles Bader <miles@gnu.ai.mit.edu>
#
# This program 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.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

SHELL = /bin/sh

srcdir = @srcdir@
top_srcdir = @top_srcdir@
include config.make

# @subdirs@ represents configure's list of auxilarly packages that are needed.
pkgdirs = @subdirs@

SUBDIRS = $(pkgdirs) @SUBDIRS@
SERVERS = $(pkgdirs) @COMMON@ @SERVERS@
CLIENTS = $(pkgdirs) @COMMON@ @CLIENTS@
BOTH = $(pkgdirs) @COMMON@ @SERVERS_OR_CLIENTS@
DIST_SUBDIRS = @SUBDIRS@

DISTFILES = $(DIST_SUBDIRS) ChangeLog INSTALL NEWS README THANKS TODO \
	config.guess config.make.in config.sub configure configure.in \
	iumacros.m4 install-sh mkinstalldirs rules.make paths
DISTPACKAGES = glob
MAINTCLEAN = configure

DISTCLEAN = include config.make config.status config.log config.cache \
	Makefile pathdefs.make paths.defs

all:	   $(addsuffix -all,$(BOTH))
install:   install-both
uninstall: uninstall-both
clients:   $(addsuffix -all,$(CLIENTS))
servers:   $(addsuffix -all,$(SERVERS))

clean: clean-subdirs
distclean: distclean-subdirs
	$(RM) -rf $(DISTCLEAN)
maintainer-clean: maintainer-clean-subdirs
	$(RM) -rf $(DISTCLEAN) $(MAINTCLEAN)

# We can't use the generic %-subdirs rule because we don't want to do make dist
# in aux package directories; those will get done using DISTPACKAGES.
dist-subdirs:	$(addprefix dist-, $(DIST_SUBDIRS))	;

%-clients: $(addprefix %-,$(CLIENTS))	;
%-servers: $(addprefix %-,$(SERVERS))	;
%-both:    $(addprefix %-,$(BOTH))	;
%-subdirs: $(addprefix %-,$(SUBDIRS))	;

$(addsuffix -all,$(SUBDIRS))       : %-all       : ; $(MAKE) -C $* all
$(addprefix install-,$(SUBDIRS))   : install-%   : ; $(MAKE) -C $* install
$(addprefix uninstall-,$(SUBDIRS)) : uninstall-% : ; $(MAKE) -C $* uninstall
$(addprefix clean-,$(SUBDIRS))     : clean-%     : ; $(MAKE) -C $* clean
$(addprefix distclean-,$(SUBDIRS)) : distclean-% : ; $(MAKE) -C $* distclean
$(addprefix maintainer-clean-,$(SUBDIRS)) : maintainer-clean-% : ; $(MAKE) -C $* maintainer-clean

$(addprefix dist-,$(SUBDIRS))      : dist-%      :
	$(MAKE) -C $* dist DISTDIR=../$(DISTDIR)/$*

dist: dist-prepare dist-subdirs dist-package

DISTDIR = `cat distname`
distname: libinetutils/version.c
	echo inetutils-`sed -e '/inetutils_version/!d' \
	    -e 's/[^0-9.]*\([0-9.a-z]*\).*/\1/' -e q $<` > $@-tmp
	mv $@-tmp $@
dist-prepare: distname
	rm -rf $(DISTDIR)
	mkdir $(DISTDIR)
	$(LINK_DISTFILES)
	@for P in $(DISTPACKAGES); do \
          { ln 2>/dev/null $(srcdir)/$$P $(DISTDIR)/$$P		 \
            && echo ln $(srcdir)/$$P $(DISTDIR)/$$P; }		 \
          || { echo cp -pfR $(srcdir)/$$P $(DISTDIR)/$$P	 \
	      ; cp -pfR $(srcdir)/$$P $(DISTDIR)/$$P; };	 \
	done
dist-package: distname
	tar --gzip -chvf $(DISTDIR).tar.gz $(DISTDIR)
	rm -rf $(DISTDIR) distname

.PHONY: clients servers both subdirs
