Skip to content

Commit

Permalink
Refactorized makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Nov 18, 2018
1 parent f09c0be commit 4e0bb4b
Show file tree
Hide file tree
Showing 34 changed files with 408 additions and 424 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ uninstall:
# Show targets
########################################################################

.PHONY: help
.PHONY: list

help:
list:
echo 'Usage: make TARGET [parameter=value...]'
echo 'Targets:'; \
$(MAKE) --print-data-base --just-print 2>&1 \
Expand All @@ -138,10 +138,10 @@ help:
| sed 's/:\+$$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=4
echo 'Default parameters:'; \
echo ' prefix = /usr/local'; \
echo ' bindir = /usr/local/bin'; \
echo ' datadir = /usr/local/share'; \
echo ' mandir = /usr/local/share/man'
echo ' prefix = $(prefix)'; \
echo ' bindir = $(bindir)'; \
echo ' datadir = $(datadir)'; \
echo ' mandir = $(mandir)'

########################################################################
# Generate help text
Expand Down
6 changes: 4 additions & 2 deletions bin/jqt
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ function merge
# Render template
########################################################################

declare -a JQ_PATH=( '-L' "$DATADIR/jqt" )
declare -a JQ_PATH=( '-L' "${DATADIR}/jqt" )

# < stdin > stdout
function render
Expand Down Expand Up @@ -544,7 +544,7 @@ Preprocessor options Data options
Template options -C
-L DIRECTORY -H
-i MODULE -S
-j MODULE:NAME Information options
-j MODULE:NAME Information options
Document options -h, --help
-4, -5 -p
-d FILE -V, --version
Expand Down Expand Up @@ -709,6 +709,8 @@ while getopts :hVD:I:P:L:i:j:45d:weprt:m:M:T:CHS-: opt; do
;;
version) echo "$SELF $VERSION"; exit 0
;;
datadir) echo "${DATADIR}"; exit 0
;;
# Pandoc options:
base-header-level=*) PANDOC_OPTS[${#PANDOC_OPTS[@]}]="--$OPTARG";;
bibliography=*) PANDOC_OPTS[${#PANDOC_OPTS[@]}]="--$OPTARG";;
Expand Down
164 changes: 31 additions & 133 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -1,158 +1,56 @@
########################################################################
# Makefile
#
# Project: jqt
# Author: <Joan Josep Ordinas Rosa> [email protected]
# Description: Makefile for JQT web site management.
# Published: https://fadado.github.io/jqt/
#
# Variables:
# $(Metadata)
# Rules:
# $(Metadata) directory target and clobber method
# Project specific makefile. All the imported modules are expected to be
# independent, valid for any project without any change. This should be
# the only makefile to edit by hand!
#
########################################################################

########################################################################
# Load _Make_ configuration.
########################################################################

include make.d/configuration.make

# Do not try to rebuilt static makefiles.
Makefile make.d/configuration.make: ;

########################################################################
# Metadata directory for all generated make and metadata files.
########################################################################

Metadata ?= .meta

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

# Delete all generated metadata
clobber:: ; @rm -rf $(Metadata)

########################################################################
# Print debug info.
########################################################################

ifneq (,$(TRACE))
ifdef MAKE_RESTARTS
$(info Makefile phase restarted: $(MAKE_RESTARTS))
endif
endif

########################################################################
# Check command line sanity.
########################################################################

# Target 'clobber' must be alone.
ifeq (clobber,$(filter clobber,$(MAKECMDGOALS)))
ifneq (1,$(words $(MAKECMDGOALS)))
$(error Target "clobber" must be alone)
endif
endif
# Variables used:
# Root
#
# Variables modified:
# JQTFLAGS

# Do not build to clobber immediately.
ifeq (clobber,$(MAKECMDGOALS))
ifeq (,$(wildcard $(Metadata)))
$(error Nothing to clobber)
endif
endif
#Meta := .meta
#VERBOSE := 1
#TRACE := 1

# Do not build to clean immediately.
ifeq (clean,$(filter clean,$(MAKECMDGOALS)))
ifeq (,$(wildcard $(Metadata)))
$(error Nothing to clean)
endif
endif
include make.d/Makefile.make

# Check _root_ intentions.
ifeq (,$(filter install uninstall,$(MAKECMDGOALS)))
ifeq (0,$(shell id --user))
$(error Root only can make "(un)install" targets)
endif
else
ifneq (0,$(shell id --user))
$(error Only root can make "(un)install" targets)
endif
endif
# Last phase, after metadata configuration.
ifdef __build

########################################################################
# Include all makefile phases.
# Build pages options.
########################################################################

# Recursive variable used in all included makefiles. This works because the
# included files do not include other makefiles.

THIS = $(lastword $(MAKEFILE_LIST))
# Pandoc options
JQTFLAGS += -5 --toc-depth=4

########################################################################
# Derive metadata from `config.yaml` or `config.json`.

-include $(Metadata)/phase1.make
include make.d/phase1.make

# Do not try to rebuilt static makefiles.
make.d/phase1.make: ;

# If `__phase_1` is not defined because `phase1.make` does not exists, after
# this point the rest of the file is ignored, but `phase1.make` is built
# because a rule exists in the file `config.make`. Then this `Makefile` is
# restarted, `MAKE_RESTARTS` is be equal to 1, `phase1.make` is now loaded and
# `__phase_1` is defined. Equivalent situation happens in all phases.

ifdef __phase_1

# HTML 5 validation.
########################################################################
# Build metadata from filesystem introspection.

-include $(Metadata)/phase2.make
include make.d/phase2.make
# Download vnu.jar from `https://github.com/validator/validator/releases`.

# Do not try to rebuilt static makefiles.
make.d/phase2.make: ;
.PHONY: h5.valid h5.lint

ifdef __phase_2

########################################################################
# Define standard rules and rules for HTML pages and nodes.

-include $(Metadata)/phase3.make
include make.d/phase3.make

# Do not try to rebuilt static makefiles.
make.d/phase3.make: ;

ifdef __phase_3

########################################################################
# Several complementary makefiles.

include make.d/sitemap.make
include make.d/styles.make
##include make.d/tools.make

# Do not try to rebuilt static makefiles.
make.d/sitemap.make: ;
make.d/styles.make: ;
##make.d/tools.make: ;

########################################################################
# Project specific makefile. All the previous modules are expected to be
# independent, valid for any project without any change. This file must
# exist but can be empty.
# Validation tool.
VNU := /usr/local/vnu/vnu.jar

include config.make
# Validation.
h5.valid: build
@xmlwf $(Root)/*.html
@java -jar $(VNU) --errors-only --format gnu $(Root)/*.html

# Do not try to rebuilt static makefiles.
config.make: ;
# Validation with warnings.
h5.lint: build
@xmlwf $(Root)/*.html
@java -jar $(VNU) --format text $(Root)/*.html

endif # __phase_3
endif # __phase_2
endif # __phase_1
endif # __build

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
54 changes: 27 additions & 27 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,19 @@

## Extension conventions for content files

The files in the `content` and `data` directories must follow some conventions in the file
The files in the `content` directory must follow some conventions in the file
extensions:

* Web site pages
- `content/content.md`
- `content/data.md`
- `content/engine.md`
- `content/index.md`
- `content/structure.md`

* Partial MarkDown to be included
- `content/EXAMPLE.text`
- `content/FLOW.text`
- `content/LINKS.text`
- `content/opt/\*.text`

* Other unrelated MarkDown files
- `content/help.text`
- `content/jqt.1.text`

* Extension conventions for data files
- `data/table.csv`
- `data/snippets.md`
- `data/document.json`
- `data/document.yaml`
* `*.md`: Web site pages.
* `*.text`: Partial MarkDown to be included and other unrelated MarkDown files.

The files in the `data` directory must follow some conventions in the file
extensions:

* `*.md`: MarkDown snippets in front-matter.
* `*.csv`: CSV data files.
* `*.json`: JSON documents.
* `*.yaml`: YAML documents.

# Variables

Expand All @@ -41,13 +29,14 @@ predefined variables:
* `.site.Blocks`
* `.site.Content`
* `.site.Data`
* `.site.Destination`
* `.site.Root`
* `.site.Layouts`
* `.site.Metadata`
* `.site.Meta`
* `.site.Styles`

In the configuration file you can assign new values to all predefined variables
except `Metadata`, with hardcoded value in the file `Makefile`.
except `Meta`, with default value defined in the file `make.d/Makefile.make`.
You can modify this variable at the very beggining of your `Makefile`.

## Page variables

Expand Down Expand Up @@ -76,7 +65,7 @@ Front-matter members and the predefined variables.

```
Slug
|---^---|
|---^---|
content/name.html
|-^|
Id
Expand All @@ -96,6 +85,17 @@ content/extras/indexes/name.html
Path
```

# _Sake_: static site build automation system

## Current _GMake_ commands

```
Usage: make TARGET [parameter=value...]
Targets:
build clobber h5.lint list
clean configure h5.valid touch
```

<!--
vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=markdown
-->
44 changes: 0 additions & 44 deletions docs/config.make

This file was deleted.

Loading

0 comments on commit 4e0bb4b

Please sign in to comment.