aboutsummaryrefslogtreecommitdiffstats
path: root/lib/odbc/configure.in
blob: 77b576ee881ec136047c48ad2b77c31a2b8a5313 (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
dnl define([AC_CACHE_LOAD], )dnl
dnl define([AC_CACHE_SAVE], )dnl

if test "x$no_recursion" != "xyes" -a "x$OVERRIDE_CONFIG_CACHE" = "x"; then
    # We do not want to use a common cache!
    cache_file=/dev/null
fi



dnl Process this file with autoconf to produce a configure script.
AC_INIT(c_src/odbcserver.c)

if test -z "$ERL_TOP" || test ! -d $ERL_TOP ; then
  AC_CONFIG_AUX_DIRS(autoconf)
else
  erl_top=${ERL_TOP}
  AC_CONFIG_AUX_DIRS($erl_top/erts/autoconf)
fi

if test "X$host" != "Xfree_source" -a "X$host" != "Xwin32"; then
    AC_CANONICAL_HOST
else
    host_os=win32
fi

dnl Checks for programs.
AC_PROG_CC

dnl ---------------------------------------------------------------------
dnl Special windows stuff regarding CFLAGS and details in the environment...
dnl ---------------------------------------------------------------------
AC_MSG_CHECKING(for mixed cygwin and native VC++ environment)
if test "X$CC" = "Xcc.sh" -a "X$host" = "Xwin32"; then
	if test -x /usr/bin/cygpath; then
		CFLAGS="-O2"
		AC_MSG_RESULT([yes])
		MIXED_CYGWIN_VC=yes
	else
		AC_MSG_RESULT([undeterminable])
		AC_MSG_ERROR(Seems to be mixed windows but not with cygwin, cannot handle this!)
	fi
else
	AC_MSG_RESULT([no])
	MIXED_CYGWIN_VC=no
fi
AC_SUBST(MIXED_CYGWIN_VC)

AC_PROG_MAKE_SET
AC_CHECK_PROGS(DED_LD, [ld.sh ld], '$(CC)')
AC_SUBST(DED_LD)

# Sockets
#--------------------------------------------------------------------
#	Check for the existence of the -lsocket and -lnsl libraries.
#	The order here is important, so that they end up in the right
#	order in the command line generated by make.  Here are some
#	special considerations:
#	1. Use "connect" and "accept" to check for -lsocket, and
#	   "gethostbyname" to check for -lnsl.
#	2. Use each function name only once:  can't redo a check because
#	   autoconf caches the results of the last check and won't redo it.
#	3. Use -lnsl and -lsocket only if they supply procedures that
#	   aren't already present in the normal libraries.  This is because
#	   IRIX 5.2 has libraries, but they aren't needed and they're
#	   bogus:  they goof up name resolution if used.
#	4. On some SVR4 systems, can't use -lsocket without -lnsl too.
#	   To get around this problem, check for both libraries together
#	   if -lsocket doesn't work by itself.
#--------------------------------------------------------------------
erl_checkBoth=0
AC_CHECK_FUNC(connect, erl_checkSocket=0, erl_checkSocket=1)
if test "$erl_checkSocket" = 1; then
    AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket", erl_checkBoth=1)
fi
if test "$erl_checkBoth" = 1; then
    tk_oldLibs=$LIBS
    LIBS="$LIBS -lsocket -lnsl"
    AC_CHECK_FUNC(accept, odbc_erl_checkNsl=0, [LIBS=$tk_oldLibs])
fi
AC_CHECK_FUNC(gethostbyname, , AC_CHECK_LIB(nsl, main, [LIBS="$LIBS -lnsl"]))

dnl Checks for header files.
AC_HEADER_STDC
case $have_pthread_lib-$host_os in
    yes-linux*)
	dnl NPTL test stolen from $ERL_TOP/erts/aclocal.m4
	AC_MSG_CHECKING(for Native POSIX Thread Library)
	case `getconf GNU_LIBPTHREAD_VERSION 2>/dev/null` in
	    nptl*) nptl=yes;;
	    NPTL*) nptl=yes;;
	    *)  nptl=no;;
	esac
	AC_MSG_RESULT($nptl)
	if test $nptl = yes; then
	    need_nptl_incldir=no
	    AC_CHECK_HEADER(nptl/pthread.h, need_nptl_incldir=yes)
	    if test $need_nptl_incldir = yes; then
		# Ahh...
		nptl_path="$C_INCLUDE_PATH:$CPATH:/usr/local/include:/usr/include"
		nptl_ws_path=
		save_ifs="$IFS"; IFS=":"
		for dir in $nptl_path; do
		    if test "x$dir" != "x"; then
			nptl_ws_path="$nptl_ws_path $dir"
		    fi
		done
		IFS=$save_ifs
		nptl_incldir=
		for dir in $nptl_ws_path; do
	            AC_CHECK_HEADER($dir/nptl/pthread.h,
				    nptl_incldir=$dir/nptl)
		    if test "x$nptl_incldir" != "x"; then
			CFLAGS="$CFLAGS -isystem $nptl_incldir"
			dnl CPPFLAGS is for configure internal use
			CPPFLAGS="$CPPFLAGS -isystem $nptl_incldir"
			break
		    fi
		done
		if test "x$nptl_incldir" = "x"; then
		    AC_MSG_ERROR(Failed to locate nptl system include directory)
		fi
	    fi
	fi
	;;
    *)
	;;
