Skip to content

Commit

Permalink
Protected target clobber
Browse files Browse the repository at this point in the history
  • Loading branch information
fadado committed Apr 5, 2017
1 parent cfe3e83 commit 9b250e5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
59 changes: 33 additions & 26 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ Metadata := .yummy
# Layouts
# Styles

# While clobbering don't introspect
ifeq (,$(filter clobber,$(MAKECMDGOALS)))

# Include metadata
include make.d/metadata.make

endif

########################################################################
# jqt command with options
########################################################################
Expand Down Expand Up @@ -123,29 +128,30 @@ ifdef __globals__

# Default target
all: $(Targets) static
@echo 1>&2 'Imprimatur!'

# Destination directory
$(Destination):
$(info ==> $@)
mkdir $@ >/dev/null 2>&1 || true
@mkdir $@ >/dev/null 2>&1 || true

# Copy assets
static: | $(Destination)
cp --verbose --recursive --update $(Assets)/* $(Destination) \
@cp --verbose --recursive --update $(Assets)/* $(Destination) \
| sed "s/^.*-> ./==> /;s/.$$//"

# Snippets
$(Metadata)/snippets.json: $(Content)/snippets.yaml \
| $(Metadata)
$(info ==> $@)
jqt -T < $< | yaml2json > $@
@jqt -T < $< | yaml2json > $@

# HTML pages
define Target
$(Destination)/$(1).html: $(Content)/$(1).md $(Layouts)/$(2).html \
| $(Destination)
$$(info ==> $$@)
$(JQT) -d $$< $(Layouts)/$(2).html | $(DETAILS) > $$@
@$(JQT) -d $$< $(Layouts)/$(2).html | $(DETAILS) > $$@
endef

$(eval $(call Target,$(Home),page))
Expand All @@ -154,12 +160,12 @@ $(foreach p,$(Other),$(eval $(call Target,$(p),page-toc)))
# CSS stylesheet
$(Destination)/styles.css: $(Styles)/page.css
$(info ==> $@)
jqt -P CSS-min -I$(Styles) < $< > $@
@jqt -P CSS-min -I$(Styles) < $< > $@

# Man page: jqt(1)
$(ManPage): $(Content)/$(JQT_Man).markdown
$(info ==> $@)
$(GPP_MD) -I$(Content) < $< \
@$(GPP_MD) -I$(Content) < $< \
| pandoc --standalone --from markdown --to man \
| gzip > $@

Expand All @@ -169,48 +175,49 @@ endif # __globals__
# Utilities
########################################################################

.PHONY: clean clobber build help

clean:
@rm -rf $(Destination)/* $(ManPage)

ifdef __globals__
clobber:
@rm -rf $(Destination) $(ManPage) $(Metadata)
else
clobber: ;
endif

build: clean all

# Show targets
.PHONY: help
help:
echo 'Targets:'; \
@echo 'Targets:'; \
$(MAKE) --print-data-base --just-print 2>&1 \
| grep -v '^[mM]akefile' \
| awk '/^[^ \t.%][-A-Za-z0-9_]*:/ { print $$1 }' \
| sort --unique \
| sed 's/:\+$$//' \
| pr --omit-pagination --indent=4 --width=80 --columns=4

ifdef __globals__

.PHONY: clean clobber build valid lint

clean:
rm -rf $(Destination)/* $(ManPage)

clobber: clean
rm -rf $(Destination) $(Metadata)

build: clean all
.PHONY: valid lint

# Validation using vnu.jar
VNU := /usr/local/vnu/vnu.jar
valid: all
xmlwf $(Destination)/*.html
java -jar $(VNU) --errors-only --format gnu $(Destination)/*.html
@xmlwf $(Destination)/*.html
@java -jar $(VNU) --errors-only --format gnu $(Destination)/*.html

# Validation with warnings using vnu.jar
lint: all
xmlwf $(Destination)/*.html
java -jar $(VNU) --format text $(Destination)/*.html
@xmlwf $(Destination)/*.html
@java -jar $(VNU) --format text $(Destination)/*.html

# Generate Help text (need explicit call: `make /tmp/help`)
/tmp/help: $(Content)/help.markdown
$(info ==> $@)
jqt -P MarkDown -I$(Content) < $< \
@jqt -P MarkDown -I$(Content) < $< \
| pandoc --from markdown --to plain - \
| sed '1,7b;/^$$/d;s/_\([A-Z]\+\)_/\1/g;/^[^A-Z]/s/^/ /' \
> $@

endif # __globals__

# vim:ai:sw=8:ts=8:noet:fileencoding=utf8:syntax=make
16 changes: 10 additions & 6 deletions docs/make.d/config.make
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ ifndef version_test
$(error GNU Make version $(MAKE_VERSION); version >= 3.82 is needed)
endif

#!# Only one target at the same time
#!MAKECMDGOALS ?= all
#!ifneq (1,$(words $(MAKECMDGOALS)))
#!$(error Only one target accepted!)
#!endif
# Only one target at the same time
MAKECMDGOALS ?= all

# Check 'root' intentions
ifeq (,$(filter install uninstall,$(MAKECMDGOALS)))
Expand All @@ -25,6 +22,13 @@ else
SUDO := sudo
endif

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

########################################################################
# Configuration
########################################################################
Expand All @@ -37,7 +41,7 @@ MAKEFLAGS += --no-builtin-variables
MAKEFLAGS += --warn-undefined-variables

# Make will not print the recipe used to remake files.
.SILENT:
#.SILENT:

# Eliminate use of the built-in implicit rules. Also clear out the
# default list of suffixes for suffix rules.
Expand Down
8 changes: 4 additions & 4 deletions docs/make.d/metadata.make
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Metadata directory
$(Metadata):
$(info ==> $@)
mkdir $@ >/dev/null 2>&1 || true
@mkdir $@ >/dev/null 2>&1 || true

#
# Configuration files
Expand All @@ -35,7 +35,7 @@ ifeq (config.yaml, $(wildcard config.yaml))
$(Metadata)/config.json: config.yaml \
| $(Metadata)
$(info ==> $@)
yaml2json < $< \
@yaml2json < $< \
| jq --sort-keys '$(JSON_GLOBALS)' > $@

else ifeq (config.json, $(wildcard config.json))
Expand All @@ -44,7 +44,7 @@ else ifeq (config.json, $(wildcard config.json))
$(Metadata)/config.json: config.json \
| $(Metadata)
$(info ==> $@)
jqt -Pjson < $< \
@jqt -Pjson < $< \
| jq --sort-keys '$(JSON_GLOBALS)' > $@

else
Expand All @@ -69,7 +69,7 @@ endef
# Create makefile with globals
$(Metadata)/globals.make: $(Metadata)/config.json
$(info ==> $@)
jq --sort-keys \
@jq --sort-keys \
--raw-output \
'$(MAKE_GLOBALS)' \
< $< > $@
Expand Down

0 comments on commit 9b250e5

Please sign in to comment.