-
Notifications
You must be signed in to change notification settings - Fork 2
/
makertn
executable file
·143 lines (116 loc) · 3.37 KB
/
makertn
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/sh
# SCRIPT: makertn
# Builds the hashing library
# Usage: makertn
# Uncomment the next 3 lines, if you set the paths manually
#DB2PATH=
#APRPATH=
#APUPATH=
# Uncomment the next line, if you want to use xlc on AIX
#COMPILER=xlc
# Set DB2PATH to the DB2 instance home
# Set APRPATH to where apr-1-config is located
# Set APUPATH to where apu-1-config is located
OS=`uname`
# Some variable magic
if [ -z $DB2_HOME ] && [ -z $DB2PATH ] || [ ! -e $DB2PATH ]; then
echo "DB2 instance directory not found. Please set DB2PATH at the beginning of the script."
exit 1
else
if [ -z $DB2PATH ]; then
DB2PATH=$DB2_HOME
fi
fi
if [ -z $APRPATH ]; then
APRCFG=`which apr-1-config`
else
APRCFG=$APRPATH/apr-1-config
fi
if [ -z $APRCFG ] || [ ! -e $APRCFG ]; then
echo "apr-1-config not found. Please set APRPATH at the beginning of the script."
exit 1
fi
if [ -z $APUPATH ]; then
APUCFG=`which apu-1-config`
else
APUCFG=$APUPATH/apu-1-config
fi
if [ -z $APUCFG ] || [ ! -e $APUCFG ]; then
echo "apu-1-config not found. Please set APUPATH at the beginning of the script."
exit 1
fi
copy_lib() {
# Copy the shared library to the function subdirectory.
# The user must have write permission to this directory.
if [ ! -w $DB2PATH/function/ ]; then
echo "no write permissions for $DB2PATH/function. Are you running this script as the instance user?"
exit 1
fi
if [ -f $DB2PATH/function/hash ]; then
rm -f $DB2PATH/function/hash
fi
cp hash $DB2PATH/function
if [ "$?" == "0" ]; then
echo "libary installed successfully."
fi
if [ ! -L $DB2PATH/function/unfenced/hash ]; then
ln -s $DB2PATH/function/hash $DB2PATH/function/unfenced/hash
fi
}
APR_CFLAGS="`$APRCFG --cppflags --includes`"
APU_CFLAGS="`$APUCFG --includes`"
APR_LFLAGS="`$APRCFG --link-ld --libs`"
APU_LFLAGS="`$APUCFG --link-ld --libs`"
APRRTMP="`$APRCFG --link-ld |cut -f2 -d' '`"
APURTMP="`$APUCFG --link-ld |cut -f2 -d' '`"
if [ "${APRRTMP:1:1}" == "L" ]; then
APRR=${APRRTMP:2}
ELOPT1="-Wl,-rpath,$APRR"
ELOPT1A=":$APRR"
fi
if [ "${APURTMP:1:1}" == "L" ]; then
APUR=${APURTMP:2}
ELOPT2="-Wl,-rpath,$APUR"
ELOPT2A=":$APUR"
fi
if [ "$OS" == "AIX" -a "$COMPILER" == "xlc" ]; then
EXTRA_CFLAG=-q64
LIB=lib64
xlc_r $EXTRA_CFLAG -c db2hash.c hash.c -I$DB2PATH/include $APR_CFLAGS $APU_CFLAGS
xlc_r $EXTRA_CFLAG -qmkshrobj -o hash db2hash.o hash.o -L$DB2PATH/$LIB -ldb2 $APR_LFLAGS $APU_LFLAGS -bE:hash.exp
copy_lib
exit
fi
# Set the runtime path since routines run as setuid
if [ "$OS" == "AIX" ]; then
EXTRA_LFLAG="-Wl,-G,-blibpath:$DB2PATH/lib${ELOPT1A}${ELOPT2A}"
else
EXTRA_LFLAG="-Wl,-rpath,$DB2PATH/lib $ELOPT1 $ELOPT2"
fi
# additional flags for Darwin
if [ "$OS" == "Darwin" ]; then
D_C_FLAGS="-arch x86_64"
D_L_FLAGS="-arch x86_64 -dynamiclib"
fi
if [ "$1" == "-v" ]; then
echo "DB2PATH : " $DB2PATH
echo "COMPILER : " $COMPILER
echo
echo "APR_CFLAGS : " $APR_CFLAGS
echo "APU_CFLAGS : " $APU_CFLAGS
echo "APR_LFLAGS : " $APR_LFLAGS
echo "APU_LFLAGS : " $APU_LFLAGS
echo
echo "APRCFG : " $APRCFG
echo "APUCFG : " $APUCFG
echo "APRR : " $APRR
echo "APUR : " $APUR
echo
echo "EXTRA_LFLAG: " $EXTRA_LFLAG
echo
fi
# Compile the program
gcc -fPIC -I$DB2PATH/include -c db2hash.c hash.c $APR_CFLAGS $APU_CFLAGS $D_C_FLAGS
# Link the program and create a shared library
gcc -shared -o hash db2hash.o hash.o $EXTRA_LFLAG -L$DB2PATH/lib -ldb2 $APR_LFLAGS $APU_LFLAGS $D_L_FLAGS
copy_lib