esac
AC_CHECK_HEADERS([fcntl.h netdb.h stdlib.h string.h sys/socket.h])

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T

dnl Checks for library functions.
AC_CHECK_FUNCS([memset socket])
	
# ODBC 
/bin/rm -f $ERL_TOP/lib/odbc/SKIP

have_pthread_lib=no
have_odbc_lib=no
	
AC_SUBST(TARGET_FLAGS)
    case $host_os in
        darwin*)
                TARGET_FLAGS="-DUNIX"
                AC_CHECK_LIB(pthread, pthread_create,
                           [AC_DEFINE(HAVE_LIBPTHREAD, 1, [Define if you have the pthread library (-lpthread).])
                            LIBS="$LIBS -lpthread"
                            have_pthread_lib=yes])
	        if test ! -d "$with_odbc"; then				
		    ODBC_LIB= -L"/usr/lib"
		    ODBC_INCLUDE="-I/usr/lib/include"
		else
		    ODBC_LIB=-L"$with_odbc/lib"
		    ODBC_INCLUDE="-I$with_odbc/include"
		fi
			    
               AC_CHECK_LIB(iodbc, SQLAllocHandle,[ODBC_LIB="$ODBC_LIB -liodbc" odbc_lib_link_sucess=yes])
            ;;
        win32|cygwin)
		TARGET_FLAGS="-DWIN32"
		AC_CHECK_LIB(ws2_32, main)
		if test ! -d "$with_odbc"; then				
		    ODBC_LIB=""   
		    ODBC_INCLUDE=""
		else
		    ODBC_LIB=-L"$with_odbc/lib"
		    ODBC_INCLUDE="-I$with_odbc/include"
		fi
		AC_CHECK_LIB(odbc32, main, [ODBC_LIB="$ODBC_LIB -lodbc32" odbc_lib_link_sucess=yes])
	    ;;
	    *)
	       TARGET_FLAGS="-DUNIX"
	       AC_CHECK_LIB(pthread, pthread_create,
			    [AC_DEFINE(HAVE_LIBPTHREAD, 1, [Define if you have the pthread library (-lpthread).])
			     LIBS="$LIBS -lpthread"
			     have_pthread_lib=yes])
	       if test ! -d "$with_odbc"; then			
	       AC_MSG_CHECKING([for odbc in standard locations])
	         for dir in /usr/local/odbc /usr/local /usr/odbc \
		     /usr /opt/local/pgm/odbc /usr/local/pgm/odbc
		 do
		    if test -f "$dir/include/sql.h"; then
		      is_odbc_std_location=yes	   
		       ODBC_LIB=-L"$dir/lib"
		       ODBC_INCLUDE="-I$dir/include"
		       break	
		    fi	    
	         done	    			
                 if  test "x$is_odbc_std_location" != "xyes"; then
		    AC_MSG_RESULT(no)
		    AC_MSG_WARN([No odbc library found skipping odbc])
		    echo "No odbc library found" > $ERL_TOP/lib/odbc/SKIP
	         else
		      AC_MSG_RESULT($ODBC_LIB)
		      AC_CHECK_LIB(odbc, SQLAllocHandle,[ODBC_LIB="$ODBC_LIB -lodbc" odbc_lib_link_sucess=yes])			 
	         fi     
              else
                ODBC_LIB=-L"$with_odbc/lib"
                ODBC_INCLUDE="-I$with_odbc/include"
	        AC_CHECK_LIB(odbc, SQLAllocHandle,[ODBC_LIB="$ODBC_LIB -lodbc" odbc_lib_link_sucess=yes])		
              fi
	  ;;
esac

if test "x$odbc_lib_link_sucess" != "xyes";  then
    AC_MSG_WARN(["ODBC library - link check failed"])
    echo "ODBC library - link check failed" > $ERL_TOP/lib/odbc/SKIP
fi
		
AC_SUBST(ODBC_LIB)
AC_SUBST(ODBC_INCLUDE)

AC_OUTPUT(c_src/$host/Makefile:c_src/Makefile.in)