Skip to content

Commit

Permalink
Fine grained dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Nov 24, 2018
1 parent 77534ea commit 6aedd1c
Show file tree
Hide file tree
Showing 37 changed files with 79 additions and 46 deletions.
10 changes: 4 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,13 @@ setup:

.PHONY: install uninstall

SAKE=$(datadir)/$(PROJECT)/sake/

install: all
install --directory $(bindir) $(datadir) $(mandir)/man1 $(SAKE)/{make.d,milligram}
install --directory $(bindir) $(datadir) $(mandir)/man1 $(datadir)/$(PROJECT)/{sake.d,milligram}
install --verbose --compare --mode 555 bin/* $(bindir)
install --verbose --compare --mode 644 share/*.* $(datadir)/$(PROJECT)
install --verbose --compare --mode 644 share/*.m $(datadir)/$(PROJECT)
install --verbose --compare --mode 644 $(ManPage) $(mandir)/man1
install --verbose --compare --mode 644 share/sake/make.d/*.* $(SAKE)/make.d
install --verbose --compare --mode 644 share/sake/milligram/*.* $(SAKE)/milligram
install --verbose --compare --mode 644 share/sake.d/*.* $(datadir)/$(PROJECT)/sake.d
install --verbose --compare --mode 644 share/milligram/*.* $(datadir)/$(PROJECT)/milligram
sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/jqt
sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/sake

Expand Down
9 changes: 6 additions & 3 deletions bin/sake
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ shopt -s expand_aliases
declare -r SELF=${0##*/}

# Exported to use in makefiles and Sakefile
declare -xr DATADIR='/usr/local/share'
declare -xr SAKE="${DATADIR}/jqt/sake"
declare -xr JQTLIB='/usr/local/share/jqt'

# GMake call
declare -ri CORES=2
Expand Down Expand Up @@ -55,13 +54,17 @@ case $1 in
| awk '/^[^ \t.%][-A-Za-z0-9_.]*:/ { print $1 }' \
| sort --unique \
| sed 's/:\+$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=5
| pr --omit-pagination --width=80 --columns=6
;;
touch)
if test -e config.yaml; then touch config.yaml; else touch config.json; fi
shift
_sake build "$@"
;;
clober)
shift
_sake clobber "$@"
;;
*)
_sake "$@"
;;
Expand Down
18 changes: 16 additions & 2 deletions docs/Sakefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,18 @@
#VERBOSE := 1
#TRACE := 1
#VNU := java -jar /usr/local/vnu/vnu.jar
#JQTFLAGS += ...

########################################################################
# Starting makefile
########################################################################

include $(SAKE)/make.d/main.make
include $(JQTLIB)/sake.d/main.make

########################################################################
# Last phase, after metadata configuration.
########################################################################

ifdef __build

# Add some Pandoc options
Expand All @@ -39,10 +41,22 @@ JQTFLAGS += -5 --toc-depth=4
# experimental
########################################################################

# 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/>.*$$//' \
| sort
| jq -nrR -f ./phase3_layout.jq --arg Layouts $(Layouts)

endif # __build

Expand Down
1 change: 0 additions & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ defaults:
Datasets:
- snippets.md
Dependencies:
- layouts/default.html
- content/macros.m
- content/LINKS.txt
# Flags:
Expand Down
29 changes: 29 additions & 0 deletions docs/phase3_layout.jq
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
########################################################################
# phase3_layout.jq -- Define contents for `$(Meta)/phase3_layout.json`.
#
# jq -nRr -f phase3_layout.jq
# < ...
# > $(Meta)/phase3_layout.json

def makedepend:
def branch($root; $tree):
def _branch:
if in($tree)
then . , ($tree[.][] | _branch)
else .
end
;
[$root | _branch][1:] | sort
;
reduce inputs as $line ({}; ($line/"\t") as [$key,$value] | .[$key]+=[$value])
| . as $tree
| reduce keys_unsorted[] as $r ({}; .[$r]=branch($r; $tree))
| . as $dependents
| $tree | keys[]
| select(startswith($Layouts+"/"))
| "\(.): \($dependents[.] | join(" "))"
;

makedepend

# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 3 additions & 22 deletions share/sake/make.d/main.make → share/sake.d/main.make
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# main.make -- Main makefile.
#
# Imported variables:
# SAKE
# DATADIR
# JQTDIR
#
# Variables:
# Meta
Expand Down Expand Up @@ -51,20 +50,9 @@ endif
# Check command line sanity.
########################################################################

# TODO: check only one target is present?

# Target 'clean' must be alone.
ifeq (clean,$(filter clean,$(MAKECMDGOALS)))
# Check only one target is present.
ifneq (1,$(words $(MAKECMDGOALS)))
$(error Target "clean" must be alone)
endif
endif

