#############################################################################
#       $Id: GNUmakefile,v 1.19 1996/07/29 05:02:57 josullvn Exp $
#   $Source: /afs/cs.cmu.edu/project/TCA/Master/tcaV8/tools/nanny/GNUmakefile,v $
# $Revision: 1.19 $
#     $Date: 1996/07/29 05:02:57 $
#       $Id: GNUmakefile,v 1.19 1996/07/29 05:02:57 josullvn Exp $
#   $Author: josullvn $
#    $State: Exp $
#   $Locker:  $
#
# PROJECT:	Xavier
#
# FILE:		GNUmakefile
#		Based on Erebus prototypical Makefile
#		Makefile.proto,v 1.1 1992/06/16 22:50:21 jwest Exp 
#
# DESCRIPTION:
# Used with gmake, compiles code.
#
# EXPORTS:
#	The following targets are available as part of Makefile.std:
#		all bins libs privs objs
#		clean install
#		update add commit diff
#		lint depend
#
# HISTORY:
#
# $Log: GNUmakefile,v $
# Revision 1.19  1996/07/29  05:02:57  josullvn
# Bloody hell. This commiting is a bit different than under Xavier. Short
# story is cleaned up some purify bugs, and also made changes to nanny
# which should make it a bit better - Improving performance over multiple
# machines, explict quietening of nondisplayed processes, replacing of
# runConsole with xfMiniConsole, which is multithreaded, vt102 compilant,
# adds a uniform emacs-like command line editing feature, better on small
# screens and otherwise fab.
#
# Revision 1.18  1996/06/28  14:07:10  reids
# Fixed quite a few bugs -- with graphics, interaction with script, and
#   killing processes
#
# Revision 1.17  1996/05/14  22:52:33  rich
# libforms.a is not part of tca.
#
# Revision 1.16  1996/03/29  15:57:11  reids
# Consolidated the common code between xCallbacks and xfCallbacks, and
#   xRunConsole and xfRunConsole.
# Added a way to add macro definitions to resource files ("define: <x> <y>").
# Fixed a bug that was causing the xfRunConsole to crash when a task was
#   restarted.
#
# Revision 1.15  1996/02/20  11:40:06  josullvn
# Made extensive changes:
#    added xfRunConsole, an xforms based interface which was quick
#    To change the interface, from the nanny dir run
#    /afs/cs/user/josullvn/xforms/DESIGN/fdesign xfConsole
#    to get going, and made debugging easier.
#    added tons of comments.
#    Debug spews a lot more info back, so just compile
#    with DEBUG=DEBUG if you really need it.
#    I've added some timeouts to the code, which will
#    probably be tweaked later. There are in xfCallbacks.c
#    Its become better at keeping processes going, and
#    so its harder to quit. Using shutdown can be
#    painful. Killing the processes individually is
#    probably better. Need to do a reverse dependancy when quitting.
#    Multiple machines are again poor. It doesn't wait sufficently
#    for dependencies - so you need to run things explicitly...
#
# Revision 1.14  1996/02/18  21:15:00  reids
# Change the names of the lex and yacc (bison) files so there is no chance
#   of over-writing script.c again
#
# Revision 1.13  1996/02/14  22:15:10  rich
# Use flex rather than lex because linux does not have lex.
#
# Revision 1.12  1996/02/13  02:34:33  rich
# Trying to fix script.c problem.
#
# Revision 1.11  1996/02/12  00:46:10  rich
# Scripting does not compile, removed.
#
# Revision 1.10  1996/02/11  21:35:17  rich
# Updated GNUmakefiles for faster complilation.  Use FAST_COMPILE=1 for
# routine recompiles.
#
# Revision 1.9  1996/02/11  04:13:16  rich
# Fixed dependency for script.o.
#
# Revision 1.8  1996/02/10  16:52:10  rich
# Made private functions static and fixed some forward declarations.
#
# Revision 1.7  1996/02/05  15:56:41  reids
# Added scripting capabilities to nanny -- using lex/bison to parse script
#  files according to the script.bnf standard.
# Integrated support for running/stopping/suspending scripts into the
#  runConsole window.
#
# Revision 1.6  1996/02/01  04:04:12  rich
# Generalized updateVersion and added recursion.
#
# Revision 1.5  1996/01/22  21:30:52  reids
# Fixed the way stdout is handled, using pseudo-terminals, so that it preserves
#   the line-buffering mode of the real TTY.
# Added support for running scripts (not really integrated, yet, but initial
#   tests are working).
#
# Revision 1.4  1996/01/12  01:07:05  rich
# Change for depend file.
#
# Revision 1.3  1996/01/12  00:53:54  rich
# Simplified GNUmakefiles.
#
# Revision 1.2  1995/12/17  21:25:50  rich
# Need to create obj and bin directories.
#
# Revision 1.1  1995/12/17  20:25:29  rich
# Moved Nanny to the tca release.
#
# Revision 1.34  1995/11/16  23:39:52  robocomp
# Create BETA release for robot machines on noonan.
#
# Revision 1.33  1995/11/14  20:17:19  robocomp
# Added a beta release in the local ragweed directory.
#
# Revision 1.32  1995/09/26  20:35:28  rich
# Fixed order of system specific libraries.
# Removed extra "extern"s.
#
# Revision 1.31  1995/09/20  01:58:41  rich
# Reduced the number of libraries needed.
# Cleaned up warnings.
#
# Revision 1.30  1995/08/06  00:04:54  rich
# Changes for new devUtils in tca-8.1.
#
# Revision 1.29  1995/07/30  02:01:12  rich
# Moved common defines to etc/GNUmakefile.defs.
# Added loadRobotConfig.
#
# Revision 1.28  1995/07/19  02:00:56  rich
# Changes for sync target.
#
# Revision 1.27  1995/07/13  14:04:43  robocomp
# Linux specific changes. ps under linux is 1 character longer, and occasionally
# writes to stderr. Also, added a linux simulator due to the different paths
#
# Revision 1.26  1995/07/13  11:09:24  josullvn
# Two bugs were present. a) syscalls were being interrupted, and b) the
# processes button management got screwy after a while. The first is due
# to Devutils, second fixed by removing a reliance on xclient data. Also
# added features to newProcess whereby it is now menu driven.
# Added tca.rc, removing those processes from the Simulator resource files.
#
# Revision 1.25  1995/07/12  07:39:50  josullvn
# Filled in README, updated resource file (Plus added Simulator2.rc)
# Changed some messages on startup, and added a bugs file
#
# Revision 1.24  1995/07/11  01:06:07  josullvn
# Whesh. OK, fixed a bug in parsing lines, where by if messages get corrupted,
# we can recover. Added a -clean option to nanny. Discovered that the old
# double newProcess bug has returned to haunt me.
#
# Revision 1.23  1995/06/25  21:02:45  rich
# Look for X11 and TCA directories, needed for Linux.
#
# Revision 1.22  1995/06/25  01:03:33  rich
# Moved devUtils to tca.
#
# Revision 1.21  1995/06/23  21:47:24  robocomp
# Added TCA=linx to GNUmakefile
# Removed some unLinux code
#
# Revision 1.20  1995/06/15  22:10:52  rich
# Linux 1.2 changes. Still does not compile.
#
# Revision 1.18  1995/06/14  01:02:09  rich
# Fixed the INC_PATH and added TCA=[v7.8,v7.9,v8.0]
#
# Revision 1.17  1995/05/25  02:49:58  rich
# Fixed lookup for nanny device and lost character problem.
#
# Revision 1.16  1995/05/23  23:58:20  josullvn
# Yeah. Fixed the SIGCHLD problem (tured out that popen is internally
# implemented with fork - when pclose was called, it generated a SIGCHLD
# which intereupted the system call which lead to trouble).
# Fixed environment variables, can now add env variables in .rc file, and
# they are passed to appropriate child. Realized that need to also
# provide an ability to pass the display variable from runConsole to the
# nanny - being worked on.
# Bug exists in devUtils (?) which large data streams. Run csh as a new process
# and do ps auxww to cause it to occur.
#
# Revision 1.15  1995/05/20  15:14:49  rich
# Don't delete depends file on make clean, only on make veryclean.
#
# Revision 1.14  1995/05/19  17:56:12  rich
# Include the null character in the strings sent.
# Added back the stdin device.  Made runConsole a public bin.
#
# Revision 1.13  1995/05/15  17:07:05  rich
# Updated interface to createLineBuffer so you can get partial lines and
# the delimit character is not replaced.
# Imporved layout of the X11 window of the console.
#
# Revision 1.12  1995/05/11  19:02:36  rich
# Fixed some communications problems.
#
# Revision 1.11  1995/05/11  10:23:48  josullvn
# Just about full handling of nanny-nanny and nanny-client messages in the
# code. Bugs with the actual communication.
# Also added a sample simulator resource file
#
# Revision 1.10  1995/05/11  01:26:08  josullvn
# Adding first pass of helpfile
#
# Revision 1.9  1995/05/11  01:22:46  rich
# Both now compile.
#
# Revision 1.8  1995/05/11  00:28:09  josullvn
# Saving stuff for joseph so I can work on it.  Rich.
#
# Revision 1.7  1995/05/10  08:43:00  josullvn
# "The I'm off to bed for the night, commit so rich can play" version.
#
# Revision 1.6  1995/05/10  06:37:48  josullvn
# More fiddling - added some stubs to nannyDev.h...
#
# Revision 1.5  1995/05/10  05:42:49  josullvn
# More file shuffling... now have runConsole and nanny
#
# Revision 1.4  1995/05/10  03:16:53  josullvn
# Still not fulling working - just aligning with Rich...
#
# Revision 1.3  1995/05/10  02:06:55  rich
# Added nanny->nanny and nanny->local communications.
#
# Revision 1.2  1995/05/08  21:31:34  josullvn
# orrected task problem in GNUmakefile
#
# Revision 1.1  1995/05/08  21:30:04  josullvn
# Commiting robust dir to allow rich access.
#
# Revision 2.20  1995/02/04  23:04:13  rich
# Machine name is sun4m for new sparcs.
#
# Revision 2.19  1995/02/03  19:58:12  rich
# Modified paths to work with /usr/local/
#
# Revision 2.18  1995/01/12  20:41:12  rich
# Check to see if cvs is in /usr/local/bin before trying to use it.
#
# Revision 2.17  1995/01/12  04:38:47  rich
# Added /usr/local/include to the sunOS include path.
#
# Revision 2.16  1995/01/12  03:49:46  rich
# Change path to cs so it works with new release in /usr/local/bin/cvs.
#
# Revision 2.15  1994/11/07  02:26:27  rich
# Combined libmath.a and liblists.a into libcommon.a and have added getbool.
#
# Revision 2.14  1994/11/06  00:52:52  rich
# Can't have both -g and -gstabs for i386_mach machines.
#
# Revision 2.13  1994/11/04  21:46:08  rich
# Changes to strip binaries for pmax_mach, alpha and sun4_mach.
#
# Revision 2.12  1994/11/03  07:32:03  rich
# ???
#
# Revision 2.11  1994/11/02  23:39:47  rich
# Changes for linux on an i486 and OSF1 on an alpha.
#
# Revision 2.10  1994/10/11  02:20:44  rich
# Cleaned up a mess due to not fixing conflicts.
#
# Revision 2.9  1994/10/10  18:48:39  reids
# This program was developed for homecoming; Xavier uses the sonar to
# determine when someone is approaching, and pans the camera in that direction
# and says clever things.
#
# Revision 2.8  1994/10/05  19:17:55  rich
# Fixed ordering in INC_PATH.
#
# Revision 2.7  1994/10/04  23:43:21  rich
# Putting $(LIBDEP) in the dependencies now works for linked files.
#
# Revision 2.6  1994/10/04  17:21:35  rich
# Fixed bug in BASE_DIR and added some support for linux.
#
# Revision 2.5  1994/10/03  04:20:26  rich
# Added a new target: ftp, to create a tar file.
#
# Revision 2.4  1994/09/30  04:43:06  rich
# Made all = install.  Added an everything target.
# Added defines for customizing CFLAGS.
#
# Revision 2.3  1994/09/28  19:20:03  rich
# Removed dependency files from the archive.
#
# Revision 2.2  1994/09/28  03:52:19  rich
# ls on mach machines does not direct errors to stderr.
#
# Revision 2.1  1994/09/28  03:22:44  rich
# Force revision number to be 2.1
#
# Revision 1.3  1994/09/28  02:19:49  rich
# /afs/cs.cmu.edu -> /afs/cs.  Also forced calculation of STD_FILE in
# GNUmakefile.
#
# Revision 1.2  1994/09/23  18:50:33  rich
# Version 2.1 alpha.
#
# Revision 1.1  1994/09/22  17:49:54  rich
# Release of version 2.0 of Xavier software.
#
#
#############################################################################

