This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
op.c: Consistent tweak; podchecker complaints
[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 {
9dea6244
CBW
39 (void)argc;
40 (void)argv;
37b1de1b 41 $main
1584259f 42 return 0;
37b1de1b 43 }
1584259f 44EOF
1584259f
PLE
45 }
46
37b1de1b
CBW
47 my $file_obj = eval { $cb->compile( source => $file_source ) };
48 unlink $file_source;
49
50 return 0 unless defined $file_obj;
51
52 my $file_exe = eval { $cb->link_executable( objects => $file_obj ) };
53 unlink $file_obj;
54
55 return 0 unless defined $file_exe;
56
57 # Don't need to try running it
58 unlink $file_exe;
59
60 push @DEFINES, $args{define};
1584259f 61}
1584259f 62
37b1de1b
CBW
63sub check_for_func
64{
65 my %args = @_;
66 my $func = delete $args{func};
9dea6244 67 check_for( %args, main => "void *p = &$func; (void)p;" );
1584259f 68}
1584259f 69
37b1de1b
CBW
70my %defines = (
71 # -Dfoo func() $Config{key}
72 HAS_GETADDRINFO => [ "getaddrinfo", "d_getaddrinfo" ],
73 HAS_GETNAMEINFO => [ "getnameinfo", "d_getnameinfo" ],
74 HAS_INET_ATON => [ "inet_aton", "d_inetaton" ],
75 HAS_INETNTOP => [ "inet_ntop", "d_inetntop" ],
76 HAS_INETPTON => [ "inet_pton", "d_inetpton" ],
77);
78
79foreach my $define ( sort keys %defines ) {
80 my ( $func, $key ) = @{$defines{$define}};
81 check_for_func(
82 confkey => $key,
83 define => $define,
84 func => $func
85 );
1584259f
PLE
86}
87
37b1de1b
CBW
88check_for(
89 confkey => "d_sockaddr_sa_len",
90 define => "HAS_SOCKADDR_SA_LEN",
91 main => "struct sockaddr sa; sa.sa_len = 0;"
92);
93
94check_for(
eabcd9c8 95 confkey => "d_sockaddr_in6",
9dea6244
CBW
96 define => "HAS_SOCKADDR_IN6",
97 main => "struct sockaddr_in6 sin6; sin6.sin6_family = AF_INET6;"
98);
99
100check_for(
37b1de1b
CBW
101 confkey => "d_sin6_scope_id",
102 define => "HAS_SIN6_SCOPE_ID",
103 main => "struct sockaddr_in6 sin6; sin6.sin6_scope_id = 0;"
104);
105
9dea6244 106check_for(
eabcd9c8 107 confkey => "d_ipv6_mreq",
9dea6244
CBW
108 define => "HAS_IPV6_MREQ",
109 main => "struct ipv6_mreq mreq; mreq.ipv6mr_interface = 0;"
110);
111
37b1de1b
CBW
112my %makefile_args;
113
114# Since we're providing a later version of a core module, before 5.12 the
115# @INC order is wrong so we'll have to go in perl rather than site dirs
116$makefile_args{INSTALLDIRS} = "perl" if $] < 5.012;
117
4ad3186e 118WriteMakefile(
eabcd9c8
A
119 NAME => 'Socket',
120 VERSION_FROM => 'Socket.pm',
121 # ABSTRACT_FROM gets confused by C<Socket>
122 ABSTRACT => 'networking constants and support functions',
d6a66728 123 ($Config{libs} =~ /(-lsocks\S*)/ ? (LIBS => [ "$1" ] ) : ()),
eabcd9c8
A
124 XSPROTOARG => '-noprototypes', # XXX remove later?
125 realclean => {FILES=> 'const-c.inc const-xs.inc'},
126 DEFINE => join( " ", map { "-D$_" } @DEFINES ),
1584259f 127 CONFIGURE_REQUIRES => {
37b1de1b 128 'ExtUtils::CBuilder' => 0,
1584259f
PLE
129 'ExtUtils::Constant' => '0.23',
130 },
9dea6244 131 MIN_PERL_VERSION => '5.006001',
eabcd9c8 132 LICENSE => 'perl',
37b1de1b 133 %makefile_args,
4ad3186e 134);
c2654555
CBW
135my @names = (
136 qw(
137 AF_802 AF_AAL AF_APPLETALK AF_CCITT AF_CHAOS AF_CTF AF_DATAKIT
138 AF_DECnet AF_DLI AF_ECMA AF_GOSIP AF_HYLINK AF_IMPLINK AF_INET AF_INET6
139 AF_ISO AF_KEY AF_LAST AF_LAT AF_LINK AF_MAX AF_NBS AF_NIT AF_NS AF_OSI
140 AF_OSINET AF_PUP AF_ROUTE AF_SNA AF_UNIX AF_UNSPEC AF_USER AF_WAN
141 AF_X25
142
143 AI_ADDRCONFIG AI_ALL AI_CANONIDN AI_CANONNAME AI_IDN
144 AI_IDN_ALLOW_UNASSIGNED AI_IDN_USE_STD3_ASCII_RULES AI_NUMERICHOST
145 AI_NUMERICSERV AI_PASSIVE AI_V4MAPPED
146
147 EAI_ADDRFAMILY EAI_AGAIN EAI_BADFLAGS EAI_BADHINTS EAI_FAIL EAI_FAMILY
148 EAI_NODATA EAI_NONAME EAI_PROTOCOL EAI_SERVICE EAI_SOCKTYPE EAI_SYSTEM
149
150 IOV_MAX
151
152 IP_OPTIONS IP_HDRINCL IP_TOS IP_TTL IP_RECVOPTS IP_RECVRETOPTS
153 IP_RETOPTS
154
155 IPV6_ADD_MEMBERSHIP IPV6_DROP_MEMBERSHIP IPV6_MTU IPV6_MTU_DISCOVER
156 IPV6_MULTICAST_HOPS IPV6_MULTICAST_IF IPV6_MULTICAST_LOOP
157 IPV6_UNICAST_HOPS IPV6_V6ONLY
158
159 MSG_BCAST MSG_BTAG MSG_CTLFLAGS MSG_CTLIGNORE MSG_DONTWAIT MSG_EOF
160 MSG_EOR MSG_ERRQUEUE MSG_ETAG MSG_FIN MSG_MAXIOVLEN MSG_MCAST
161 MSG_NOSIGNAL MSG_RST MSG_SYN MSG_TRUNC MSG_URG MSG_WAITALL MSG_WIRE
162
163 NI_DGRAM NI_IDN NI_IDN_ALLOW_UNASSIGNED NI_IDN_USE_STD3_ASCII_RULES
164 NI_NAMEREQD NI_NOFQDN NI_NUMERICHOST NI_NUMERICSERV
165
166 PF_802 PF_AAL PF_APPLETALK PF_CCITT PF_CHAOS PF_CTF PF_DATAKIT
167 PF_DECnet PF_DLI PF_ECMA PF_GOSIP PF_HYLINK PF_IMPLINK PF_INET PF_INET6
168 PF_ISO PF_KEY PF_LAST PF_LAT PF_LINK PF_MAX PF_NBS PF_NIT PF_NS PF_OSI
169 PF_OSINET PF_PUP PF_ROUTE PF_SNA PF_UNIX PF_UNSPEC PF_USER PF_WAN
170 PF_X25
171
172 SCM_CONNECT SCM_CREDENTIALS SCM_CREDS SCM_TIMESTAMP
173
174 SOCK_DGRAM SOCK_RAW SOCK_RDM SOCK_SEQPACKET SOCK_STREAM
175
176 SOL_SOCKET
177
178 SOMAXCONN
179
180 SO_ACCEPTCONN SO_ATTACH_FILTER SO_BACKLOG SO_BROADCAST SO_CHAMELEON
eabcd9c8
A
181 SO_DEBUG SO_DETACH_FILTER SO_DGRAM_ERRIND SO_DOMAIN SO_DONTLINGER
182 SO_DONTROUTE SO_ERROR SO_FAMILY SO_KEEPALIVE SO_LINGER SO_OOBINLINE
183 SO_PASSCRED SO_PASSIFNAME SO_PEERCRED SO_PROTOCOL SO_PROTOTYPE
184 SO_RCVBUF SO_RCVLOWAT SO_RCVTIMEO SO_REUSEADDR SO_REUSEPORT
c2654555
CBW
185 SO_SECURITY_AUTHENTICATION SO_SECURITY_ENCRYPTION_NETWORK
186 SO_SECURITY_ENCRYPTION_TRANSPORT SO_SNDBUF SO_SNDLOWAT SO_SNDTIMEO
187 SO_STATE SO_TYPE SO_USELOOPBACK SO_XOPEN SO_XSE
188
189 TCP_KEEPALIVE TCP_MAXRT TCP_MAXSEG TCP_NODELAY TCP_STDURG TCP_CORK
190 TCP_KEEPIDLE TCP_KEEPINTVL TCP_KEEPCNT TCP_SYNCNT TCP_LINGER2
191 TCP_DEFER_ACCEPT TCP_WINDOW_CLAMP TCP_INFO TCP_QUICKACK TCP_CONGESTION
192 TCP_MD5SIG
193
194 UIO_MAXIOV
195 ),
196 {name=>"IPPROTO_IP", type=>"IV", default=>["IV", 0]},
197 {name=>"IPPROTO_IPV6", type=>"IV", default=>["IV", 41]},
198 {name=>"IPPROTO_RAW", type=>"IV", default=>["IV", 255]},
199 {name=>"IPPROTO_ICMP", type=>"IV", default=>["IV", 1]},
200 {name=>"IPPROTO_TCP", type=>"IV", default=>["IV", 6]},
201 {name=>"IPPROTO_UDP", type=>"IV", default=>["IV", 17]},
202 {name=>"SHUT_RD", type=>"IV", default=>["IV", "0"]},
203 {name=>"SHUT_WR", type=>"IV", default=>["IV", "1"]},
204 {name=>"SHUT_RDWR", type=>"IV", default=>["IV", "2"]},
0552bf3a
NC
205);
206
c2654555
CBW
207push @names, {
208 name => $_,
209 type => "IV",
210 macro => [ "#if defined($_) || defined(HAS_$_) /* might be an enum */\n",
211 "#endif\n" ]
212} foreach qw (MSG_CTRUNC MSG_DONTROUTE MSG_OOB MSG_PEEK MSG_PROXY SCM_RIGHTS);
213
214push @names, {
215 name => $_,
216 type => "SV",
217 pre => "struct in_addr ip_address; ip_address.s_addr = htonl($_);",
218 value => "newSVpvn_flags((char *)&ip_address,sizeof(ip_address), SVs_TEMP)",
219} foreach qw(INADDR_ANY INADDR_LOOPBACK INADDR_NONE INADDR_BROADCAST);
220
221push @names, {
222 name => $_,
223 type => "SV",
224 macro => [ "#ifdef ${_}_INIT\n",
225 "#endif\n" ],
226 pre => "struct in6_addr ip6_address = ${_}_INIT;",
227 value => "newSVpvn_flags((char *)&ip6_address,sizeof(ip6_address), SVs_TEMP)",
228} foreach qw(IN6ADDR_ANY IN6ADDR_LOOPBACK);
6b0aeb77 229
9dea6244
CBW
230# Work around an old Perl core bug that affects ExtUtils::Constants on
231# pre-5.8.2 Perls. EU:C should be amended to work around this itself.
232if("$]" < 5.008002) {
233 require ExtUtils::Constant::ProxySubs;
234 no warnings "once";
235 $ExtUtils::Constant::ProxySubs::type_to_C_value{$_} = sub { () }
236 foreach qw(YES NO UNDEF), "";
237}
238
0552bf3a 239WriteConstants(
7f39e0ae 240 PROXYSUBS => {autoload => 1},
0552bf3a
NC
241 NAME => 'Socket',
242 NAMES => \@names,
243);