Added better MySQL detection, workaround for compiling safely under fedora or redhat
[odkda2.git] / compile.sh
blobb38a3005a8c0be9c3d322ad833e308bca3dee102
1 #!/bin/bash
3 if [ -n $1 ]; then
4 if [ "$1" = "install" ]; then
5 PREFIX=`cat bin/prefix`
6 ETCPATH=`cat bin/etc`
7 if [ -n "$2" ]; then
8 PREFIX="$2"
9 ETCPATH="$PREFIX/etc"
10 fi
12 INCPATH="$PREFIX/include/odk"
13 LIBPATH="$PREFIX/lib"
15 mkdir -p $PREFIX
16 mkdir -p $INCPATH
17 mkdir -p $LIBPATH
18 mkdir -p $ETCPATH
19 mkdir -p $ETCPATH/odkda2
21 mkdir -p $PREFIX/bin
22 echo "Installing: Libraries"
23 cp bin/*.so $LIBPATH
24 #cp bin/*.a $LIBPATH
25 cp bin/odkda-config $PREFIX/bin
26 ldconfig
27 echo "Installing: Development Headers"
28 mkdir -p $INCPATH/odkda
29 cp include/odkda/*.h $INCPATH/odkda/
30 cp include/*.h $INCPATH/
32 cp bin/odkda.conf $ETCPATH/odkda2
33 cp bin/*.xml $ETCPATH/odkda2
35 exit
39 if [ -n "$1" ]; then
40 PREFIX="$1"
41 ETCPATH="$PREFIX/etc"
42 else
43 PREFIX="/usr"
44 ETCPATH="/etc"
47 VERSION="0.5.8.1"
49 INCPATH="$PREFIX/include/odk"
50 LIBPATH="$PREFIX/lib"
51 CONFFILE="$ETCPATH/odkda.conf"
53 rm -f config.h
55 rm -fr bin
56 mkdir -p bin
57 export CFLAGS="-fPIC -g -Wall"
59 echo "Autoconfiguring (best guess)"
61 rm -f mysqltest.c
62 rm -f mysqltest
64 echo "
65 #include <malloc.h>
66 #include <stdio.h>
67 #include <mysql.h>
69 int main(){
71 return 1;
74 " > mysqltest.c
76 #Test for MySQL
77 if (mysql_config --libs 2>&1 >/dev/null); then
78 if (gcc mysqltest.c `mysql_config --libs --cflags` -o mysqltest 2>/dev/null >/dev/null); then
79 echo " [Detected MySQL]"
80 WITHMYSQL="Yes"
81 DEFS="$DEFS -D_USE_MYSQL"
82 else
83 WITHMYSQL="No"
85 else
86 WITHMYSQL="No"
89 rm -f mysqltest.c
90 rm -f mysqltest
92 #FreeTDS Test Program
93 rm -f tdstest.c
94 rm -f tdstest
96 echo "
97 #include <malloc.h>
98 #include <stdio.h>
99 #include <sybdb.h>
101 int main(){
103 return 1;
106 " > tdstest.c
108 if (gcc tdstest.c -o tdstest 2>/dev/null >/dev/null); then
109 echo " [Detected FreeTDS]"
110 WITHTDS="Yes"
111 DEFS="$DEFS -D_USE_TDS"
112 else
113 WITHTDS="No"
116 rm -f tdstest.c
117 rm -f tdstest
119 #Test from SQLite2
120 if (pkg-config --silence-errors --libs sqlite 2>/dev/null >/dev/null); then
121 echo " [Detected SQLite]"
122 WITHSQLITE="Yes"
123 DEFS="$DEFS -D_USE_SQLITE"
124 else
125 WITHSQLITE="No"
128 #Test for SQLite3
129 if (pkg-config --silence-errors --libs sqlite3 2>/dev/null >/dev/null); then
130 echo " [Detected SQLite3]"
131 WITHSQLITE3="Yes"
132 DEFS="$DEFS -D_USE_SQLITE3"
133 else
134 WITHSQLITE3="No"
137 #Test from PostgreSQL
138 if (pg_config --libdir 2>/dev/null >/dev/null); then
139 echo " [Detected PostgreSQL]"
140 WITHPOSTGRES="Yes"
141 DEFS="$DEFS -D_USE_POSTGRES"
142 else
143 WITHPOSTGRES="No"
146 if ( ls $ORACLE_HOME/rdbms/public/oci.h 2>/dev/null >/dev/null); then
147 echo " [Detected Oracle]"
148 WITHORACLE="Yes"
149 DEFS="$DEFS -D_USE_ORACLE"
150 else
151 WITHORACLE="No"
154 echo $PREFIX > bin/prefix
155 echo $ETCPATH > bin/etc
156 echo "char *configs[2] = {\"$ETCPATH/odkda.conf\", \"odkda.conf\"};" >> config.h
157 echo "static char* PREFIX = \"$PREFIX\";" >> config.h
158 echo "static char* VERSION = \"$VERSION\";" >> config.h
159 echo "static char* INCPATH = \"$INCPATH\";" >> config.h
160 echo "static char* LIBPATH = \"$LIBPATH\";" >> config.h
161 echo "static char* ETCPATH = \"$ETCPATH\";" >> config.h
162 echo "static char* CONFFILE = \"$ETCPATH/odkda2/odkda.conf\";" >> config.h
164 mkdir -p bin
165 export CFLAGS="-fPIC -g"
166 export DIRS='-I./include '
167 export LIBS=''
169 echo " "
170 echo "Compiling ODKDA2"
172 echo " Compiling Sources"
173 gcc src/provider.c -I./include -I./ -D_HAVE_CONFIG_ $CFLAGS `odkutils-config --cflags` -c -o bin/provider.o
174 gcc src/connection.c -I./include $CFLAGS `odkutils-config --cflags` -c -o bin/connection.o
175 gcc src/column.c -I./include $CFLAGS `odkutils-config --cflags` -c -o bin/column.o
176 gcc src/value.c -I./include $CFLAGS `odkutils-config --cflags` -c -o bin/value.o
177 gcc src/command.c -I./include $CFLAGS `odkutils-config --cflags` -c -o bin/command.o
178 gcc src/sqlcommand.c -I./include $CFLAGS `odkutils-config --cflags` -c -o bin/sqlcommand.o
179 gcc src/schema.c -I./include $CFLAGS `odkutils-config --cflags` -c -o bin/schema.o
180 gcc src/exts.c -I./include $CFLAGS `odkutils-config --cflags` -c -o bin/exts.o
182 echo " Creating Library"
183 gcc bin/provider.o bin/connection.o bin/column.o bin/value.o bin/command.o bin/sqlcommand.o bin/schema.o bin/exts.o `odkutils-config --libs --cflags` -shared -Wl,-soname,libodkda2.so $CFLAGS -o bin/libodkda2.so
185 echo " Compiling Plugins"
187 if [ $WITHMYSQL == "Yes" ]; then
188 echo " * MySQL"
189 gcc src/plugins/mysql.c -I./include -L./bin -lodkda2 $CFLAGS -shared -Wl,-soname,libodkda2-mysql.so `odkutils-config --libs --cflags` `mysql_config --libs --cflags` -o bin/libodkda2-mysql.so
190 cp src/plugins/mysql.xml bin/
193 if [ $WITHTDS == "Yes" ]; then
194 echo " * FreeTDS (MS SQL, Sybase)"
195 gcc src/plugins/tds.c -I./include -L./bin -lodkda2 $CFLAGS -shared -Wl,-soname,libodkda2-tds.so `odkutils-config --libs --cflags` -o bin/libodkda2-tds.so
196 cp src/plugins/tds.xml bin/
199 if [ $WITHPOSTGRES == "Yes" ]; then
200 echo " * PostgreSQL"
201 gcc src/plugins/pgsql.c -I./include -L./bin -lodkda2 -lpq $CFLAGS -shared -Wl,-soname,libodkda2-pgsql.so `odkutils-config --libs --cflags` -I`pg_config --includedir` -L`pg_config --libdir` -o bin/libodkda2-pgsql.so
202 cp src/plugins/pgsql.xml bin/
205 if [ $WITHSQLITE3 == "Yes" ]; then
206 echo " * SQLite 3"
207 gcc src/plugins/sqlite3.c -I./include -L./bin -lodkda2 $CFLAGS -shared -Wl,-soname,libodkda2-sqlite3.so `odkutils-config --libs --cflags` `pkg-config --libs --cflags sqlite3` -o bin/libodkda2-sqlite3.so
208 cp src/plugins/sqlite3.xml bin/
211 echo " Creating odkda-config Script"
212 gcc src/config.c -fPIC -I./ -D_HAVE_CONFIG_ `odkutils-config --static --libs --cflags` -o bin/odkda-config
214 pushd bin
215 for f in *.xml; do
216 ./odkda-config --rlocal $f
217 done
218 popd