# Task Control Architecture Makefile
#
# FILE: Makefile
#
# ABSTRACT:
# Makes the tca libraries and central server.
#
# $Source: /afs/cs.cmu.edu/project/TCA/Master/tcaV8/src/makefile,v $ 
# $Revision: 1.29 $
# $Date: 1994/05/06 07:12:14 $
# $Author: rich $
#
# REVISION HISTORY:
#
# $Log: makefile,v $
# Revision 1.29  1994/05/06  07:12:14  rich
# Fixed makefile so it includes centralIO.[hc].
# Updated INSTALL for systems without gunzip and gmake.
#
# Revision 1.28  1994/05/06  04:47:12  rich
# Put central io routines in a new file.
# Fixed GNUmakefile.
#
# Revision 1.27  1994/05/05  00:46:22  rich
# Added a gmake makefile GNUmakefile so that the system can be easily
# compiled on different machines.
# Can now create the targets: tarfile and ftp for creating versions for export.
#
# Fixed a number of places were tcaExitHnd was not expected to return.
# Set the tcaSeverGlobal to 0 when the socket is closed.
#
# Revision 1.26  1994/04/29  02:37:30  rich
# Shared library code should use -fpic rather than -fPIC.
#
# Revision 1.25  1994/04/28  16:16:22  reids
# Changes in TCA Version 7.6:
#  1) New functions: tcaIgnoreLogging and tcaResumeLogging
#  2) Code for MacIntosh (MPW) version of TCA
#
# Revision 1.24  1994/04/26  16:23:37  rich
# Now you can register an exit handler before anything else and it will
# get called if connecting to central fails.
# Also added code to handle pipe breaks during writes.
#
# Revision 1.23  1994/04/16  21:20:57  rich
# Forgot to turn optimization back on.
#
# Revision 1.22  1994/04/16  19:42:33  rich
# First release of TCA for the DEC alpha.
# Changes were needed because longs are 64 bits.
# Fixed alignment assumption in the data message format.
# Fixed the way offsets are calculated for variable length arrays.  This
# was a problem even without 64 bit longs and pointers.
#
# Added the commit date to the version information printed out with the -v
# option.
#
# Now uses standard defines for byte order
# (BYTE_ORDER = BIG_ENDIAN, LITTLE_ENDIAN or PDP_ENDIAN)
#
# Defined alignment types: ALIGN_INT ALINE_LONGEST and ALIGN_WORD.
#
# *** WARNING ***
# sending longs between alphas and non-alpha machines will probably not work.
# *** WARNING ***
#
# Revision 1.21  1994/04/15  17:09:59  reids
# Changes to support vxWorks version of TCA 7.5
#
# Revision 1.20  1994/04/04  16:01:21  reids
# Fixed the way data transfer occurred from/to big and little Endian machines
#
# Revision 1.19  1994/03/28  02:23:08  rich
# parseFmttrs needs to be in the server objects and not the module objects.
#
# Revision 1.18  1994/03/27  22:50:34  rich
# Fixed problem with lisp version not working because of some compiler
# flags used for the shared library version.
# TCA now compiles for alphas, but does not run.
#
# Revision 1.17  1994/01/31  19:26:28  reids
# Oops.  Made a mistake.  Changing things back again
#
# Revision 1.16  1994/01/31  19:09:09  reids
# makefile used to put obj, lib, bin, etc. under ./; it is now put under ../
#
# Revision 1.15  1994/01/31  18:28:08  reids
# Several major changes (and some minor ones)
# 1. tcaFreeData and tcaFreeReply now work even if the data or message format
#    is NULL
# 2. Using the "-t" option in central, message taps are added as a child of the
#    task tree node that was tapped.
# 3. Named formatters are now expanded only when needed
# For more details, see ../doc/tca-7-4.release.notes
#
# Revision 1.14  1994/01/18  17:08:20  rich
# Need to create non-dynamic library for suns for static linking.
#
# Revision 1.13  1994/01/06  21:50:01  rich
# Updated the makefile to create the sunOS dynamic library with the right
# version number.
#
# Revision 1.12  1993/12/14  17:34:10  rich
# Changed getMGlobal to GET_M_GLOBAL and changed getSGlobal to
# GET_S_GLOBAL to conform to Chris' software standards.
#
# Patched problem with connecting between machines with different byte
# orders.  The real fix requires changing the way formats are stored.
# Searching for structural similar formats does not guarantee that you
# find the right format.
#
# Revision 1.11  1993/12/01  18:04:00  rich
# Fixed a problem with the port number being double converted to network
# byte order.
# Some general cleanup.
#
# Revision 1.10  1993/11/22  01:53:13  rich
# Fixed "make clean" and the makefile cflags_sun4 for the sun4_mach architecture.
#
# Revision 1.9  1993/11/21  20:18:22  rich
# Added shared library for sun4c_411 sunos machines.
# Added install to the makefile.
# Fixed problems with global variables.
#
#
# Modified it to take advantage of the @sys expansion for multiple
# architectures, and to fit in with the xavier structure.
# RTG.

