# $Id$
# DDD top-level Makefile.

# Copyright (C) 1996-1998 Technische Universitaet Braunschweig, Germany.
# Written by Andreas Zeller <zeller@gnu.org>.
# 
# This file is part of DDD.
# 
# DDD 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 3 of the License, or (at your option) any later version.
# 
# DDD 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 DDD -- see the file COPYING.
# If not, see <http://www.gnu.org/licenses/>.
# 
# DDD is the data display debugger.
# For details, see the DDD World-Wide-Web page, 
# `http://www.gnu.org/software/ddd/',
# or send a mail to the DDD developers <ddd@gnu.org>.

### CUSTOMIZATION SECTION --- Please check the settings below.
# Typical values are enclosed in ().

## The shell to use.  (/bin/sh)
SHELL = /bin/sh

## The source directory.  (.)
srcdir = @srcdir@
VPATH = @srcdir@

## Subdirectories.  (readline termcap libiberty ddd)
SUBDIRS = @subdirs@

## Architecture.
# The host we were compiled on.  (CPU-COMPANY-SYSTEM)
host_canonical = @host@

# The target we were compiled for.  (CPU-COMPANY-SYSTEM)
target_canonical = @target@

### END OF CUSTOMIZATION SECTION ---
### You shouldn't need to change anything below this line.

## Some programs
# The make program, if not predefined.  ()
@SET_MAKE@

# The autoconf program.  (autoconf)
AUTOCONF = @AUTOCONF@

# The aclocal program.  (aclocal)
ACLOCAL = @ACLOCAL@


## Default target: build all

default: all
	@:
.PHONY: default

## Recursive targets

FLAGS_TO_PASS=\
"host_canonical=$(host_canonical)"\
"target_canonical=$(target_canonical)"

# distclean, realclean -- must cleanup top-level directory

DISTCLEAN_TARGETS = distclean realclean

.PHONY: $(DISTCLEAN_TARGETS)
$(DISTCLEAN_TARGETS): FORCE
	@target=$@; \
	rootme=`pwd`; export rootme; \
	srcroot=`cd $(srcdir); pwd`; export srcroot; \
	for i in $(SUBDIRS); do \
	  rm -f ./$$i/config.cache ./$$i/config.log; \
	  if [ -f ./$$i/Makefile ]; then \
	    echo "==> Making $$target in ./$$i..."; \
	    if (cd ./$$i; $(MAKE) $(FLAGS_TO_PASS) $${target}); then true; \
	    else exit 1; fi; \
          else true; fi; \
        done
	rm -f config.status config.cache config.log Makefile MakeOut
	rm -f .gdbhist *.spec


# other recursive targets

OTHER_TARGETS = all clean mostlyclean TAGS

.PHONY: $(OTHER_TARGETS)
$(OTHER_TARGETS): FORCE
	@target=$@; \
	rootme=`pwd`; export rootme; \
	srcroot=`cd $(srcdir); pwd`; export srcroot; \
	for i in $(SUBDIRS); do \
	  if [ -f ./$$i/Makefile ]; then \
	    echo "==> Making $$target in ./$$i..."; \
	    if (cd ./$$i; $(MAKE) $(FLAGS_TO_PASS) $${target}); then true; \
	    else exit 1; fi; \
          else true; fi; \
        done



## DDD-only targets

DDD_TARGETS = \
	love check debug it depend strip dvi ps pdf man html tags \
	install install-prog install-lib install-man install-info \
	install-c++-lib install-c++-includes \
	uninstall uninstall-prog uninstall-lib uninstall-man uninstall-info \
	uninstall-c++-lib uninstall-c++-includes picsclean

.PHONY: $(DDD_TARGETS)
$(DDD_TARGETS): FORCE
	@target=$@; \
	rootme=`pwd`; export rootme; \
	srcroot=`cd $(srcdir); pwd`; export srcroot; \
	echo "==> Making $$target in ./ddd..."; \
	cd ./ddd; $(MAKE) $${target}


## Dummy targets
.PHONY: scratch
scratch: clean all depend it
	@:

### Distribution stuff

# Build a DDD distribution.
.PHONY: dist
dist:	diststuff disttouch distclean snapshot htmldist picsdist

# Create architecture-independent files in DDD subdirectory.
.PHONY: diststuff
diststuff:
	@cd $(srcdir); \
	target=$@; \
	rootme=`pwd`; export rootme; \
	srcroot=`cd $(srcdir); pwd`; export srcroot; \
	echo "==> Making $@ in ddd..."; \
	( cd ./ddd; $(MAKE) diststuff )

# Touch `configure' files souch that they don't get re-created.
.PHONY: disttouch
disttouch:
	@cd $(srcdir); \
	for i in $(SUBDIRS); do \
	  if test -f ./$$i/Makefile && test -f ./$$i/configure; then \
	    echo "==> Making configure in $$i..."; \
	    if (cd ./$$i; $(MAKE) configure); then true; \
	    else exit 1; fi; \
	    if (cd ./$$i; touch configure); then true; \
	    else exit 1; fi; \
          else true; fi; \
        done

