##############################################################################
#                                                                            #
#    Makefile,v
#    Main Makefile
#                                                                            #
#    Copyright (C) 1995 A. Bode, S. Lamberts, T. Ludwig, C. R"oder           #
#                                                                            #
#    PFSLib (Parallel I/O on workstations)                                   #
#                                                                            #
#    PFSLib offers parallel access to files for a parallel application       #
#    running on a cluster of workstations.                                   #
#    It is intended but not restricted to be used in message passing         #
#    applications based on PVM, NXLib, MPI, and other.                       #
#                                                                            #
#    PFSLib consists of a LIBRARY, deamon PROGRAMS, and utility PROGRAMS.    #
#                                                                            #
#    PFSLib is free software; you can redistribute the LIBRARY and/or        #
#    modify it under the terms of the GNU Library General Public             #
#    License as published by the Free Software Foundation; either            #
#    version 2 of the License, or (at your option) any later version.        #
#    You can redistribute the daemon PROGRAMS and utility PROGRAMS           #
#    and/or modify them under the terms of the GNU General Public            #
#    License as published by the Free Software Foundation; either            #
#    version 2 of the License, or (at your option) any later version.        #
#                                                                            #
#    PFSLib 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       #
#    Library General Public License and GNU General Public License           #
#    for more details.                                                       #
#                                                                            #
#    You should have received a copy of the GNU Library General Public       #
#    License and the GNU General Public License along with this              #
#    library; if not, write to the Free                                      #
#    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.      #
#                                                                            #
#    Contact to the authors:                                                 #
#                                                                            #
#    electronic mail: pfslib@informatik.tu-muenchen.de                       #
#                                                                            #
#    paper mail:      Prof. Dr. A. Bode                                      #
#                     Lehrstuhl f"ur Rechnertechnik und                      #
#                     Rechnerorganisation                                    #
#                     Institut f"ur Informatik                               #
#                     Technische Universit"at M"unchen                       #
#                     80290 M"unchen                                         #
#                     Germany                                                #
#                                                                            #
#    This project was partially funded by a research grant form Intel        #
#    Corporation.                                                            #
#                                                                            #
##############################################################################


##############################################################################
#                                                                            #
#  RCS Filename : Makefile,v
#  RCS Date     : 1996/12/27 16:07:21
#  RCS Revision : 1.11
#  RCS Author   : lamberts
#  RCS State    : V2_0_B
#                                                                            #
#  Authors: Stefan Lamberts                                                  #
#                                                                            #
##############################################################################


##############################################################################
# Different architectures                                                    #
##############################################################################
#
# Coose one of the following architectures
#
# If you want to use a compiler other than gcc edit the appropriate 
# Makefile.$(ARCH)
#

# Sun 4 running SunOS 4.1.X #
#ARCH	= SUN4

# Sun 4 running SunOS 5.X called Solaris 2 #
#ARCH	= SUN4SOL2

# HP running HPUX 9.X #
#ARCH	= HPPA

# IBM RS6000 running AIX 3.2 #
#ARCH	= RS6K

# IBM PC and Compatible running Linux
#ARCH	= LINUX

##############################################################################
# Installation directory                                                     #
##############################################################################

INSTALLDIR	= $(HOME)/PFSLib_V2_0_$(ARCH)

##############################################################################
# DO NOT EDIT BELOW THIS LINE                                                #
##############################################################################

##############################################################################
# Macros                                                                     #
##############################################################################

SHELL		= /bin/sh

ADDDIR		= add
PFSDDIR		= pfsd
IODDIR		= iod
CLNTDIR		= clnt
CMDDIR		= cmds
INCDIR		= include

DIRS		= $(ADDDIR) $(PFSDDIR) $(IODDIR) $(CLNTDIR) $(CMDDIR) $(INCDIR)

ARCH_FILE	= .arch
DEFINES_FILE	= .cppdefines
IODPATH_FILE    = .iod_exec_path

INSTALLBINDIR	= $(INSTALLDIR)/bin
INSTALLLIBDIR	= $(INSTALLDIR)/lib
INSTALLINCDIR	= $(INSTALLDIR)/include

IOD_EXEC_PATH	= $(INSTALLBINDIR)/iod

##############################################################################
# Default commands and flags                                                 #
##############################################################################

#
# NO_XDR_DIST_LIST	: DIST_LIST will no be converted to XDR format
#			  This will work on heterogeneous machines and
#			  performs much better.
#
# DEBUG			: Print debug information.
#
# TIMING		: Produce timing information for internal PFSLib
#			  functions and offers a call to print this
#			  information.
#
# FILE_LOCKING		: Perform Unix file locking during I/O operations.
#
# CHILD_DEBUG		: Child process waits in idle loop for debugging
#			  purposes.
#
# LOCAL_ATM_IF		: Identify the local machine addressed via its
#			  ATM interface's IP address as the local machine.
#			  This is based on the ".atm" hostname extension.
#
# TIGHT_FILES           : Use unoccupied regions in distributed files.
#			  Write operations are still local but may be
#			  split in write to different locations in the
#			  file.
#
# IODBG			: iod processes go into background.  The rsh
#                         process terminates. iod processes write
#                         error messages to a logfile.
#
# MMAP_READ		: iod processes use mmap to map the of the file
#                         into memory instead of allocating buffer
#                         space and reading from the file with read().
#
# TCP_TRANSFER		: Use basic TCP socket to read data form iod
#			  process.
#
# NO_IOD_START_CHK	: Don't check whether iod processes were
#			  started successfully.
#

CPPDEFINES	= -DNO_XDR_DIST_LIST -DTIGHT_FILES -DLOCAL_ATM_IF -DIODBG -DNO_IOD_START_CHK

ANSI_C		= -DANSI_C
#CC		= purify -cache-dir=$(HOME)/.purify-cache gcc27
CC		= gcc
CFLAGS 		= -ansi -O -w
#CFLAGS		= -ansi -g -Dlint -Wall -pedantic -Wtraditional -Wshadow -Wpointer-arith -Wcast-qual -Wcast-align -Wconversion

LDFLAGS		=
LDLIBS		=
SVCLDLIBS	= -lrpcsvc

AR		= ar
ARFLAGS		= rv
RANLIB		= ranlib

LINT		= lint
LINTFLAGS	= -a -b -c -h
# lint option to create .ln file
LINT_ln		= -i

RM		= rm -f

MKDIR		= mkdir -p

include Makefile.$(ARCH)

##############################################################################
# Main targets                                                               #
##############################################################################

install: all inst_files
	@echo
	@echo "****************************************************************************"
	@echo "*"
	@echo "* Installation of PFSLib in directory $(INSTALLDIR)"
	@echo "* completed."
	@echo "*"
	@echo "* Adding $(INSTALLBINDIR) to your PATH environment"
	@echo "* variable is recomended."
	@echo "*"
	@echo "* To run applications in the example subdirectory set the environment"
	@echo "* variable PFSLIBPATH to $(INSTALLDIR)."
	@echo "*"
	@echo "****************************************************************************"
	@echo

all: check pfsd_client iod_client add_objs pfsd_server iod_server lib cmd

uninstall: uninst_files

##############################################################################
# Check Architecture and CPPDEFINES                                          #
##############################################################################

check: check_arch check_cpp check_iod_path

check_arch:
	@if [ -f $(ARCH_FILE) ] ;\
	then\
		arch=`cat $(ARCH_FILE)` ;\
		if [ "$$arch" != "$(ARCH)" ] ;\
		then \
			echo "Cleaning due to wrong architecture" ;\
			$(MAKE) $(MFLAGS)\
				"RM=$(RM)"\
				clean;\
			echo "$(ARCH)" > $(ARCH_FILE) ;\
			echo;\
		fi \
	else\
		echo "$(ARCH)" > $(ARCH_FILE) ;\
	fi

check_cpp:
	@if [ -f $(DEFINES_FILE) ] ;\
	then\
		cppdefines=`cat $(DEFINES_FILE)` ;\
		if [ "$$cppdefines" != "$(CPPDEFINES)" ] ;\
		then \
			echo "Cleaning due to different CPP definitions" ;\
			$(MAKE) $(MFLAGS)\
				"RM=$(RM)"\
				clean;\
			echo "$(CPPDEFINES)" > $(DEFINES_FILE) ;\
			echo;\
		fi \
	else\
		echo "$(CPPDEFINES)" > $(DEFINES_FILE) ;\
	fi

check_iod_path:
	@if [ -f $(IODPATH_FILE) ]; \
	then \
		iep=`cat $(IODPATH_FILE)`; \
		if [ "$$iep" != "$(IOD_EXEC_PATH)" ]; \
		then \
			echo "Removing pfsd_iod.o due to different IOD_EXEC_PATH"; \
			rm -f pfsd/pfsd_iod.o; \
			echo "$(IOD_EXEC_PATH)" > $(IODPATH_FILE); \
		fi \
	else \
		echo "$(IOD_EXEC_PATH)" > $(IODPATH_FILE); \
	fi



##############################################################################
# Installation                                                               #
##############################################################################

inst_files:: $(INSTALLDIR) $(INSTALLBINDIR) $(INSTALLLIBDIR) $(INSTALLINCDIR)

inst_files::
	@echo "Installing PFSLib for $(ARCH) in directory $(INSTALLDIR)"
	@echo ' V2_0_B ' > $(INSTALLDIR)/.rcs.state.tag
	@cp $(DEFINES_FILE) $(INSTALLDIR)

uninst_files::
	@echo "Uninstalling PFSLib for $(ARCH) from directory $(INSTALLDIR)"

uninst_files \
inst_files::
	@for dir in $(DIRS);\
	do\
	(\
		echo "Going to directory $$dir";\
		cd $$dir;\
		$(MAKE) $(MFLAGS)\
		"INSTALLBINDIR=$(INSTALLBINDIR)"\
		"INSTALLLIBDIR=$(INSTALLLIBDIR)"\
		"INSTALLINCDIR=$(INSTALLINCDIR)"\
		$@;\
	)\
	done
	@echo

uninst_files::
	-rmdir	$(INSTALLBINDIR)
	-rmdir	$(INSTALLLIBDIR)
	-rmdir	$(INSTALLINCDIR)
	-rmdir  $(INSTALLDIR)
	@echo

$(INSTALLDIR) \
$(INSTALLBINDIR) \
$(INSTALLLIBDIR) \
$(INSTALLINCDIR):
	@echo "Creating directory $@"
	$(MKDIR) $@
	@echo

##############################################################################
# Additional files                                                           #
##############################################################################

add_objs:
	@echo "Making $@ for $(ARCH)"
	@(\
	echo "Going to directory $(ADDDIR)";\
	cd $(ADDDIR);\
	$(MAKE) $(MFLAGS)\
		"ARCH=$(ARCH)"\
		"CC=$(CC)"\
		"CFLAGS=$(CFLAGS)"\
		"ANSI_C=$(ANSI_C)"\
		"CPPDEFINES=$(CPPDEFINES)"\
		"ARCHCPPFLAGS=$(ARCHCPPFLAGS)"\
		$@;\
	)
	@echo


##############################################################################
# pfsd client and server files                                               #
##############################################################################

pfsd_client \
pfsd_server:
	@echo "Making $@ for $(ARCH)"
	@(\
	echo "Going to directory $(PFSDDIR)";\
	cd $(PFSDDIR);\
	$(MAKE) $(MFLAGS)\
		"INSTALLBINDIR=$(INSTALLBINDIR)"\
		"ARCH=$(ARCH)"\
		"CC=$(CC)"\
		"CFLAGS=$(CFLAGS)"\
		"ANSI_C=$(ANSI_C)"\
		"CPPDEFINES=$(CPPDEFINES)"\
		"ARCHCPPFLAGS=$(ARCHCPPFLAGS)"\
		"LDFLAGS=$(LDFLAGS)"\
		"LDLIBS=$(LDLIBS)"\
		"SVCLDLIBS=$(SVCLDLIBS)"\
		"IOD_EXEC_PATH=$(IOD_EXEC_PATH)"\
		$@;\
	)
	@echo

##############################################################################
# iod client and server files                                                #
##############################################################################

iod_client \
iod_server:
	@echo "Making $@ for $(ARCH)"
	@(\
	echo "Going to directory $(IODDIR)";\
	cd $(IODDIR);\
	$(MAKE) $(MFLAGS)\
		"INSTALLBINDIR=$(INSTALLBINDIR)"\
		"ARCH=$(ARCH)"\
		"CC=$(CC)"\
		"CFLAGS=$(CFLAGS)"\
		"ANSI_C=$(ANSI_C)"\
		"CPPDEFINES=$(CPPDEFINES)"\
		"ARCHCPPFLAGS=$(ARCHCPPFLAGS)"\
		"LDFLAGS=$(LDFLAGS)"\
		"LDLIBS=$(LDLIBS)"\
		"SVCLDLIBS=$(SVCLDLIBS)"\
		$@;\
	)
	@echo

##############################################################################
# library                                                                    #
##############################################################################

lib:
	@echo "Making client library for $(ARCH)"
	@(\
	echo "Going to directory $(CLNTDIR)";\
	cd $(CLNTDIR);\
	$(MAKE) $(MFLAGS)\
		"INSTALLLIBDIR=$(INSTALLBINDIR)"\
		"ARCH=$(ARCH)"\
		"CC=$(CC)"\
		"CFLAGS=$(CFLAGS)"\
		"ANSI_C=$(ANSI_C)"\
		"CPPDEFINES=$(CPPDEFINES)"\
		"ARCHCPPFLAGS=$(ARCHCPPFLAGS)"\
		"AR=$(AR)"\
		"ARFLAGS=$(ARFLAGS)"\
		"RANLIB=$(RANLIB)"\
		lib;\
	)
	@echo

##############################################################################
# rpc files                                                                  #
##############################################################################

rpc \
rpcmod \
rpcclean:
	@echo "Making $@ for rpcgen generated files"
	@for dir in $(PFSDDIR) $(IODDIR);\
	do\
	(\
		echo "Going to directory $$dir";\
		cd $$dir;\
		$(MAKE) $(MFLAGS) $@;\
		echo;\
	)\
	done
	@echo

##############################################################################
# commands                                                                   #
##############################################################################

cmd: lib
	@(\
	echo "Making command for $(ARCH)";\
	echo "Going to directory $(CMDDIR)";\
	cd $(CMDDIR);\
	$(MAKE) $(MFLAGS)\
		"INSTALLBINDIR=$(INSTALLBINDIR)"\
		"ARCH=$(ARCH)"\
		"CC=$(CC)"\
		"CFLAGS=$(CFLAGS)"\
		"ANSI_C=$(ANSI_C)"\
		"CPPDEFINES=$(CPPDEFINES)"\
		"ARCHCPPFLAGS=$(ARCHCPPFLAGS)"\
		"LDFLAGS=$(LDFLAGS)"\
		"LDLIBS=$(LDLIBS)";\
	echo;\
	)

##############################################################################
# Additional targets                                                         #
##############################################################################

dist: realclean rpcclean rpcmod

realclean:: localrealclean

clean:: localclean

tags:: localtags

clean \
lint \
realclean \
tags::
	@echo "Making $@"
	@for dir in $(DIRS);\
	do\
	(\
		echo "Going to directory $$dir";\
		cd $$dir;\
		$(MAKE) $(MFLAGS)\
		"RM=$(RM)"\
		"ARCH=$(ARCH)"\
		"ANSI_C=$(ANSI_C)"\
		"CPPDEFINES=$(CPPDEFINES)"\
		"ARCHCPPFLAGS=$(ARCHCPPFLAGS)"\
		"LINT=$(LINT)"\
		"LINTFLAGS=$(LINTFLAGS)"\
		"LINT_ln=$(LINT_ln)" $@;\
		echo;\
	)\
	done

localtags:
	@(\
		files="" ;\
		for dir in $(DIRS);\
		do\
			dirfiles=`echo $$dir/*.c`;\
			if [ "$$dirfiles" != "$$dir/*.c" ];\
			then\
				files="$$files $$dirfiles";\
			fi;\
		done;\
		echo "Making TAGS with $$files";\
		etags -t $$files;\
	)
	@echo

localrealclean: localclean
	$(RM) TAGS *~

localclean:
	$(RM) $(ARCH_FILE) $(DEFINES_FILE)
##############################################################################
# End of Makefile                                                            #
##############################################################################
