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.
9 # See https://github.com/Perl/perl5/issues/12824
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.
17 unshift @INC, ".." if -f "../TestInit.pm";
20 use TestInit qw(T A); # T is chdir to the top level, A makes paths absolute
24 use File::Path 'rmtree';
26 use IPC::Cmd qw(can_run);
28 if ($Config{'usecrosscompile'} && !can_run($Config{'cc'})) {
29 skip_all("compiler not available (cross-compiling)");
34 my $VERBOSE = grep {$_ eq '-v'} @ARGV;
36 ok(try_compile_and_link(<<'CODE'));
41 int main(int argc, char **argv) {
47 # from Time::HiRes's Makefile.PL with minor modifications
48 sub try_compile_and_link {
51 my $ld_exeext = ($^O eq 'cygwin' || $^O eq 'MSWin32' ||
52 $^O eq 'os2' && $Config{ldflags} =~ /-Zexe\b/) ? '.exe' :
53 (($^O eq 'vos') ? $Config{exe_ext} : '');
56 my $tempdir = tempfile();
62 my $obj_ext = $Config{obj_ext} || ".o";
64 if (open(my $tmpc, ">$tmp.c")) {
66 unless (close($tmpc)) {
69 warn "Failing closing code file: $!\n" if $VERBOSE;
74 File::Spec->catdir(File::Spec->updir, File::Spec->updir);
76 my $ccflags = $Config{'ccflags'} . ' ' . "-I$COREincdir"
77 . ' -DPERL_NO_INLINE_FUNCTIONS';
79 if ($^O eq "MSWin32") {
80 $ccflags .= " -I../../win32 -I../../win32/include";
85 # Include libs to be sure of linking against bufferoverflowU.lib for
86 # the SDK2003 compiler on Windows. See win32/Makefile for more details.
87 if ($^O eq "MSWin32" && $Config{cc} =~ /\bcl\b/i) {
88 $libs = " /link $Config{'libs'}";
91 my $null = File::Spec->devnull;
93 my $errornull = $VERBOSE ? '' : ">$null 2>$null";
95 # Darwin g++ 4.2.1 is fussy and demands a space.
96 # FreeBSD g++ 4.2.1 does not.
97 # We do not know the reaction of either to the presence of brown M&Ms.
99 if ($^O eq "MSWin32" && $Config{cc} =~ /\bcl\b/i) {
103 my $tmp_exe = "$tmp$ld_exeext";
105 my $cccmd = "$Config{'cc'} $out_opt$tmp_exe $ccflags $tmp.c $libs $errornull";
108 $cccmd = "$Config{'cc'} /include=($COREincdir) $tmp.c";
112 open( my $cmdfile, ">$tmp.com" );
113 print $cmdfile "\$ SET MESSAGE/NOFACILITY/NOSEVERITY/NOIDENT/NOTEXT\n";
114 print $cmdfile "\$ $cccmd\n";
115 print $cmdfile "\$ IF \$SEVERITY .NE. 1 THEN EXIT 44\n"; # escalate
117 system("\@ $tmp.com");
124 printf "cccmd = $cccmd\n" if $VERBOSE;
125 my $res = system($cccmd);
126 $ok = defined($res) && $res == 0 && -s $tmp_exe && -x _;