## Copyright (C) 1993,1994 by the author(s).
# 
# This software is published in the hope that it will be useful, but
# WITHOUT ANY WARRANTY for any part of this software to work correctly
# or as described in the manuals. See the ShapeTools Public License
# for details.
#
# Permission is granted to use, copy, modify, or distribute any part of
# this software but only under the conditions described in the ShapeTools 
# Public License. A copy of this license is supposed to have been given
# to you along with ShapeTools in a file named LICENSE. Among other
# things, this copyright notice and the Public License must be
# preserved on all copies.

#
# Makefile for shape_RMS (release management system)
#
# Authors: Andreas Lampen (Andreas.Lampen@cs.tu-berlin.de)
#          Axel Mahler (Axel.Mahler@cs.tu-berlin.de)
#
# $Header: Makefile[6.1] Fri Jan 28 20:31:43 1994 andy@cs.tu-berlin.de frozen $
#

# --------------------------------------------------------------------
#		locations and general macros
# --------------------------------------------------------------------

# The base directory of the project's development area.

BASE = /home/stone/shape/development

# Path of a subsystem relative to the root of the system hierarchy
# (e.g. vc/save)

NODEPATH = src/rms

# A short name for the (sub)system (used for building the release ID)

NODENAME = shape_RMS

# The operating system, $(TARGET) shall be built for.

HOSTSYSTEM = s_sunos_4

# The processor type.

HOSTTYPE = sun4

# Preprocessor switches. (eg. -DSTATISTICS)

SWITCHES = 

# Locations and modes for the installation of executables, header
# files, libraries and manuals.

INSTALLBASE = /home/stone/shape
INSTALLBINPATH = $(INSTALLBASE)/bin
INSTALLBINMODE = 755
INSTALLINCPATH = $(INSTALLBASE)/include
INSTALLINCMODE = 444
INSTALLLIBPATH = $(INSTALLBASE)/lib
INSTALLSHAPELIBPATH = $(INSTALLBASE)/lib/shape
INSTALLLIBMODE = 444
INSTALLMANPATH = $(INSTALLBASE)/man
INSTALLMANMODE = 444

# Directories, where local libraries and header files are to be
# installed for project wide use.

LOCALLIBPATH     = $(BASE)/lib
LOCALINCLUDEPATH = $(BASE)/include

# --------------------------------------------------------------------
#		the system's components
# --------------------------------------------------------------------

#
# The system (program, library, etc.) to be built. If you want to
# manage multiple programs, you should introduce multiple targets
# (like TARGET1 TARGET2 or any better names). In this case you 
# have to adjust the system building actions accordingly.

TARGET1 = sfind
TARGET2 = lastrelease

# The release number generator. The version number of this file will
# be used as release identifier for the whole system.

VERSIONFILE = Release	# source
VERSIONOBJECT =		# derived (if source contains program code)

# The names of the subdirectories containing subsystems which are also
# to be built.

SUBSYSTEMS = 

# Aliases for (filesystem links to) $(TARGET).

ALIASES = 

# The regular source and header files.

SOURCE1 = sfind.sh
SOURCE2 = lastrelease.sh
SOURCES = $(SOURCE1) $(SOURCE2)

HEADERS = Makefile.tmpl Shapefile.tmpl Release.tmpl release.c.tmpl \
	stdconf stdrules stdtargets stdvar \
	user_at cptree gen_rel_id mkpdir

# Auxiliary source and header files that are not genuine part of the
# system (eg. a test environment). These will also be processed on
# system building, but will *not* be included in releases.

AUXSOURCES = 

AUXHEADERS = 

# Interface header files. These are the header files to be installed
# together with eg. a library. $(IFHEADERS) usually is a subset of
# $(HEADERS).

IFHEADERS = $(HEADERS)

# The manuals

MANUALS = $(MAN1) $(MAN3) $(MAN4) $(MAN5) $(MAN6) $(MAN7) $(MAN8)
MAN1 = shape_RMS.1 shape_build.1 shape_depend.1 shape_patch.1 \
	shape_releas.1 shape_tar.1 sfind.1
MAN3 = 
MAN4 = 
MAN5 = 
MAN6 = 
MAN7 = shape_stdrul.7 shape_stdvar.7 shape_tmpl.7
MAN8 = 

# All source components of the system (should not be changed)

COMPONENTS = $(SOURCES) $(HEADERS) $(MANUALS) Shapefile Makefile Dependencies

# The derived files. All files, that are autamatically produced during
# a build process should be listed here.

OBJECTS = $(VERSIONOBJECT)

