make/tests/scripts/targets/POSIX
Paul Smith c01222c018 [SV 35711] Check for special targets earlier
GNU make must recognize some special targets as they are defined.
Because of the way targets are defined, we were not recognizing these
special targets until we were handling the NEXT statement.  However
that's too late for some special targets such as .POSIX etc. which can
change the behavior of make during parsing.

Check for special targets earlier, as soon as we've finished parsing
the target introduction line (before we've even parsed the recipe).

* NEWS: Mention the change.
* src/read.c (check_specials): New function to look for special
targets.  Move checks from eval() and record_files() to this new
function.
(eval): Call check_specials() after we've completed parsing the target
introduction line.  Move default goal detection to check_specials().
(record_files): Move handling of .POSIX, .SECONDEXPANSION, and
.ONESHELL to check_specials().
* tests/scripts/misc/bs-nl: Remove workaround for late .POSIX issue.
* tests/scripts/targets/POSIX: Add a comment.
2020-11-29 17:55:02 -05:00

58 lines
1.6 KiB
Perl

# -*-perl-*-
$description = "Test the behaviour of the .POSIX target.";
$details = "";
# Ensure turning on .POSIX enables the -e flag for the shell
# We can't assume the exit value of "false" because on different systems it's
# different.
my $script = 'false; true';
my $flags = '-ec';
my $out = `$sh_name $flags '$script' 2>&1`;
my $err = $? >> 8;
run_make_test(qq!
.POSIX:
all: ; \@$script
!,
'', "#MAKE#: *** [#MAKEFILE#:3: all] Error $err\n", 512);
# User settings must override .POSIX
# In the standard .POSIX must be the first thing in the makefile
# but we relax that rule in GNU make.
$flags = '-xc';
$out = `$sh_name $flags '$script' 2>&1`;
run_make_test(qq!
.SHELLFLAGS = $flags
.POSIX:
all: ; \@$script
!,
'', $out);
# Test the default value of various POSIX-specific variables
my %POSIX = (AR => 'ar', ARFLAGS => '-rv',
YACC => 'yacc', YFLAGS => '',
LEX => 'lex', LFLAGS => '',
LDFLAGS => '',
CC => 'c99', CFLAGS => '-O1',
FC => 'fort77', FFLAGS => '-O1',
SCCSFLAGS => '', SCCSGETFLAGS => '-s');
my $make = join('', map { "\t\@echo '$_=\$($_)'\n" } sort keys %POSIX);
my $r = join('', map { "$_=$POSIX{$_}\n"} sort keys %POSIX);
run_make_test(qq!
.POSIX:
all:
$make
!,
'', $r);
# Make sure that local settings take precedence
%ENV = (%ENV, map { $_ => "xx-$_" } keys %POSIX);
$r = join('', map { "$_=xx-$_\n"} sort keys %POSIX);
run_make_test(undef, '', $r);
# This tells the test driver that the perl test script executed properly.
1;