html.mk

static html creation framework using make(1) and cpp(1)
Log | Files | Refs | README | LICENSE

commit 8601b7c12cbd977d46657bda6526d6e6b0b3b070
parent 818a835deceb519cf3571aba7c709456f04e92e0
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Sat, 14 Aug 2021 21:30:13 +0000

mk: do not preprocess comments

Stop the preprocessor from removing C style comments from included files.
Add a test for this too.

Diffstat:
Mbsd.html.mk | 3++-
At/include_comments.t | 41+++++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/bsd.html.mk b/bsd.html.mk @@ -24,12 +24,13 @@ all: ${SRCS:S/.in$/.html/} _SUBDIRUSE # Respects the CPPFLAGS variable. # # -I: global files and targets generated in object directory can be included +# -C: preserve comments # -P: the files being preprocessed are not C # -o: the final HTML files are written in the object directory # .SUFFIXES: .in .html .in.html: - cpp ${CPPFLAGS} -I${.OBJDIR} -P -o ${.OBJDIR}/$@ $< + cpp ${CPPFLAGS} -I${.OBJDIR} -C -P -o ${.OBJDIR}/$@ $< # # Main dependency target. Create `.d' files containing deps from `.in' files. diff --git a/t/include_comments.t b/t/include_comments.t @@ -0,0 +1,41 @@ +# +# Make sure comments are not stripped from preprocessed files. +# +use Modern::Perl; +use Test::Cmd; +use Test::File::Contents; +use Test::More tests => 5; + + +my $cmd = Test::Cmd->new( prog => '/usr/bin/make', workdir => '' ); +my $html_mk = $cmd->here . "/bsd.html.mk"; + +$cmd->write( 'Makefile', <<EOF ); +.include "$html_mk" +EOF +$cmd->write( 'index.in', '#include "comments.c"' ); +$cmd->write( 'comments.c', <<EOF ); +/* single line comment */ +-- +/* + * multi line comment + */ +-- +// C++ style comment +EOF + +$cmd->run( args => 'depend', chdir => $cmd->curdir ); +is( $cmd->stderr, '', 'make depend stderr' ); +is( $? >> 8, 0, 'make depend exit status' ); + +$cmd->run( chdir => $cmd->curdir ); +is( $cmd->stderr, '', 'make stderr' ); +is( $? >> 8, 0, 'make exit status' ); + +my $contents; +$cmd->read( \$contents, 'index.html' ); +$contents =~ s/^\n//mg; +$cmd->write( 'index.html', $contents ); + +files_eq_or_diff( $cmd->workdir . '/comments.c', + $cmd->workdir . '/index.html' );