#
# Makefile to compile and install the SUIF compiler
#

# default variables -- these may be overridden
WORKDIR =	src
LOGFILE =	install.log
SHELL =		/bin/sh
SUBDIRS =	basesuif
SUB_PACKAGES =	basesuif

default: build

include $(SUIFHOME)/Makefile.rules
# read the standard definitions
include $(SUIFHOME)/Makefile.defs

MACHINCL =	$(MACHDIR)/include

source:	Makefile.local Makefile.std Makefile.sub Makefile.rules Makefile.defs \
	README.suif FAQ

setup:
	@echo
	@echo "    Setting up directory structures for SUIF."
	@echo
	@# create the include directory
	@if test ! -d $(INCLDIR); then mkdir $(INCLDIR); else : ; fi
	@# create the machine-specific directories
	@if test ! -d $(MACHDIR); then mkdir $(MACHDIR); else : ; fi
	@if test ! -d $(BINDIR); then mkdir $(BINDIR); else : ; fi
	@if test ! -d $(LIBDIR); then mkdir $(LIBDIR); else : ; fi
	@if test ! -d $(SODIR); then mkdir $(SODIR); else : ; fi
	@if test ! -d $(MANDIR); then mkdir $(MANDIR); else : ; fi
	@if test ! -d $(INFODIR); then mkdir $(INFODIR); else : ; fi
	@if test ! -d $(HTMLDIR); then mkdir $(HTMLDIR); else : ; fi
	@if test ! -d $(DOCDIR); then mkdir $(DOCDIR); else : ; fi
	@if test ! -d $(AUTOINITDIR); then mkdir $(AUTOINITDIR); else : ; fi
	@if test ! -d $(VERDATADIR); then mkdir $(VERDATADIR); else : ; fi
	@if test ! -d $(TCLDIR); then mkdir $(TCLDIR); else : ; fi
	@if test ! -d $(MACHINCL); then mkdir $(MACHINCL); else : ; fi
	@# put the FORTRAN header file in the MACHINCL directory
	@# note: other files (e.g. varargs.h) need to go there, too
	@rm -f $(MACHINCL)/sf2c.h
	@( cd $(MACHINCL); ln -s ../../include/sf2c.h . )
	@#
	@# There's a chicken-and-egg proglem with the basesuif/scripts
	@# package: it needs to be installed for packages to install.  So
	@# we short circuit it by installing the scripts here.
	@if test -d src/basesuif/scripts; then cp src/basesuif/scripts/* \
		$(BINDIR); else : ; fi
	@rm -f $(BINDIR)/Makefile

reinstall: show-reinstall

install: show-install

show-install show-reinstall-bin show-reinstall: source
	@if test ! -d $(BINDIR); then \
		echo 1>&2; \
		echo "    The directory structure needed for" \
			"SUIF has not yet been set up." 1>&2; \
		echo "    You will have to run \`\`gmake setup''" \
			"before attempting to install" 1>&2; \
		echo "    the system.  Please see the README" \
			"file for more critical" 1>&2; \
		echo "    information on setup and installation." 1>&2; \
		echo 1>&2; \
		exit 1; \
	else \
		true; \
	fi
	@if test ""$(NIGHTLY) = "" ; then \
		echo; \
		echo "    The full SUIF compiler system is now being" \
			"installed.  To make it"; \
		echo "    easier to tell whether there are installation" \
			"problems and where"; \
		echo "    they occurred, each subpackage will be installed" \
			"separately and"; \
		echo "    the full installation details will be recorded" \
			"in the file"; \
		echo "    "$(LOGFILE)" in each subdirectory.  As each" \
			"installation is"; \
		echo "    completed, a single line will be printed here" \
			"indicating the"; \
		echo "    success or failure of that particular" \
			"installation."; \
		echo; \
	else \
		true; \
	fi
	@if test ""$(NIGHTLY_STATUS) = master ; then \
		rm -f $(NIGHTLYREADYDIR)/* ; \
	else \
		true; \
	fi
	@export SUB_PACKAGES ; SUB_PACKAGES= ; \
	for dir in $(SUBDIRS); do \
	    if test ""$(NIGHTLY_STATUS) = slave ; then \
		file_stall -silent -name $$dir $(NIGHTLYREADYDIR)/$$dir; \
	    fi; \
	    if test -d $(SUIFHOME)/RCS/$$dir ; then \
		rm -rf $(WORKDIR)/$$dir; \
	    fi; \
	    if test ! -d $(WORKDIR)/$$dir; then \
		mkdir $(WORKDIR)/$$dir; \
		ln -s $(SUIFHOME)/RCS/$$dir $(WORKDIR)/$$dir/RCS ; \
		(cd $(WORKDIR)/$$dir; co Makefile > /dev/null 2>&1); \
	    fi; \
	    if test -d $(WORKDIR)/$$dir; then \
		( cd $(WORKDIR)/$$dir; \
		$(MAKE) $@ | grep -v 'Entering directory' | \
			grep -v 'Leaving directory'; \
		$(MAKE) clean 1>> $(LOGFILE) 2>&1 ); \
	    fi; \
	    if test ""$(NIGHTLY_STATUS) = master ; then \
		touch $(NIGHTLYREADYDIR)/$$dir; \
	    else \
		true; \
	    fi; \
	done

install-noisy: source
	@export SUB_PACKAGES ; SUB_PACKAGES= ; \
	for dir in $(SUBDIRS); do \
	    if test -d $(WORKDIR)/$$dir; then \
		( cd $(WORKDIR)/$$dir; \
		SUB_PACKAGES= $(MAKE) install ; \
		$(MAKE) clean ); \
	    fi; \
	done

install-ver:
	@ver_assert_ver_does_not_exist $(VERSION)
	@ver_build_current $(VERSION)

build:
	@export SUB_PACKAGES ; SUB_PACKAGES= ; \
	for dir in $(SUBDIRS); do \
	    if test -d $(WORKDIR)/$$dir; then \
		( cd $(WORKDIR)/$$dir; $(MAKE) ); \
	    fi; \
	done

clean:
	@-export SUB_PACKAGES ; SUB_PACKAGES= ; \
	for dir in $(SUBDIRS); do \
		if test -d $(WORKDIR)/$$dir; then \
		    ( cd $(WORKDIR)/$$dir; $(MAKE) clean ); \
		fi \
	done

clean-rcs-links:
		suif-recursive-make clean-rcs-links
		if test -d RCS ; then \
			rm RCS > /dev/null 2>&1 ; \
			echo > /dev/null 2>&1 ; \
		else : ; \
		fi

sub-packages:
	@echo $(SUBDIRS)
