Salome HOME
merge from branch BR_V5_DEV
[modules/kernel.git] / salome_adm / unix / config_files / check_sockets.m4
1 dnl  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 dnl
3 dnl  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 dnl  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 dnl
6 dnl  This library is free software; you can redistribute it and/or
7 dnl  modify it under the terms of the GNU Lesser General Public
8 dnl  License as published by the Free Software Foundation; either
9 dnl  version 2.1 of the License.
10 dnl
11 dnl  This library is distributed in the hope that it will be useful,
12 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 dnl  Lesser General Public License for more details.
15 dnl
16 dnl  You should have received a copy of the GNU Lesser General Public
17 dnl  License along with this library; if not, write to the Free Software
18 dnl  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 dnl
20 dnl  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 dnl
22 AC_DEFUN([CHECK_SOCKETS],[
23
24 dnl Author
25
26 dnl Warren Young <warren@etr-usa.com>
27 dnl M4 Source Code
28
29 echo
30 echo ---------------------------------------------
31 echo testing sockets
32 echo ---------------------------------------------
33 echo
34
35 AC_CACHE_CHECK(for libraries containing socket functions,
36 ac_cv_socket_libs, [
37         oCFLAGS=$CFLAGS
38
39         AC_TRY_LINK([
40                         #include <sys/types.h>
41                         #include <sys/socket.h>
42                         #include <netinet/in.h>
43                         #include <arpa/inet.h>
44                 ],
45                 [
46                         struct in_addr add;
47                         int sd = socket(AF_INET, SOCK_STREAM, 0);
48                         inet_ntoa(add);
49                 ],
50                 ac_cv_socket_libs=-lc, ac_cv_socket_libs=no)
51
52         if test x"$ac_cv_socket_libs" = "xno"
53         then
54                 CFLAGS="$oCFLAGS -lsocket"
55                 AC_TRY_LINK([
56                                 #include <sys/types.h>
57                                 #include <sys/socket.h>
58                                 #include <netinet/in.h>
59                                 #include <arpa/inet.h>
60                         ],
61                         [
62                                 struct in_addr add;
63                                 int sd = socket(AF_INET, SOCK_STREAM, 0);
64                                 inet_ntoa(add);
65                         ],
66                         ac_cv_socket_libs=-lsocket, ac_cv_socket_libs=no)
67         fi
68
69         if test x"$ac_cv_socket_libs" = "xno"
70         then
71                 CFLAGS="$oCFLAGS -lsocket -lnsl"
72                 AC_TRY_LINK([
73                                 #include <sys/types.h>
74                                 #include <sys/socket.h>
75                                 #include <netinet/in.h>
76                                 #include <arpa/inet.h>
77                         ],
78                         [
79                                 struct in_addr add;
80                                 int sd = socket(AF_INET, SOCK_STREAM, 0);
81                                 inet_ntoa(add);
82                         ],
83                         ac_cv_socket_libs="-lsocket -lnsl", ac_cv_socket_libs=no)
84         fi
85
86         CFLAGS=$oCFLAGS
87 ])
88
89         if test x"$ac_cv_socket_libs" = "xno"
90         then
91                 AC_MSG_ERROR([Cannot find socket libraries])
92         elif test x"$ac_cv_socket_libs" = "x-lc"
93         then
94                 SOCKETLIBS=""
95                 CPPFLAGS="-DHAVE_SOCKET $CPPFLAGS"
96                 CORBA_IDLCXXFLAGS="-DHAVE_SOCKET $CORBA_IDLCXXFLAGS"
97                 CORBA_IDLPYFLAGS="-DHAVE_SOCKET $CORBA_IDLPYFLAGS"
98         else
99                 SOCKETLIBS="$ac_cv_socket_libs"
100                 CPPFLAGS="-DHAVE_SOCKET $CPPFLAGS"
101                 CORBA_IDLCXXFLAGS="-DHAVE_SOCKET $CORBA_IDLCXXFLAGS"
102                 CORBA_IDLPYFLAGS="-DHAVE_SOCKET $CORBA_IDLPYFLAGS"
103         fi
104
105         AC_SUBST(SOCKETLIBS)
106         AC_SUBST(SOCKETFLAGS)
107 ]) dnl CHECK_SOCKET