# Target 'clobber' must be alone.
ifeq (clobber,$(filter clobber,$(MAKECMDGOALS)))
ifneq (1,$(words $(MAKECMDGOALS)))
$(error Target "clobber" must be alone)
endif
$(error Only one target accepted)
endif

# Do not build to clobber immediately.
Expand All @@ -74,13 +62,6 @@ $(error Nothing to clobber)
endif
endif

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

########################################################################
# Include all makefile phases.
########################################################################
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 15 additions & 5 deletions share/sake/make.d/phase3.jq → share/sake.d/phase3.jq
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ def dependencies:
else "" end
+
if .Datasets
then " " + ([.Datasets[] | basename | "\($Meta)/\(.).json"] | join(" "))
then " " + ([.Datasets[] | basename | "$(Meta)/\(.).json"] | join(" "))
else "" end
;

def dataset:
if .Datasets
then " " + ([.Datasets[] | basename | "-m\(.):\($Meta)/\(.).json"] | join(" "))
then " " + ([.Datasets[] | basename | "-m\(.):$(Meta)/\(.).json"] | join(" "))
else "" end
;

Expand All @@ -35,11 +35,11 @@ def flags:
;

def page:
" -mpage:\($Meta)/pages/\(.Id).json"
" -mpage:$(Meta)/pages/\(.Id).json"
;

def layout:
" \($Layouts)/\(.Layout).html"
" $(Layouts)/\(.Layout).html"
;

# _site/jqt/index.html: content/index.md layouts/page.html content/macros.m content/LINKS.txt content/EXAMPLE.txt
Expand All @@ -50,17 +50,27 @@ def layout:
# $(info ==> $@)
# @$(JQT) -d $< -mpage:.meta/pages/blog/2017-04-13-hello.json layouts/page.html | $(DETAILS) > $@
def page_rule:
.[] |
$Root+"/"+.URL+": " + .Source + layout + dependencies,
"\t$(info ==> $@)",
"\t@$(JQT) -d $<" + dataset + flags + page + layout + " | $(DETAILS) > $@"
;

# %.html: _site/%.html ;
# blog/%.html: _site/blog/%.html ;
def page_target:
map(.Path)
| unique[]
| "\(.)%.html: $(Root)/\(.)%.html ;"
;

#
# Output makefile
#

"__phase_3 := 1\n",
(.[] | page_rule), # for each page
page_target, # for each path
page_rule, # for each page
"\n# \u0076im:syntax=make"

# vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=jq
4 changes: 2 additions & 2 deletions share/sake/make.d/phase3.make → share/sake.d/phase3.make
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ endef
# Extra prerequisites for HTML pages.
#

$(PagesHTML): $(Root)/%.html : $(Meta)/pages/%.json
$(PagesHTML): $(Meta)/phase3.make $(Blocks)/*/markup.html $(Blocks)/*/*/markup.html \
$(PagesHTML): $(Meta)/phase3.make \
| $$(dir $$@)

# Content example for `$(Meta)/phase3.make`:
Expand All @@ -84,6 +83,7 @@ $(PagesHTML): $(Meta)/phase3.make $(Blocks)/*/markup.html $(Blocks)/*/*/markup.h
build:: $(PagesHTML)
@cp --verbose --recursive --update $(Assets)/* $(Root) \
| sed "s/^.*-> ./==> /;s/.$$//"
date -Iseconds > $(Meta)/lastbuild

# Delete secondary files.
clobber:: ; @rm -rf *~ *.bak *.log
Expand Down
File renamed without changes.
File renamed without changes.
9 changes: 4 additions & 5 deletions share/sake/make.d/styles.make → share/sake.d/styles.make
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
# Exported rules for:
# $(Root)/styles.css

# DATADIR defined in `sake` script.
_sake := $(DATADIR)/jqt/sake
# JQTLIB defined in `sake` script.

# Secondary prerequisites.
$(Root)/styles.css: \
$(_sake)/milligram/*.css \
$(_sake)/milligram/*.m \
$(JQTLIB)/milligram/*.css \
$(JQTLIB)/milligram/*.m \
$(Styles)/*.css \
$(Blocks)/*/style.css \
$(Blocks)/*/*/style.css \

$(Root)/styles.css: $(Styles)/main.css $(THIS) \
| $(Root)
$(info ==> $@)
jqt -P CSS-min -I$(_sake) -I$(Styles) < $< > $@
jqt -P CSS-min -I$(JQTLIB) -I$(Styles) < $< > $@

build:: $(Root)/styles.css

Expand Down
File renamed without changes.

0 comments on commit 6aedd1c

Please sign in to comment.