#############################################################################
# Module Configuration Macros
#############################################################################

PROJECT_DIR	= /afs/cs/project/TCA/release/alpha

INSTALL_DIR	= ../..
ifndef BASE_DIR
BASE_DIR	:= $(shell cd $(INSTALL_DIR);/bin/pwd)
endif
MODULE_DIR	= tools/nanny
PROJECT		= tca
MODULE		= nanny
SUBDIRS		=
DEPEND_FILE	= $(PWD)/GNUmakefile.$(THIS_MACHINE)
DEPEND_PREFIX	= $(ODIR)/ 
VERSION_FILE	= nanny.h
VERSION_PREFIX	= NANNY

#############################################################################
# Where are the standard files?
#############################################################################

ifndef FAST_COMPILE
PWD 	:= $(shell /bin/pwd)
endif

ifndef STD_FILE
STD_FILE := $(shell ls $(BASE_DIR)/etc/GNUmakefile.std | grep -v "not found")
ifeq ($(STD_FILE),)
STD_FILE := $(PROJECT_DIR)/etc/GNUmakefile.std
endif
DEFS_FILE := $(shell ls $(BASE_DIR)/etc/GNUmakefile.defs | grep -v "not found")
ifeq ($(DEFS_FILE),)
DEFS_FILE := $(PROJECT_DIR)/etc/GNUmakefile.defs
endif
endif

