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