2012-11-09 15:57:14 +01:00
|
|
|
# ===== Variables =====
|
|
|
|
|
|
|
|
PEGJS_VERSION = `cat $(VERSION_FILE)`
|
|
|
|
|
2012-03-04 11:46:28 +01:00
|
|
|
# ===== Directories =====
|
|
|
|
|
2012-11-10 15:08:38 +01:00
|
|
|
SRC_DIR = src
|
|
|
|
LIB_DIR = lib
|
|
|
|
BIN_DIR = bin
|
|
|
|
BROWSER_DIR = browser
|
|
|
|
SPEC_DIR = spec
|
|
|
|
BENCHMARK_DIR = benchmark
|
|
|
|
NODE_MODULES_DIR = node_modules
|
|
|
|
NODE_MODULES_BIN_DIR = $(NODE_MODULES_DIR)/.bin
|
2012-03-04 11:46:28 +01:00
|
|
|
|
|
|
|
# ===== Files =====
|
|
|
|
|
2015-10-13 05:26:51 +02:00
|
|
|
MAIN_FILE = $(LIB_DIR)/peg.js
|
|
|
|
|
2016-01-24 21:22:21 +01:00
|
|
|
PARSER_SRC_FILE = $(SRC_DIR)/parser.pegjs
|
|
|
|
PARSER_OUT_FILE = $(LIB_DIR)/parser.js
|
|
|
|
PARSER_OUT_FILE_NEW = $(LIB_DIR)/parser.js.new
|
2012-03-04 11:46:28 +01:00
|
|
|
|
2012-11-10 14:21:14 +01:00
|
|
|
BROWSER_FILE_DEV = $(BROWSER_DIR)/peg-$(PEGJS_VERSION).js
|
|
|
|
BROWSER_FILE_MIN = $(BROWSER_DIR)/peg-$(PEGJS_VERSION).min.js
|
2012-03-04 11:46:28 +01:00
|
|
|
|
2016-09-08 13:29:06 +02:00
|
|
|
SPEC_SERVER_FILE = $(SPEC_DIR)/server
|
|
|
|
|
2012-11-10 14:21:14 +01:00
|
|
|
VERSION_FILE = VERSION
|
2012-03-04 11:46:28 +01:00
|
|
|
|
|
|
|
# ===== Executables =====
|
|
|
|
|
2016-01-22 13:48:22 +01:00
|
|
|
ESLINT = $(NODE_MODULES_BIN_DIR)/eslint
|
2015-10-13 05:26:51 +02:00
|
|
|
BROWSERIFY = $(NODE_MODULES_BIN_DIR)/browserify
|
2012-11-10 15:08:38 +01:00
|
|
|
UGLIFYJS = $(NODE_MODULES_BIN_DIR)/uglifyjs
|
|
|
|
JASMINE_NODE = $(NODE_MODULES_BIN_DIR)/jasmine-node
|
2012-03-04 11:46:28 +01:00
|
|
|
PEGJS = $(BIN_DIR)/pegjs
|
|
|
|
BENCHMARK_RUN = $(BENCHMARK_DIR)/run
|
|
|
|
|
|
|
|
# ===== Targets =====
|
|
|
|
|
2012-11-10 14:21:14 +01:00
|
|
|
# Default target
|
|
|
|
all: browser
|
|
|
|
|
2012-03-04 11:46:28 +01:00
|
|
|
# Generate the grammar parser
|
|
|
|
parser:
|
2016-01-24 21:22:21 +01:00
|
|
|
# We need to prepend ESLint header to the generated parser file because we
|
|
|
|
# don't want the various unused variables there to get reported. This is a bit
|
|
|
|
# tricky because the file is used when generating its own new version, which
|
|
|
|
# means we can't start writing the header there until we call $(PEGJS).
|
|
|
|
|
2016-07-04 09:03:09 +02:00
|
|
|
$(PEGJS) -o $(PARSER_OUT_FILE_NEW) $(PARSER_SRC_FILE)
|
2016-01-24 21:22:21 +01:00
|
|
|
|
|
|
|
rm -f $(PARSER_OUT_FILE)
|
|
|
|
|
2016-05-02 16:42:10 +02:00
|
|
|
echo '/* eslint-env node, amd */' >> $(PARSER_OUT_FILE)
|
2016-01-24 21:22:21 +01:00
|
|
|
echo '/* eslint no-unused-vars: 0 */' >> $(PARSER_OUT_FILE)
|
|
|
|
echo >> $(PARSER_OUT_FILE)
|
|
|
|
cat $(PARSER_OUT_FILE_NEW) >> $(PARSER_OUT_FILE)
|
|
|
|
|
|
|
|
rm $(PARSER_OUT_FILE_NEW)
|
2012-03-04 11:46:28 +01:00
|
|
|
|
2012-11-10 14:21:14 +01:00
|
|
|
# Build the browser version of the library
|
|
|
|
browser:
|
|
|
|
mkdir -p $(BROWSER_DIR)
|
|
|
|
|
|
|
|
rm -f $(BROWSER_FILE_DEV)
|
|
|
|
rm -f $(BROWSER_FILE_MIN)
|
2012-11-10 09:47:22 +01:00
|
|
|
|
2012-11-10 14:21:14 +01:00
|
|
|
echo '/*' >> $(BROWSER_FILE_DEV)
|
|
|
|
echo " * PEG.js $(PEGJS_VERSION)" >> $(BROWSER_FILE_DEV)
|
|
|
|
echo ' *' >> $(BROWSER_FILE_DEV)
|
2014-12-15 15:28:57 +01:00
|
|
|
echo ' * http://pegjs.org/' >> $(BROWSER_FILE_DEV)
|
2012-11-10 14:21:14 +01:00
|
|
|
echo ' *' >> $(BROWSER_FILE_DEV)
|
2016-01-15 09:38:15 +01:00
|
|
|
echo ' * Copyright (c) 2010-2016 David Majda' >> $(BROWSER_FILE_DEV)
|
2013-12-07 15:39:27 +01:00
|
|
|
echo ' * Licensed under the MIT license.' >> $(BROWSER_FILE_DEV)
|
2012-11-10 14:21:14 +01:00
|
|
|
echo ' */' >> $(BROWSER_FILE_DEV)
|
2015-10-13 05:26:51 +02:00
|
|
|
|
2016-09-07 18:08:27 +02:00
|
|
|
$(BROWSERIFY) \
|
|
|
|
--standalone peg \
|
|
|
|
--transform [ babelify --presets [ es2015 ] --compact false ] \
|
|
|
|
$(MAIN_FILE) >> $(BROWSER_FILE_DEV)
|
2012-11-10 14:21:14 +01:00
|
|
|
|
2013-12-14 11:49:00 +01:00
|
|
|
$(UGLIFYJS) \
|
|
|
|
--mangle \
|
|
|
|
--compress warnings=false \
|
|
|
|
--comments /Copyright/ \
|
|
|
|
-o $(BROWSER_FILE_MIN) \
|
|
|
|
$(BROWSER_FILE_DEV)
|
2012-11-10 14:21:14 +01:00
|
|
|
|
|
|
|
# Remove browser version of the library (created by "browser")
|
|
|
|
browserclean:
|
|
|
|
rm -rf $(BROWSER_DIR)
|
2012-03-04 11:46:28 +01:00
|
|
|
|
2012-02-27 19:59:54 +01:00
|
|
|
# Run the spec suite
|
2012-11-10 14:21:14 +01:00
|
|
|
spec:
|
2012-02-27 19:59:54 +01:00
|
|
|
$(JASMINE_NODE) --verbose $(SPEC_DIR)
|
|
|
|
|
2012-03-04 11:46:28 +01:00
|
|
|
# Run the benchmark suite
|
2012-11-10 14:21:14 +01:00
|
|
|
benchmark:
|
2012-03-04 11:46:28 +01:00
|
|
|
$(BENCHMARK_RUN)
|
|
|
|
|
2016-01-22 13:48:22 +01:00
|
|
|
# Run ESLint on the source
|
|
|
|
lint:
|
|
|
|
$(ESLINT) \
|
2012-11-10 14:21:14 +01:00
|
|
|
`find $(LIB_DIR) -name '*.js'` \
|
2012-02-27 19:59:54 +01:00
|
|
|
`find $(SPEC_DIR) -name '*.js' -and -not -path '$(SPEC_DIR)/vendor/*'` \
|
2016-09-08 13:29:06 +02:00
|
|
|
$(SPEC_SERVER_FILE) \
|
2012-04-19 12:59:40 +02:00
|
|
|
$(BENCHMARK_DIR)/*.js \
|
|
|
|
$(BENCHMARK_RUN) \
|
2012-03-04 11:46:28 +01:00
|
|
|
$(PEGJS)
|
|
|
|
|
2016-01-22 13:48:22 +01:00
|
|
|
.PHONY: all parser browser browserclean spec benchmark lint
|
|
|
|
.SILENT: all parser browser browserclean spec benchmark lint
|