Skip to content

Commit

Permalink
Implemented sake wrapper to make.
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Nov 22, 2018
1 parent 4e0bb4b commit 77534ea
Show file tree
Hide file tree
Showing 40 changed files with 243 additions and 134 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,17 @@ setup:

.PHONY: install uninstall

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

install: all
test -d $(bindir) || mkdir --verbose --parents $(bindir)
test -d $(datadir)/$(PROJECT) || mkdir --verbose --parents $(datadir)/$(PROJECT)
test -d $(mandir)/man1 || mkdir --verbose --parents $(mandir)/man1
install --directory $(bindir) $(datadir) $(mandir)/man1 $(SAKE)/{make.d,milligram}
install --verbose --compare --mode 555 bin/* $(bindir)
install --verbose --compare --mode 644 share/* $(datadir)/$(PROJECT)
install --verbose --compare --mode 644 share/*.* $(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
sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/jqt
sed -i -e "s#DATADIR='.*'#DATADIR='$(datadir)'#" $(bindir)/sake

uninstall:
rm --verbose --force -- $(addprefix $(prefix)/,$(wildcard bin/*))
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ The file `Makefile` concentrates all the routine procedures, like running the te
or install last versions of scripts in the system directories. The main defined _targets_
are:

* `list`: list all targets defined in the Makefile.

* `check`: run the _jqt_ tests. This is the default target.

* `clean`: remove all files generated during tests execution.
Expand All @@ -39,8 +41,6 @@ are:

* `uninstall`: remove installed files from the system directories.

* `help`: list all targets defined in the Makefile.

### Installation

In systems with the GNU software installed tools such as [Bash](https://www.gnu.org/software/bash/),
Expand All @@ -50,7 +50,7 @@ or [Pandoc](http://pandoc.org/); for example, in recent _Fedora Linux_ distribut
the following command will install all the extra software _jqt_ needs:

```zsh
$ sudo dnf -y install make general-purpose-preprocessor jq pandoc PyYAML
$ sudo dnf -y install make general-purpose-preprocessor jq pandoc python2-pyyaml
```

To install _jqt_ simply run `make install` on the _jqt_ repository top
Expand All @@ -67,7 +67,7 @@ _jqt_ top directory:
```zsh
$ sudo mkdir -p /usr/local/bin /usr/local/share/jqt
$ sudo cp bin/* /usr/local/bin
$ sudo cp share/* /usr/local/share/jqt
$ sudo cp -r share/* /usr/local/share/jqt
$ [[ $PATH =~ /usr/local/bin ]] || echo 'Add /usr/local/bin to your PATH'
```

Expand All @@ -84,9 +84,9 @@ another `jqt` uses.

### Documentation

The directory [`docs`](./docs/) contains the source files for _jqt_ documentation, and is in itself a subproject with his
own makefile. Please see the directory [`docs`](./docs/) for all information on
this subproject.
The directory [`docs`](./docs/) contains the source files for _jqt_
documentation. Please see the directory [`docs`](./docs/) for all information
on this subproject.

<!--
vim:ts=4:sw=4:ai:et:fileencoding=utf8:syntax=markdown
Expand Down
70 changes: 70 additions & 0 deletions bin/sake
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

#
# Wraps make
#

# Options
set -o errexit -o noglob -o nounset -o pipefail
shopt -s expand_aliases

# Script name
declare -r SELF=${0##*/}

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

# GMake call
declare -ri CORES=2
declare -ra makeflags=(
--jobs=$(( CORES * 150 / 100 )) # CORES * 1.5
--makefile=Sakefile
--output-sync=target
)
alias _sake='exec make "${makeflags[@]}"'

# Check project on current directory
if test ! -e Sakefile; then
echo 1>&2 "${SELF}: no \`Sakefile\` found."
exit 1
fi
if test ! -e config.yaml && test ! -e config.json; then
echo 1>&2 "${SELF}: no \`config.yaml\` or \`config.json\` file found."
exit 1
fi

# Check arguments
[[ $# == 0 ]] && set -- build

# Run _sake
case $1 in
help)
echo 1>&2 "${SELF}: Target \`help\` not implemented."
exit 1
;;
new)
echo 1>&2 "${SELF}: Target \`new\` not implemented."
exit 1
;;
list)
echo 'Usage: sake [goal] [[options] [variable=string] ...]'
echo 'Goals:'
_sake --jobs=1 --dry-run --print-data-base --question 2>&1 \
| grep -v '^[SmM]akefile' \
| awk '/^[^ \t.%][-A-Za-z0-9_.]*:/ { print $1 }' \
| sort --unique \
| sed 's/:\+$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=5
;;
touch)
if test -e config.yaml; then touch config.yaml; else touch config.json; fi
shift
_sake build "$@"
;;
*)
_sake "$@"
;;
esac

# vim:ai:sw=4:ts=4:et:syntax=sh
29 changes: 24 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ predefined variables:

