#! /bin/sh
#############################################################################
# (c) Copyright IBM Corp. 2007 All rights reserved.
#
# The following sample of source code ("Sample") is owned by International
# Business Machines Corporation or one of its subsidiaries ("IBM") and is
# copyrighted and licensed, not sold. You may use, copy, modify, and
# distribute the Sample in any form without payment to IBM, for the purpose of
# assisting you in the development of your applications.
#
# The Sample code is provided to you on an "AS IS" basis, without warranty of
# any kind. IBM HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR
# IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Some jurisdictions do
# not allow for the exclusion or limitation of implied warranties, so the above
# limitations or exclusions may not apply to you. IBM shall not be liable for
# any damages you suffer as a result of using, copying, modifying or
# distributing the Sample, even if IBM has been advised of the possibility of
# such damages.
#############################################################################
# SCRIPT: bldapp
# Builds C++ applications for Linux
# Usage: bldapp <prog_name> [ <db_name> [ <userid> <password> ]]
# Set DB2PATH to where DB2 will be accessed.
# The default is the standard instance path.
DB2PATH=$HOME/sqllib
# Default flags
EXTRA_C_FLAGS=""
# Figure out which Linux architecture we are on
HARDWAREPLAT=`uname -m`
# Default to native bitwidth for the platform
if [ "$HARDWAREPLAT" = "x86_64" ] || [ "$HARDWAREPLAT" = "ppc64" ] ||
[ "$HARDWAREPLAT" = "s390x" ] || [ "$HARDWAREPLAT" = "ia64" ]
then
BITWIDTH=64
else
# x86 is the only native 32-bit platform
BITWIDTH=32
fi
# Uncomment the next line to force a 32-bit application compile/link
#BITWIDTH=32
# Set flags for 32-bit compilation on non-native 32-bit platforms
if [ $BITWIDTH = "32" ]
then
LIB="lib32"
if [ "$HARDWAREPLAT" = "s390x" ]
then
EXTRA_C_FLAGS="-m31"
else
if [ "$HARDWAREPLAT" = "ia64" ]
then
# DB2 does not support 32-bit applications on Linux on IA64
BITWIDTH=64
else
EXTRA_C_FLAGS="-m32"
fi
fi
fi
# Set flags for 64-bit compilation
if [ $BITWIDTH = "64" ]
then
LIB="lib64"
if [ "$HARDWAREPLAT" != "ia64" ]
then
# gcc on ia64 does not support the -m64 flag
EXTRA_C_FLAGS="-m64"
fi
fi
# Setup the embedded library path
EXTRA_LFLAG="-Wl,-rpath,$DB2PATH/$LIB"
# If an embedded SQL program, precompile and bind it.
# Note: some .sqC files contain no SQL but link in
# utilemb.sqC, so if you get this warning, ignore it:
# SQL0053W No SQL statements were found in the program.
if [ -f $1".sqC" ]
then
./embprep $1 $2 $3 $4
# Compile the utilemb.C error-checking utility.
g++ $EXTRA_C_FLAGS -I$DB2PATH/include -c utilemb.C
else
# Compile the utilapi.C error-checking utility.
g++ $EXTRA_C_FLAGS -I$DB2PATH/include -c utilapi.C
fi
# Compile the program.
g++ $EXTRA_C_FLAGS -I$DB2PATH/include -c $1.C
if [ -f $1".sqC" ]
then
# Link the program with utilemb.o
g++ $EXTRA_C_FLAGS -o $1 $1.o utilemb.o $EXTRA_LFLAG -L$DB2PATH/$LIB -ldb2
else
# Link the program with utilapi.o
g++ $EXTRA_C_FLAGS -o $1 $1.o utilapi.o $EXTRA_LFLAG -L$DB2PATH/$LIB -ldb2
fi