THIS_ARCH = $(HOST_ARCH:-%=%)$(MACHINE)

# places where files live :
IDIR    = ./
LDIR    = lib/
BDIR    = bin/
ODIR    = obj/
LODIR   = lispObj/
VODIR   = vxObj/
TESTDIR = ../test/
TSDIR   = ../tests/
PWD = `(cd ..;/bin/pwd)`
INSTALLDIR = $(PWD)/

# Add the ability to use the debugging malloc library to track down
# bugs.  Uncomment the next line if you want to compile using the
# library.

#DBMALLOC = dbmalloc
DBMALLOC_DIR = /afs/cs/project/robocomp/xavier

INCPATH_pmax = -I/usr/cs/include -I/usr/include -I/include
INCPATH_sun4 = -I/usr/include -I/include
INCPATH_i386 = -I/usr/cs/include -I/usr/include -I/include
INCPATH_alpha = 
INCPATH_dbmalloc = -I$(DBMALLOC_DIR)/include
INCPATH =  -I. -I../include $(INCPATH_$(DBMALLOC)) $(INCPATH_$(THIS_ARCH))

LIBS_pmax = -lm -lc
LIBS_sun4 = -lm -lc
LIBS_i386 = -lm -lc
LIBS_alpha = 
LIBS_dbmalloc = -ldbmalloc
LIBS = $(LIBS_$(THIS_ARCH)) -ltca $(LIBS_$(DBMALLOC))

# need this so the installed version can find the library for sunos. 
LIBPATH_pmax = -L/usr/cs/lib -L/usr/lib -L/lib
LIBPATH_sun4 = -L/usr/cs/lib -L/usr/lib -L/lib
LIBPATH_i386 = -L/usr/cs/lib -L/usr/lib -L/lib
LIBPATH_alpha = 
LIBPATH_dbmalloc = -L$(DBMALLOC_DIR)/lib
LIBPATH = -Llib -L../lib -L$(INSTALLDIR)lib $(LIBPATH_$(DBMALLOC))\
           $(LIBPATH_$(THIS_ARCH))

LISPINCLUDES = -I/usr/misc/.allegro/lib/misc

# create the compiler call.

# C flags for compiling central and c libraries.
CFLAGS_pmax = -g -O2
# CFLAGS_sun4 = -pg -static -O2 -fpcc-struct-return
CFLAGS_sun4 = -g -O2 -fpcc-struct-return -fpic
#CFLAGS_i386 = -m486 -pg -static -O2 -fpcc-struct-return -fno-builtin
CFLAGS_i386 = -g -O2 -m486 -fpcc-struct-return -fno-builtin
CFLAGS_alpha = -g -O2 -fpcc-struct-return  -fno-builtin
CFLAGS_dbmalloc = -DUSE_DBMALLOC