# --------------------------------------------------------------------
#		tools, flags, libraries etc.
# --------------------------------------------------------------------

MAKE = make
SHELL = /bin/sh

INCLUDES = -I$(LOCALINCLUDEPATH)
MAKECFLAGS = -g
MAKELDFLAGS = -g

CC = cc
CFLAGS  = $(INCLUDES) $(MAKECFLAGS) $(SWITCHES)
LDFLAGS = $(MAKELDFLAGS)

RANLIB  = /usr/bin/ranlib

# System libraries, local libraries and lint libraries.

SYSLIBS   =
LOCALLIBS =
LINTLIBS  =

# --------------------------------------------------------------------
#			the targets
# --------------------------------------------------------------------

# The default action (do not change)

all: +all $(ALLTARGETS)

# The final system building action.

targets: $(TARGET1) $(TARGET2)

$(TARGET1): $(SOURCE1)
	@rm -f $(TARGET1); \
	if [ $(HOSTSYSTEM) = s_ultrix ]; \
	then \
	  echo '#!/bin/sh5' > $(TARGET1); \
	else \
	  echo '#!/bin/sh' > $(TARGET1); \
	fi
	cat $(SOURCE1) >> $(TARGET1);
	@chmod +x $(TARGET1)

$(TARGET2): $(SOURCE2)
	@rm -f $(TARGET2); \
	if [ $(HOSTSYSTEM) = s_ultrix ]; \
	then \
	  echo '#!/bin/sh5' > $(TARGET2); \
	else \
	  echo '#!/bin/sh' > $(TARGET2); \
	fi
	cat $(SOURCE2) >> $(TARGET2);
	@chmod +x $(TARGET2)

installtargets: installincludes $(INSTALLBINPATH)/$(TARGET1) $(INSTALLBINPATH)/$(TARGET2)

$(INSTALLBINPATH)/$(TARGET1): $(TARGET1)
	@echo "Installing $(TARGET1) in $(INSTALLBINPATH)"; \
	if [ -f $(INSTALLBINPATH)/$(TARGET1) ] && \
	   [ ! -w $(INSTALLBINPATH)/$(TARGET1) ]; \
	then \
	  chmod u+w $(INSTALLBINPATH)/$(TARGET1); \
	fi; \
	cp $(TARGET1) $(INSTALLBINPATH)/$(TARGET1); \
	chmod $(INSTALLBINMODE) $(INSTALLBINPATH)/$(TARGET1); \
	_aliases="$(ALIASES)"; \
	for i in $$_aliases; \
	do \
	  rm -f $(INSTALLBINPATH)/$$i; \
	  echo "linking $(INSTALLBINPATH)/$(TARGET1) to $(INSTALLBINPATH)/$$i"; \
	  ln $(INSTALLBINPATH)/$(TARGET1) $(INSTALLBINPATH)/$$i; \
	done

$(INSTALLBINPATH)/$(TARGET2): $(TARGET2)
	@echo "Installing $(TARGET2) in $(INSTALLBINPATH)"; \
	if [ -f $(INSTALLBINPATH)/$(TARGET2) ] && \
	   [ ! -w $(INSTALLBINPATH)/$(TARGET2) ]; \
	then \
	  chmod u+w $(INSTALLBINPATH)/$(TARGET2); \
	fi; \
	cp $(TARGET2) $(INSTALLBINPATH)/$(TARGET2); \
	chmod $(INSTALLBINMODE) $(INSTALLBINPATH)/$(TARGET2); \
	_aliases="$(ALIASES)"; \
	for i in $$_aliases; \
	do \
	  rm -f $(INSTALLBINPATH)/$$i; \
	  echo "linking $(INSTALLBINPATH)/$(TARGET2) to $(INSTALLBINPATH)/$$i"; \
	  ln $(INSTALLBINPATH)/$(TARGET2) $(INSTALLBINPATH)/$$i; \
	done

installmanuals: $(MANUALS)
	@-_manuals="$(MAN1)"; \
	for i in $$_manuals; \
	do \
	  echo "Installing $$i in $(INSTALLMANPATH)/man1"; \
	  if [ ! -w $(INSTALLMANPATH)/man1/$$i ]; \
	  then \
	    chmod u+w $(INSTALLMANPATH)/man1/$$i; \
	  fi; \
	  cp $$i $(INSTALLMANPATH)/man1/$$i; \
	  chmod $(INSTALLMANMODE) $(INSTALLMANPATH)/man1/$$i; \
	done; \
	_manuals="$(MAN7)"; \
	for i in $$_manuals; \
	do \
	  echo "Installing $$i in $(INSTALLMANPATH)/man7"; \
	  if [ ! -w $(INSTALLMANPATH)/man7/$$i ]; \
	  then \
	    chmod u+w $(INSTALLMANPATH)/man7/$$i; \
	  fi; \
	  cp $$i $(INSTALLMANPATH)/man7/$$i; \
	  chmod $(INSTALLMANMODE) $(INSTALLMANPATH)/man7/$$i; \
	done

