html.mk

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

commit 6505da8c00d8edba1e89dbf3e29ebb5e32cba632
parent 8c7d166c4f6ac21b55a2ef8eab142c8d658526ed
Author: Kyle Milz <krwmilz@gmail.com>
Date:   Thu, 22 Jul 2021 04:16:56 +0000

mk: use CPPFLAGS instead of INCLUDE

It was confusing to use INCLUDE instead of the idiomatic CPPFLAGS which is
more flexible and a well known variable.

Add a test for this using a two directory site where both dirs include
a common file.

Diffstat:
Mbsd.html.mk | 10++++------
At/include_subdir.t | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 6 deletions(-)

diff --git a/bsd.html.mk b/bsd.html.mk @@ -5,12 +5,9 @@ # # These variables shoud not be modified here but set in Makefiles instead. -# - TOP: Directory containing the `mk' directory # - SRCS: List of source files to transform into HTML documents # -TOP ?= . SRCS ?= index.in -INCLUDE = ${.CURDIR}/${TOP}/include # Clear existing suffixes. @@ -32,6 +29,7 @@ all: _SUBDIRUSE # # Use the C preprocessor to turn input source files into HTML. +# Respects the CPPFLAGS variable. # # -I: global files and targets generated in object directory can be included # -P: the files being preprocessed are not C @@ -39,12 +37,12 @@ all: _SUBDIRUSE # .SUFFIXES: .in .html .in.html: - cpp -I${INCLUDE} -I${.OBJDIR} -P -o ${.OBJDIR}/$@ $< + cpp ${CPPFLAGS} -I${.OBJDIR} -P -o ${.OBJDIR}/$@ $< # # Use the C preprocessor to generate dependency files from input source -# files. +# files. Respects the CPPFLAGS variable. # # -I: XXX # -M: generate Makefile dependency target instead of preprocessing @@ -54,7 +52,7 @@ all: _SUBDIRUSE # .SUFFIXES: .depend .in.depend: - cpp -I${INCLUDE} -M -MG -MF $@ -MT ${@:.depend=.html} $< + cpp ${CPPFLAGS} -M -MG -MF $@ -MT ${@:.depend=.html} $< # Create the final `.depend' file from all of the individual dependency files. .if !empty(SRCS) diff --git a/t/include_subdir.t b/t/include_subdir.t @@ -0,0 +1,54 @@ +# +# Create a one directory site in tree with common include dir. +# +use Modern::Perl; +use Test::Cmd; +use Test::More tests => 6; + + +my $cmd = Test::Cmd->new( prog => '/usr/bin/make', workdir => '' ); +my $html_mk = $cmd->here . "/bsd.html.mk"; + +$cmd->subdir( 'include', 'dir', ); + +# Makefile +$cmd->write( 'Makefile', <<EOF ); +SUBDIR += dir +CPPFLAGS= -Iinclude + +.include "$html_mk" +EOF + +# index.in +$cmd->write( 'index.in', <<EOF ); +#include "head.html" +this is the root file' +EOF + +# include/head.html +$cmd->write( [ 'include', 'head.html' ], 'this is the head file' ); + +# dir/index.in +$cmd->write( ['dir', 'index.in' ], <<EOF ); +#include "head.html" +'this is the dir file' +EOF + +# dir/Makefile +$cmd->write( ['dir', 'Makefile' ], <<EOF ); +CPPFLAGS= -I../include + +.include "$html_mk" +EOF + +$cmd->run( args => "depend", chdir => $cmd->curdir ); + +like( $cmd->stdout, qr{.*}, 'make depend stdout' ); +is( $cmd->stderr, "", 'make depend stderr' ); +is( $? >> 8, 0, 'make depend exit status' ); + +$cmd->run( chdir => $cmd->curdir ); + +like( $cmd->stdout, qr{.*}, 'make stdout' ); +is( $cmd->stderr, "", 'make stderr' ); +is( $? >> 8, 0, 'make exit status' );