@ -20,31 +20,21 @@ MODULES = utils \
# ===== Directories =====
SRC_DIR = src
LIB_DIR = lib
BIN_DIR = bin
BROWSER_DIR = browser
SPEC_DIR = spec
BENCHMARK_DIR = benchmark
EXAMPLES_DIR = examples
LIB_DIR = lib
DIST_DIR = dist
DIST_WEB_DIR = $( DIST_DIR) /web
DIST_NODE_DIR = $( DIST_DIR) /node
# ===== Files =====
PARSER_SRC_FILE = $( SRC_DIR) /parser.pegjs
PARSER_OUT_FILE = $( SRC _DIR) /parser.js
PARSER_OUT_FILE = $( LIB_DIR) /parser.js
PEGJS_SRC_FILE = $( SRC_DIR) /peg .js
PEGJS_LIB_FILE = $( LIB_DIR) /peg .js
BROWSER_FILE_DEV = $( BROWSER_DIR) /peg-$( PEGJS_VERSION) .js
BROWSER_FILE_MIN = $( BROWSER_DIR) /peg-$( PEGJS_VERSION) .min .js
PEGJS_DIST_FILE_DEV = $( DIST_WEB_DIR) /peg-$( PEGJS_VERSION) .js
PEGJS_DIST_FILE_MIN = $( DIST_WEB_DIR) /peg-$( PEGJS_VERSION) .min.js
PACKAGE_JSON_FILE = package.json
CHANGELOG_FILE = CHANGELOG
LICENSE_FILE = LICENSE
README_FILE = README.md
VERSION_FILE = VERSION
VERSION_FILE = VERSION
# ===== Executables =====
@ -56,107 +46,86 @@ BENCHMARK_RUN = $(BENCHMARK_DIR)/run
# ===== Targets =====
# Default target
all : browser
# Generate the grammar parser
parser :
$( PEGJS) $( PARSER_SRC_FILE) $( PARSER_OUT_FILE)
# Build the PEG.js library
build :
mkdir -p $( LIB_DIR)
rm -f $( PEGJS_LIB_FILE)
# Build the browser version of the library
browser :
mkdir -p $( BROWSER_DIR)
rm -f $( BROWSER_FILE_DEV)
rm -f $( BROWSER_FILE_MIN)
# The following code is inspired by CoffeeScript's Cakefile.
echo '/*' >> $( PEGJS_LI B_FILE)
echo " * PEG.js $( PEGJS_VERSION) " >> $( PEGJS_LI B_FILE)
echo ' *' >> $( PEGJS_LI B_FILE)
echo ' * http://pegjs.majda.cz/' >> $( PEGJS_LI B_FILE)
echo ' *' >> $( PEGJS_LI B_FILE)
echo ' * Copyright (c) 2010-2012 David Majda' >> $( PEGJS_LI B_FILE)
echo ' * Licensed under the MIT license' >> $( PEGJS_LI B_FILE)
echo ' */' >> $( PEGJS_LI B_FILE)
echo 'var PEG = (function(undefined) {' >> $( PEGJS_LI B_FILE)
echo ' var modules = {' >> $( PEGJS_LI B_FILE)
echo ' define: function(name, factory) {' >> $( PEGJS_LI B_FILE)
echo ' var dir = name.replace(/(^|\/)[^/]+$$/, "$$1"),' >> $( PEGJS_LI B_FILE)
echo ' module = { exports: {} };' >> $( PEGJS_LI B_FILE)
echo '' >> $( PEGJS_LI B_FILE)
echo ' function require(path) {' >> $( PEGJS_LI B_FILE)
echo ' var name = dir + path,' >> $( PEGJS_LI B_FILE)
echo ' regexp = /[^\/]+\/\.\.\/|\.\//;' >> $( PEGJS_LI B_FILE)
echo '' >> $( PEGJS_LI B_FILE)
echo " /* Can't use /.../g because we can move backwards in the string. */" >> $( PEGJS_LI B_FILE)
echo ' while (regexp.test(name)) {' >> $( PEGJS_LI B_FILE)
echo ' name = name.replace(regexp, "");' >> $( PEGJS_LI B_FILE)
echo ' }' >> $( PEGJS_LI B_FILE)
echo '' >> $( PEGJS_LI B_FILE)
echo ' return modules[name];' >> $( PEGJS_LI B_FILE)
echo ' }' >> $( PEGJS_LI B_FILE)
echo '' >> $( PEGJS_LI B_FILE)
echo ' factory(module, require);' >> $( PEGJS_LI B_FILE)
echo ' this[name] = module.exports;' >> $( PEGJS_LI B_FILE)
echo ' }' >> $( PEGJS_LI B_FILE)
echo ' };' >> $( PEGJS_LI B_FILE)
echo '' >> $( PEGJS_LI B_FILE)
for module in $( MODULES) ; do \
echo " modules.define(\" $$ module\", function(module, require) { " >> $( PEGJS_LI B_FILE) ; \
sed -e 's/^/ /' src /$$ module.js >> $( PEGJS_LI B_FILE) ; \
echo ' });' >> $( PEGJS_LI B_FILE) ; \
echo '' >> $( PEGJS_LI B_FILE) ; \
echo '/*' >> $( BROWSER _FILE_DEV )
echo " * PEG.js $( PEGJS_VERSION) " >> $( BROWSER _FILE_DEV )
echo ' *' >> $( BROWSER _FILE_DEV )
echo ' * http://pegjs.majda.cz/' >> $( BROWSER _FILE_DEV )
echo ' *' >> $( BROWSER _FILE_DEV )
echo ' * Copyright (c) 2010-2012 David Majda' >> $( BROWSER _FILE_DEV )
echo ' * Licensed under the MIT license' >> $( BROWSER _FILE_DEV )
echo ' */' >> $( BROWSER _FILE_DEV )
echo 'var PEG = (function(undefined) {' >> $( BROWSER _FILE_DEV )
echo ' var modules = {' >> $( BROWSER _FILE_DEV )
echo ' define: function(name, factory) {' >> $( BROWSER _FILE_DEV )
echo ' var dir = name.replace(/(^|\/)[^/]+$$/, "$$1"),' >> $( BROWSER _FILE_DEV )
echo ' module = { exports: {} };' >> $( BROWSER _FILE_DEV )
echo '' >> $( BROWSER _FILE_DEV )
echo ' function require(path) {' >> $( BROWSER _FILE_DEV )
echo ' var name = dir + path,' >> $( BROWSER _FILE_DEV )
echo ' regexp = /[^\/]+\/\.\.\/|\.\//;' >> $( BROWSER _FILE_DEV )
echo '' >> $( BROWSER _FILE_DEV )
echo " /* Can't use /.../g because we can move backwards in the string. */" >> $( BROWSER _FILE_DEV )
echo ' while (regexp.test(name)) {' >> $( BROWSER _FILE_DEV )
echo ' name = name.replace(regexp, "");' >> $( BROWSER _FILE_DEV )
echo ' }' >> $( BROWSER _FILE_DEV )
echo '' >> $( BROWSER _FILE_DEV )
echo ' return modules[name];' >> $( BROWSER _FILE_DEV )
echo ' }' >> $( BROWSER _FILE_DEV )
echo '' >> $( BROWSER _FILE_DEV )
echo ' factory(module, require);' >> $( BROWSER _FILE_DEV )
echo ' this[name] = module.exports;' >> $( BROWSER _FILE_DEV )
echo ' }' >> $( BROWSER _FILE_DEV )
echo ' };' >> $( BROWSER _FILE_DEV )
echo '' >> $( BROWSER _FILE_DEV )
for module in $( MODULES) ; do \
echo " modules.define(\" $$ module\", function(module, require) { " >> $( BROWSER _FILE_DEV ) ; \
sed -e 's/^/ /' lib /$$ module.js >> $( BROWSER _FILE_DEV ) ; \
echo ' });' >> $( BROWSER _FILE_DEV ) ; \
echo '' >> $( BROWSER _FILE_DEV ) ; \
done
echo ' return modules["peg"]' >> $( PEGJS_LIB_FILE)
echo '})();' >> $( PEGJS_LIB_FILE)
echo '' >> $( PEGJS_LIB_FILE)
echo 'if (typeof module !== "undefined") {' >> $( PEGJS_LIB_FILE)
echo ' module.exports = PEG;' >> $( PEGJS_LIB_FILE)
echo '}' >> $( PEGJS_LIB_FILE)
# Remove built PEG.js library (created by "build")
clean :
rm -rf $( LIB_DIR)
# Prepare dstribution files
dist : build
# Web
mkdir -p $( DIST_WEB_DIR)
cp $( PEGJS_LIB_FILE) $( PEGJS_DIST_FILE_DEV)
$( UGLIFYJS) --ascii -o $( PEGJS_DIST_FILE_MIN) $( PEGJS_LIB_FILE)
# Node.js
mkdir -p $( DIST_NODE_DIR)
cp -r \
$( LIB_DIR) \
$( BIN_DIR) \
$( EXAMPLES_DIR) \
$( PACKAGE_JSON_FILE) \
$( CHANGELOG_FILE) \
$( LICENSE_FILE) \
$( README_FILE) \
$( VERSION_FILE) \
$( DIST_NODE_DIR)
# Remove distribution file (created by "dist")
distclean :
rm -rf $( DIST_DIR)
echo ' return modules["peg"]' >> $( BROWSER_FILE_DEV)
echo '})();' >> $( BROWSER_FILE_DEV)
$( UGLIFYJS) --ascii -o $( BROWSER_FILE_MIN) $( BROWSER_FILE_DEV)
# Remove browser version of the library (created by "browser")
browserclean :
rm -rf $( BROWSER_DIR)
# Run the spec suite
spec : build
spec :
$( JASMINE_NODE) --verbose $( SPEC_DIR)
# Run the benchmark suite
benchmark : build
benchmark :
$( BENCHMARK_RUN)
# Run JSHint on the source
hint : build
hint :
$( JSHINT) \
` find $( SRC _DIR) -name '*.js' ` \
` find $( LIB_DIR) -name '*.js' ` \
` find $( SPEC_DIR) -name '*.js' -and -not -path '$(SPEC_DIR)/vendor/*' ` \
$( BENCHMARK_DIR) /*.js \
$( BENCHMARK_RUN) \
$( PEGJS)
.PHONY : spec benchmark hint parser build clean dist distclean
.SILENT : spec benchmark hint parser build clean dist distclean
.PHONY : all parser browser browserclean spec benchmark hint
.SILENT : all parser browser browserclean spec benchmark hint