Imported Upstream version 2.3
[ossec-hids.git] / src / os_dbd / dbmake.sh
1 #!/bin/sh
2
3
4 MI=""
5 ML=""
6 PI=""
7 PL=""
8
9
10 # Looking for mysql
11 ls "`which mysql 2>/dev/null`" > /dev/null 2>&1
12 if [ $? = 0 ]; then
13     
14     # Checking if mysql_config is installed to use it.
15     mysql_config --port > /dev/null 2>&1
16     if [ $? = 0 ]; then
17         MI=`mysql_config --cflags`
18         ML=`mysql_config --libs`
19     fi    
20
21     
22     # Checking on a few dirs if mysql_config is not there.
23     for i in /usr /usr/local $1
24     do    
25     for j in $i/include/mysql/mysql.h $i/include/mysql.h
26         do
27             ls $j > /dev/null 2>&1 
28             if [ $? = 0 ]; then
29                 if [ "X$MI" = "X" ]; then 
30                     MI="-I `dirname $j`";
31                 fi    
32                 break;
33             fi
34         done
35     
36     for j in $i/lib/mysql $i/lib64/mysql
37         do
38             ls $j > /dev/null 2>&1
39             if [ $? = 0 ]; then
40                 if [ "X$ML" = "X" ]; then
41                     ML="-L $j -lmysqlclient";
42                 fi
43                 break
44             fi    
45         done
46     done               
47 fi
48
49
50 # Looking for postgresql
51 ls "`which psql 2>/dev/null`" > /dev/null 2>&1
52 if [ $? = 0 ]; then
53
54     # Checking if pg_config is installed to use it.
55     pg_config --version > /dev/null 2>&1
56     if [ $? = 0 ]; then
57         PGID=`pg_config --includedir`
58         PGPI=`pg_config --pkgincludedir`
59         PGLD=`pg_config --libdir`
60         PGLI=`pg_config --pkglibdir`
61         PI="${PGID} -I${PGPI}"
62         PL="-L${PGLD} -L${PGLI}"
63     fi
64                                 
65     for i in /usr /usr/local /usr/local/pgsql /usr/pgsql /usr/postgresql $1
66     do    
67     for j in $i/include/pgsql/libpq-fe.h $i/include/libpq-fe.h $i/include/postgresql/libpq-fe.h
68         do
69             ls $j > /dev/null 2>&1 
70             if [ $? = 0 ]; then
71                 if [ "X$PI" = "X" ]; then
72                     PI=`dirname $j`;
73                 fi    
74                 break;
75             fi
76         done
77     
78     for j in $i/lib/pgsql $i/lib/postgresql $i/lib64/pgsql $i/lib64/postgresql
79         do
80             ls $j > /dev/null 2>&1
81             if [ $? = 0 ]; then
82                 if [ "X$PL" = "X" ]; then
83                     PG_MAIN=`dirname $j`;
84                     PL="-L$j -L${PG_MAIN}";
85                 fi
86                 break
87             fi    
88         done
89     done               
90 fi
91
92
93
94
95 # Printing error if mysql is not found
96 if [ "X$MI" = "X" -a "X$ML" = "X" ]; then
97     echo "" >&2
98     echo "Error: MySQL client libraries not installed." >&2
99     echo "" >&2
100 fi
101
102 # Printing error if postgresql is not found
103 if [ "X$PI" = "X" -a "X$PL" = "X" ]; then
104     echo "" >&2
105     echo "Error: PostgreSQL client libraries not installed." >&2
106     echo "" >&2
107 fi
108
109
110 # Final cflags -- can not be empty.
111 if [ "X$MI" = "X" -o "X$ML" = "X" ]; then
112     MYSQL_FINAL=""
113 else
114     echo "Info: Compiled with MySQL support." >&2
115     MYSQL_FINAL="$MI $ML -DDBD -DUMYSQL"    
116 fi
117
118 # For postgresql
119 if [ "X$PI" = "X" -o "X$PL" = "X" ]; then
120     POSTGRES_FINAL=""
121 else
122     echo "Info: Compiled with PostgreSQL support." >&2
123     POSTGRES_FINAL="-I$PI $PL -lpq -DDBD -DUPOSTGRES"    
124 fi
125
126
127 if [ "X${MYSQL_FINAL}" = "X" -a "X${POSTGRES_FINAL}" = "X" ]; then
128     echo "Error: DB libraries not installed." >&2
129     exit 1;
130 fi    
131
132 echo "${MYSQL_FINAL} ${POSTGRES_FINAL}"
133
134 exit 0;
135