Skip to content

Commit

Permalink
Completed makefile modules
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 9, 2017
1 parent 3a635c6 commit 26415b7
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 154 deletions.
160 changes: 91 additions & 69 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
# Makefile for web site management
#
# Project: jqt
# Author: [email protected] <Joan Josep Ordinas Rosa>
# Author: <Joan Josep Ordinas Rosa> [email protected]
# Published: https://fadado.github.io/jqt/
########################################################################

# Debug tool
ifdef MAKE_RESTARTS
$(info Makefile restarted: $(MAKE_RESTARTS))
endif

# Make configuration
include make.d/prelude.make

Expand All @@ -20,20 +15,13 @@ Version := $(shell cat ../VERSION)
# Metadata directory
Metadata := .meta

# Do not build to clobber immediately
ifeq (clobber,$(MAKECMDGOALS))
ifeq (,$(wildcard $(Metadata)))
$(error Nothing to clobber)
endif
endif

# ======================================================================
-include $(Metadata)/globals.make
#
# Load global parameters. If `globals.make` not exists it is built when
# restarting with a rule defined in `config.make`.
#
# Variables:
# Exported variables:
# __globals__
# Assets
# Blocks
Expand Down Expand Up @@ -88,10 +76,11 @@ include make.d/pathnames.make
# PagesJSON
# Exported targets:
# $(Destination)
# all
# all paths starting at $(Destination) and $(Metadata)
# Additional dependencies defined:
# each HTML page from his metadata and directory
# each HTML node from his metadata and directory
# $(Destination)/.../page.html => $(Metadata)/pages/.../page.json
# $(Destination)/.../node/index.html => $(Metadata)/nodes/.../node.json
# ======================================================================

# ======================================================================
Expand All @@ -103,8 +92,11 @@ include make.d/front-matter.make
# Content
# Metadata
# Exported targets:
# JSON metadata files for pages and nodes
# JSON files grouping other metadata files
# $(Metadata)/pages/.../page.json
# $(Metadata)/nodes/.../node.json
# $(Metadata)/pages.json
# $(Metadata)/nodes.json
# $(Metadata)/sections.json
# ======================================================================

# ======================================================================
Expand All @@ -113,12 +105,14 @@ include make.d/front-matter.make
# Load rules for pages and nodes. If not exists is built when restarting with
# rule defined in `rules.make`.
#
# Variables:
# Exported variables:
# __html__
# Exported targets:
# rules for all HTML files
# ======================================================================

ifdef __html__

# Options for `jqt`.
JQTFLAGS = \
-5 \
Expand All @@ -128,6 +122,8 @@ JQTFLAGS = \
-msnippets:$(Metadata)/snippets.json \
--toc-depth=4 \

endif

# ======================================================================
include make.d/rules.make
#
Expand All @@ -140,34 +136,45 @@ include make.d/rules.make
# Metadata
# Exported targets:
# $(Metadata)/html.make
#
# all
# build
# clean
# clobber
# xbuild
# ======================================================================

########################################################################
# Rules
########################################################################

.PHONY: clean clobber build rebuild xbuild

