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

Commit

Permalink
Merge pull request #6 from martinthomson/rewrite
Browse files Browse the repository at this point in the history
Rewrite makefile
  • Loading branch information
dontcallmedom committed Jan 19, 2016
2 parents 8507380 + 0d8a9f8 commit 4c09a21
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 55 deletions.
146 changes: 91 additions & 55 deletions Makefile
@@ -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 ..
SUPPORTDIR ?= support
BUILDDIR ?= 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 tidy.config webrtc-respec-ci/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 webidl html5valid linkcheck

.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 ..
.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: 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 $@

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)))

.PHONY: linewrap
linewrap:
$(SUPPORTDIR)/tidy-html5/build/cmake/tidy -quiet --tidy-mark no -i -w $(LINEWRAPLENGTH) -utf8 -m $(INPUT)
$(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

## Build a processed copy of the spec

BUILD_INPUT = $(shell tail -n +2 W3CTRMANIFEST)
BUILD_FILES = $(addprefix $(BUILDDIR)/,$(BUILD_INPUT))
include $(SUPPORTDIR)/build.mk
$(SUPPORTDIR)/build.mk: W3CTRMANIFEST $(SUPPORTDIR)
@echo ' $(foreach f,$(BUILD_INPUT),$(BUILDDIR)/$(f): $(f) $(BUILDDIR)\n\t@mkdir -p $$(dir $$@)\n\tcp -f $$< $$@\n)' > $@

$(OUTPUT): $(INPUT) $(SUPPORTDIR)/respec $(BUILD_FILES)
phantomjs --ignore-ssl-errors=true --ssl-protocol=tlsv1 $(SUPPORTDIR)/respec/tools/respec2html.js -e -w $< $@


## Machine setup

.PHONY: travissetup
# .travis.yml need to install libwww-perl libcss-dom-perl python-lxml
travissetup::
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
@@ -0,0 +1,4 @@
char-encoding: utf8
indent: yes
wrap: 100
tidy-mark: no

0 comments on commit 4c09a21

Please sign in to comment.