Skip to content
This repository has been archived by the owner on Feb 15, 2021. It is now read-only.

Commit

Permalink
Rewrite makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
martinthomson committed Dec 21, 2015
1 parent 8507380 commit ee42a82
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 54 deletions.
144 changes: 90 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,64 +1,100 @@
RESPEC_BRANCH=gh-pages
SUPPORTDIR ?= $(CURDIR)/support
REPOS="https://github.com/w3c/respec https://github.com/dontcallmedom/webidl-checker https://github.com/dontcallmedom/widlproc https://github.com/dontcallmedom/linkchecker https://github.com/htacg/tidy-html5"
LINEWRAP=false
LINEWRAPLENGTH=100

INPUT=`cat W3CTRMANIFEST|head -1|cut -d '?' -f 1`

.PHONY: support
support:
@mkdir -p $(SUPPORTDIR)
@for repo in "$(REPOS)"; do \
git clone $$repo $(SUPPORTDIR)/`basename $$repo`;\
done
@cd $(SUPPORTDIR)/respec && git checkout $(RESPEC_BRANCH) && cd ..
@cd $(SUPPORTDIR)/tidy-html5/build/cmake && cmake ../.. && make
@cd $(SUPPORTDIR)/widlproc && make obj/widlproc && cd ..
BUILDDIR ?= $(CURDIR)/build
REPOS = https://github.com/w3c/respec|gh-pages https://github.com/dontcallmedom/webidl-checker https://github.com/dontcallmedom/widlproc https://github.com/dontcallmedom/linkchecker https://github.com/htacg/tidy-html5
TIDYCONF ?= $(firstword $(wildcard $(CURDIR)/tidy.config tidy.config))
LINEWRAP ?= false

.PHONY: travissetup
# .travis.yml need to install libwww-perl libcss-dom-perl python-lxml
travissetup: support
@pip install html5lib html5validator
ifndef TIDY
TIDY = $(SUPPORTDIR)/tidy-html5/build/cmake/tidy
BUILD_TIDY = true
endif
WIDLPROC_PATH ?= $(SUPPORTDIR)/widlproc/obj/widlproc

INPUT = $(shell head -1 W3CTRMANIFEST | cut -d '?' -f 1)
OUTPUT = $(BUILDDIR)/output.html

.PHONY: setup
setup: support
sudo apt-get install libwww-perl libcss-dom-perl perl phantomjs python2.7 python-pip python-lxml cmake
sudo pip install html5lib html5validator
.PHONY: check
check: tidycheck respec webidl html5valid linkcheck

.PHONY: tidycheck
tidycheck: $(TIDY)
$(TIDY) -quiet -config $(TIDYCONF) -errors $(INPUT)
# optionally check line wrapping
ifeq (true,$(LINEWRAP))
$(TIDY) -quiet -config $(TIDYCONF) $(INPUT) | diff -q $(INPUT) - || \
(echo $(INPUT)" has lines not wrapped at "$(LINEWRAPLENGTH)" characters" && false)
endif

.PHONY: update
update:
for repo in "$(REPOS)"; do \
echo $$repo && cd $(SUPPORTDIR)/`basename $$repo` && git pull ; cd .. ;\
done
@cd $(SUPPORTDIR)/respec && git checkout $(RESPEC_BRANCH) && cd ..
@cd $(SUPPORTDIR)/widlproc && make obj/widlproc && cd ..
$(OUTPUT): $(INPUT) $(SUPPORTDIR)/respec
phantomjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 $(SUPPORTDIR)/respec/tools/respec2html.js -e -w $< $@

.PHONY: build
build:
@mkdir -p build
# copy auxiliary files listed in W3CTRMANIFEST
cat W3CTRMANIFEST|tail -n +2|xargs -I '{}' cp --parent '{}' build
.PHONY: webidl
webidl: $(OUTPUT) $(SUPPORTDIR)/webidl-checker $(WIDLPROC_PATH)
WIDLPROC_PATH=$(WIDLPROC_PATH) python $(SUPPORTDIR)/webidl-checker/webidl-check $< > /dev/null

