This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add a space after -o to keep Darwin's g++ happy, in t/porting/extrefs.t
[perl5.git] / t / porting / extrefs.t
CommitLineData
68fd3ca5
TC
1#!./perl -w
2
3# What does this test?
4# Test that changes to perl header files don't cause external
5# references by simplying #including them. This breaks library probe
6# code on CPAN, and can break cflags.SH.
7#
8# Why do we test this?
9# See https://rt.perl.org/rt3/Ticket/Display.html?id=116989
10#
11# It's broken - how do I fix it?
12# You added an initializer or static function to a header file that
13# references some symbol you didn't define, you need to remove it.
14
68fd3ca5
TC
15BEGIN {
16 require "./test.pl";
17 unshift @INC, ".." if -f "../TestInit.pm";
18}
19
20use TestInit qw(T A); # T is chdir to the top level, A makes paths absolute
d8846a96
TC
21use strict;
22use warnings;
68fd3ca5
TC
23use Config;
24use File::Path 'rmtree';
25use Cwd;
26
68fd3ca5
TC
27plan(tests => 1);
28
5069e7f0
NC
29my $VERBOSE = grep {$_ eq '-v'} @ARGV;
30
68fd3ca5
TC
31ok(try_compile_and_link(<<'CODE'));
32#include "EXTERN.h"
33#include "perl.h"
34#include "XSUB.h"
35
36int main(int argc, char **argv) {
37 return 0;
38}
39CODE
40
41
42# from Time::HiRes's Makefile.PL with minor modifications
43sub try_compile_and_link {
44 my ($c, %args) = @_;
45
11dc1f92 46 my $ld_exeext = ($^O eq 'cygwin' || $^O eq 'MSWin32' ||
68fd3ca5
TC
47 $^O eq 'os2' && $Config{ldflags} =~ /-Zexe\b/) ? '.exe' :
48 (($^O eq 'vos') ? $Config{exe_ext} : '');
68fd3ca5
TC
49
50 my ($ok) = 0;
51 my $tempdir = tempfile();
52 my $cwd = getcwd();
53 mkdir $tempdir;
54 chdir $tempdir;
55 my ($tmp) = "temp";
68fd3ca5
TC
56
57 my $obj_ext = $Config{obj_ext} || ".o";
68fd3ca5 58
d8846a96
TC
59 if (open(my $tmpc, ">$tmp.c")) {
60 print $tmpc $c;
61 unless (close($tmpc)) {
62 chdir($cwd);
63 rmtree($tempdir);
64 warn "Failing closing code file: $!\n" if $VERBOSE;
65 return 0;
68fd3ca5
TC
66 }
67
d8846a96 68 my $COREincdir = File::Spec->catdir(File::Spec->updir);
68fd3ca5
TC
69
70 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir"
71 . ' -DPERL_NO_INLINE_FUNCTIONS';
72
11dc1f92
TC
73 if ($^O eq "MSWin32") {
74 $ccflags .= " -I../win32 -I../win32/include";
75 }
76
77 my $null = File::Spec->devnull;
78
79 my $errornull = $VERBOSE ? '' : ">$null 2>$null";
80
128e8abd
NC
81 # Darwin g++ 4.2.1 is fussy and demands a space.
82 # FreeBSD g++ 4.2.1 does not.
83 # We do not know the reaction of either to the presence of brown M&Ms.
84 my $out_opt = "-o ";
11dc1f92
TC
85 if ($^O eq "MSWin32" && $Config{cc} =~ /\bcl\b/i) {
86 $out_opt = "/Fe";
87 }
88
89 my $tmp_exe = "$tmp$ld_exeext";
d8846a96 90
11dc1f92 91 my $cccmd = "$Config{'cc'} $out_opt$tmp_exe $ccflags $tmp.c $errornull";
d8846a96 92
68fd3ca5
TC
93 if ($^O eq 'VMS') {
94 $cccmd = "$Config{'cc'} /include=($COREincdir) $tmp.c";
95 }
96
68fd3ca5 97 if ($^O eq 'VMS') {
d8846a96
TC
98 open( my $cmdfile, ">$tmp.com" );
99 print $cmdfile "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
100 print $cmdfile "\$ $cccmd\n";
101 print $cmdfile "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
102 close $cmdfile;
68fd3ca5
TC
103 system("\@ $tmp.com");
104 $ok = $?==0;
105 chdir($cwd);
106 rmtree($tempdir);
68fd3ca5
TC
107 }
108 else
109 {
68fd3ca5
TC
110 printf "cccmd = $cccmd\n" if $VERBOSE;
111 my $res = system($cccmd);
112 $ok = defined($res) && $res == 0 && -s $tmp_exe && -x _;
113
68fd3ca5
TC
114 chdir($cwd);
115 rmtree($tempdir);
68fd3ca5
TC
116 }
117 }
118
119 return $ok;
120}