commit d666891675d13f2130f3dd295ac8e0c9d667d157
parent d6151abb125085285a72a77966bbb68e40484bf7
Author: Kyle Milz <krwmilz@gmail.com>
Date: Thu, 29 Jul 2021 08:36:39 +0000
mk: remove SRCS and CP_OBJ error checking
The hand rolled error checking for SRCS files existing and CP_OBJ files
existing was nice, but it was flawed and kind of complicated. The error
messages are worse now, but make returns non zero now.
I'm hoping there is a better way to improve the error messages.
Adjust tests to match.
Diffstat:
4 files changed, 38 insertions(+), 43 deletions(-)
diff --git a/bsd.html.mk b/bsd.html.mk
@@ -13,19 +13,11 @@ SRCS ?= index.in
# Clear existing suffixes.
.SUFFIXES:
-
-# Check SRCS array for nonexisting files.
-.for src in ${SRCS}
-. if !exists(${.CURDIR}/${src})
-all:
- @>&2 echo "html.mk: file '${src}' in SRCS array does not exist."
-.else
-all: ${src:.in=.html}
-. endif
-.endfor
-
-
-all: _SUBDIRUSE
+#
+# Files in the SRCS array must have '.in' suffix otherwise they will not be
+# built.
+#
+all: ${SRCS:S/.in$/.html/} _SUBDIRUSE
#
# Use the C preprocessor to turn input source files into HTML.
@@ -143,23 +135,18 @@ _created.gen:
# Plain file copy.
#
.for file in ${CP_OBJ}
-.if !exists(${.CURDIR}/${file})
-all:
- @>&2 echo "html.mk: file '${file}' in CP_OBJ array does not exist."
-.else
-
#
# We can get away with using the same file name here and make still being
# able to distinguish the files because we use absolute paths.
#
-${.OBJDIR}/${file}: ${.CURDIR}/${file}
- cp ${.CURDIR}/${file} $@
+${.OBJDIR}/${file}: ${.CURDIR}/${file}
+ cp $? $@
all: ${.OBJDIR}/${file}
-.endif
.endfor
+
#
# Helper targets for misc tasks.
#
diff --git a/t/cp_unhappy.t b/t/cp_unhappy.t
@@ -14,16 +14,30 @@ BSDSRCDIR = /tmp
BSDOBJDIR = destdir
EOF
+$cmd->write( 'Makefile', <<EOF );
+.include "site.mk"
+.include "$html_mk"
+EOF
+
+$cmd->subdir( 'destdir' );
+
+$cmd->run( args => 'obj', chdir => $cmd->curdir );
+like( $cmd->stdout, qr{obj -> destdir}, 'make obj stdout' );
+is( $cmd->stderr, '', 'make obj stderr' );
+is( $? >> 8, 0, 'make obj exit status' );
+
+
#
# 1) CP_OBJ nonexistent file.
#
-my $e = "html.mk: file 'does_not_exist' in CP_OBJ array does not exist.";
+my $e = "make: don't know how to make .*/does_not_exist";
$cmd->write( 'Makefile', <<EOF );
CP_OBJ = does_not_exist
SRCS =
+.include "site.mk"
.include "$html_mk"
EOF
@@ -31,7 +45,7 @@ $cmd->run( chdir => $cmd->curdir );
is( $cmd->stdout, '', 'make stdout' );
like( $cmd->stderr, qr{$e}, 'make stderr' );
-is( $? >> 8, 0, 'make exit status' );
+is( $? >> 8, 2, 'make exit status' );
#
# 2) CP_OBJ directory, obj exists
@@ -39,7 +53,7 @@ is( $? >> 8, 0, 'make exit status' );
my $o = "cp .*/cp_dir .*/obj/cp_dir";
$e = 'cp: .*/cp_dir is a directory \(not copied\)';
-$cmd->subdir( 'destdir', 'cp_dir' );
+$cmd->subdir( 'cp_dir' );
$cmd->write( 'Makefile', <<EOF );
CP_OBJ = cp_dir
SRCS =
@@ -48,11 +62,6 @@ SRCS =
.include "$html_mk"
EOF
-$cmd->run( args => 'obj', chdir => $cmd->curdir );
-like( $cmd->stdout, qr{obj -> destdir}, 'make obj stdout' );
-is( $cmd->stderr, '', 'make obj stderr' );
-is( $? >> 8, 0, 'make obj exit status' );
-
$cmd->run( chdir => $cmd->curdir );
like( $cmd->stdout, qr{$o}, 'make stdout' );
like( $cmd->stderr, qr{$e}, 'make stderr' );
diff --git a/t/srcs_missing.t b/t/srcs_missing.t
@@ -1,5 +1,5 @@
#
-# The default SRCS file is missing.
+# There is an error when the default SRCS file is missing.
#
use Modern::Perl;
use Test::Cmd;
@@ -13,9 +13,9 @@ $cmd->write( 'Makefile', <<EOF );
.include "$html_mk"
EOF
-my $e = "html.mk: file 'index.in' in SRCS array does not exist.";
+my $e = "make: don't know how to make index.in";
$cmd->run( chdir => $cmd->curdir );
is( $cmd->stdout, '', 'make stdout' );
like( $cmd->stderr, qr{$e}, 'make stderr' );
-is( $? >> 8, 0, 'make exit status' );
+is( $? >> 8, 2, 'make exit status' );
diff --git a/t/srcs_suffix.t b/t/srcs_suffix.t
@@ -1,6 +1,6 @@
#
# No and strange file suffixes in SRCS array.
-# These are different cases because make behaviour is dependant on suffixes.
+# These are different cases because make behaviour is dependent on suffixes.
#
use Modern::Perl;
use Test::Cmd;
@@ -10,7 +10,7 @@ my $cmd = Test::Cmd->new( prog => '/usr/bin/make', workdir => '' );
my $html_mk = $cmd->here . "/bsd.html.mk";
#
-# 1) File with no suffix in SRCS array and does not exist
+# 1) File with no suffix in SRCS array and does not exist errors
#
$cmd->write( 'Makefile', <<EOF );
SRCS = no_file_suffix
@@ -19,16 +19,15 @@ SRCS = no_file_suffix
EOF
# This is an ok error message.
-my $e = "html.mk: file 'no_file_suffix' in SRCS array does not exist.";
+my $e = "make: don't know how to make no_file_suffix";
$cmd->run( chdir => $cmd->curdir );
is( $cmd->stdout, '', 'make stdout' );
like( $cmd->stderr, qr{$e}, 'make stderr' );
-is( $? >> 8, 0, 'make exit status' );
+is( $? >> 8, 2, 'make exit status' );
#
-# 1a) File with no suffix in SRCS array but file exists.
-# XXX Strange behaviour... this should be an error with a message.
+# 1a) File with no suffix in SRCS array but file exists shows no error.
#
$cmd->write( 'no_file_suffix', '' );
@@ -37,8 +36,9 @@ is( $cmd->stdout, '', 'make stdout' );
is( $cmd->stderr, '', 'make stderr' );
is( $? >> 8, 0, 'make exit status' );
+
#
-# 2) File with bad suffix in SRCS array that does not exist.
+# 2) File with bad suffix in SRCS array that does not exist errors.
#
$cmd->write( 'Makefile', <<EOF );
SRCS = bad.sfx
@@ -46,16 +46,15 @@ SRCS = bad.sfx
.include "$html_mk"
EOF
-$e = "html.mk: file 'bad.sfx' in SRCS array does not exist.";
+$e = "make: don't know how to make bad.sfx";
$cmd->run( chdir => $cmd->curdir );
is( $cmd->stdout, '', 'make stdout' );
like( $cmd->stderr, qr{$e}, 'make stderr' );
-is( $? >> 8, 0, 'make exit status' );
+is( $? >> 8, 2, 'make exit status' );
#
-# 2b) File with bad suffix in SRCS array but file exists.
-# XXX Strange behaviour... this should be an error with a message.
+# 2b) File with bad suffix in SRCS array but file exists shows no error.
#
$cmd->write( 'bad.sfx', '' );