I’m working on using a Makefile to help perform build steps for my JS in my application. The goal is to use Make’s ability to only deal with modified files to prevent extraneous copying and such.
To build the JS you need to
- copy the original .js files from the main dev directory to a build directory
- minimize the copied file and create a -min.js version of the file
- generate a meta.js which has the information on the YUI modules in the built JS files for the combo loader.
So I’ve been working on the Makefile working backwards. meta.js depends on -min.js which depends on $builddir/b/*.js which is copied from %origdir/*.js
In looking through things it seems I should be able to use %.js in order to catch any matching files, but when I try this out I get:
make: *** No rule to make target `bookie/static/js/build/b/%-min.js', needed by `bookie/static/js/build/b/meta.js'. Stop.
This is what I’m working with, anyone know what I’m doing wrong? I want that when I make js it copies over the changed .js files, minifies them, and then regenerates the meta.js.
# Makefile to help automate tasks in bookie
WD := $(shell pwd)
PY := bin/python
BOOKIE_JS = bookie/static/js/bookie
JS_BUILD_PATH = bookie/static/js/build
JS_META_SCRIPT = $(PY) scripts/js/generate_meta.py
EXTENSION = $(WD)/extensions
CHROME_BUILD = $(EXTENSION)/chrome_ext/lib
# JAVASCRIPT
#
# Javascript tools for building out combo loader build directory, out meta.js,
# and syncing things over to the chrome extension directory.
.PHONY: js
js: $(JS_BUILD_PATH)/b/meta.js
$(JS_BUILD_PATH)/b/meta.js: $(JS_BUILD_PATH)/b/%-min.js
echo "META"
$(JS_META_SCRIPT) -n YUI_MODULES -s $(JS_BUILD_PATH)/b/ \
-o $(JS_BUILD_PATH)/b/meta.js \
-x -min.js$
$(JS_BUILD_PATH)/b/%-min.js: $(JS_BUILD_PATH)/b/$*.js
echo "MIN"
rm $(JS_BUILD_PATH)/b/meta.js || true
scripts/js/jsmin_all.py $(JS_BUILD_PATH)/b
$(JS_BUILD_PATH)/b/%.js: $(BOOKIE_JS)/$*.js
echo "Initial"
cp $? $(JS_BUILD_PATH)/b/
cp $? $(CHROME_BUILD)/
.PHONY: clean_js
clean_js:
rm -rf $(JS_BUILD_PATH)/* || true
Make wildcards don’t work the way you think. Let’s start with this rule:
The
%implies that it’s a pattern rule, so Make expects a corresponding%in the prerequisite list. Instead it looks as if you’re trying to use either the automatic variable$*(which can’t be used in the prerequisite list) or the wildcard*(which can’t be used without thewildcardcommand). Try it this way:This works, but only if you specify exactly which file(s) you want; it doesn’t copy every
.jsfile in the dev directory (more on this later).Now for
-min.js. I can’t tell exactly how this rule works, but it looks as if you run a python script that acts on all *.js files in the directory at once. If that’s correct, then it doesn’t make sense to have a rule that makesfoo-min.jsfromfoo.js; there should be a rule to run the script, and we need a list of all the.jsfiles it will need:Finally,
meta.js:EDIT:
I think I see what you’re trying to do. There are a couple of ways to do it; the simplest is just to combine the three rules into one:
This will act only on the
.jsfiles in dev that are newer thanmeta.js(or all of them ifmeta.jsdoesn’t yet exist).