Salome HOME
6a834c580a685c67a1483d1ad48009c183b5f82a
[tools/configuration.git] / autotools / m4 / check_sockets.m4
1 dnl Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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
23 AC_DEFUN([CHECK_SOCKETS],[
24
25 dnl Author
26
27 dnl Warren Young <warren@etr-usa.com>
28 dnl M4 Source Code
29
30 echo
31 echo ---------------------------------------------
32 echo testing sockets
33 echo ---------------------------------------------
34 echo
35
36 AC_CACHE_CHECK(for libraries containing socket functions,
37 ac_cv_socket_libs, [
38         oCFLAGS=$CFLAGS
39
40         AC_TRY_LINK([
41                         #include <sys/types.h>
42                         #include <sys/socket.h>
43                         #include <netinet/in.h>
44                         #include <arpa/inet.h>
45                 ],
46                 [
47                         struct in_addr add;
48                         int sd = socket(AF_INET, SOCK_STREAM, 0);
49                         inet_ntoa(add);
50                 ],
51                 ac_cv_socket_libs=-lc, ac_cv_socket_libs=no)
52
53         if test x"$ac_cv_socket_libs" = "xno"
54         then
55                 CFLAGS="$oCFLAGS -lsocket"
56                 AC_TRY_LINK([
57                                 #include <sys/types.h>
58                                 #include <sys/socket.h>
59                                 #include <netinet/in.h>
60                                 #include <arpa/inet.h>
61                         ],
62                         [
63                                 struct in_addr add;
64                                 int sd = socket(AF_INET, SOCK_STREAM, 0);
65                                 inet_ntoa(add);
66                         ],
67                         ac_cv_socket_libs=-lsocket, ac_cv_socket_libs=no)
68         fi
69
70         if test x"$ac_cv_socket_libs" = "xno"
71         then
72                 CFLAGS="$oCFLAGS -lsocket -lnsl"
73                 AC_TRY_LINK([
74                                 #include <sys/types.h>
75                                 #include <sys/socket.h>
76                                 #include <netinet/in.h>
77                                 #include <arpa/inet.h>
78                         ],
79                         [
80                                 struct in_addr add;
81                                 int sd = socket(AF_INET, SOCK_STREAM, 0);
82                                 inet_ntoa(add);
83                         ],
84                         ac_cv_socket_libs="-lsocket -lnsl", ac_cv_socket_libs=no)
85         fi
86
87         CFLAGS=$oCFLAGS
88 ])
89
90         if test x"$ac_cv_socket_libs" = "xno"
91         then
92                 AC_MSG_ERROR([Cannot find socket libraries])
93         elif test x"$ac_cv_socket_libs" = "x-lc"
94         then
95                 SOCKETLIBS=""
96                 CPPFLAGS="-DHAVE_SOCKET $CPPFLAGS"
97                 CORBA_IDLCXXFLAGS="-DHAVE_SOCKET $CORBA_IDLCXXFLAGS"
98                 CORBA_IDLPYFLAGS="-DHAVE_SOCKET $CORBA_IDLPYFLAGS"
99         else
100                 SOCKETLIBS="$ac_cv_socket_libs"
101                 CPPFLAGS="-DHAVE_SOCKET $CPPFLAGS"
102                 CORBA_IDLCXXFLAGS="-DHAVE_SOCKET $CORBA_IDLCXXFLAGS"
103                 CORBA_IDLPYFLAGS="-DHAVE_SOCKET $CORBA_IDLPYFLAGS"
104         fi
105
106         AC_SUBST(SOCKETLIBS)
107         AC_SUBST(SOCKETFLAGS)
108 ]) dnl CHECK_SOCKET