##########
# Include standard definitions
##########

include $(DEFS_FILE)

##########
# Override defaults here.
##########

CC		= gcc
CFLAGS_gcc	= -Wcomment -Wformat -Wimplicit -Wswitch -Wuninitialized

XLIBS		=  -lXaw -lXmu -lXext -lXt -lX11

LIBRARIES	= -lforms \
		  -lDevUtils -lezx -ltca $(XLIBS) -lm \
		 $(LIBS_$(THIS_MACHINE)) $(LIBS_$(THIS_OS)) $(LIBS_$(DBMALLOC))

DEFINES		= 

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

# Generated files - installed
PUBLIC_BINS		= nanny xfMiniConsole readline \
			  xfRunConsole runConsole # These are for lzrs
PUBLIC_LIBS		= 
PUBLIC_LINTS		= 

MODULE_LIBS		= 
MODULE_LINTS		= 

# Source files - installed
PUBLIC_INCS		= 
PUBLIC_MANS		= 
PUBLIC_DOCS		= 

MODULE_INCS		= 
MODULE_DOCS		= 

INCS			= $(MODULE_INCS) $(PUBLIC_INCS)

# Generated files - not installed
PRIVS	= 

CONSOLE_OBJS =  runConsole.o callbacks.o history.o messages.o y.tab.o \
		messageConsoleHandle.o nannyDev.o script.o scriptParse.o