installincludes: $(IFHEADERS)
	@-_components="$(IFHEADERS)"; \
	for i in $$_components; \
	do \
	  echo "Installing $$i in $(INSTALLSHAPELIBPATH)"; \
	  if [ -f $(INSTALLSHAPELIBPATH)/$$i ] && \
	     [ ! -w $(INSTALLSHAPELIBPATH)/$$i ]; \
	  then \
	    chmod u+w $(INSTALLSHAPELIBPATH)/$$i 2> /dev/null; \
	  fi; \
	  if [ -f $(INSTALLSHAPELIBPATH)/$$i ] && \
	     [ ! -w $(INSTALLSHAPELIBPATH)/$$i ]; \
	  then \
	    rm -f $(INSTALLSHAPELIBPATH)/$$i; \
	  fi; \
	  cp $$i $(INSTALLSHAPELIBPATH)/$$i; \
	  if [ $$i = "user_at" ] || [ $$i = "cptree" ] || \
	     [ $$i = "gen_rel_id" ] || [ $$i = "mkpdir" ]; \
	  then \
	    chmod $(INSTALLBINMODE) $(INSTALLSHAPELIBPATH)/$$i; \
	  else \
	    chmod $(INSTALLLIBMODE) $(INSTALLSHAPELIBPATH)/$$i; \
	  fi; \
	done

# The cleanup action. Removes all automatically rederivable files.

doclean:
	rm -f $(TARGET1) $(TARGET2) $(ALIASES) $(OBJECTS)

# Recursive builds. Performed *before* building $(TARGET)

subsystems:
	@_subsystems="$(SUBSYSTEMS)"; \
	for i in $$_subsystems; \
	do \
	  echo cd $$i; \
	  (cd $$i; $(MAKE) \
		BASE=$(BASE) \
		HOSTSYSTEM=$(HOSTSYSTEM) \
		HOSTTYPE=$(HOSTTYPE) \
		SWITCHES="$(SWITCHES)" \
		INSTALLBASE=$(INSTALLBASE) \
		INSTALLBINPATH=$(INSTALLBINPATH) \
		INSTALLBINMODE=$(INSTALLBINMODE) \
		INSTALLINCPATH=$(INSTALLINCPATH) \
		INSTALLINCMODE=$(INSTALLINCMODE) \
		INSTALLLIBPATH=$(INSTALLLIBPATH) \
		INSTALLSHAPELIBPATH=$(INSTALLSHAPELIBPATH) \
		INSTALLLIBMODE=$(INSTALLLIBMODE) \
		INSTALLMANPATH=$(INSTALLMANPATH) \
		INSTALLMANMODE=$(INSTALLMANMODE) \
		LOCALLIBPATH=$(LOCALLIBPATH) \
		LOCALINCLUDEPATH=$(LOCALINCLUDEPATH) \
		MAKE="$(MAKE)" \
		SHELL="$(SHELL)" \
		CC="$(CC)" \
		CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		RANLIB="$(RANLIB)" \
		SYSLIBS="$(SYSLIBS)" \
		VERSIONBINDING=$(VERSIONBINDING) \
		COMPILER=$(COMPILER) \
		QUALITY=$(QUALITY) \
		TOTALRELEASEBASE=$(TOTALRELEASEBASE) \
		PARTIALRELEASEBASE=$(PARTIALRELEASEBASE) \
		ALLTARGETS= \
		MAINTARGET= \
		SHAPELIBPATH=$(SHAPELIBPATH) $(MAINTARGET) ); \
	done

# --------------------------------------------------------------------
#			internals (do not modify)
# --------------------------------------------------------------------

install: +install $(ALLTARGETS)

localinstall: +localinstall $(ALLTARGETS)

clean: +clean $(ALLTARGETS)

