Skip to content

Commit

Permalink
Refined make rules
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 19, 2017
1 parent c9a2097 commit da8282c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 22 deletions.
13 changes: 10 additions & 3 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@
# Make configuration
include make.d/prelude.make

# jqt version
Version := 0.5.1

# Metadata directory
Metadata := .meta

# jqt version
Version := 0.5.1

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

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

# ======================================================================
-include $(Metadata)/phase1.make
include make.d/config.make
Expand Down
2 changes: 1 addition & 1 deletion docs/content/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Managing the data model with jqt
description: jqt combines one template with one MarkDown document and a data model.
keywords: jqt, JSON, YAML, gpp, preprocessing, data model
updated: "2016-08-28T10:27:09Z"
use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[DeIMmnPRT].txt"]
use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[DeIMmPRT].txt"]
---
<%include content/macros.m>&
<%include content/LINKS.txt>&
Expand Down
2 changes: 1 addition & 1 deletion docs/content/engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: The jqt template engine
description: jqt orchestrates several shell utilities to transform MarkDown text and YAML or JSON data into a final HTML page.
keywords: jqt, jq, YAML, gpp, preprocessing, template engine
updated: "2016-08-28T10:27:09Z"
use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[4CDdeHhIijLMmnPprSTtVw].txt"]
use: [content/macros.m, content/LINKS.txt, content/FLOW.txt, "content/opt/[4CDdeHhIijLMmPprSTtVw].txt"]
---
<%include content/macros.m>&
<%include content/LINKS.txt>&
Expand Down
File renamed without changes.
70 changes: 63 additions & 7 deletions docs/jqt.make
Original file line number Diff line number Diff line change
@@ -1,21 +1,75 @@
########################################################################
#
# Specific makefile for this web site
#
# Defined rules for:
# $(Metadata)/snippets.json
# $(ManPage)
# /tmp/help
# Defined targets:
# all
# clean
# clobber
# init

########################################################################
# Data files
########################################################################

# Snippets
$(Metadata)/snippets.json: $(Data)/snippets.yaml \
| $(Metadata)
# Declare explicitly modules with -m, -M or -j; this must be decided by a
# human!
JQTFLAGS += -msnippets:$(Metadata)/snippets.json

# To define in phase2.make from
# find $(Data) -name '*.*'

DataMD := $(Metadata)/snippets.json
DataYAML :=
DataJSON :=
DataCSV :=

# =========================
# To move to pathnames.make
# =========================

#
# Files derived from $(Data)/*
#

ifneq (,$(DataMD))
$(DataMD): $(Metadata)/%.json : $(Data)/%.md | $(Metadata)
$(info ==> $@)
@jqt -T < $< | yaml2json > $@
endif

$(DestinationPages): $(Metadata)/snippets.json
ifneq (,$(DataYAML))
$(DataYAML): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@yaml2json > $@
endif

JQTFLAGS += -msnippets:$(Metadata)/snippets.json
ifneq (,$(DataJSON))
$(DataJSON): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@jqt -P json < $< > $@
endif

ifneq (,$(DataCSV))
$(DataCSV): $(Metadata)/%.json : $(Data)/%.yaml | $(Metadata)
$(info ==> $@)
@csv2json < $< > $@
endif

clean:: ; @rm -f $(Metadata)/snippets.json
DataFiles := $(DataMD) $(DataYAML) $(DataJSON) $(DataCSV)

ifneq (,$(DataFiles))

$(DestinationPages): $(DataFiles)

init::
@$(MAKE) -s $(DataFiles)

endif

########################################################################
# Build pages options
Expand All @@ -29,7 +83,9 @@ JQTFLAGS += \
-5 \
--toc-depth=4 \
-iblocks/filters \
-msections:$(Metadata)/sections.json \

# only for derived nodes?
# -msections:$(Metadata)/sections.json \
########################################################################
# Generate man page for jqt
Expand Down
22 changes: 14 additions & 8 deletions docs/make.d/pages.make
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
# Create makefile containing rules for all HTML files
########################################################################

# Rules for each page (depend also on sections.json only to force build)
$(Metadata)/phase3.make: $(Metadata)/pages.json $(Metadata)/sections.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make
# Build rules for each page
$(Metadata)/phase3.make: $(Metadata)/pages.json make.d/pages.make make.d/phase3.jq $(Metadata)/phase2.make
$(info ==> $@)
@jq --raw-output \
--arg Metadata $(Metadata) \
Expand All @@ -32,10 +32,11 @@ $(Metadata)/phase3.make: $(Metadata)/pages.json $(Metadata)/sections.json make.d
# Variables used in $(Metadata)/phase3.make.
#

JQTFLAGS = \
-I./ \
-msite:$(Metadata)/config.json \
-j'$$'pages:$(Metadata)/pages \
define JQTFLAGS :=
-msite:$(Metadata)/config.json \
-j'$$'pages:$(Metadata)/pages \
-I./
endef

JQT = jqt $(JQTFLAGS)

Expand Down Expand Up @@ -88,10 +89,15 @@ touch:
fresh: clobber
@$(MAKE) -s all

init:
# make all metadata except files derived from $(Data)
init::
ifdef MAKE_RESTARTS
@:
else
@rm -rf $(Metadata)
@$(MAKE) -s $(Metadata)/phase3.make

endif

endif # __phase_3

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
3 changes: 2 additions & 1 deletion docs/make.d/pathnames.make
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ $(Metadata)/phase2.make: make.d/pathnames.make make.d/phase2.jq $(Metadata)/phas
--slurp \
--raw-output \
--from-file make.d/phase2.jq \
--arg DF "$$(find $(Data) -name '*.*')" \
--arg Content $(Content) \
--arg Destination $(Destination) \
--arg Metadata $(Metadata) \
Expand Down Expand Up @@ -99,6 +100,6 @@ $(Metadata)/sections.json: $(Metadata)/pages.json
$(info ==> $@)
@jq '[.[].section] | unique | map(select(.))' < $< > $@

endif
endif # __phase_2

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
14 changes: 13 additions & 1 deletion docs/make.d/phase2.jq
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# phase2.jq --arg Content $(Content) --arg Destination $(Destination) --arg Metadata $(Metadata)
# phase2.jq --arg Content $(Content) --arg Destination $(Destination) --arg Metadata $(Metadata) --arg DF "$$(find $(Data) -name '*.*')
#
# Generate phase2.make from `find` output.

Expand Down Expand Up @@ -48,6 +48,16 @@ def mpages($documents):
| "MetadataPages := " + ($json | join(" ")) + "\n" + mrule
;


def data($files):
($files / "\n") as $names
| [($names[] | select(test(".md$")))] as $DataMD
| [($names[] | select(test(".yaml$")))] as $DataYAML
| [($names[] | select(test(".json$")))] as $DataJSON
| [($names[] | select(test(".csv$")))] as $DataCSV
| ""
;

########################################################################
# Output makefile
########################################################################
Expand All @@ -58,12 +68,14 @@ def mpages($documents):
| mpaths($paths) as $MetadataPaths
| dpages($documents) as $DestinationPages
| mpages($documents) as $MetadataPages
| data($DF) as $DataFiles
|
"__phase_2 := 1",
$DestinationPaths,
$MetadataPaths,
$DestinationPages,
$MetadataPages,
$DataFiles,
comment

# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq

0 comments on commit da8282c

Please sign in to comment.