Update README.md
[user-js.git] / Makefile
blobad6d81eea2202ed61a0e95e114e15596360b1aa2
1 SHELL=/bin/bash
3 .PHONY: all
4 all: whatdoesitdo tests
6 .PHONY: FORCE
7 FORCE:
9 ##### INSTALLATION METHODS #####
11 locked_user.js: user.js FORCE # generate a locked configuration file
12 sed 's/^user_pref/lockPref/' $< >| $@
14 systemwide_user.js: user.js FORCE # generate a system-wide configuration file
15 sed 's/user_pref(/pref(/' $< >| $@
17 debian_locked.js: user.js FORCE # generate a locked, system-wide configuration file
18 sed 's/^user_pref(\("[^"]\+"\),\s\+\([^)]\+\));\(\s*\/\/.*\)\?$$/pref(\1, \2, locked);/' $< >| $@
21 ##### TESTS #####
22 # Requirements: node-acorn shellcheck
24 .PHONY: tests
25 tests: test-acorn test-shellcheck # run all tests
27 .PHONY: test-acorn
28 test-acorn: # validate user.js syntax
29 acorn --silent user.js
31 .PHONY: test-shellcheck
32 test-shellcheck: # check/lint shell scripts
33 shellcheck *.sh
36 ##### DIFF GENERATION/COMPARISONS WIT UPSTREAM/TOR BROWSER #####
38 TBBBRANCH=tor-browser-68.8.0esr-9.5-1
39 000-tor-browser.js: FORCE # download Tor Browser custom configuration reference
40 wget -nv "https://gitweb.torproject.org/tor-browser.git/plain/browser/app/profile/firefox.js?h=$(TBBBRANCH)" -O $@
42 PREF_REGEX = ^\(user_\)\?pref/s/^.*pref("\([^"]\+\)",\s*\([^)]\+\).*$$
43 .PHONY: diff-tbb
44 diff-tbb: 000-tor-browser.js # differences between values from this user.js and tor browser's values
45 diff <(sed -n '/$(PREF_REGEX)/\1 = \2/p' user.js | sort) <(sed -n '/$(PREF_REGEX)/\1 = \2/p' $< | sort)
47 .PHONY: diff-tbb-2
48 diff-tbb-2: 000-tor-browser.js # differences between values from this user.js and tor browser's values (alternate method)
49 for setting in $$( comm -12 <(sed -n '/$(PREF_REGEX)/\1/p' user.js | sort) <(sed -n '/$(PREF_REGEX)/\1/p' $< | sort)); do diff <(grep "^\(user_\)\?pref(\"$${setting}\"" user.js | sed -n '/$(regex)/\1 = \2/p' | sort) <(grep "^\(user_\)\?pref(\"$${setting}\"" $< | sed -n '/$(regex)/\1 = \2/p' | sort); done
51 .PHONY: diff-tbb-missing-from-user.js
52 diff-tbb-missing-from-user.js: 000-tor-browser.js # preferences that are present in tor browser's defaults, but not in this user.js
53 comm -13 <(sed -n '/$(PREF_REGEX)/\1/p' user.js | sort) <(sed -n '/$(PREF_REGEX)/\1/p' $< | sort)
55 # specify wanted Firefox version/revision below (eg. "tip", "FIREFOX_AURORA_45_BASE", "9577ddeaafd85554c2a855f385a87472a089d5c0"). See https://hg.mozilla.org/mozilla-central/tags
56 SOURCEVERSION=tip
57 FIREFOX_SOURCE_PREFS= \
58 https://hg.mozilla.org/mozilla-central/raw-file/$(SOURCEVERSION)/modules/libpref/init/all.js \
59 https://hg.mozilla.org/mozilla-central/raw-file/$(SOURCEVERSION)/testing/profiles/common/user.js \
60 https://hg.mozilla.org/mozilla-central/raw-file/$(SOURCEVERSION)/testing/profiles/reftest/user.js \
61 https://hg.mozilla.org/mozilla-central/raw-file/$(SOURCEVERSION)/js/src/tests/user.js \
62 https://hg.mozilla.org/mozilla-central/raw-file/$(SOURCEVERSION)/browser/app/profile/firefox.js \
63 https://hg.mozilla.org/mozilla-central/raw-file/tip/devtools/client/preferences/debugger.js \
64 https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/branding/unofficial/pref/firefox-branding.js \
65 https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/branding/official/pref/firefox-branding.js \
66 https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/branding/nightly/pref/firefox-branding.js \
67 https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/branding/aurora/pref/firefox-branding.js \
68 https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/locales/en-US/firefox-l10n.js \
69 https://hg.mozilla.org/mozilla-central/raw-file/tip/browser/app/profile/channel-prefs.js
70 .PHONY: diff-sourceprefs.js
71 diff-sourceprefs.js: # download and sort all known preferences files from Firefox (mozilla-central) source
72 @for SOURCEFILE in $(FIREFOX_SOURCE_PREFS); do wget -nv "$$SOURCEFILE" -O - ; done | egrep "(^pref|^user_pref)" | sort --unique >| sourceprefs.js
74 .PHONY: diff-upstream-duplicates
75 diff-upstream-duplicates: diff-sourceprefs.js # preferences with common values with default Firefox configuration
76 @sed 's/^pref(/user_pref(/' sourceprefs.js | sed -E "s/[[:space:]]+/ /g" | sort > sourceprefs_sorted.js
77 @grep "^user_pref" user.js | sed -E "s/[[:space:]]+/ /g" | sort > userjs_sorted.js
78 @comm -1 -2 sourceprefs_sorted.js userjs_sorted.js
80 .PHONY: diff-upstream-missing-from-user.js
81 diff-upstream-missing-from-user.js: diff-sourceprefs.js # preferences present in firefox source but not covered by user.js
82 # configure ignored preferences in ignore.list
83 @SOURCE_PREFS=$$(egrep '(^pref|^user_pref)' $< | awk -F'"' '{print $$2}'); \
84 for SOURCE_PREF in $$SOURCE_PREFS; do \
85 grep "\"$$SOURCE_PREF\"" user.js ignore.list >/dev/null || echo "Not covered by user.js : $$SOURCE_PREF"; \
86 done | sort --unique
88 .PHONY: diff-upstream-deprecated
89 diff-upstream-deprecated: diff-sourceprefs.js # preferences in hardened user.js that are no longer present in firefox source
90 @HARDENED_PREFS=$$(egrep "^user_pref" user.js | cut -d'"' -f2); \
91 for HARDENED_PREF in $$HARDENED_PREFS; do \
92 grep "\"$$HARDENED_PREF\"" $< >/dev/null || echo "Deprecated : $$HARDENED_PREF"; \
93 done | sort --unique
95 .PHONY: diff-stats
96 diff-stats: diff-sourceprefs.js # count preferences number, various stats
97 @echo "$$(egrep "^user_pref" user.js | wc -l | cut -f1) preferences in user.js"
98 @echo "$$(wc -l $< | cut -d" " -f1) preferences in Firefox source"
101 ##### MISC #####
103 .PHONY: clean
104 clean: # clean automatically generated files/build/test artifacts
105 @rm -f sourceprefs.js sourceprefs_sorted.js userjs_sorted.js 000-tor-browser.js debian_locked.js systemwide_user.js
107 ##### DOCUMENTATION GENERATION #####
109 .PHONY: doc-whatdoesitdo
110 doc-whatdoesitdo: # generate the README "What does it do?" section
111 @./gen-readme.sh
113 .PHONY: doc-toc
114 doc-toc: # generate the README table of contents
115 @l2headers=$$(egrep "^## " README.md |cut -d" " -f1 --complement ); \
116 echo "$$l2headers" | while read line; do \
117 anchor=$$(echo "$$line" | tr '[:upper:]' '[:lower:]' | sed 's/ /-/g' | sed 's/\?//g'); \
118 echo "* [$$line](#$$anchor)"; \
119 done
121 .PHONY: help
122 help: # generate list of targets with descriptions
123 @sed -n '/^[a-z0-9]/s/^\(.\+\):.*\s\+#\s\+\(.\+\)$$/\1\t\2/p' $(MAKEFILE_LIST) | expand -t20