# C flags for compiling the lisp library.
CFLAGS_LISP_pmax = -O2 -G 0
CFLAGS_LISP_sun4 = -O2 -fpcc-struct-return
CFLAGS_LISP_i386 = -O2 -m486 -fpcc-struct-return -fno-builtin
CFLAGS_LISP_alpha = -O2 -fpcc-struct-return -fno-builtin

WARNINGS_pmax = -Wstrict-prototypes
WARNINGS_sun4 = -Wstrict-prototypes
WARNINGS_i386 = -Wstrict-prototypes
WARNINGS_alpha = -Wstrict-prototypes

WARNINGS = -Wall -Wpointer-arith $(WARNINGS_$(THIS_ARCH))

CFLAGS = -g $(WARNINGS) -D$(THIS_ARCH) $(CFLAGS_$(DBMALLOC))\
         $(CFLAGS_$(THIS_ARCH)) 
CFLAGS_LISP = -g $(WARNINGS) -D$(THIS_ARCH) $(CFLAGS_LISP_$(THIS_ARCH))
#CFLAGS_traditional = -g $(WARNINGS) -D$(THIS_ARCH) $(CFLAGS_$(THIS_ARCH))

GCC = gcc $(CFLAGS) $(INCPATH) $(LIBPATH)
GCC_LISP = gcc $(CFLAGS_LISP) $(INCPATH) $(LIBPATH)
#CC = gcc $(CFLAGS_traditional) -traditional $(INCPATH) $(LIBPATH)

MODOBJS =  list.o behaviors.o tcModError.o \
         datamsg.o formatters.o hash.o \
         idtable.o key.o monMod.o \
         primFmttrs.o reg.o resMod.o sendMsg.o \
         taskTreeMod.o tcaMatrix.o \
         tcaMem.o tcaRef.o tplModule.o msgTapMod.o \
         excepMod.o comModule.o globalM.o

MODDATA = globalM.o

MODULEOBJS = $(MODOBJS:%.o=$(ODIR)%.o)

MODULESHARE = $(MODOBJS:%.o=$(ODIR)%.o)

MODULEDATA = $(MODDATA:%.o=$(ODIR)%.o)

SERVOBJS = comServer.o dispatch.o lex.o \
        recvMsg.o queue.o res.o \
        tplConstr.o tms.o cells.o qlattice.o \
        rules.o mon.o tcerror.o logging.o \
        printData.o taskTree.o msgTap.o exception.o globalS.o \
	parseFmttrs.o centralIO.o

# exception.o excModule.o preference.o prefModule.o

#SERVEROBJS = $(SERVOBJS:%.o=$(ODIR)%.o) $(MODOBJS:%.o=$(ODIR)%.o) \
#             $(MODDATA:%.o=$(ODIR)%.o)

SERVEROBJS = $(SERVOBJS:%.o=$(ODIR)%.o)

LISPOBJS = $(MODOBJS:%.o=$(LODIR)%.o)

VXOBJS = $(MODOBJS:%.o=vx/%.o)


TESTOBJS = $(SERVEROBJS) $(MODULEOBJS)


lib_pmax = $(LDIR)libtca.a
lib_sun4 = $(LDIR)libtca.a $(LDIR)libtca.so.7.6 $(LDIR)libtca.sa.7.6
lib_i386 = $(LDIR)libtca.a
lib_alpha = $(LDIR)libtca.a

lib_tca  = $(lib_$(THIS_ARCH))

all_pmax = $(LDIR)libtca_lisp.a
all_sun4 = $(LDIR)libtca_lisp.a
all_i386 = 
all_alpha = 

include makefile.include

all: $(BDIR)central $(lib_tca) $(all_$(THIS_ARCH))

everything: all $(BDIR)a $(BDIR)b $(BDIR)exceptTest 

install: all
	rm -f $(INSTALLDIR)$(LDIR)libtca*
	mv $(LDIR)libtca* $(INSTALLDIR)$(LDIR)
	ranlib $(INSTALLDIR)$(LDIR)libtca*.*a*
	mv $(BDIR)central $(INSTALLDIR)$(BDIR)central
	cp tca.h $(INSTALLDIR)include

#include the dependencies file

include makefile.depend

#test: $(lib_tca) c gs1 gs2

#test: $(lib_tca) c a b 

#test: $(lib_tca) c a b t m t2 t3 m1 m2

$(BDIR)central: $(ODIR)central.o $(SERVEROBJS) $(lib_$(THIS_ARCH)) 
	$(GCC) -o $(BDIR)central $(ODIR)central.o $(SERVEROBJS) $(LIBS)

$(ODIR)print.o: print.c model.h
	$(GCC) -c print.c -o $(ODIR)print.o

$(BDIR)gs1: gs1.c $(lib_tca) $(ODIR)print.o model.h
	$(GCC) -o $(BDIR)gs1 gs1.c print.o $(LIBS)

$(BDIR)gs2: gs2.c $(lib_tca) $(ODIR)print.o model.h
	$(GCC) -o $(BDIR)gs2 gs2.c print.o $(LIBS)

$(BDIR)m: $(TESTDIR)mt.c $(lib_tca)
	$(GCC) -o $(BDIR)m $(TESTDIR)mt.c $(LIBS)

$(BDIR)m1: $(TESTDIR)mtest1.c $(lib_tca)
	$(GCC) -o $(BDIR)m1 $(TESTDIR)mtest1.c $(LIBS)

$(BDIR)m2: $(TESTDIR)mtest2.c $(lib_tca)
	$(GCC) -o $(BDIR)m2 $(TESTDIR)mtest2.c $(LIBS)

$(BDIR)t2: $(TESTDIR)t2.c $(lib_tca)
	$(GCC) -o $(BDIR)t2 $(TESTDIR)t2.c $(LIBS)

$(BDIR)t3: $(TESTDIR)t3.c $(lib_tca)
	$(GCC) -o $(BDIR)t3 $(TESTDIR)t3.c $(LIBS)

$(BDIR)a3: $(TESTDIR)a3.c $(lib_tca)
	$(GCC) -o $(BDIR)a3 $(TESTDIR)a3.c $(LIBS)

$(BDIR)b3: $(TESTDIR)b3.c $(lib_tca)
	$(GCC) -o $(BDIR)b3 $(TESTDIR)b3.c $(LIBS)

$(BDIR)ra: $(TESTDIR)ra.c $(lib_tca)
	$(GCC) -o $(BDIR)ra $(TESTDIR)ra.c $(LIBS)

$(BDIR)rb: $(TESTDIR)rb.c $(lib_tca)
	$(GCC) -o $(BDIR)rb $(TESTDIR)rb.c $(LIBS)

$(BDIR)rc: $(TESTDIR)rc.c $(lib_tca)
	$(GCC) -o $(BDIR)rc $(TESTDIR)rc.c $(LIBS)

$(BDIR)testDouble: testDouble.c $(lib_tca)
	$(GCC) -o $(BDIR)testDouble testDouble.c $(LIBS)

$(BDIR)a: $(TESTDIR)a1.c $(lib_tca)
	$(GCC) -static -o $(BDIR)a $(TESTDIR)a1.c $(LIBS)

$(BDIR)b: $(TESTDIR)b1.c $(lib_tca)
	$(GCC) -o $(BDIR)b $(TESTDIR)b1.c $(LIBS)

$(BDIR)exceptTest: $(TESTDIR)exceptTest.c $(lib_tca)
	$(GCC) -o $(BDIR)exceptTest $(TESTDIR)exceptTest.c $(LIBS)

$(BDIR)t: $(TESTDIR)tapTest.c $(lib_tca)
	$(GCC) -o $(BDIR)t $(TESTDIR)tapTest.c $(LIBS)

$(BDIR)st: $(TESTDIR)showTree.c $(lib_tca)
	$(GCC) -o $(BDIR)st $(TESTDIR)showTree.c $(LIBS)

$(BDIR)rehmet: $(TSDIR)rehmet.c
	$(GCC) -o $(BDIR)rehmet $(TSDIR)rehmet.c $(LIBS)

$(LDIR)libtca.a: $(MODULEOBJS)
	rm -f $(LDIR)libtca.a
	ar rvu $(LDIR)libtca.a $(MODULEOBJS)
	ranlib $(LDIR)libtca.a

$(LDIR)libtca_lisp.a: $(LISPOBJS)
	rm -f $(LDIR)libtca_lisp.a
	ar rvu $(LDIR)libtca_lisp.a $(LISPOBJS)
	ranlib $(LDIR)libtca_lisp.a

$(LDIR)libtca_vx.a: $(VXOBJS)
	ld -r -o $(LDIR)libtca_vx.a $(VXOBJS)

$(LDIR)libtca.so.7.6: $(MODULESHARE)
	ld -assert pure-text -o $(LDIR)libtca.so.7.6 $(MODULESHARE) $(LIBPATH)

$(LDIR)libtca.sa.7.6: $(MODULEDATA)
	rm -f $(LDIR)libtca.sa.7.6
	ar rvu $(LDIR)libtca.sa.7.6 $(MODULEDATA)
	ranlib $(LDIR)libtca.sa.7.6

clean:
	rm -f *~
	(cd bin;rm -f c a b t m t2 t3 m1 m2 st ra rb rc)
	rm -f lib/libtca*.a
	rm -f obj/*.o
	rm -f $(LODIR)*.o
	rm -f $(VODIR)*.o

$(BDIR)interface: interface.c $(IDIR)interface.h
	$(GCC) -o $(BDIR)interface interface.c $(LDIR)libtca_sun4.a -lc -lm

$(ODIR)%.o: %.c
	$(GCC) -c $*.c -o $(ODIR)$*.o

$(LODIR)%.o: %.c
	$(GCC_LISP) -DLISP -c $*.c -o $(LODIR)$*.o \
	$(INCPATH) $(LISPINCLUDES)

sizesTest: $(TESTDIR)sizesTest.c $(lib_tca) $(SERVEROBJS)
	$(GCC) $(TESTDIR)sizesTest.c -o sizesTest $(SERVEROBJS) $(LIBS)

a: $(TESTDIR)a1.c $(lib_tca)
	$(GCC) $(TESTDIR)a1.c -o a $(LIBS)

b: $(TESTDIR)b.c $(LDIR)libtca.a
	$(GCC) $(TESTDIR)b.c -o b $(LIBS)

TESTSRCS = $(SERVEROBJS:$(ODIR)%.o=%.c) central.c

ALINTDIR = /usr/lang/SC1.0

lint:  $(TESTSRCS)
	$(ALINTDIR)alint -abhx $(INC) -D$(ARCH) $(TESTSRCS)

llint:  $(TESTSRCS)
	$(ALINTDIR)alint -abhx $(INC) $(LISPINCLUDES) -D$(ARCH) -DLISP $(TESTSRCS)

mlint:  $(TESTSRCS)
	$(ALINTDIR)alint -abhx $(INC) -DMACH486 $(TESTSRCS)

depend: 
	rm -f makefile.depend
	gcc -MM $(INC) *.c | awk '/.*\.o/ (printf "$$(ODIR)%s\n", $$0;next) /.*/' > makefile.depend
	gcc -MM $(INC) *.c | awk '/.*\.o/ (printf "$$(LODIR)%s\n", $$0;next) /.*/' >> makefile.depend
	gcc -MM $(INC) *.c | awk '/.*\.o/ (printf "$$(VODIR)%s\n", $$0;next) /.*/' >> makefile.depend

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

# end #
# DO NOT DELETE THIS LINE -- make depend depends on it.