.PHONY: check
check: build
# check input to respec is clean
$(SUPPORTDIR)/tidy-html5/build/cmake/tidy -quiet -errors $(INPUT)
# optionally check line wrapping
if [ "$(LINEWRAP)" = "true" ] ; then \
$(SUPPORTDIR)/tidy-html5/build/cmake/tidy -quiet --tidy-mark no -i -w $(LINEWRAPLENGTH) -utf8 $(INPUT)|diff -q $(INPUT) - || (echo $(INPUT)" has lines not wrapped at "$(LINEWRAPLENGTH)" characters" && false);\
fi
# check respec validity
phantomjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 $(SUPPORTDIR)/respec/tools/respec2html.js -e -w $(INPUT) build/output.html
# check WebIDL validity
WIDLPROC_PATH=$(SUPPORTDIR)/widlproc/obj/widlproc python $(SUPPORTDIR)/webidl-checker/webidl-check build/output.html > /dev/null
.PHONY: html5valid
html5valid: $(OUTPUT)
# check that resulting HTML is valid
html5validator --root build/
# check internal links (we exclude http links to avoid reporting SNAFUs)
perl -T $(SUPPORTDIR)/linkchecker/bin/checklink -S 0 -q -b -X "^http(s)?:" build/output.html
html5validator --root $(dir $<)

.PHONY: linkcheck
linkcheck: $(OUTPUT) $(SUPPORTDIR)/linkchecker
# check internal links only (we exclude http links to avoid reporting SNAFUs)
perl -T $(SUPPORTDIR)/linkchecker/bin/checklink -S 0 -q -b -X "^http(s)?:" $<

.PHONY: tidy
tidy: $(TIDY)
$(TIDY) -quiet -config $(TIDYCONF) -m $(INPUT)

## Build prerequisites

include $(SUPPORTDIR)/repos.mk

$(SUPPORTDIR) $(BUILDDIR):
@mkdir -p $@

.PHONY: linewrap
linewrap:
$(SUPPORTDIR)/tidy-html5/build/cmake/tidy -quiet --tidy-mark no -i -w $(LINEWRAPLENGTH) -utf8 -m $(INPUT)
to_url = $(firstword $(subst |, ,$(1)))
branch_arg = $(if $(word 2,$(subst |, ,$(1))),-b $(word 2,$(subst |, ,$(1))),)
to_dir = $(SUPPORTDIR)/$(notdir $(call to_url,$(1)))
to_dot = $(SUPPORTDIR)/.$(notdir $(call to_url,$(1)))

$(SUPPORTDIR)/repos.mk: $(SUPPORTDIR)
@echo ' $(foreach repo,$(REPOS),$(call to_dir,$(repo)): $(call to_dot,$(repo))\n$(call to_dot,$(repo)): $<\n\t[ -d $(call to_dir,$(repo)) ] && git -C $(call to_dir,$(repo)) pull || git clone --depth 5 $(call branch_arg,$(repo)) $(call to_url,$(repo)) $(call to_dir,$(repo))\n\t@touch $$@\n\n)' > $@

ifdef BUILD_TIDY
$(TIDY): $(SUPPORTDIR)/tidy-html5
@cd $(SUPPORTDIR)/tidy-html5/build/cmake && cmake -DCMAKE_BUILD_TYPE=Release ../..
@$(MAKE) -C $(SUPPORTDIR)/tidy-html5/build/cmake
endif

$(WIDLPROC_PATH): $(SUPPORTDIR)/widlproc
@$(MAKE) -C $< obj/widlproc

.PHONY: update force_update
update: force_update $(foreach repo,$(REPOS),$(call to_dir,$(repo))) $(tidy) $(WIDLPROC_PATH)
force_update:
@touch $(SUPPORTDIR)/repos.mk

## Copy auxiliary files listed in W3CTRMANIFEST

BUILD_FILES = $(shell tail -n +2 W3CTRMANIFEST)
.PHONY: build_files
build_files: $(addprefix $(BUILDDIR),$(BUILD_FILES))
include $(SUPPORTDIR)/build.mk
$(SUPPORTDIR)/build.mk: W3CTRMANIFEST $(SUPPORTDIR)
@echo ' $(foreach f,$(BUILD_FILES),$(BUILDDIR)/$(f): $(f) $(BUILDDIR)\n\t@cp -f $$< $$@\n)' > $@

## Machine setup

.PHONY: travissetup
# .travis.yml need to install libwww-perl libcss-dom-perl python-lxml
travissetup: support
pip install html5lib html5validator

.PHONY: setup
setup:
sudo apt-get install libwww-perl libcss-dom-perl perl phantomjs python2.7 python-pip python-lxml cmake
sudo pip install html5lib html5validator

clean::
rm -rf $(CURDIR)/support $(CURDIR)/build
4 changes: 4 additions & 0 deletions tidy.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
char-encoding: utf8
indent: yes
wrap: 100
tidy-mark: no

0 comments on commit ee42a82

Please sign in to comment.