#! /bin/ksh                                         

#  (C) COPYRIGHT International Business Machines Corp. 1995, 1999
#  All Rights Reserved.
#
#  US Government Users Restricted Rights - Use, duplication or
#  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

# bldcc script file
 # Builds a sample c program.
 # Usage:  bldcc <prog_name> [ <db_name> [ <userid> <password> ]]
  
 # Set DB2PATH to where DB2 will be accessed. 
 # The default is the standard instance path.
 DB2PATH=/student1/db2/db2d34/sqllib
  
 # Connect to a database.
 if (($# < 2))
 then
    db2 connect to cscd34
 elif (($# < 3))
 then
    db2 connect to $2
 else
    db2 connect to $2 user $3 using $4
 fi
  
 # Precompile the program.
 db2 prep $1.sqc bindfile
  
 # Bind the program to the database.
 db2 bind $1.bnd
  
 # Disconnect from the database.
 db2 connect reset
  
# Compile the util.c error-checking utility.
 cc -I$DB2PATH/include -c util.c
  
 # Compile the program.  (Using the SPARCompiler C compiler)
 cc -I$DB2PATH/include  -c $1.c
  
 # Link the program.
 cc -o $1 $1.o util.o -L$DB2PATH/lib -R$DB2PATH/lib -ldb2
  

