| 1 |
# |
| 2 |
# check a bunch of stuff. |
| 3 |
# write #define/#undef to file given in ARGV[0]. |
| 4 |
# now also writes #include's too. |
| 5 |
# |
| 6 |
|
| 7 |
use strict; |
| 8 |
use warnings; |
| 9 |
use Config; |
| 10 |
use File::Spec (); |
| 11 |
use File::Temp (); |
| 12 |
use Devel::CheckLib; |
| 13 |
|
| 14 |
select STDERR; $|=1; |
| 15 |
select STDOUT; $|=1; |
| 16 |
|
| 17 |
my ($out, $flagfile) = @ARGV; |
| 18 |
my $conf = []; |
| 19 |
my $flags = []; |
| 20 |
my $WIN32 = 0; # native |
| 21 |
|
| 22 |
# set this once a working random found |
| 23 |
my $RANDFOUND = 0; |
| 24 |
|
| 25 |
# try to make all temp files here |
| 26 |
my $TMPDIR = File::Temp->newdir('UUID-conf-XXXXXXXX', TMPDIR => 1, CLEANUP => 0); |
| 27 |
|
| 28 |
generate_conf($conf, $flags); |
| 29 |
write_conf ($conf, $out); |
| 30 |
|
| 31 |
#unlink($_) for <assertlib*.obj>; |
| 32 |
my $tmpglob = File::Spec->catfile( $TMPDIR, 'assert*' ); |
| 33 |
unlink($_) for <"$tmpglob">; |
| 34 |
rmdir $TMPDIR; |
| 35 |
|
| 36 |
exit 0; |
| 37 |
|
| 38 |
sub generate_conf { |
| 39 |
my ($defines, $flags) = @_; |
| 40 |
my $longest = 0; |
| 41 |
|
| 42 |
# if lencheck is 1, \$longest is longest so far. sub is expected to |
| 43 |
# update it if it has one longer and skip actual test. |
| 44 |
# |
| 45 |
# if lencheck is 0, \$longest contains global longest. sub is expected |
| 46 |
# to use that when printing and to run the test. |
| 47 |
|
| 48 |
for my $check ( 1, 0 ) { |
| 49 |
# win32 native if on windows but not under some |
| 50 |
# sort of unix environ. i.e. native. |
| 51 |
# sets $WIN32. do this first. |
| 52 |
my $platform = try_platform($check, \$longest, $defines); |
| 53 |
|
| 54 |
# NOTE: winsock2.h must precede Windows.h, |
| 55 |
# at least for Cygwin. |
| 56 |
try_headers($check, \$longest, $defines, $platform, q( |
| 57 |
# |
| 58 |
# format: |
| 59 |
# SYMBOL FILE [PLATFORM [PLATFORM [...]]] |
| 60 |
# |
| 61 |
# if FILE is found SYMBOL will be defined and |
| 62 |
# the header included in EUMM.h. |
| 63 |
# |
| 64 |
# if one or more PLATFORMs are listed, one must |
| 65 |
# match that returned from try_platform() or the |
| 66 |
# check is skipped. |
| 67 |
# |
| 68 |
# if no platforms are listed, the header is tried |
| 69 |
# on every platform. |
| 70 |
# |
| 71 |
# invalid platforms are ignored but, if it is the |
| 72 |
# only platform for a symbol, the file will not |
| 73 |
# be checked. |
| 74 |
# |
| 75 |
# valid platforms: alien, cygwin, native, unix. |
| 76 |
# (alien = Strawberry) |
| 77 |
# |
| 78 |
# comments and blank lines allowed. |
| 79 |
# |
| 80 |
HAVE_WINSOCK2_H winsock2.h native skip |
| 81 |
HAVE_WINDOWS_H Windows.h alien cygwin native skip |
| 82 |
HAVE_IPHLPAPI_H iphlpapi.h native skip |
| 83 |
HAVE_BCRYPT_H bcrypt.h alien native skip |
| 84 |
#------------------------------------------------------------------------- |
| 85 |
HAVE_CTYPE_H ctype.h alien native unix skip |
| 86 |
HAVE_DISPATCH_DISPATCH_H dispatch/dispatch.h unix skip |
| 87 |
HAVE_ERR_H err.h unix skip |
| 88 |
HAVE_ERRNO_H errno.h alien native unix skip |
| 89 |
#------------------------------------------------------------------------- |
| 90 |
HAVE_FCNTL_H fcntl.h alien native unix skip |
| 91 |
HAVE_INTTYPES_H inttypes.h alien native unix skip |
| 92 |
HAVE_IO_H io.h alien native skip |
| 93 |
HAVE_MEMORYAPI_H memoryapi.h alien native skip |
| 94 |
#------------------------------------------------------------------------- |
| 95 |
HAVE_NETINET_IN_H netinet/in.h unix skip |
| 96 |
HAVE_NET_IF_DL_H net/if_dl.h unix skip |
| 97 |
HAVE_NET_IF_H net/if.h unix skip |
| 98 |
HAVE_PROCESS_H process.h alien native skip |
| 99 |
#------------------------------------------------------------------------- |
| 100 |
#HAVE_PTHREAD_H pthread.h alien unix skip |
| 101 |
HAVE_SEMAPHORE_H semaphore.h cygwin unix skip |
| 102 |
HAVE_STDINT_H stdint.h alien native unix skip |
| 103 |
HAVE_STDIO_H stdio.h alien native unix skip |
| 104 |
#------------------------------------------------------------------------- |
| 105 |
HAVE_STDLIB_H stdlib.h alien native unix skip |
| 106 |
HAVE_STRING_H string.h alien native unix skip |
| 107 |
HAVE_SYS_FILE_H sys/file.h alien unix skip |
| 108 |
HAVE_SYS_FUTEX_H sys/futex.h unix skip |
| 109 |
#------------------------------------------------------------------------- |
| 110 |
HAVE_SYS_IOCTL_H sys/ioctl.h unix skip |
| 111 |
HAVE_SYS_MMAN_H sys/mman.h cygwin unix skip |
| 112 |
HAVE_SYS_RANDOM_H sys/random.h cygwin unix skip |
| 113 |
HAVE_SYS_RESOURCE_H sys/resource.h unix skip |
| 114 |
#------------------------------------------------------------------------- |
| 115 |
HAVE_SYS_SOCKET_H sys/socket.h unix skip |
| 116 |
HAVE_SYS_SOCKIO_H sys/sockio.h unix skip |
| 117 |
HAVE_SYS_STAT_H sys/stat.h alien native unix skip |
| 118 |
HAVE_SYS_TIME_H sys/time.h alien unix skip |
| 119 |
#------------------------------------------------------------------------- |
| 120 |
HAVE_SYS_TYPES_H sys/types.h alien native unix skip |
| 121 |
HAVE_SYS_WAIT_H sys/wait.h unix skip |
| 122 |
HAVE_TIME_H time.h alien native unix skip |
| 123 |
HAVE_UNISTD_H unistd.h alien unix skip |
| 124 |
#------------------------------------------------------------------------- |
| 125 |
HAVE_WINCRYPT_H wincrypt.h alien native skip |
| 126 |
)); |
| 127 |
|
| 128 |
try_arc4random ($check, \$longest, $defines, $platform); |
| 129 |
try_BCryptGenRandom ($check, \$longest, $defines, $platform); |
| 130 |
try_CryptGenRandom ($check, \$longest, $defines, $platform); |
| 131 |
try_getentropy ($check, \$longest, $defines, $platform); |
| 132 |
try_getrandom ($check, \$longest, $defines, $platform); |
| 133 |
#try_gettimeofday ($check, \$longest, $defines, $platform); |
| 134 |
try_lstat ($check, \$longest, $defines, $platform); |
| 135 |
try_sa_len ($check, \$longest, $defines, $platform); |
| 136 |
try_srwlock ($check, \$longest, $defines, $platform); |
| 137 |
try_symlink ($check, \$longest, $defines, $platform); |
| 138 |
#try_threads ($check, \$longest, $defines, $platform); |
| 139 |
} |
| 140 |
} |
| 141 |
|
| 142 |
sub try_headers { |
| 143 |
my ($check, $long, $defines, $platform, $block) = @_; |
| 144 |
my @lines = split /\n/, $block; |
| 145 |
for my $line ( @lines ) { |
| 146 |
chomp $line; |
| 147 |
$line =~ s/\s*\#.*$//; # strip comments and tail space |
| 148 |
$line =~ s/^\s+//; # strip lead space |
| 149 |
next if $line =~ /^\s*$/; # skip empty lines |
| 150 |
|
| 151 |
my ($symbol, $file, @more) = split /\s+/, $line; |
| 152 |
|
| 153 |
# platform match ? |
| 154 |
my $skip = 0; |
| 155 |
if (scalar @more) { |
| 156 |
$skip = 1; |
| 157 |
for (@more) { $skip=0 if $_ eq $platform } |
| 158 |
} |
| 159 |
|
| 160 |
check_header($check, $skip, $long, $defines, $symbol, $file); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
sub check_header { |
| 165 |
my ($check, $skip, $long, $defines, $symbol, $file) = @_; |
| 166 |
|
| 167 |
if ($skip) { |
| 168 |
return if $check; |
| 169 |
push @$defines, "#undef $symbol"; |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
my $msg = join ' ', 'Checking for', $file; |
| 174 |
my $len = length $msg; |
| 175 |
if ($check) { |
| 176 |
$$long = $len if $len > $$long; |
| 177 |
return; |
| 178 |
} |
| 179 |
my $more = $$long - $len; |
| 180 |
print $msg, ' ..', '.'x$more, ' '; |
| 181 |
|
| 182 |
if ($skip) { |
| 183 |
print "skip\n"; |
| 184 |
push @$defines, "#undef $symbol"; |
| 185 |
return; |
| 186 |
} |
| 187 |
|
| 188 |
my ($conf, $fh) = gen_confh_fh($defines); |
| 189 |
print $fh join("\n", map {s/^\s+//; $_} split(/\n/, qq{ |
| 190 |
#include <${file}> |
| 191 |
})); |
| 192 |
close $fh; |
| 193 |
|
| 194 |
my $win32permit = 1; |
| 195 |
$win32permit = 0 if !$WIN32 && $symbol =~ /WINSOCK/; |
| 196 |
$win32permit = 0 if !$WIN32 && $symbol =~ /IPHLPAPI/; |
| 197 |
|
| 198 |
if ( $win32permit && check_lib( |
| 199 |
header => $conf, |
| 200 |
#lib => 'c', # because not linking here.. duh! |
| 201 |
ccflags => '-I.', |
| 202 |
debug => 0, |
| 203 |
)) { |
| 204 |
push @$defines, "#define $symbol 1"; |
| 205 |
push @$defines, "#include <${file}>"; |
| 206 |
print "found\n"; |
| 207 |
} |
| 208 |
else { |
| 209 |
push @$defines, "#undef $symbol"; |
| 210 |
print "none\n"; |
| 211 |
} |
| 212 |
unlink $conf; |
| 213 |
} |
| 214 |
|
| 215 |
sub gen_confh { |
| 216 |
my ($defs) = @_; |
| 217 |
my ($fh, $fname) = File::Temp::tempfile( |
| 218 |
'assertconfXXXXXXXX', SUFFIX => '.h', DIR => $TMPDIR, UNLINK => 0 |
| 219 |
); |
| 220 |
print $fh "$_\n" for @$defs; |
| 221 |
close $fh; |
| 222 |
return $fname; |
| 223 |
} |
| 224 |
|
| 225 |
sub gen_confh_fh { |
| 226 |
my ($defs) = @_; |
| 227 |
my ($fh, $fname) = File::Temp::tempfile( |
| 228 |
'assertconfXXXXXXXX', SUFFIX => '.h', DIR => $TMPDIR, UNLINK => 0 |
| 229 |
); |
| 230 |
print $fh "$_\n" for @$defs; |
| 231 |
return $fname, $fh; |
| 232 |
} |
| 233 |
|
| 234 |
sub try_arc4random { |
| 235 |
my ($check, $long, $defs, $platform) = @_; |
| 236 |
my $msg = 'Checking for arc4random()'; |
| 237 |
my $len = length $msg; |
| 238 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 239 |
my $more = $$long - $len; |
| 240 |
print $msg, ' ..', '.'x$more, ' '; |
| 241 |
if ($RANDFOUND or $platform eq 'native') { |
| 242 |
push @$defs, '#undef HAVE_ARC4RANDOM'; |
| 243 |
print "skip\n"; |
| 244 |
return; |
| 245 |
} |
| 246 |
my $conf = gen_confh($defs); |
| 247 |
if ( check_lib( |
| 248 |
header => $conf, |
| 249 |
lib => 'c', # always do at least this |
| 250 |
ccflags => '-I.', |
| 251 |
debug => 0, |
| 252 |
function => q{ |
| 253 |
unsigned char p[4]; |
| 254 |
int c = 4; |
| 255 |
arc4random_buf(&p, c); |
| 256 |
return 0; |
| 257 |
}, |
| 258 |
)) { |
| 259 |
push @$defs, '#define HAVE_ARC4RANDOM 1'; |
| 260 |
print "found\n"; |
| 261 |
$RANDFOUND = 1; |
| 262 |
} |
| 263 |
else { |
| 264 |
push @$defs, '#undef HAVE_ARC4RANDOM'; |
| 265 |
print "none\n"; |
| 266 |
} |
| 267 |
unlink $conf; |
| 268 |
} |
| 269 |
|
| 270 |
sub try_BCryptGenRandom { |
| 271 |
my ($check, $long, $defs, $platform) = @_; |
| 272 |
my $msg = 'Checking for BCryptGenRandom()'; |
| 273 |
my $len = length $msg; |
| 274 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 275 |
my $more = $$long - $len; |
| 276 |
print $msg, ' ..', '.'x$more, ' '; |
| 277 |
if ($RANDFOUND or $platform eq 'unix') { |
| 278 |
push @$defs, '#undef HAVE_BCRYPTGENRANDOM'; |
| 279 |
print "skip\n"; |
| 280 |
return; |
| 281 |
} |
| 282 |
my $conf = gen_confh($defs); |
| 283 |
if ( check_lib( |
| 284 |
header => $conf, |
| 285 |
lib => 'bcrypt', |
| 286 |
ccflags => '-I.', |
| 287 |
debug => 0, |
| 288 |
function => q{ |
| 289 |
unsigned char p[4]; |
| 290 |
int r, c = 4; |
| 291 |
r = BCryptGenRandom(NULL, p, c, BCRYPT_USE_SYSTEM_PREFERRED_RNG); |
| 292 |
return 0; |
| 293 |
(void)r; |
| 294 |
}, |
| 295 |
)) { |
| 296 |
push @$defs, '#define HAVE_BCRYPTGENRANDOM 1'; |
| 297 |
print "found\n"; |
| 298 |
$RANDFOUND = 1; |
| 299 |
} |
| 300 |
else { |
| 301 |
push @$defs, '#undef HAVE_BCRYPTGENRANDOM'; |
| 302 |
print "none\n"; |
| 303 |
} |
| 304 |
unlink $conf; |
| 305 |
} |
| 306 |
|
| 307 |
sub try_CryptGenRandom { |
| 308 |
my ($check, $long, $defs, $platform) = @_; |
| 309 |
my $msg = 'Checking for CryptGenRandom()'; |
| 310 |
my $len = length $msg; |
| 311 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 312 |
my $more = $$long - $len; |
| 313 |
print $msg, ' ..', '.'x$more, ' '; |
| 314 |
if ($RANDFOUND or $platform eq 'unix') { |
| 315 |
push @$defs, '#undef HAVE_CRYPTGENRANDOM'; |
| 316 |
print "skip\n"; |
| 317 |
return; |
| 318 |
} |
| 319 |
my $conf = gen_confh($defs); |
| 320 |
if ( check_lib( |
| 321 |
header => $conf, |
| 322 |
lib => 'crypto', |
| 323 |
ccflags => '-I.', |
| 324 |
debug => 0, |
| 325 |
function => q{ |
| 326 |
unsigned char p[4]; |
| 327 |
int r, c = 4; |
| 328 |
r = CryptGenRandom((HCRYPTPROV)NULL, c, p); |
| 329 |
return 0; |
| 330 |
(void)r; |
| 331 |
}, |
| 332 |
)) { |
| 333 |
push @$defs, '#define HAVE_CRYPTGENRANDOM 1'; |
| 334 |
print "found\n"; |
| 335 |
$RANDFOUND = 1; |
| 336 |
} |
| 337 |
else { |
| 338 |
push @$defs, '#undef HAVE_CRYPTGENRANDOM'; |
| 339 |
print "none\n"; |
| 340 |
} |
| 341 |
unlink $conf; |
| 342 |
} |
| 343 |
|
| 344 |
sub try_getentropy { |
| 345 |
my ($check, $long, $defs, $platform) = @_; |
| 346 |
my $msg = 'Checking for getentropy()'; |
| 347 |
my $len = length $msg; |
| 348 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 349 |
my $more = $$long - $len; |
| 350 |
print $msg, ' ..', '.'x$more, ' '; |
| 351 |
if ($RANDFOUND or $platform eq 'native') { |
| 352 |
push @$defs, '#undef HAVE_GETENTROPY'; |
| 353 |
print "skip\n"; |
| 354 |
return; |
| 355 |
} |
| 356 |
my $conf = gen_confh($defs); |
| 357 |
if ( check_lib( |
| 358 |
header => $conf, |
| 359 |
lib => 'c', # always do at least this |
| 360 |
ccflags => '-I.', |
| 361 |
debug => 0, |
| 362 |
function => q{ |
| 363 |
unsigned char p[4]; |
| 364 |
int r, c = 4; |
| 365 |
r = getentropy(&p, c); |
| 366 |
return 0; |
| 367 |
(void)r; |
| 368 |
}, |
| 369 |
)) { |
| 370 |
push @$defs, '#define HAVE_GETENTROPY 1'; |
| 371 |
print "found\n"; |
| 372 |
$RANDFOUND = 1; |
| 373 |
} |
| 374 |
else { |
| 375 |
push @$defs, '#undef HAVE_GETENTROPY'; |
| 376 |
print "none\n"; |
| 377 |
} |
| 378 |
unlink $conf; |
| 379 |
} |
| 380 |
|
| 381 |
sub try_getrandom { |
| 382 |
my ($check, $long, $defs, $platform) = @_; |
| 383 |
my $msg = 'Checking for getrandom()'; |
| 384 |
my $len = length $msg; |
| 385 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 386 |
my $more = $$long - $len; |
| 387 |
print $msg, ' ..', '.'x$more, ' '; |
| 388 |
if ($RANDFOUND or $platform eq 'native') { |
| 389 |
push @$defs, '#undef HAVE_GETRANDOM'; |
| 390 |
print "skip\n"; |
| 391 |
return; |
| 392 |
} |
| 393 |
my $conf = gen_confh($defs); |
| 394 |
if ( check_lib( |
| 395 |
header => $conf, |
| 396 |
lib => 'c', # always do at least this |
| 397 |
ccflags => '-I.', |
| 398 |
debug => 0, |
| 399 |
function => ' |
| 400 |
unsigned char p[4]; |
| 401 |
int r, c = 4; |
| 402 |
r = getrandom(c, &p, 0); |
| 403 |
return 0; |
| 404 |
(void)r; |
| 405 |
', |
| 406 |
)) { |
| 407 |
push @$defs, '#define HAVE_GETRANDOM 1'; |
| 408 |
print "found\n"; |
| 409 |
$RANDFOUND = 1; |
| 410 |
} |
| 411 |
else { |
| 412 |
push @$defs, '#undef HAVE_GETRANDOM'; |
| 413 |
print "none\n"; |
| 414 |
} |
| 415 |
unlink $conf; |
| 416 |
} |
| 417 |
|
| 418 |
sub try_gettimeofday { |
| 419 |
my ($check, $long, $defs, $platform) = @_; |
| 420 |
my $msg = 'Checking for gettimeofday()'; |
| 421 |
my $len = length $msg; |
| 422 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 423 |
my $more = $$long - $len; |
| 424 |
print $msg, ' ..', '.'x$more, ' '; |
| 425 |
my $conf = gen_confh($defs); |
| 426 |
if ( check_lib( |
| 427 |
header => $conf, |
| 428 |
lib => 'c', # always do at least this |
| 429 |
ccflags => '-I.', |
| 430 |
debug => 0, |
| 431 |
function => ' |
| 432 |
struct timeval tv; |
| 433 |
int r = gettimeofday(&tv, 0); |
| 434 |
return 0; |
| 435 |
(void)r; |
| 436 |
', |
| 437 |
)) { |
| 438 |
push @$defs, '#define HAVE_GETTIMEOFDAY 1'; |
| 439 |
print "found\n"; |
| 440 |
} |
| 441 |
else { |
| 442 |
push @$defs, '#undef HAVE_GETTIMEOFDAY'; |
| 443 |
print "none\n"; |
| 444 |
} |
| 445 |
unlink $conf; |
| 446 |
} |
| 447 |
|
| 448 |
sub try_lstat { |
| 449 |
my ($check, $long, $defs, $platform) = @_; |
| 450 |
my $msg = 'Checking for lstat()'; |
| 451 |
my $len = length $msg; |
| 452 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 453 |
my $more = $$long - $len; |
| 454 |
print $msg, ' ..', '.'x$more, ' '; |
| 455 |
my $conf = gen_confh($defs); |
| 456 |
|
| 457 |
my $Werror = $WIN32 ? '-WX' : '-Werror'; |
| 458 |
my $lib = $WIN32 ? 'ucrt' : 'c'; |
| 459 |
|
| 460 |
if ( check_lib( |
| 461 |
header => $conf, |
| 462 |
lib => $lib, # always do at least this |
| 463 |
ccflags => "-I. $Werror", |
| 464 |
debug => 0, |
| 465 |
function => q{ |
| 466 |
struct stat buf; |
| 467 |
int rc, islink; |
| 468 |
rc = lstat("foo", &buf); |
| 469 |
islink = ((buf.st_mode & S_IFMT) == S_IFLNK); |
| 470 |
return 0; |
| 471 |
(void)rc; |
| 472 |
(void)islink; |
| 473 |
}, |
| 474 |
)) { |
| 475 |
push @$defs, '#define HAVE_LSTAT 1'; |
| 476 |
print "found\n"; |
| 477 |
} |
| 478 |
else { |
| 479 |
push @$defs, '#undef HAVE_LSTAT'; |
| 480 |
print "none\n"; |
| 481 |
} |
| 482 |
unlink $conf; |
| 483 |
} |
| 484 |
|
| 485 |
sub try_symlink { |
| 486 |
my ($check, $long, $defs, $platform) = @_; |
| 487 |
my $msg = 'Checking for symlink()'; |
| 488 |
my $len = length $msg; |
| 489 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 490 |
my $more = $$long - $len; |
| 491 |
print $msg, ' ..', '.'x$more, ' '; |
| 492 |
my $conf = gen_confh($defs); |
| 493 |
|
| 494 |
my $link = File::Spec->catfile( $TMPDIR, 'assertlibSYMLINK.h' ); |
| 495 |
my $has_symlink = eval { |
| 496 |
symlink $conf, $link; |
| 497 |
return 1 if -l $link; |
| 498 |
return 0; |
| 499 |
}; |
| 500 |
|
| 501 |
my $Werror = $WIN32 ? '-WX' : '-Werror'; |
| 502 |
my $lib = $WIN32 ? 'ucrt' : 'c'; |
| 503 |
|
| 504 |
if ( check_lib( |
| 505 |
header => $conf, |
| 506 |
lib => $lib, # always do at least this |
| 507 |
ccflags => "-I. $Werror", |
| 508 |
debug => 0, |
| 509 |
function => qq{ |
| 510 |
struct stat buf; |
| 511 |
int rc; |
| 512 |
rc = lstat("$link", &buf); |
| 513 |
if ((buf.st_mode & S_IFMT) == S_IFLNK) |
| 514 |
return 0; |
| 515 |
return 1; |
| 516 |
(void)rc; |
| 517 |
}, |
| 518 |
)) { |
| 519 |
push @$defs, '#define HAVE_SYMLINK 1'; |
| 520 |
print "found\n"; |
| 521 |
} |
| 522 |
else { |
| 523 |
push @$defs, '#undef HAVE_SYMLINK'; |
| 524 |
print "none\n"; |
| 525 |
} |
| 526 |
unlink $conf, $link; |
| 527 |
} |
| 528 |
|
| 529 |
sub try_sa_len { |
| 530 |
my ($check, $long, $defs, $platform) = @_; |
| 531 |
my $msg = 'Checking for sa_len member'; |
| 532 |
my $len = length $msg; |
| 533 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 534 |
my $more = $$long - $len; |
| 535 |
print $msg, ' ..', '.'x$more, ' '; |
| 536 |
if ($platform ne 'unix') { |
| 537 |
push @$defs, '#undef HAVE_SA_LEN'; |
| 538 |
print "skip\n"; |
| 539 |
return; |
| 540 |
} |
| 541 |
my $conf = gen_confh($defs); |
| 542 |
if ( check_lib( |
| 543 |
header => $conf, |
| 544 |
lib => 'c', # always do at least this |
| 545 |
ccflags => '-I.', |
| 546 |
debug => 0, |
| 547 |
function => q{ |
| 548 |
struct ifreq ifr; |
| 549 |
unsigned char *r; |
| 550 |
r = (unsigned char*)&ifr.ifr_addr.sa_len; |
| 551 |
return 0; |
| 552 |
(void)r; |
| 553 |
}, |
| 554 |
)) { |
| 555 |
push @$defs, '#define HAVE_SA_LEN 1'; |
| 556 |
print "found\n"; |
| 557 |
} |
| 558 |
else { |
| 559 |
push @$defs, '#undef HAVE_SA_LEN'; |
| 560 |
print "none\n"; |
| 561 |
} |
| 562 |
unlink $conf; |
| 563 |
} |
| 564 |
|
| 565 |
sub try_srwlock { |
| 566 |
my ($check, $long, $defs, $platform) = @_; |
| 567 |
my $msg = 'Checking for SRWLocks'; |
| 568 |
my $len = length $msg; |
| 569 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 570 |
my $more = $$long - $len; |
| 571 |
print $msg, ' ..', '.'x$more, ' '; |
| 572 |
if ($platform ne 'alien' && $platform ne 'native') { |
| 573 |
push @$defs, '#undef HAVE_SRWLOCK'; |
| 574 |
print "skip\n"; |
| 575 |
return; |
| 576 |
} |
| 577 |
my ($conf, $fh) = gen_confh_fh($defs); |
| 578 |
print $fh join("\n", map {s/^\s+//; $_} split(/\n/, qq{ |
| 579 |
typedef SRWLOCK uu_lock_t; |
| 580 |
typedef struct { uu_lock_t LOCK; } smem_t; |
| 581 |
static smem_t smem; |
| 582 |
#define UMTX_init InitializeSRWLock(&smem.LOCK) |
| 583 |
#define UMTX_lock AcquireSRWLockExclusive(&smem.LOCK) |
| 584 |
#define UMTX_unlock ReleaseSRWLockExclusive(&smem.LOCK) |
| 585 |
})); |
| 586 |
close $fh; |
| 587 |
if ( check_lib( |
| 588 |
header => $conf, |
| 589 |
lib => 'kernel32', # always do at least this |
| 590 |
ccflags => '-I.', |
| 591 |
debug => 0, |
| 592 |
function => q{ |
| 593 |
UMTX_init; |
| 594 |
UMTX_lock; |
| 595 |
UMTX_unlock; |
| 596 |
return 0; |
| 597 |
}, |
| 598 |
)) { |
| 599 |
push @$defs, '#define HAVE_SRWLOCK 1'; |
| 600 |
print "found\n"; |
| 601 |
} |
| 602 |
else { |
| 603 |
push @$defs, '#undef HAVE_SRWLOCK'; |
| 604 |
print "none\n"; |
| 605 |
} |
| 606 |
unlink $conf; |
| 607 |
} |
| 608 |
|
| 609 |
sub try_platform { |
| 610 |
my ($check, $long, $defs) = @_; |
| 611 |
my $msg = 'Checking platform'; |
| 612 |
my $len = length $msg; |
| 613 |
if ($check) { $$long = $len if $len > $$long } |
| 614 |
my $more = $$long - $len; |
| 615 |
print $msg, ' ..', '.'x$more, ' ' |
| 616 |
unless $check; |
| 617 |
|
| 618 |
my $rv; |
| 619 |
my $iscygwin = $^O eq 'cygwin'; |
| 620 |
my $iswin32 = $^O eq 'MSWin32'; |
| 621 |
my $isnmake = $Config{make} eq 'nmake'; |
| 622 |
|
| 623 |
{ |
| 624 |
if ( $iswin32 and $isnmake ) { |
| 625 |
$WIN32 = 1; |
| 626 |
$rv = 'native'; |
| 627 |
last if $check; |
| 628 |
push @$defs, '#define USE_WIN32_NATIVE 1'; |
| 629 |
push @$defs, '#undef USE_WIN32_ALIEN'; |
| 630 |
push @$defs, '#undef USE_WIN32_CYGWIN'; |
| 631 |
} |
| 632 |
elsif ( $iscygwin ) { |
| 633 |
$WIN32 = 0; |
| 634 |
$rv = 'cygwin'; |
| 635 |
last if $check; |
| 636 |
push @$defs, '#undef USE_WIN32_NATIVE'; |
| 637 |
push @$defs, '#undef USE_WIN32_ALIEN'; |
| 638 |
push @$defs, '#define USE_WIN32_CYGWIN 1'; |
| 639 |
} |
| 640 |
elsif ( $iswin32 ) { |
| 641 |
$rv = 'alien'; # strawberry |
| 642 |
last if $check; |
| 643 |
push @$defs, '#undef USE_WIN32_NATIVE'; |
| 644 |
push @$defs, '#define USE_WIN32_ALIEN 1'; |
| 645 |
push @$defs, '#undef USE_WIN32_CYGWIN'; |
| 646 |
} |
| 647 |
else { |
| 648 |
$WIN32 = 0; |
| 649 |
$rv = 'unix'; |
| 650 |
last if $check; |
| 651 |
push @$defs, '#undef USE_WIN32_NATIVE'; |
| 652 |
push @$defs, '#undef USE_WIN32_ALIEN'; |
| 653 |
push @$defs, '#undef USE_WIN32_CYGWIN'; |
| 654 |
} |
| 655 |
} |
| 656 |
print $rv, "\n" unless $check; |
| 657 |
return $rv; |
| 658 |
} |
| 659 |
|
| 660 |
sub try_threads { |
| 661 |
my ($check, $long, $defs, $platform) = @_; |
| 662 |
my $msg = 'Checking for thread storage'; |
| 663 |
my $len = length $msg; |
| 664 |
if ($check) { $$long = $len if $len > $$long; return; } |
| 665 |
my $more = $$long - $len; |
| 666 |
# can we skip this if not -Duseithreads ? |
| 667 |
|
| 668 |
my ($conf1, $fh1) = gen_confh_fh($defs); |
| 669 |
print $fh1 q{ |
| 670 |
int dec(void) { |
| 671 |
static __thread int foo = 3; |
| 672 |
return --foo; |
| 673 |
} |
| 674 |
}; |
| 675 |
close $fh1; |
| 676 |
|
| 677 |
my ($conf2, $fh2) = gen_confh_fh($defs); |
| 678 |
print $fh2 q{ |
| 679 |
int dec(void) { |
| 680 |
static __declspec(thread) int foo = 3; |
| 681 |
return --foo; |
| 682 |
} |
| 683 |
}; |
| 684 |
close $fh2; |
| 685 |
|
| 686 |
my $Werror = $WIN32 ? '-WX' : '-Werror'; |
| 687 |
my $lib = $WIN32 ? 'ucrt' : 'c'; |
| 688 |
|
| 689 |
if ( check_lib( |
| 690 |
header => $conf1, |
| 691 |
lib => $lib, # always do at least this |
| 692 |
ccflags => "-I. $Werror", |
| 693 |
debug => 0, |
| 694 |
function => q{ |
| 695 |
int rv; |
| 696 |
rv = dec(); |
| 697 |
rv = dec(); |
| 698 |
rv = dec(); |
| 699 |
return rv; |
| 700 |
}, |
| 701 |
)) { |
| 702 |
push @$defs, '#define TLS __thread'; |
| 703 |
print $msg, ' ..', '.'x$more, ' __thread'; |
| 704 |
} |
| 705 |
elsif ( check_lib( |
| 706 |
header => $conf2, |
| 707 |
lib => $lib, # always do at least this |
| 708 |
ccflags => "-I. $Werror", |
| 709 |
debug => 0, |
| 710 |
function => q{ |
| 711 |
int rv; |
| 712 |
rv = dec(); |
| 713 |
rv = dec(); |
| 714 |
rv = dec(); |
| 715 |
return rv; |
| 716 |
}, |
| 717 |
)) { |
| 718 |
push @$defs, '#define TLS __declspec(thread)'; |
| 719 |
print $msg, ' ..', '.'x$more, ' __declspec(thread)'; |
| 720 |
} |
| 721 |
else { |
| 722 |
push @$defs, '#undef TLS'; |
| 723 |
print $msg, ' ..', '.'x$more, ' none'; |
| 724 |
} |
| 725 |
unlink $conf1, $conf2; |
| 726 |
} |
| 727 |
|
| 728 |
sub write_conf { |
| 729 |
my ($defines, $outfile) = @_; |
| 730 |
|
| 731 |
open my $fh, '>', $outfile |
| 732 |
or die 'open: ', $outfile, ": $!"; |
| 733 |
|
| 734 |
print $fh "#ifndef ULIB__EUMM_H\n"; |
| 735 |
print $fh "#define ULIB__EUMM_H\n"; |
| 736 |
|
| 737 |
print $fh "$_\n" |
| 738 |
for @$defines; |
| 739 |
|
| 740 |
print $fh "#endif\n"; |
| 741 |
} |