# Create a snapshot distribution from the current DDD development tree.
.PHONY: snapshot
snapshot:
	rm -fr proto-toplev; mkdir proto-toplev
	( \
	    srcroot=`cd $(srcdir); pwd`; export srcroot; \
	    ddd=`sed -n < $(srcdir)/ddd/configure.in 's/^ddd *= *//p'`; \
	    VER=`sed -n < $(srcdir)/ddd/configure.in 's/^VERSION *= *//p'`; \
	    VER=`echo $$VER | sed 's/[^0-9]*\([0-9][^ ]*\) .*/\1/'`; \
	    echo "==> Making $$ddd-$$VER.tar.gz"; \
	    rm -f $$ddd-$$VER.tar.gz; \
	    ln -s $$srcroot proto-toplev/$$ddd-$$VER; \
	    find $(srcdir) -name RCS -prune \
		-o -name CVS -prune \
		-o -name PICS -prune \
		-o -name html -prune \
		-o -name proto-toplev -prune \
		-o -name etc -prune \
		-o -name tests -prune \
		-o -name '.gdbinit.in' -print \
		-o -name '.[a-zA-Z0-9]*' -prune \
		-o -name '*.o' -prune \
		-o -name '*.a' -prune \
		-o -name '*~' -prune \
		-o -name '*#' -prune \
		-o \( -name "$$ddd" -type l \) -prune \
		-o -name "$$ddd-$$VER-*" -prune \
		-o -name "userinfo" -prune \
		-o -name "huffencode" -prune \
		-o -name "ctest" -prune \
		-o -name "cxxtest" -prune \
		-o -name "stringify" -prune \
		-o -name "sun" -prune \
		-o -name "linux" -prune \
		-o -type f -print -o -type l -print | \
	        sed "s,^$(srcdir)/,$$ddd-$$VER/," | sort \
		> proto-toplev/FILES; \
	    ( cd proto-toplev; gtar --create --dereference \
		--verbose --files-from FILES \
		--file - ) | gzip -v -9 > $$ddd-$$VER.tar.gz; \
	)
	rm -fr proto-toplev


# Create a HTML manual distribution.
.PHONY: htmldist
htmldist:
	rm -fr proto-toplev; mkdir proto-toplev
	( \
	    srcroot=`cd $(srcdir); pwd`; export srcroot; \
	    ddd=`sed -n < ddd/configure.in 's/^ddd *= *//p'`; \
	    VER=`sed -n < ddd/configure.in 's/^VERSION *= *//p'`; \
	    VER=`echo $$VER | sed 's/[^0-9]*\([0-9][^ ]*\) .*/\1/'`; \
	    echo "==> Making $$ddd-$$VER-html-manual.tar.gz"; \
	    rm -f $$ddd-$$VER-pics.tar.gz; \
	    ln -s $$srcroot proto-toplev/$$ddd-$$VER; \
	    find $(srcdir)/doc/html -name RCS -prune \
		-o -name CVS -prune \
		-o -name proto-toplev -prune \
		-o -name '.[a-zA-Z0-9]*' -prune \
		-o -name '*.o' -prune \
		-o -name '*.a' -prune \
		-o -name '*~' -prune \
		-o -name '*#' -prune \
		-o -type f -print -o -type l -print | \
	        sed "s,^$(srcdir)/,$$ddd-$$VER/," | sort \
		> proto-toplev/FILES; \
	    ( cd proto-toplev; gtar --create --dereference \
		--verbose --files-from FILES \
		--file - ) | gzip -v -9 > $$ddd-$$VER-html-manual.tar.gz; \
	)
	rm -fr proto-toplev


# Create a picture distribution.
.PHONY: picsdist
picsdist:
	rm -fr proto-toplev; mkdir proto-toplev
	( \
	    srcroot=`cd $(srcdir); pwd`; export srcroot; \
	    ddd=`sed -n < ddd/configure.in 's/^ddd *= *//p'`; \
	    VER=`sed -n < ddd/configure.in 's/^VERSION *= *//p'`; \
	    VER=`echo $$VER | sed 's/[^0-9]*\([0-9][^ ]*\) .*/\1/'`; \
	    echo "==> Making $$ddd-$$VER-pics.tar.gz"; \
	    rm -f $$ddd-$$VER-pics.tar.gz; \
	    ln -s $$srcroot proto-toplev/$$ddd-$$VER; \
	    find $(srcdir)/ddd/PICS -name RCS -prune \
		-o -name CVS -prune \
		-o -name proto-toplev -prune \
		-o -name '.[a-zA-Z0-9]*' -prune \
		-o -name '*.o' -prune \
		-o -name '*.a' -prune \
		-o -name '*~' -prune \
		-o -name '*#' -prune \
		-o -type f -print -o -type l -print | \
	        sed "s,^$(srcdir)/,$$ddd-$$VER/," | sort \
		> proto-toplev/FILES; \
	    ( cd proto-toplev; gtar --create --dereference \
		--verbose --files-from FILES \
		--file - ) | gzip -v -9 > $$ddd-$$VER-pics.tar.gz; \
	)
	rm -fr proto-toplev


## Configuration stuff.

Makefile: Makefile.in config.status
	CONFIG_FILES=$@ CONFIG_HEADERS= $(SHELL) ./config.status

$(srcdir)/configure: $(srcdir)/ddd/aclocal.m4 $(srcdir)/configure.in
	-cd $(srcdir) && $(AUTOCONF) -l $(srcdir)/ddd

$(srcdir)/ddd/aclocal.m4: $(srcdir)/ddd/acinclude.m4 $(srcdir)/configure.in
	-cd $(srcdir)/ddd && $(ACLOCAL)

config.status: $(srcdir)/configure
	-$(SHELL) ./config.status --recheck || $(SHELL) $(srcdir)/configure -v

.PRECIOUS: Makefile configure config.status

## FORCE target

.PHONY: FORCE
FORCE:
	@:
