Skip to content

Commit

Permalink
Make layouts dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Nov 25, 2018
1 parent 6aedd1c commit e727f4d
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 201 deletions.
10 changes: 8 additions & 2 deletions bin/sake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Wraps make
#

# Environment
declare -ri NCORES=${NCORES:-2}

# Options
set -o errexit -o noglob -o nounset -o pipefail
shopt -s expand_aliases
Expand All @@ -15,9 +18,8 @@ declare -r SELF=${0##*/}
declare -xr JQTLIB='/usr/local/share/jqt'

# GMake call
declare -ri CORES=2
declare -ra makeflags=(
--jobs=$(( CORES * 150 / 100 )) # CORES * 1.5
--jobs=$(( NCORES * 150 / 100 )) # NCORES * 1.5
--makefile=Sakefile
--output-sync=target
)
Expand Down Expand Up @@ -61,6 +63,10 @@ case $1 in
shift
_sake build "$@"
;;
config)
shift
_sake configure "$@"
;;
clober)
shift
_sake clobber "$@"
Expand Down
12 changes: 0 additions & 12 deletions docs/Sakefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,9 @@ JQTFLAGS += -5 --toc-depth=4

# TODO: new, help, man page, SITE section on web, taxonomies (flags, series...)

# Remove?
#$(PagesHTML): $(Root)/%.html : $(Meta)/pages/%.json
#$(PagesHTML): $(Root)/blog/%.html : $(Meta)/pages/blog/%.json


# TODO: show content pending to render?
#newer: $(Meta)/lastbuild


# TODO: move to phase3
depend:
grep -r '<%include\s\+[^>]\+>' blocks/ layouts/\
| sed -e 's/:.*<%include\s\+/\t/;s/>.*$$//' \
| jq -nrR -f ./phase3_layout.jq --arg Layouts $(Layouts)

endif # __build

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
29 changes: 0 additions & 29 deletions docs/phase3_layout.jq

This file was deleted.

4 changes: 2 additions & 2 deletions share/sake.d/configuration.make
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ MAKECMDGOALS ?= build
# Make configuration.
########################################################################

# Use renamed makefile
MAKE += --makefile=Sakefile
#!# Use renamed makefile
#!MAKE += --makefile=Sakefile

# Disable builtins.
MAKEFLAGS += --no-builtin-rules
Expand Down
104 changes: 75 additions & 29 deletions share/sake.d/main.make
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,44 @@
# main.make -- Main makefile.
#
# Imported variables:
# JQTDIR
# JQTLIB
#
# Variables:
# Meta
# Rules:
# $(Meta) directory target and clobber target
# $(Meta) directory `mkdir`, `clobber' and ' clean' targets
# $(Root) directory `mkdir`, `clobber' and ' clean' targets
# Targets:
# build
# clean
# clobber
# nuke
# configure
#
########################################################################

# Where all *.make files resides...
MDIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

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

# Where all *.make files resides...
MDIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))

include $(MDIR)/configuration.make

# Do not try to rebuilt static makefiles.
$(CURDIR)/Sakefile $(MDIR)/main.make $(MDIR)/configuration.make: ;

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

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

########################################################################
# Metadata directory for all generated make and metadata files.
########################################################################
Expand All @@ -36,16 +53,6 @@ $(Meta):
# Delete all generated metadata
clobber:: ; @rm -rf $(Meta)

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

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

########################################################################
# Check command line sanity.
########################################################################
Expand All @@ -55,7 +62,7 @@ ifneq (1,$(words $(MAKECMDGOALS)))
$(error Only one target accepted)
endif

# Do not build to clobber immediately.
# Do not remake $(Meta)/phase[123].make to clobber immediately.
ifeq (clobber,$(MAKECMDGOALS))
ifeq (,$(wildcard $(Meta)))
$(error Nothing to clobber)
Expand All @@ -66,11 +73,15 @@ endif
# Include all makefile phases.
########################################################################

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

# Current makefile.
# $(THIS) works because the included files do not include other makefiles.
THIS = $(lastword $(MAKEFILE_LIST))

# JQ script generating target
SCRIPT = $(MDIR)/$$(basename $$(notdir $$@)).jq

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

Expand All @@ -80,11 +91,12 @@ THIS = $(lastword $(MAKEFILE_LIST))
# Do not try to rebuilt static makefiles.
$(MDIR)/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.
# If `__phase_1` is not defined because `$(Meta)/phase1.make` does not
# exists, after this point the rest of the file is ignored, but
# `$(Meta)/phase1.make` is built because a rule exists in the file
# `$(MDIR)/phase1.make`. Then this `Makefile` is restarted,
# `MAKE_RESTARTS` is be equal to 1, `$(Meta)/phase1.make` is now loaded
# and `__phase_1` is defined. Equivalent situation happens in all phases.

ifdef __phase_1

Expand All @@ -103,6 +115,7 @@ ifdef __phase_2
# Define standard rules and rules for HTML pages and nodes.

-include $(Meta)/phase3.make
-include $(Meta)/phase3d.make
include $(MDIR)/phase3.make

# Do not try to rebuilt static makefiles.
Expand All @@ -111,8 +124,47 @@ $(MDIR)/phase3.make: ;
ifdef __phase_3
__build := 1

########################################################################
# Standard targets.
########################################################################

sake_builtin := new help touch list
.PHONY: build clean clobber nuke configure $(sake_builtin)

# Filter builtin tools defined in `sake`script.
$(sake_builtin): ; @echo 'sake: Target `$@` not implemented.'

# Copy Assets after create HTML pages.
build:: $(PagesHTML)
@cp --verbose --recursive --update $(Assets)/* $(Root) \
| sed "s/^.*-> ./==> /;s/.$$//"
date -Iseconds > $(Meta)/lastbuild

# Delete secondary files.
clobber:: ; @rm -rf *~ *.bak *.log

# Delete metadata. Usage: `sake nuke && sake configure`.
nuke: ; @rm -rf $(Meta)

# Build all metadata and data files.
configure: $(DataFiles) # $(PagesJSON) are built for phase2.make

########################################################################
# Site destination directory.

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

# Delete generated files. Usage: `sake clean && sake`.
clean: ; @rm -rf $(Root)/*

# Delete destination directory.
clobber:: ; @rm -rf $(Root)

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

include $(MDIR)/sitemap.make
include $(MDIR)/styles.make
Expand All @@ -123,12 +175,6 @@ $(MDIR)/sitemap.make: ;
$(MDIR)/styles.make: ;
$(MDIR)/tools.make: ;

# Filter builtin tools defined in `sake`script.
sake_builtin := new help touch list
.PHONY: $(sake_builtin)
$(sake_builtin):
echo 'sake: Target `$@` not implemented.'

endif # __phase_3
endif # __phase_2
endif # __phase_1
Expand Down
2 changes: 1 addition & 1 deletion share/sake.d/phase1.jq
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# phase1.jq -- Define contents for `$(Meta)/phase2.make`.
#
# jq -r -f phase1.jq
# < $(Meta)/site.json
# < $(Meta)/phase1_site.json
# > $(Meta)/phase1.make

#
Expand Down
68 changes: 25 additions & 43 deletions share/sake.d/phase1.make
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
#
# Rules defined in $(MDIR)/phase1.make:
# $(Meta)/config.json
# $(Meta)/site.json
# $(Meta)/phase1_site.json
# $(Meta)/phase1.make
# $(Root) directory rule and clobber and clean targets

SUPER := $(MDIR)/main.make

Expand All @@ -24,65 +23,48 @@ SUPER := $(MDIR)/main.make
########################################################################

#
# Create `$(Meta)/config.json` from `config.yaml` or `config.json`.
# Create `$(Meta)/phase1.make` from `$(Meta)/phase1_site.json` using
# `$(MDIR)/phase1.jq`.
#
ifeq (config.yaml,$(wildcard config.yaml))

# Convert `config.yaml` to `$(Meta)/config.json`.
$(Meta)/config.json: $(CURDIR)/config.yaml $(SUPER) $(THIS) \
| $(Meta)
$(info ==> $@)
yaml2json < $< > $@

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

# Convert `config.json` to `$(Meta)/config.json`.
$(Meta)/config.json: $(CURDIR)/onfig.json $(SUPER) $(THIS) \
| $(Meta)
$(Meta)/phase1.make: $(SUPER) $(THIS) $(CURDIR)/Sakefile
$(Meta)/phase1.make: $(Meta)/phase1_site.json $(SCRIPT)
$(info ==> $@)
jqt -Pjson < $< > $@

else
$(error Configuration file not found)
endif
jq --raw-output \
--from-file $(MDIR)/phase1.jq \
< $< > $@

#
# Create `$(Meta)/site.json` from `$(Meta)/config.json` using
# Create `$(Meta)/phase1_site.json` from `$(Meta)/config.json` using
# `$(MDIR)/phase1_site.jq`.
#
$(Meta)/site.json: $(Meta)/config.json $(MDIR)/phase1_site.jq
$(Meta)/phase1_site.json: $(Meta)/config.json $(SCRIPT) $(THIS)
$(info ==> $@)
jq --sort-keys \
--from-file $(MDIR)/phase1_site.jq \
--arg Meta $(Meta) \
< $< > $@

#
# Create `$(Meta)/phase1.make` from `$(Meta)/site.json` using
# `$(MDIR)/phase1.jq`.
# Create `$(Meta)/config.json` from `config.yaml` or `config.json`.
#
$(Meta)/phase1.make: $(Meta)/site.json $(MDIR)/phase1.jq
$(info ==> $@)
jq --raw-output \
--from-file $(MDIR)/phase1.jq \
< $< > $@

ifdef __phase_1

########################################################################
# Site destination directory.
########################################################################
ifeq (config.yaml,$(wildcard config.yaml))

$(Root):
# Convert `config.yaml` to `$(Meta)/config.json`.
$(Meta)/config.json: $(CURDIR)/config.yaml $(THIS) \
| $(Meta)
$(info ==> $@)
mkdir --parents $@ >/dev/null 2>&1 || true
yaml2json < $< > $@

# Delete generated files.
clean: ; @rm -rf $(Root)/*
else ifeq (config.json,$(wildcard config.json))

# Delete destination directory.
clobber:: ; @rm -rf $(Root)
# Convert `config.json` to `$(Meta)/config.json`.
$(Meta)/config.json: $(CURDIR)/config.json $(THIS) \
| $(Meta)
$(info ==> $@)
jqt -Pjson < $< > $@

endif # __phase_1
else
$(error Configuration file not found)
endif

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
2 changes: 1 addition & 1 deletion share/sake.d/phase1_site.jq
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# jq -S -f phase1_site.jq --arg Meta $(Meta)
# < $(Meta)/config.json
# > $(Meta)/site.json
# > $(Meta)/phase1_site.json

# Delete `.defaults` and add some new members with default value if not defined
# in the configuration file.
Expand Down
Loading

0 comments on commit e727f4d

Please sign in to comment.