Skip to content

Commit

Permalink
Makefile subdivided in fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 4, 2017
1 parent 76fe0b9 commit f4b651e
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# cache
/docs/.yummy
# built site
/docs/_site
# man pages
jqt.1.gz
# other
Expand Down
67 changes: 13 additions & 54 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,49 +1,6 @@
# jqt documentation management

########################################################################
# Prerequisites
########################################################################

# We are using some of the newest GNU Make features... so require GNU
# Make version >= 3.82
version_test := $(filter 3.82,$(firstword $(sort $(MAKE_VERSION) 3.82)))
ifndef version_test
$(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed)
endif

########################################################################
# Configuration
########################################################################

# Disable builtins.
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables

# Warn when an undefined variable is referenced.
MAKEFLAGS += --warn-undefined-variables

# Make will not print the recipe used to remake files.
.SILENT:

# Eliminate use of the built-in implicit rules. Also clear out the
# default list of suffixes for suffix rules.
.SUFFIXES:

# Sets the default goal to be used if no targets were specified on the
# command line.
.PHONY: all
.DEFAULT_GOAL := all

# Default shell: if we require GNU Make, why not require Bash?
SHELL := /bin/bash

# The argument(s) passed to the shell are taken from the variable
# .SHELLFLAGS.
.SHELLFLAGS := -o errexit -o pipefail -o nounset -c

# Make will delete the target of a rule if it has changed and its recipe
# exits with a nonzero exit status.
.DELETE_ON_ERROR:
include make.d/config.make

########################################################################
# Variables
Expand Down Expand Up @@ -147,23 +104,23 @@ $(Destination)/styles.css: \
all: $(Targets) cp_assets

# Directories
$(Metadata) \
$(Destination):
$(info ==> $@)
mkdir $@ >/dev/null 2>&1 || true

# Metadata files
$(Metadata)/config.json: config.yaml \
| $(Metadata)
yaml2json <$< >$@
# Assets
cp_assets: | $(Destination)
cp --verbose --recursive --update $(Assets)/* $(Destination)

# META !!!!!!!!
include make.d/metadata.make

# Snippets
$(Metadata)/snippets.json: $(Content)/snippets.yaml \
| $(Metadata)
$(info ==> $@)
jqt -T <$< | yaml2json > $@

# Assets
cp_assets: | $(Destination)
cp --verbose --recursive --update $(Assets)/* $(Destination)

# HTML pages
define Target
$(Destination)/$(1).html: $(Content)/$(1).md $(Layouts)/$(2).html \
Expand All @@ -189,6 +146,7 @@ $(ManPage): $(Content)/jqt.1.markdown

# Help text
/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/^/ /' \
Expand Down Expand Up @@ -219,12 +177,13 @@ help:
| sed 's/:\+$$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=4

# Validation with vnu.jar
# Validation using vnu.jar
VNU := /usr/local/vnu/vnu.jar
valid: all
xmlwf $(Destination)/*.html
java -jar $(VNU) --errors-only --format gnu $(Destination)/*.html

# Validation with warnings using vnu.jar
lint: all
xmlwf $(Destination)/*.html
java -jar $(VNU) --format text $(Destination)/*.html
Expand Down
82 changes: 82 additions & 0 deletions docs/make.d/config.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
########################################################################
# Prerequisites
########################################################################

# We are using some of the newest GNU Make features... so require GNU
# Make version >= 3.82
version_test := $(filter 3.82,$(firstword $(sort $(MAKE_VERSION) 3.82)))
ifndef version_test
$(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed)
endif

#!# Only one target at the same time
#!MAKECMDGOALS ?= all
#!ifneq (1,$(words $(MAKECMDGOALS)))
#!$(error Only one target accepted!)
#!endif

# Check 'root' intentions
ifeq (,$(filter install uninstall,$(MAKECMDGOALS)))
ifeq (0,$(shell id --user))
$(error Root only can make "(un)install" targets)
endif
endif

########################################################################
# Configuration
########################################################################

# Disable builtins.
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables

# Warn when an undefined variable is referenced.
MAKEFLAGS += --warn-undefined-variables

# Make will not print the recipe used to remake files.
.SILENT:

# Eliminate use of the built-in implicit rules. Also clear out the
# default list of suffixes for suffix rules.
.SUFFIXES:

# Sets the default goal to be used if no targets were specified on the
# command line.
.PHONY: all
.DEFAULT_GOAL := all

# Default shell: if we require GNU Make, why not require Bash?
SHELL := /bin/bash

# The argument(s) passed to the shell are taken from the variable
# .SHELLFLAGS.
.SHELLFLAGS := -o errexit -o pipefail -o nounset -c

# Make will delete the target of a rule if it has changed and its recipe
# exits with a nonzero exit status.
.DELETE_ON_ERROR:

#!# Enable a second expansion of the prerequisites
#!.SECONDEXPANSION:

########################################################################
# Common macros
########################################################################

# Hacks for string manipulation
comma := ,
empty :=
space := $(empty) $(empty)

# Hack for list manipulation
rest = $(wordlist 2,2147483648,$1)

#!# Make a directory if it no exists
#!define mkdir
#! if test ! -d $1; then \
#! echo 1>&2 '==> $1'; \
#! mkdir --parents $1; \
#! fi
#!endef

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
34 changes: 34 additions & 0 deletions docs/make.d/metadata.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
########################################################################
# Metadata
########################################################################

# Imported variables:
# Metadata

# Metadata directory
$(Metadata):
$(info ==> $@)
mkdir $@ >/dev/null 2>&1 || true

# Main configuration file
ifeq (config.yaml, $(wildcard config.yaml))

# Convert config.yaml to $(Metadata)/config.json
$(Metadata)/config.json: config.yaml \
| $(Metadata)
$(info ==> $@)
yaml2json <$< >$@

else ifeq (config.json, $(wildcard config.json))

# Convert config.json to $(Metadata)/config.json
$(Metadata)/config.json: config.json \
| $(Metadata)
$(info ==> $@)
cp $< $@

else
$(error Configuration file not found)
endif

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make

0 comments on commit f4b651e

Please sign in to comment.