RUNCONSOLE_OBJS = $(CONSOLE_OBJS) xRunConsole.o xtUtil.o xCallbacks.o
RUNCONSOLE_OBJECTS = $(patsubst %,$(ODIR)/%,$(RUNCONSOLE_OBJS))

XFRUNCONSOLE_OBJS = $(CONSOLE_OBJS) xfRunConsole.o xfConsole.o xfCallbacks.o
XFRUNCONSOLE_OBJECTS = $(patsubst %,$(ODIR)/%,$(XFRUNCONSOLE_OBJS))

XFMINICONSOLE_OBJS = $(CONSOLE_OBJS) xfMiniConsole.o xfRunMiniConsole.o xfMiniCallbacks.o
XFMINICONSOLE_OBJECTS = $(patsubst %,$(ODIR)/%,$(XFMINICONSOLE_OBJS))

NANNY_OBJS = nanny.o nannyDev.o nannyUtils.o messages.o messageNannyHandle.o 
NANNY_OBJECTS = $(patsubst %,$(ODIR)/%,$(NANNY_OBJS))

READLINE_OBJS = readline.o
READLINE_OBJECTS = $(patsubst %,$(ODIR)/%,$(READLINE_OBJS))

_OBJS = resource.o

_OBJECTS = $(patsubst %,$(ODIR)/%,$(_OBJS))

