Created
December 11, 2012 19:56
-
-
Save wiseman/4261580 to your computer and use it in GitHub Desktop.
Example makefile for google closure compilation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From http://oinksoft.com/static/closure-tools/Makefile.example | |
# This is an example Makefile for a project that uses all of the Closure | |
# Tools: Compiler, Library, Templates, Stylesheets, and Linter. | |
# | |
# `make deps`: Download and build all dependencies (compiler, etc.). | |
# | |
# `make`: Compile the project for development (does not use Closure | |
# Stylesheet map $(CSS_MAP), uses compilation flags that should be | |
# good for development). | |
# | |
# `make closure-final`: Compile the project for release. | |
# | |
# `make clean`: Remove compiled files. | |
# | |
# `make clean-deps`: Remove all files added by `make deps`. | |
# | |
# `make lint`: Run the Closure Linter over project source code. | |
# | |
# NOTE: This task depends on a bash function `join-with` to exclude | |
# JavaScript generated by Closure Templates. It is defined as | |
# follows: | |
# | |
# # usage: join-with SEPARATOR ITEM ITEM2 ITEM3 ... | |
# join-with() { | |
# local IFS="$1" | |
# shift | |
# echo "$*" | |
# } | |
# | |
# `make js-size`: Recompiles and reports the file size of the generated | |
# JavaScript. | |
# | |
# There are other sub-tasks below not documented here. | |
.PHONY: all clean closure closure-final js js-final js-size lint gss \ | |
gss-final tpl deps download-deps venv-fetch build-deps venv-build \ | |
venv clean-deps | |
# Common | |
BUILD = build | |
SRC = src | |
NAMESPACE = oink.edit | |
all: closure | |
clean: | |
rm -f $(BUILD)/*.js $(BUILD)/*.css $(CSS_MAP) | |
closure: gss tpl js | |
closure-final: gss-final tpl js-final | |
# JavaScript | |
JS_SRC = $(SRC)/js | |
ROOT_NS = $(NAMESPACE).main | |
MIN_SCRIPT = $(BUILD)/$(NAMESPACE).min.js | |
TMP_MIN_SCRIPT = $(BUILD)/$(NAMESPACE).min.js.part | |
G_CC_FLAGS = --root=$(G_CLIB_GOOG) \ | |
--root=$(G_CLIB_3P) \ | |
--root=$(JS_SRC) \ | |
--root=$(SOY_JS) \ | |
--namespace=$(ROOT_NS) \ | |
--output_mode=compiled \ | |
--compiler_jar=$(G_CC) \ | |
-f --js=$(G_CLIB_GOOG)/deps.js \ | |
-f --generate_exports \ | |
-f --compilation_level=ADVANCED_OPTIMIZATIONS | |
G_CC_DFLAGS = $(G_CC_FLAGS) \ | |
-f --formatting=PRETTY_PRINT \ | |
-f --debug \ | |
-f --jscomp_warning=accessControls \ | |
-f --jscomp_warning=ambiguousFunctionDecl \ | |
-f --jscomp_warning=checkRegExp \ | |
-f --jscomp_warning=checkTypes \ | |
-f --jscomp_warning=checkVars \ | |
-f --jscomp_warning=const \ | |
-f --jscomp_warning=constantProperty \ | |
-f --jscomp_warning=deprecated \ | |
-f --jscomp_warning=duplicateMessage \ | |
-f --jscomp_warning=es5Strict \ | |
-f --jscomp_warning=externsValidation \ | |
-f --jscomp_warning=fileoverviewTags \ | |
-f --jscomp_warning=globalThis \ | |
-f --jscomp_warning=internetExplorerChecks \ | |
-f --jscomp_warning=invalidCasts \ | |
-f --jscomp_warning=missingProperties \ | |
-f --jscomp_warning=nonStandardJsDocs \ | |
-f --jscomp_warning=strictModuleDepCheck \ | |
-f --jscomp_warning=typeInvalidation \ | |
-f --jscomp_warning=undefinedNames \ | |
-f --jscomp_warning=undefinedVars \ | |
-f --jscomp_warning=unknownDefines \ | |
-f --jscomp_warning=uselessCode \ | |
-f --jscomp_warning=visibility | |
G_CC_PFLAGS = $(G_CC_FLAGS) \ | |
-f --js=$(CSS_MAP) | |
G_LINT_FLAGS = --exclude_files "$(CSS_MAP),$$(join-with , $(JS_TEMPLATES)/*)" \ | |
--recurse $(JS_SRC) \ | |
--strict \ | |
--jslint_error=all \ | |
js: | |
@$(G_CLIB_BUILD) $(G_CC_DFLAGS) --output_file=$(TMP_MIN_SCRIPT) \ | |
&& mv $(TMP_MIN_SCRIPT) $(MIN_SCRIPT) | |
js-final: | |
@$(G_CLIB_BUILD) $(G_CC_PFLAGS) --output_file=$(TMP_MIN_SCRIPT) \ | |
&& mv $(TMP_MIN_SCRIPT) $(MIN_SCRIPT) | |
js-size: closure-final | |
@du -h $(MIN_SCRIPT) | |
@du -h $(MIN_SS) | |
lint: | |
@bash -c '$(ACTIVENV) && source src/bash/utils.bash && gjslint $(G_LINT_FLAGS)' | |
# Stylesheets | |
MIN_SS = $(BUILD)/$(NAMESPACE).min.css | |
TMP_MIN_SS = $(BUILD)/$(NAMESPACE).min.css.part | |
CSS_MAP = $(JS_SRC)/.css_map.js | |
GSS_SRC = $(SRC)/gss/* | |
G_SS_FLAGS = | |
G_SS_PFLAGS = $(G_SS_FLAGS) \ | |
--output-renaming-map-format CLOSURE_COMPILED \ | |
--output-renaming-map $(CSS_MAP) \ | |
--rename CLOSURE | |
gss: | |
@java -jar $(G_SS) $(G_SS_FLAGS) --output-file $(TMP_MIN_SS) $(GSS_SRC) \ | |
&& mv $(TMP_MIN_SS) $(MIN_SS) | |
@echo $(MIN_SS) | |
gss-final: | |
@java -jar $(G_SS) $(G_SS_PFLAGS) --output-file $(TMP_MIN_SS) $(GSS_SRC) \ | |
&& mv $(TMP_MIN_SS) $(MIN_SS) | |
@echo $(MIN_SS) | |
@echo $(CSS_MAP) | |
# Templates | |
TPL_SRC = $(SRC)/soy | |
SOY_JS = $(G_TPL_ROOT)/javascript | |
JS_TEMPLATES = $(JS_SRC)/oink/edit/tpl | |
G_TPL_FLAGS = --codeStyle STRINGBUILDER \ | |
--cssHandlingScheme goog \ | |
--outputPathFormat $(JS_TEMPLATES)/{INPUT_FILE_NAME_NO_EXT}.js \ | |
--shouldGenerateJsdoc \ | |
--shouldProvideRequireSoyNamespaces | |
tpl: | |
@rm -rf $(JS_TEMPLATES)/*.js | |
@java -jar $(G_TPL) $(G_TPL_FLAGS) $(TPL_SRC)/*.soy | |
@ls -1 $(JS_TEMPLATES)/*.js | |
# Dependencies | |
DEPS_ROOT = .contrib | |
G_ROOT = $(DEPS_ROOT)/goog-closure | |
VENV = $(DEPS_ROOT)/venv | |
ACTIVENV = source $(VENV)/bin/activate | |
G_CC_URL = http://closure-compiler.googlecode.com/svn/trunk/ | |
G_CLIB_URL = http://closure-library.googlecode.com/svn/trunk/ | |
G_TPL_URL = http://closure-templates.googlecode.com/svn/trunk/ | |
G_LINT_URL = http://closure-linter.googlecode.com/svn/trunk/ | |
G_SS_URL = https://code.google.com/p/closure-stylesheets/ | |
G_CC_ROOT = $(G_ROOT)/compiler | |
G_CLIB_ROOT = $(G_ROOT)/library | |
G_TPL_ROOT = $(G_ROOT)/templates | |
G_LINT_ROOT = $(G_ROOT)/linter | |
G_SS_ROOT = $(G_ROOT)/stylesheets | |
G_CC = $(G_CC_ROOT)/build/compiler.jar | |
G_CLIB_BUILD = $(G_CLIB_ROOT)/closure/bin/build/closurebuilder.py | |
G_CLIB_GOOG = $(G_CLIB_ROOT)/closure/goog | |
G_CLIB_3P = $(G_CLIB_ROOT)/third_party/closure/goog | |
G_TPL = $(G_TPL_ROOT)/build/SoyToJsSrcCompiler.jar | |
G_SS = $(G_SS_ROOT)/build/closure-stylesheets.jar | |
deps: download-deps build-deps | |
download-deps: venv-fetch | |
mkdir -p $(G_ROOT) | |
svn co $(G_CC_URL) $(G_CC_ROOT) | |
svn co $(G_CLIB_URL) $(G_CLIB_ROOT) | |
svn co $(G_TPL_URL) $(G_TPL_ROOT) | |
git clone $(G_SS_URL) $(G_SS_ROOT) | |
venv-fetch: | |
svn co $(G_LINT_URL) $(G_LINT_ROOT) | |
build-deps: venv-build | |
cd $(G_CC_ROOT) && ant jar | |
cd $(G_TPL_ROOT) && ant SoyToJsSrcCompiler | |
cd $(G_SS_ROOT) && ant jar | |
venv-build: | |
virtualenv $(VENV) | |
bash -c '$(ACTIVENV) && cd $(G_LINT_ROOT) && python setup.py install' | |
venv: venv-fetch venv-build | |
clean-deps: | |
rm -rf $(DEPS_ROOT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment