#############################################################################
#       $Id: Makefile,v 1.5 1995/07/08 18:25:14 rich Exp $
# $Revision: 1.5 $
#     $Date: 1995/07/08 18:25:14 $
#   $Author: rich $
#    $State: Exp $
#   $Locker:  $
#
# PROJECT:	TCA
#
# FILE:		Makefile
#		Based on Erebus prototypical Makefile
#		Makefile.proto,v 1.1 1992/06/16 22:50:21 jwest Exp 
#
# DESCRIPTION:
# Makes the tca test routines.
#
# EXPORTS:
#	The following targets are available as part of Makefile.std:
#		all bins libs privs objs
#		clean install
#
# HISTORY:
#
# $Log: Makefile,v $
# Revision 1.5  1995/07/08  18:25:14  rich
# Change all /afs/cs to /afs/cs.cmu.edu to get ride of conflict problems.
#
# Revision 1.4  1995/07/08  17:51:27  rich
# Linux Changes.  Also added GNUmakefile.defs.
#
# Revision 1.3  1995/07/06  21:18:52  rich
# Solaris and Linux changes.
#
# Revision 1.2  1995/01/18  16:48:49  rich
# Saving changes to the test routines so I can compare 7.8 and 7.9.
#
# Revision 1.1  1994/11/02  21:36:06  rich
# Now works for linux machines (i486).
# Got afs to work on alpha (and hopefully other vendor OS's)
# Added generic Makefile and asynchronous sender/receiver.
# Made libc.h and tcaMatrix.h module includes.
#
#
#############################################################################

.KEEP_STATE:

#############################################################################
# Site Configuration Macros
#############################################################################

# For most machines, this gets a string that can be used to determine
# the machine.
THIS_OS = `uname`
THIS_MACHINE = `uname -m`

PROJECT_RELEASE_DIR	= /afs/cs.cmu.edu/project/TCA/release
VERSION_DIR	= tca-$(TCA_VERSION_MAJOR).$(TCA_VERSION_MINOR)
PROJECT_DIR	= $(PROJECT_RELEASE_DIR)/$(VERSION_DIR)

INSTALL_DIR	= ..
PROJECT		= tca
MODULE		= test

#############################################################################
# Standard directories
#############################################################################

PUBLIC_BIN_DIR		= $(INSTALL_DIR)/bin
PUBLIC_INC_DIR 		= $(INSTALL_DIR)/include
PUBLIC_LIB_DIR		= $(INSTALL_DIR)/lib
PUBLIC_MAN_DIR		= $(INSTALL_DIR)/man/man1
PUBLIC_DOC_DIR		= $(INSTALL_DIR)/doc

MODULE_INC_DIR		= $(PUBLIC_INC_DIR)/$(MODULE)
MODULE_LIB_DIR		= $(PUBLIC_LIB_DIR)/$(MODULE)
MODULE_DOC_DIR		= $(PUBLIC_DOC_DIR)/$(MODULE)

INSTALL		= install

INS_BIN_FLAGS	= -m 555
INS_INC_FLAGS	= -c -m 444
INS_LIB_FLAGS	= -m 666
INS_LINT_FLAGS	= -m 444
INS_MAN_FLAGS	= -c -m 444
INS_DOC_FLAGS	= -c -m 444
INS_FTP_FLAGS	= -m 444

CC		= cc
AR		= ar
RM		= /bin/rm -f
MAKE		= /bin/make
SHELL		= /bin/sh
# change to RANLIB = echo for systems without ranlib.
RANLIB		= ranlib

#############################################################################
# Program Configuration Macros
#############################################################################

#
# Create the flags sent to the C compiler.  Note the following can be
# used on the command line to make:
# `CFLAG_EXT="-yourFlags"' : can set your own flags.
# You can also override the default DEFINES with DEFINES="-DMYDEFINE"
#

INC_PATH	= -I. -I$(PUBLIC_INC_DIR) -I$(MODULE_INC_DIR) \
		-I$(PROJECT_DIR)/include \
		-I$(PROJECT_DIR)/include/$(MODULE)

DEFINES		= 
CPPFLAGS	= $(INC_PATH) $(DEFINES)
CFLAGS		= -O2 $(CFLAGS_EXT)

LIB_PATH	= -L. -L./lib -L../lib -L$(PUBLIC_LIB_DIR) -L$(MODULE_LIB_DIR)\
		-L$(PROJECT_DIR)/lib -L$(PROJECT_DIR)/lib/$(MODULE)

LDFLAGS 	= $(LIB_PATH)
LIBRARIES	= -ltca

ARFLAGS		= rv

##########
# File Definition Macros.  Deletion of generated files assumed
#    to be o.k.  Source files will never be deleted.
##########

# Generated files - installed
PUBLIC_BINS		= 
PUBLIC_LIBS		= 

MODULE_LIBS		= 

# Source files - installed
PUBLIC_INCS		= 
PUBLIC_MANS		= 
PUBLIC_DOCS		= 

MODULE_INCS		= 
MODULE_DOCS		= 

INCS			= $(MODULE_INCS) $(PUBLIC_INCS)

# Generated files - not installed
PRIVS	= a1 b1 a1_var b1_var exceptTest m1 mt mt1 t2 sender sender2 \
	sender3 receiver receiver2 receiver3 lt1 lt2

OBJS	= a1.o a1_var.o b1.o b1_var.o b1_old.o exoeptTest.o \
	m1.o mt.o mt1.o t2.o lt1.o lt2.o sender.o sender2.o sender3.o \
	receiver.o receiver2.o receiver3.o

# Source files - not installed

SRCS            = a1.c a1_old.c b1.c b1_old.c exceptTest.c m1.c mt.c \
		mt1.c t2.c a1_var.c b1_var.c sender.c sender2.c sender3.c\
		receiver.c receiver2.c receiver3.c lt1.c lt2.c

PRIVATE_INCS	= sample.h sample_old.h common.h lt.h

MISC		= GNUmakefile README Makefile

# All source files
SRCS_ALL	= $(INCS) $(PRIVATE_INCS) $(SRCS) $(MANS) $(DOCS) $(MISC)

# Files to be removed by 'make clean' and 'make realclean'
DELETES		= core $(DEPEND_FILE) \
	  	  $(PUBLIC_BINS) $(PUBLIC_LIBS) \
		  $(MODULE_LIBS) $(PRIVS) $(OBJS) make.state \
		  $(wildcard .nse_dep*) $(wildcard *.CKP) $(wildcard \#*\#) \
		  $(wildcard *~) $(wildcard .*~) $(wildcard *.CKP)\
	          $(wildcard *.BAK) $(wildcard .*.BAK)

# Files never to be removed, even if Make encounters an error
.PRECIOUS: $(SRCS_ALL)

##########
# Default Target
##########

all install_libs install::

all:: srcs libs bins privs

##########
# User Defined Targets
##########

# Define rules for all files listed in BINS, LIBS, and in this section.
# Example executable, object, library, and combined objects are shown below:
#
#  $(BDIR)/sample: file1.o file2.o $(LIBDEP)
#	$(LINK.c) -o $@ file1.o file2.o $(LIBRARIES)
#
#  $(ODIR)/alternateName.o: file1.c
#	$(COMPILE.c) -o $@ file1.c
#
#  $(LDIR)/libsample.a: file1.o file2.o
#	-$(RM) $@
#	$(AR) $(ARFLAGS) $@ file1.o file2.o
#	$(RANLIB) $@
#
#  $(ODIR)/combined.o: $(ODIR)/part1.o $(ODIR)/part2.o
#	$(LD) -r -o $@ $(ODIR)/part1.o $(ODIR)/part2.o; chmod a-x $@

$(PRIVS):
	$(LINK.c) -o $@ $@.c $(LIBRARIES)

##########
# Include standard target definitions and RCS rules
##########

# make sure everyone is using the same default paths.
LPATH=:/usr/cs/lib:/usr/lib:/usr/misc/lib
CPATH=:/usr/misc/include
.EXPORT: LPATH
.EXPORT: CPATH

COMPILE.c=$(CC) $(CFLAGS) $(CPPFLAGS) -c
LINK.c=$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)

# C++ support
.SUFFIXES: suffixes .cc .cxx

.cc:
	$(LINK.c) -o $@ $< $(LDLIBS)
.cc.o:
	$(COMPILE.c) -o $@ $<
.cxx:
	$(LINK.c) -o $@ $< $(LDLIBS)
.cxx.o:
	$(COMPILE.c) -o $@ $<
.c.o:
	$(COMPILE.c) -o $@ $<
.c:
	$(LINK.c) -o $@ $< $(LIBRARIES)
.o:
	$(LINK.c) -o $@ $< $(LIBRARIES)

##########
# Standard Targets
##########

srcs: $(SRCS_ALL)
bins: $(PUBLIC_BINS)
libs: $(PUBLIC_LIBS) $(MODULE_LIBS)
privs: $(PRIVS)
objs: $(OBJS)

clean::
	$(RM) $(DELETES);
	$(RM) .nse_dep*
	$(RM) *.CKP
	$(RM) \#*\#
	$(RM) *~
	$(RM) .*~
	$(RM) *.CKP
	$(RM) *.BAK
	$(RM) .*.BAK

##########
#install rules
##########

install:: install_incs install_libs

install:: install_bins

install_bins: $(PUBLIC_BINS)
	-mkdir $(PUBLIC_BIN_DIR)
	-for bin in $(PUBLIC_BINS); do \
	  $(RM) $(PUBLIC_BIN_DIR)/$$bin;\
	  $(INSTALL) $$bin $(PUBLIC_BIN_DIR);\
	  chmod $(INS_BIN_MODE) $(PUBLIC_BIN_DIR)/$$bin;\
	done;

install_libs:: $(PUBLIC_LIBS)
	-mkdir $(PUBLIC_LIB_DIR)
	-for inc in $(PUBLIC_LIBS); do \
	  $(RM) $(PUBLIC_LIB_DIR)/$$inc;\
	  $(INSTALL) $$inc $(PUBLIC_LIB_DIR);\
	  chmod $(INS_LIB_MODE) $(PUBLIC_LIB_DIR)/$$inc;\
	done;

install_libs:: $(MODULE_LIBS)
	-mkdir $(MODULE_LIB_DIR)
	-for inc in $(MODULE_LIBS); do \
	  $(RM) $(MODULE_LIB_DIR)/$$inc;\
	  $(INSTALL) $$inc $(MODULE_LIB_DIR);\
	  chmod $(INS_LIB_MODE) $(MODULE_LIB_DIR)/$$inc;\
	done;

install_incs:: $(PUBLIC_INCS)
	-mkdir $(PUBLIC_INC_DIR)
	-for inc in $(PUBLIC_INCS); do \
	  $(RM) $(PUBLIC_INC_DIR)/$$inc;\
	  $(INSTALL) $$inc $(PUBLIC_INC_DIR);\
	  chmod $(INS_INC_MODE) $(PUBLIC_INC_DIR)/$$inc;\
	done;

install_incs:: $(MODULE_INCS)
	-mkdir $(MODULE_INC_DIR)
	-for inc in $(MODULE_INCS); do \
	  $(RM) $(MODULE_INC_DIR)/$$inc;\
	  $(INSTALL) $$inc $(MODULE_INC_DIR);\
	  chmod $(INS_INC_MODE) $(MODULE_INC_DIR)/$$inc;\
	done;

.PHONY: srcs bins libs privs objs clean depend clean_depend \
	install install_bins install_libs install_incs install_mans \
	install_docs msg link_tar ftp tar