+all:
	@-if [ -n "$(ALLTARGETS)" ]; \
	then : ; \
	else \
	  $(MAKE) ALLTARGETS="subsystems targets" MAINTARGET=all \
		BASE=$(BASE) \
		HOSTSYSTEM=$(HOSTSYSTEM) \
		HOSTTYPE=$(HOSTTYPE) \
		SWITCHES="$(SWITCHES)" \
		INSTALLBASE=$(INSTALLBASE) \
		INSTALLBINPATH=$(INSTALLBINPATH) \
		INSTALLBINMODE=$(INSTALLBINMODE) \
		INSTALLINCPATH=$(INSTALLINCPATH) \
		INSTALLINCMODE=$(INSTALLINCMODE) \
		INSTALLLIBPATH=$(INSTALLLIBPATH) \
		INSTALLSHAPELIBPATH=$(INSTALLSHAPELIBPATH) \
		INSTALLLIBMODE=$(INSTALLLIBMODE) \
		INSTALLMANPATH=$(INSTALLMANPATH) \
		INSTALLMANMODE=$(INSTALLMANMODE) \
		LOCALLIBPATH=$(LOCALLIBPATH) \
		LOCALINCLUDEPATH=$(LOCALINCLUDEPATH) \
		MAKE="$(MAKE)" \
		SHELL="$(SHELL)" \
		CC="$(CC)" \
		CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		RANLIB="$(RANLIB)" \
		SYSLIBS="$(SYSLIBS)" \
		VERSIONBINDING=$(VERSIONBINDING) \
		COMPILER=$(COMPILER) \
		QUALITY=$(QUALITY) \
		TOTALRELEASEBASE=$(TOTALRELEASEBASE) \
		PARTIALRELEASEBASE=$(PARTIALRELEASEBASE) \
		SHAPELIBPATH=$(SHAPELIBPATH) all; \
	fi

+install:
	@-if [ -n "$(ALLTARGETS)" ]; \
	then : ; \
	else \
	  $(MAKE) ALLTARGETS="subsystems installtargets" \
		MAINTARGET=install \
		BASE=$(BASE) \
		HOSTSYSTEM=$(HOSTSYSTEM) \
		HOSTTYPE=$(HOSTTYPE) \
		SWITCHES="$(SWITCHES)" \
		INSTALLBASE=$(INSTALLBASE) \
		INSTALLBINPATH=$(INSTALLBINPATH) \
		INSTALLBINMODE=$(INSTALLBINMODE) \
		INSTALLINCPATH=$(INSTALLINCPATH) \
		INSTALLINCMODE=$(INSTALLINCMODE) \
		INSTALLLIBPATH=$(INSTALLLIBPATH) \
		INSTALLSHAPELIBPATH=$(INSTALLSHAPELIBPATH) \
		INSTALLLIBMODE=$(INSTALLLIBMODE) \
		INSTALLMANPATH=$(INSTALLMANPATH) \
		INSTALLMANMODE=$(INSTALLMANMODE) \
		LOCALLIBPATH=$(LOCALLIBPATH) \
		LOCALINCLUDEPATH=$(LOCALINCLUDEPATH) \
		MAKE="$(MAKE)" \
		SHELL="$(SHELL)" \
		CC="$(CC)" \
		CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		RANLIB="$(RANLIB)" \
		SYSLIBS="$(SYSLIBS)" \
		VERSIONBINDING=$(VERSIONBINDING) \
		COMPILER=$(COMPILER) \
		QUALITY=$(QUALITY) \
		TOTALRELEASEBASE=$(TOTALRELEASEBASE) \
		PARTIALRELEASEBASE=$(PARTIALRELEASEBASE) \
		SHAPELIBPATH=$(SHAPELIBPATH) install; \
	fi

+clean:
	@-if [ -n "$(ALLTARGETS)" ]; \
	then : ; \
	else \
	  $(MAKE) ALLTARGETS="subsystems doclean" MAINTARGET=clean \
		BASE=$(BASE) \
		HOSTSYSTEM=$(HOSTSYSTEM) \
		HOSTTYPE=$(HOSTTYPE) \
		SWITCHES="$(SWITCHES)" \
		LOCALLIBPATH=$(LOCALLIBPATH) \
		LOCALINCLUDEPATH=$(LOCALINCLUDEPATH) \
		MAKE="$(MAKE)" \
		SHELL="$(SHELL)" \
		CC="$(CC)" \
		CFLAGS="$(CFLAGS)" \
		LDFLAGS="$(LDFLAGS)" \
		RANLIB="$(RANLIB)" \
		SYSLIBS="$(SYSLIBS)" \
		VERSIONBINDING=$(VERSIONBINDING) \
		COMPILER=$(COMPILER) \
		QUALITY=$(QUALITY) \
		TOTALRELEASEBASE=$(TOTALRELEASEBASE) \
		PARTIALRELEASEBASE=$(PARTIALRELEASEBASE) \
		SHAPELIBPATH=$(SHAPELIBPATH) clean; \
	fi
