Commit | Line | Data |
---|---|---|
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 |
15 | BEGIN { |
16 | require "./test.pl"; | |
17 | unshift @INC, ".." if -f "../TestInit.pm"; | |
18 | } | |
19 | ||
20 | use TestInit qw(T A); # T is chdir to the top level, A makes paths absolute | |
d8846a96 TC |
21 | use strict; |
22 | use warnings; | |
68fd3ca5 TC |
23 | use Config; |
24 | use File::Path 'rmtree'; | |
25 | use Cwd; | |
26 | ||
68fd3ca5 TC |
27 | plan(tests => 1); |
28 | ||
5069e7f0 NC |
29 | my $VERBOSE = grep {$_ eq '-v'} @ARGV; |
30 | ||
68fd3ca5 TC |
31 | ok(try_compile_and_link(<<'CODE')); |
32 | #include "EXTERN.h" | |
33 | #include "perl.h" | |
34 | #include "XSUB.h" | |
35 | ||
36 | int main(int argc, char **argv) { | |
37 | return 0; | |
38 | } | |
39 | CODE | |
40 | ||
41 | ||
42 | # from Time::HiRes's Makefile.PL with minor modifications | |
43 | sub 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 | ||
24ec451b SH |
77 | my $libs = ''; |
78 | ||
79 | # Include libs to be sure of linking against bufferoverflowU.lib for | |
80 | # the SDK2003 compiler on Windows. See win32/Makefile for more details. | |
81 | if ($^O eq "MSWin32" && $Config{cc} =~ /\bcl\b/i) { | |
82 | $libs = " /link $Config{'libs'}"; | |
83 | } | |
84 | ||
11dc1f92 TC |
85 | my $null = File::Spec->devnull; |
86 | ||
87 | my $errornull = $VERBOSE ? '' : ">$null 2>$null"; | |
88 | ||
128e8abd NC |
89 | # Darwin g++ 4.2.1 is fussy and demands a space. |
90 | # FreeBSD g++ 4.2.1 does not. | |
91 | # We do not know the reaction of either to the presence of brown M&Ms. | |
92 | my $out_opt = "-o "; | |
11dc1f92 TC |
93 | if ($^O eq "MSWin32" && $Config{cc} =~ /\bcl\b/i) { |
94 | $out_opt = "/Fe"; | |
95 | } | |
96 | ||
97 | my $tmp_exe = "$tmp$ld_exeext"; | |
d8846a96 | 98 | |
24ec451b | 99 | my $cccmd = "$Config{'cc'} $out_opt$tmp_exe $ccflags $tmp.c $libs $errornull"; |
d8846a96 | 100 | |
68fd3ca5 TC |
101 | if ($^O eq 'VMS') { |
102 | $cccmd = "$Config{'cc'} /include=($COREincdir) $tmp.c"; | |
103 | } | |
104 | ||
68fd3ca5 | 105 | if ($^O eq 'VMS') { |
d8846a96 TC |
106 | open( my $cmdfile, ">$tmp.com" ); |
107 | print $cmdfile "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n"; | |
108 | print $cmdfile "\$ $cccmd\n"; | |
109 | print $cmdfile "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate | |
110 | close $cmdfile; | |
68fd3ca5 TC |
111 | system("\@ $tmp.com"); |
112 | $ok = $?==0; | |
113 | chdir($cwd); | |
114 | rmtree($tempdir); | |
68fd3ca5 TC |
115 | } |
116 | else | |
117 | { | |
68fd3ca5 TC |
118 | printf "cccmd = $cccmd\n" if $VERBOSE; |
119 | my $res = system($cccmd); | |
120 | $ok = defined($res) && $res == 0 && -s $tmp_exe && -x _; | |
121 | ||
68fd3ca5 TC |
122 | chdir($cwd); |
123 | rmtree($tempdir); | |
68fd3ca5 TC |
124 | } |
125 | } | |
126 | ||
127 | return $ok; | |
128 | } |