# Delete generated publications
clean::
@rm -rf $(Destination)/*

# Delete all generated files and directories
clobber::
@rm -rf $(Destination) $(Metadata)

# Build again all documents
build: clean all
# ======================================================================
include make.d/tools.make
#
# Tools independent of any target.
#
# Parameters:
# vnudir
# Imported variables:
# Destination
# Exported targets:
# help
# valid
# lint
# ======================================================================

# ======================================================================
include make.d/styles.make
#
# Build CSS main stylesheet.
#
rebuild: clobber
@$(MAKE) -s all
# Imported variables:
# Destination
# Blocks
# Styles
# Exported targets:
# $(Destination)/styles.css
# all
# ======================================================================

# Build again all config.yaml dependents
xbuild:
@touch config.yaml
@$(MAKE) -s all
########################################################################
# Specific rules this web site
########################################################################

# Snippets
$(Metadata)/snippets.json: $(Content)/snippets.yaml \
Expand All @@ -178,39 +185,54 @@ $(Metadata)/snippets.json: $(Content)/snippets.yaml \
# Extra dependencies
$(Pages): $(Metadata)/snippets.json $(Blocks)/filters.jq

# Generate CSS stylesheet
all:: $(Destination)/styles.css

# Styles
$(Destination)/styles.css: \
$(Blocks)/*/*style.css \
$(Styles)/*.css \
$(Styles)/*.m \
$(Styles)/milligram/*.css \
#
# Generate man page for jqt
#

# CSS stylesheet
$(Destination)/styles.css: $(Styles)/page.css
# gpp for the man page (to be build without calling jqt!)
GPP_MD := gpp \
-U '<%' '>' '\B' '\B' '\W>' '<' '>' '$$' '' \
-M '<%' '>' '\B' '\B' '\W>' '<' '>' \
+sccc '&\n' '' '' \
+sccc '\\n' '' '' \
+sccc '<\#' '\#>\n' '' \
+siqi "'" "'" '\' \
+siQi '"' '"' '\' \
+ssss '<!--' '-->' '' \
+ssss '`' '`' '' \
+ssss '\n```' '\n```' '' \
+ssss '\n~~~' '\n~~~' '' \
#
ManPage := ../jqt.1.gz

# Man page: jqt(1)
$(ManPage): $(Content)/jqt.1.markdown
$(info ==> $@)
@jqt -P CSS-min -I$(Styles) < $< > $@

# Generate man page for jqt
include make.d/man.make
@$(GPP_MD) -I$(Content) < $< \
| pandoc --standalone --from markdown --to man \
| gzip > $@

# last all:: rule
all:: # copy Assets
@cp --verbose --recursive --update $(Assets)/* $(Destination) \
| sed "s/^.*-> ./==> /;s/.$$//"
@echo 1>&2 'Imprimatur.'
# Add prerequisites and recipes to common targets
all:: $(ManPage)

########################################################################
# Tools
########################################################################
clean::
@rm -f $(ManPage)

# Validate HTML 5
include make.d/vnu.make
clobber::
@rm -f $(ManPage)

# help and other targets
include make.d/tools.make
########################################################################
# Generate Help text
# Independent target: helps generating text for `jqt -h`
# Needs explicit call: `make /tmp/help`
#
/tmp/help: $(Content)/help.markdown
$(info ==> $@)
@jqt -P MarkDown -I$(Content) < $< \
| pandoc --from markdown --to plain - \
| sed '1,7b;/^$$/d;s/_\([A-Z]\+\)_/\1/g;/^[^A-Z]/s/^/ /' \
> $@

endif # __globals__

Expand Down
9 changes: 6 additions & 3 deletions docs/make.d/front-matter.make
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
# Content
# Metadata
# Exported targets:
# JSON metadata files for pages and nodes
# JSON files grouping other metadata files
# $(Metadata)/pages/.../page.json
# $(Metadata)/nodes/.../node.json
# $(Metadata)/pages.json
# $(Metadata)/nodes.json
# $(Metadata)/sections.json

########################################################################
# Collect metadata for pages
Expand Down Expand Up @@ -130,6 +133,6 @@ $(Metadata)/sections.json: $(Metadata)/pages.json

$(Metadata)/nodes.json: $(NodesJSON)
$(info ==> $@)
@[[ "$^" != "" ]] && jq --slurp '{ nodes: . }' $^ > $@ || true
@test -n "$^" && jq --slurp '{ nodes: . }' $^ > $@ || true

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
46 changes: 0 additions & 46 deletions docs/make.d/man.make

This file was deleted.

7 changes: 4 additions & 3 deletions docs/make.d/pathnames.make
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
# Pages
# PagesJSON
# Exported targets:
# all
# $(Destination)
# all paths at $(Destination) and $(Metadata)
# Additional dependencies defined:
# each HTML page from his metadata and directory
# each HTML node from his metadata and directory
# $(Destination)/.../page.html => $(Metadata)/pages/.../page.json
# $(Destination)/.../node/index.html => $(Metadata)/nodes/.../node.json

########################################################################
# Derived pathnames
Expand Down Expand Up @@ -97,7 +98,7 @@ $(Nodes): | $$(dir $$@)
$(PagesJSON): | $$(dir $$@)
$(NodesJSON): | $$(dir $$@)

# Add prerequisites to main target
# Add prerequisites to default goal
all:: $(Pages)

#########################################################################
Expand Down
12 changes: 12 additions & 0 deletions docs/make.d/prelude.make
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
# rest
# filename

# Debug tool
ifdef MAKE_RESTARTS
$(info Makefile restarted: $(MAKE_RESTARTS))
endif

########################################################################
# Prerequisites
########################################################################
Expand Down Expand Up @@ -40,6 +45,13 @@ $(error Target "clobber" must be alone)
endif
endif

# Do not build to clobber immediately
ifeq (clobber,$(MAKECMDGOALS))
ifeq (,$(wildcard $(Metadata)))
$(error Nothing to clobber)
endif
endif

########################################################################
# Make configuration
########################################################################
Expand Down
Loading

0 comments on commit 26415b7

Please sign in to comment.