In the configuration file you can assign new values to all predefined variables
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`.
You can modify this variable at the very beggining of your `Sakefile`.

## Page variables

Expand Down Expand Up @@ -87,13 +87,32 @@ content/extras/indexes/name.html

# _Sake_: static site build automation system

## Current _GMake_ commands
## Sakefile

_Sake_ managed projects must have a makefile named `Sakefile`, and this
makefile must contain the following include:

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

## Current _Sake_ commands

Targets not defined now: `help`, `new`.

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

## Autocompletion

Hint (on _Fedora_): to enable autocompletion for `sake` do this:

```
$ cd /usr/share/bash-completion/completions
$ sudo sed -i make -e '/^complete -F/s/$/ sake/'
$ sudo ln -s make sake
```

<!--
Expand Down
43 changes: 18 additions & 25 deletions docs/Makefile → docs/Sakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,41 @@
# independent, valid for any project without any change. This should be
# the only makefile to edit by hand!
#
# Variables used:
# Root
#
# Variables modified:
# JQTFLAGS

########################################################################
# Variables to define before include if default values must be changed.
########################################################################

#Meta := .meta
#JQTFLAGS +=
#VERBOSE := 1
#TRACE := 1
#VNU := java -jar /usr/local/vnu/vnu.jar

include make.d/Makefile.make
########################################################################
# Starting makefile
########################################################################

# Last phase, after metadata configuration.
ifdef __build
include $(SAKE)/make.d/main.make

########################################################################
# Build pages options.
# Last phase, after metadata configuration.
########################################################################
ifdef __build

# Pandoc options
# Add some Pandoc options
JQTFLAGS += -5 --toc-depth=4

########################################################################
# HTML 5 validation.
# experimental
########################################################################

# Download vnu.jar from `https://github.com/validator/validator/releases`.

.PHONY: h5.valid h5.lint

# Validation tool.
VNU := /usr/local/vnu/vnu.jar

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

# Validation with warnings.
h5.lint: build
@xmlwf $(Root)/*.html
@java -jar $(VNU) --format text $(Root)/*.html
depend:
grep -r '<%include\s\+[^>]\+>' blocks/ layouts/\
| sed -e 's/:.*<%include\s\+/\t/;s/>.*$$//' \
| sort

endif # __build

Expand Down
2 changes: 1 addition & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ defaults:
lang: *lang
Layout: page-toc
Datasets:
- snippets
- snippets.md
Dependencies:
- layouts/default.html
- content/macros.m
Expand Down
6 changes: 6 additions & 0 deletions docs/content/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ The CSS minimization is not extremely aggressive, but is safe and fast.

## Tools

### Build automation

One step over any templating system is a static site generator. A companion
site generator to <%cite jqt> is <%cite sake>, a simple wrapper to
<%cite 'GNU Make'> used to build this very same site.

### Data conversion

When preparing data inputs sometimes you need to mix files in several formats.
Expand Down
26 changes: 0 additions & 26 deletions docs/make.d/tools.make

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# VERBOSE
# TRACE

TRACE ?=
VERBOSE ?=
export TRACE ?=
export VERBOSE ?=

########################################################################
# Prerequisites.
Expand All @@ -26,6 +26,9 @@ MAKECMDGOALS ?= build
# Make configuration.
########################################################################

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

# Disable builtins.
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --no-builtin-variables
Expand Down
25 changes: 22 additions & 3 deletions docs/make.d/Makefile.make → share/sake/make.d/main.make
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
########################################################################
# Makefile.make -- Main makefile.
# main.make -- Main makefile.
#
# Imported variables:
# SAKE
# DATADIR
#
# Variables:
# $(Meta)
# Meta
# Rules:
# $(Meta) directory target and clobber target
#
Expand All @@ -18,7 +22,7 @@ MDIR := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
include $(MDIR)/configuration.make

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

########################################################################
# Metadata directory for all generated make and metadata files.
Expand Down Expand Up @@ -47,6 +51,15 @@ endif
# Check command line sanity.
########################################################################

# TODO: check only one target is present?

# Target 'clean' must be alone.
ifeq (clean,$(filter clean,$(MAKECMDGOALS)))
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)))
Expand Down Expand Up @@ -129,6 +142,12 @@ $(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
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/make.d/phase1.make → share/sake/make.d/phase1.make
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# $(Meta)/phase1.make
# $(Root) directory rule and clobber and clean targets

SUPER := $(MDIR)/Makefile.make
SUPER := $(MDIR)/main.make

########################################################################
# Files derived from user defined configuration file.
Expand Down Expand Up @@ -63,7 +63,7 @@ $(Meta)/site.json: $(Meta)/config.json $(MDIR)/phase1_site.jq
#
$(Meta)/phase1.make: $(Meta)/site.json $(MDIR)/phase1.jq
$(info ==> $@)
jq --raw-output \
jq --raw-output \
--from-file $(MDIR)/phase1.jq \
< $< > $@

Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 77534ea

Please sign in to comment.