OBJS	= $(_OBJECTS) $(RUNCONSOLE_OBJECTS) $(XFRUNCONSOLE_OBJECTS) $(XFMINICONSOLE_OBJECTS) $(NANNY_OBJECTS) $(READLINE_OBJECTS)

# Source files - not installed

SRCS		= resource.c messages.c callbacks.c \
		xtUtil.c runConsole.c xRunConsole.c xCallbacks.c history.c\
		nanny.c nannyDev.c nannyUtils.c messageConsoleHandle.c \
		messageNannyHandle.c script.c scriptParse.c scriptp.l scriptp.y \
		xfRunConsole.c xfConsole.c xfCallbacks.c \
		xfRunMiniConsole.c xfMiniConsole.c xfMiniCallbacks.c \
		readline.c

PRIVATE_INCS	= callbacks.h runConsole.h history.h \
	        nannyDev.h nannyUtils.h resource.h messages.h messageHandle.h\
		nanny.h nannyCommon.h script.h scriptParse.h \
		xCallbacks.h xRunConsole.h xtUtil.h \
                xfConsole.h xfRunConsole.h forms.h \
		xfMiniConsole.h xfRunMiniConsole.h

# Got to fix up the forms libraries later...
MISC	= GNUmakefile README Simulator.rc tca.rc BUGS script.bnf \
	  xfConsole.fd xfMiniConsole.fd

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

all:: srcs libs bins privs

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

# Define rules for all files listed in BINS, LIBS, and LINTS 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 $@

$(BDIR)/runConsole: $(RUNCONSOLE_OBJECTS) $(_OBJECTS) $(LIBDEP)
	$(LINK.c) -o $@ $(RUNCONSOLE_OBJECTS) $(_OBJECTS) $(LIBRARIES)

$(BDIR)/xfRunConsole: $(XFRUNCONSOLE_OBJECTS) $(_OBJECTS) $(LIBDEP)
	$(LINK.c) -o $@ $(XFRUNCONSOLE_OBJECTS) $(_OBJECTS) $(LIBRARIES)

$(BDIR)/xfMiniConsole: $(XFMINICONSOLE_OBJECTS) $(_OBJECTS) $(LIBDEP)
	$(LINK.c) -o $@ $(XFMINICONSOLE_OBJECTS) $(_OBJECTS) $(LIBRARIES)

$(BDIR)/nanny: $(NANNY_OBJECTS) $(_OBJECTS) $(LIBDEP)
	$(LINK.c) -o $@ $(NANNY_OBJECTS) $(_OBJECTS) $(LIBRARIES)

$(BDIR)/readline: $(READLINE_OBJECTS) $(_OBJECTS) $(LIBDEP)
	$(LINK.c) -o $@ $(READLINE_OBJECTS) $(_OBJECTS) $(LIBRARIES) -lreadline -ltermcap

#LEX = lex
LEX = flex
# YACC = yacc -t
YACC = bison -b y

lex.yy.c: scriptp.l
	$(LEX) scriptp.l

y.tab.c: scriptp.y lex.yy.c
	$(YACC) scriptp.y

$(ODIR)/script.o: lex.yy.c

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

include $(STD_FILE)
