#!/bin/csh
#	@(#)makevengine	1.15	09/03/97	
#
#
#
#     $Id: makevengine,v 1.2.2.1 2006/05/04 14:51:54 avvede Exp $
#     $Log: makevengine,v $
#     Revision 1.2.2.1  2006/05/04 14:51:54  avvede
#     *** empty log message ***
#
#     Revision 1.2  1998/06/24 17:02:21  avvede
#     Added nodisam
#
#     Revision 1.1  1998/03/16 20:02:57  avvede
#     Initial move to CVS
#
#
#
#	Copyright (c) 1986, 1987, 1988 by
#	Periphonics Corporation
#	4000 Veterans Memorial Highway
#	Bohemia
#	NY 11716
#
#	This software is furnished under a license and may be used and
#	copied only in accordance with the terms of such license and with
#	the inclusion of the above copyright notice. This software or any
#	other copies thereof, may not be provided or otherwise made available
#	to anyone other than the licensee. Title to and ownership of this
#	software remains with the Periphonics Corporation.
#
#	The information in this document is subject to change without notice
#	and should not be construed as a commitment by Periphonics.
#
#	Periphonics assumes no responsibility for the use or reliability of
#	its software on equipment that is not supplied by Periphonics.
#
#	File Name:
#		makevengine
#
#	Description:
#		Building customized vengine
#
#	Change				Reason
#	No.	Date		Name	for Change
#
#	1	13-dec-93	lmg	File created.
#	2	01-aug-94	lmg	Consolidated.
#       3       21-nov-94       lmg     Removed malloc lib.
#	4	30-jan-95	lmg	Made ISAM optional.
#	5	02-feb-95	lmg	Made vengine static.
#	6	27-feb-95	lmg	Changed to ld.
#	7	23-may-95	lmg	Made ISAM static.
#	8	09-aug-95	lmg	Put customer's options at the end.
# 	9	19-aug-96	jpm	added sql call libs to ccline
#       10      15-may-97       lmg     Removed sql libs. 
#	11	19-jun-97	lmg	Merged with rel5.
#
if ( ${?ASEHOME} == 0 ) then
	echo "$0 : Environment ASEHOME is not set"
	exit 1
endif

#
# Help
#
if ($#argv == 1 && ("$1" == "-help" || "$1" == "?")) then
	echo Usage: makevengine \[-T for multithreaded\] \[-o new_name\] \[arguments\]
	echo 	If new_name is used, startapp script has to be changed
	exit 1
endif

#
# Check if it's IS
#
set is="yes"
if ( -r ${ASEHOME}/etc/services ) then
	set vvpether=`egrep '^vvpether' ${ASEHOME}/etc/services`
	if ( "$vvpether" != "" ) then
		set is="no"
	endif
endif

#
# Use cc (IS) or ld (rel4.5)
#
if ( $is == "yes" ) then					# IS
	set program="-o vengine"
	set progname = "vengine"
#
# 	Create a file containing an SCCS string so the date this
# 	vengine was linked can be established.
#
	set xobj = "${ASEHOME}/etc/x_vengine.o"
	set ccline = "cc -L${ASEHOME}/lib -L${ASEHOME}/rlib"
else
	set program="-o ${ASEHOME}/bin/vengine"
	set progname = "vengine"
#
# 	Find current version
#
	set ver=`/usr/bin/uname -r`
	if ( "$ver" != "5.3" ) then
		set ver="5.4"
	endif
	set cxobj =
	set xobj =
	set ccline = "ld ${ASEHOME}/etc/${ver}/*.o -L${ASEHOME}/lib"
endif

#
# Maybe multitreaded vengine
#
if ( "$1" == "-T" ) then
	set statopt =
	set MTHR = "T"
	set MTHRlib = "-lpthread -lTvthread"
	shift
else
	set statopt = "-Bstatic"
	set MTHR =
	set MTHRlib =
endif

set opts="$*"
while ( $#argv )
	if ( "$1" == "-o" ) then
		set progname = $2
		set program = 
		break
	endif
	shift
end
#
# Generate ID
#
if ( $is == "yes" ) then					# IS
#
# 	Create a file containing an SCCS string so the date this
# 	vengine was linked can be established.
#
	set build_date = `/bin/date '+%m/%d/%Y %j %H:%M'`
	set cxsrc = "/tmp/cx_vengine.c"
	set cxobj = "/tmp/cx_vengine.o"
	/bin/rm -f $cxsrc $cxobj
	echo -n "char _cprogid_[] = " > $cxsrc
	echo -n '"@(#) ' >> $cxsrc
	echo -n "$progname CUSTOM [$build_date]" >> $cxsrc
	echo '";' >> $cxsrc
	echo cc -o $cxobj $cxsrc
	cc -c -o $cxobj $cxsrc
endif
#
# Do the compile/link.  Note, for legacy reasons we put the user
# supplied options at the end of the link line.  This is probably
# a bad thing because if optional code requires unresolved function
# bindings, the system and peri libs have already been searched.
#
# This means users may have to specify some libraries again in
# order to resolve the references.
#
set uforce = "-u dbm_open -u dbm_close -u dbm_fetch"
set obj = "${ASEHOME}/etc/vengine.o"
set libs = "-ldl ${statopt} -L/usr/lib -l${MTHR}vengine -lnodisam -l${MTHR}vvp -l${MTHR}vapi -l${MTHR}vampmsg -lisam -l${MTHR}vas ${MTHRlib} -lnsl -lsocket -lintl -lc -lw -lm -lc"
set ccline = "$ccline $obj $xobj $cxobj $uforce $libs -Bdynamic $opts $program"
echo $ccline
${ccline}


