html.mk

static html creation framework using make(1) and cpp(1)
git clone git://0x30.net/html.mk
Log | Files | Refs | README | LICENSE

bsd.html.mk (4117B)


      1 #
      2 # html.mk
      3 # This file must be included by all Makefiles.
      4 #
      5 
      6 # List of source files to transform into HTML documents
      7 SRCS ?= index.in
      8 
      9 #
     10 # Files in the SRCS array must have '.in' suffix otherwise they will not be
     11 # built.
     12 #
     13 all:	${SRCS:S/.in$/.html/} _SUBDIRUSE
     14 
     15 #
     16 # Use the C preprocessor to turn input source files into HTML.
     17 # Respects the CPPFLAGS variable.
     18 #
     19 # -I: global files and targets generated in object directory can be included
     20 # -C: preserve comments
     21 # -P: the files being preprocessed are not C
     22 # -o: the final HTML files are written in the object directory
     23 #
     24 .SUFFIXES: .in .html
     25 .in.html:
     26 	cpp ${CPPFLAGS} -I${.OBJDIR} -C -P -o ${.OBJDIR}/$@ $<
     27 
     28 #
     29 # Main dependency target. Create `.d' files containing deps from `.in' files.
     30 #
     31 depend: ${SRCS:.in=.d} _SUBDIRUSE
     32 
     33 #
     34 # Use the C preprocessor to generate dependency files from input source
     35 # files. Respect the CPPFLAGS variable.
     36 #
     37 # -M: generate Makefile dependency target instead of preprocessing
     38 # -MG: assume missing files are generated files
     39 # -MF: write dependency list to .d file where we will include it
     40 # -MT: override target name
     41 #
     42 .SUFFIXES: .d
     43 .in.d:
     44 	cpp ${CPPFLAGS} -M -MG -MF $@ -MT ${@:.d=.html} $<
     45 
     46 # Silently include any dependency files found.
     47 .for s in ${SRCS}
     48   -include ${s:.in=.d}
     49 .endfor
     50 
     51 
     52 #
     53 # Generate HTML fragments that contain <a><img> links to images.
     54 # 
     55 .SUFFIXES: .img_html
     56 .SUFFIXES: .jpeg
     57 .SUFFIXES: .jpg
     58 .SUFFIXES: .png
     59 .jpeg.img_html .jpg.img_html .png.img_html:
     60 	cp $? ${.OBJDIR}/${<F:R}.cp.${<F:E}
     61 
     62 	@# Generate thumbnail of image with `.thumb' appended to file name.
     63 	gm convert -resize 800x $? ${.OBJDIR}/${<F:R}.thumb.${<F:E}
     64 
     65 	@#
     66 	@# Create HTML fragment that uses the thumbnail as a base image
     67 	@# that is a link to the full size (copied) image, like this:
     68 	@#
     69 	@# <a href="pic.cp.jpg"><img loading='lazy' src="pic.thumb.jpg"
     70 	@#
     71 	@# NOTE: The <img> tag is not closed! You must close it, maybe with:
     72 	@# 	alt="description of image for blind people" /></a>
     73 	@#
     74 	echo "\t<a href='${<F:R}.cp.${<F:E}'>" > $@
     75 	echo "\t\t<img loading='lazy' src='${<F:R}.thumb.${<F:E}' " >> $@
     76 
     77 
     78 #
     79 # Generate HTML fragments that link to videos using the <video> tag.
     80 #
     81 .SUFFIXES: .mp4 .mp4_html
     82 .SUFFIXES: .mov .mov_html
     83 .mp4.mp4_html .mov.mov_html:
     84 	@# Copy video from source to object directory.
     85 	cp $? ${.OBJDIR}/
     86 
     87 	@# Generate html code snippet using HTML5 video tag to show video.
     88 	echo "\t<video controls>" > $@
     89 	echo "\t\t<source src='${<F}' type='video/mp4'>" >> $@
     90 	echo "\t\tYour browser does not support the video tag." >> $@
     91 	echo "\t</video>" >> $@
     92 
     93 
     94 #
     95 # Transliterate the contents of various file types when they coincidentally
     96 # (not purposefully) contain HTML markup or C preprocessor directives.
     97 #
     98 # - turn '<' and '>' into HTML named character references so they are
     99 #   displayed and not parsed
    100 # - turn '\' line continuation into HTML named character reference so they
    101 #   do not get removed by the HTML parser
    102 # - turn '#' into HTML named character reference so the preprocessor doesn't
    103 #   try and operate on it.
    104 #
    105 # Note dependency file names must be unique for this inference because all
    106 # target files will have .xliterate suffix.
    107 #
    108 .SUFFIXES: .c .html .in .sh .txt
    109 .SUFFIXES: .xliterate
    110 .c.xliterate .html.xliterate .in.xliterate .sh.xliterate .txt.xliterate:
    111 	sed \
    112 	-e "s/</\&lt;/g" \
    113 	-e "s/>/\&gt;/g" \
    114 	-e "s/\\\/\&bsol;/" \
    115 	-e "s/#/\&num;/g" \
    116 	$< > $@
    117 
    118 
    119 #
    120 # Make an HTML time attribute for direct inclusion in HTML. Populate the 
    121 # "datetime" property with an appropriatly formatted date.
    122 # Use full names for day of week and month instead of default abbreviated ones.
    123 #
    124 FMT="+%A %B %e %H:%M:%S %Z %Y"
    125 _updated.html: ${SRCS}
    126 	echo "<time datetime='`date +%Y-%m-%d`'>`date ${FMT}`</time>" > $@
    127 
    128 _created.html:
    129 	echo "<time datetime='`date +%Y-%m-%d`'>`date ${FMT}`</time>" > $@
    130 
    131 #
    132 # Plain file copy.
    133 #
    134 .for file in ${CP_OBJ}
    135 #
    136 # We can get away with using the same file name here and make still being
    137 # able to distinguish the files because we use absolute paths.
    138 #
    139 ${.OBJDIR}/${file}: ${.CURDIR}/${file} 
    140 	cp $? $@
    141 
    142 all: ${.OBJDIR}/${file}
    143 
    144 .endfor
    145 
    146 
    147 .include <bsd.obj.mk>
    148 .include <bsd.subdir.mk>