This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Carp-1.25 released to CPAN
[perl5.git] / cpan / Socket / Makefile.PL
CommitLineData
37b1de1b
CBW
1#!perl
2use strict;
3use warnings;
4
42793c05 5use ExtUtils::MakeMaker;
735631af 6use ExtUtils::Constant 0.23 'WriteConstants';
d6a66728 7use Config;
1584259f
PLE
8
9my @DEFINES;
1584259f 10
37b1de1b
CBW
11my $cb;
12my $seq = 0;
13sub check_for
14{
15 my %args = @_;
16 return if exists $Config{$args{confkey}};
17
18 require ExtUtils::CBuilder;
19 $cb ||= ExtUtils::CBuilder->new( quiet => 1 );
20
21 my $main = $args{main};
22
23 print "Checking $args{define}...\n";
1584259f 24
37b1de1b
CBW
25 my $file_base = "test-$seq"; $seq++;
26
27 my $file_source = "$file_base.c";
28
29 {
30 open( my $file_source_fh, ">", $file_source ) or die "Cannot write $file_source - $!";
31 print $file_source_fh <<"EOF";
1584259f
PLE
32#include <sys/types.h>
33#include <sys/socket.h>
34#include <netdb.h>
35#include <netinet/in.h>
36#include <arpa/inet.h>
37b1de1b
CBW
37int main(int argc, char *argv[])
38 {
39 $main
1584259f 40 return 0;
37b1de1b 41 }
1584259f 42EOF
1584259f
PLE
43 }
44
37b1de1b
CBW
45 my $file_obj = eval { $cb->compile( source => $file_source ) };
46 unlink $file_source;
47
48 return 0 unless defined $file_obj;
49
50 my $file_exe = eval { $cb->link_executable( objects => $file_obj ) };
51 unlink $file_obj;
52
53 return 0 unless defined $file_exe;
54
55 # Don't need to try running it
56 unlink $file_exe;
57
58 push @DEFINES, $args{define};
1584259f 59}
1584259f 60
37b1de1b
CBW
61sub check_for_func
62{
63 my %args = @_;
64 my $func = delete $args{func};
65 check_for( %args, main => "void *p = &$func;" );
1584259f 66}
1584259f 67
37b1de1b
CBW
68my %defines = (
69 # -Dfoo func() $Config{key}
70 HAS_GETADDRINFO => [ "getaddrinfo", "d_getaddrinfo" ],
71 HAS_GETNAMEINFO => [ "getnameinfo", "d_getnameinfo" ],
72 HAS_INET_ATON => [ "inet_aton", "d_inetaton" ],
73 HAS_INETNTOP => [ "inet_ntop", "d_inetntop" ],
74 HAS_INETPTON => [ "inet_pton", "d_inetpton" ],
75);
76
77foreach my $define ( sort keys %defines ) {
78 my ( $func, $key ) = @{$defines{$define}};
79 check_for_func(
80 confkey => $key,
81 define => $define,
82 func => $func
83 );
1584259f
PLE
84}
85
37b1de1b
CBW
86check_for(
87 confkey => "d_sockaddr_sa_len",
88 define => "HAS_SOCKADDR_SA_LEN",
89 main => "struct sockaddr sa; sa.sa_len = 0;"
90);
91
92check_for(
93 confkey => "d_sin6_scope_id",
94 define => "HAS_SIN6_SCOPE_ID",
95 main => "struct sockaddr_in6 sin6; sin6.sin6_scope_id = 0;"
96);
97
98my %makefile_args;
99
100# Since we're providing a later version of a core module, before 5.12 the
101# @INC order is wrong so we'll have to go in perl rather than site dirs
102$makefile_args{INSTALLDIRS} = "perl" if $] < 5.012;
103
4ad3186e 104WriteMakefile(
d6a66728 105 NAME => 'Socket',
c07a80fd 106 VERSION_FROM => 'Socket.pm',
d6a66728 107 ($Config{libs} =~ /(-lsocks\S*)/ ? (LIBS => [ "$1" ] ) : ()),
d6a66728 108 XSPROTOARG => '-noprototypes', # XXX remove later?
ece2ffd9 109 realclean => {FILES=> 'const-c.inc const-xs.inc'},
37b1de1b 110 DEFINE => join( " ", map { "-D$_" } @DEFINES ),
1584259f 111 CONFIGURE_REQUIRES => {
37b1de1b 112 'ExtUtils::CBuilder' => 0,
1584259f
PLE
113 'ExtUtils::Constant' => '0.23',
114 },
37b1de1b 115 %makefile_args,
4ad3186e 116);
c2654555
CBW
117my @names = (
118 qw(
119 AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF AF_DATAKIT
120 AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK AF_IMPLINK AF_INET AF_INET6
121 AF_ISO AF_KEY AF_LAST AF_LAT AF_LINK AF_MAX AF_NBS AF_NIT AF_NS AF_OSI
122 AF_OSINET AF_PUP AF_ROUTE AF_SNA AF_UNIX AF_UNSPEC AF_USER AF_WAN
123 AF_X25
124
125 AI_ADDRCONFIG AI_ALL AI_CANONIDN AI_CANONNAME AI_IDN
126 AI_IDN_ALLOW_UNASSIGNED AI_IDN_USE_STD3_ASCII_RULES AI_NUMERICHOST
127 AI_NUMERICSERV AI_PASSIVE AI_V4MAPPED
128
129 EAI_ADDRFAMILY EAI_AGAIN EAI_BADFLAGS EAI_BADHINTS EAI_FAIL EAI_FAMILY
130 EAI_NODATA EAI_NONAME EAI_PROTOCOL EAI_SERVICE EAI_SOCKTYPE EAI_SYSTEM
131
132 IOV_MAX
133
134 IP_OPTIONS IP_HDRINCL IP_TOS IP_TTL IP_RECVOPTS IP_RECVRETOPTS
135 IP_RETOPTS
136
137 IPV6_ADD_MEMBERSHIP IPV6_DROP_MEMBERSHIP IPV6_MTU IPV6_MTU_DISCOVER
138 IPV6_MULTICAST_HOPS IPV6_MULTICAST_IF IPV6_MULTICAST_LOOP
139 IPV6_UNICAST_HOPS IPV6_V6ONLY
140
141 MSG_BCAST MSG_BTAG MSG_CTLFLAGS MSG_CTLIGNORE MSG_DONTWAIT MSG_EOF
142 MSG_EOR MSG_ERRQUEUE MSG_ETAG MSG_FIN MSG_MAXIOVLEN MSG_MCAST
143 MSG_NOSIGNAL MSG_RST MSG_SYN MSG_TRUNC MSG_URG MSG_WAITALL MSG_WIRE
144
145 NI_DGRAM NI_IDN NI_IDN_ALLOW_UNASSIGNED NI_IDN_USE_STD3_ASCII_RULES
146 NI_NAMEREQD NI_NOFQDN NI_NUMERICHOST NI_NUMERICSERV
147
148 PF_802 PF_AAL PF_APPLETALK PF_CCITT PF_CHAOS PF_CTF PF_DATAKIT
149 PF_DECnet PF_DLI PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_INET6
150 PF_ISO PF_KEY PF_LAST PF_LAT PF_LINK PF_MAX PF_NBS PF_NIT PF_NS PF_OSI
151 PF_OSINET PF_PUP PF_ROUTE PF_SNA PF_UNIX PF_UNSPEC PF_USER PF_WAN
152 PF_X25
153
154 SCM_CONNECT SCM_CREDENTIALS SCM_CREDS SCM_TIMESTAMP
155
156 SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET SOCK_STREAM
157
158 SOL_SOCKET
159
160 SOMAXCONN
161
162 SO_ACCEPTCONN SO_ATTACH_FILTER SO_BACKLOG SO_BROADCAST SO_CHAMELEON
163 SO_DEBUG SO_DETACH_FILTER SO_DGRAM_ERRIND SO_DONTLINGER SO_DONTROUTE
164 SO_ERROR SO_FAMILY SO_KEEPALIVE SO_LINGER SO_OOBINLINE SO_PASSCRED
165 SO_PASSIFNAME SO_PEERCRED SO_PROTOCOL SO_PROTOTYPE SO_RCVBUF
166 SO_RCVLOWAT SO_RCVTIMEO SO_REUSEADDR SO_REUSEPORT
167 SO_SECURITY_AUTHENTICATION SO_SECURITY_ENCRYPTION_NETWORK
168 SO_SECURITY_ENCRYPTION_TRANSPORT SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO
169 SO_STATE SO_TYPE SO_USELOOPBACK SO_XOPEN SO_XSE
170
171 TCP_KEEPALIVE TCP_MAXRT TCP_MAXSEG TCP_NODELAY TCP_STDURG TCP_CORK
172 TCP_KEEPIDLE TCP_KEEPINTVL TCP_KEEPCNT TCP_SYNCNT TCP_LINGER2
173 TCP_DEFER_ACCEPT TCP_WINDOW_CLAMP TCP_INFO TCP_QUICKACK TCP_CONGESTION
174 TCP_MD5SIG
175
176 UIO_MAXIOV
177 ),
178 {name=>"IPPROTO_IP", type=>"IV", default=>["IV", 0]},
179 {name=>"IPPROTO_IPV6", type=>"IV", default=>["IV", 41]},
180 {name=>"IPPROTO_RAW", type=>"IV", default=>["IV", 255]},
181 {name=>"IPPROTO_ICMP", type=>"IV", default=>["IV", 1]},
182 {name=>"IPPROTO_TCP", type=>"IV", default=>["IV", 6]},
183 {name=>"IPPROTO_UDP", type=>"IV", default=>["IV", 17]},
184 {name=>"SHUT_RD", type=>"IV", default=>["IV", "0"]},
185 {name=>"SHUT_WR", type=>"IV", default=>["IV", "1"]},
186 {name=>"SHUT_RDWR", type=>"IV", default=>["IV", "2"]},
0552bf3a
NC
187);
188
c2654555
CBW
189push @names, {
190 name => $_,
191 type => "IV",
192 macro => [ "#if defined($_) || defined(HAS_$_) /* might be an enum */\n",
193 "#endif\n" ]
194} foreach qw (MSG_CTRUNC MSG_DONTROUTE MSG_OOB MSG_PEEK MSG_PROXY SCM_RIGHTS);
195
196push @names, {
197 name => $_,
198 type => "SV",
199 pre => "struct in_addr ip_address; ip_address.s_addr = htonl($_);",
200 value => "newSVpvn_flags((char *)&ip_address,sizeof(ip_address), SVs_TEMP)",
201} foreach qw(INADDR_ANY INADDR_LOOPBACK INADDR_NONE INADDR_BROADCAST);
202
203push @names, {
204 name => $_,
205 type => "SV",
206 macro => [ "#ifdef ${_}_INIT\n",
207 "#endif\n" ],
208 pre => "struct in6_addr ip6_address = ${_}_INIT;",
209 value => "newSVpvn_flags((char *)&ip6_address,sizeof(ip6_address), SVs_TEMP)",
210} foreach qw(IN6ADDR_ANY IN6ADDR_LOOPBACK);
6b0aeb77 211
0552bf3a 212WriteConstants(
7f39e0ae 213 PROXYSUBS => {autoload => 1},
0552bf3a
NC
214 NAME => 'Socket',
215 NAMES => \@names,
216);