I'm trying to learn Make and building a Makefile into my app to help me with building and minimizing my .js files for use of a combo loader server application later on.

What I'm trying to accomplish is that when I run make, it'll copy over to the build directory only the .js files that have changed since the last run, and then minify that file and generate a -min.js copy. Finally I need to always make sure I generate a new meta.js file.

I've pasted what I have working below, the trouble with this is that it's not picking only the changed .js files, but each file on each run. I'm missing something in how to get Make to pick only changed files in this instance.

BOOKIE_JS = bookie/static/js/bookie
JS_BUILD_PATH = bookie/static/js/build
JS_META_SCRIPT = scripts/js/generate_meta.py

jsbuild: $(JS_BUILD_PATH)/bookie/meta.js

clean_js:
    rm -rf $(JS_BUILD_PATH)/*

$(JS_BUILD_PATH)/bookie/meta.js: $(BOOKIE_JS)/y*-min.js
    $(JS_META_SCRIPT) -n YUI_MODULES -s $(BOOKIE_JS)/y* -o $(JS_BUILD_PATH)/bookie/meta.js

$(BOOKIE_JS)/y*-min.js: $(BOOKIE_JS)/y*.js
    scripts/js/jsmin_all.py $(JS_BUILD_PATH)/bookie

    # this is the part that runs for each .js file and I'd like it to only run for the *modified* files
$(BOOKIE_JS)/y*.js: $(JS_BUILD_PATH)/bookie
    cp $@ $(JS_BUILD_PATH)/bookie/

$(JS_BUILD_PATH)/bookie:
    mkdir $(JS_BUILD_PATH)/bookie

clean: clean_js

.PHONE: clean clean_js

Current output:

cp bookie/static/js/bookie/yapi.js bookie/static/js/build/bookie/
cp bookie/static/js/bookie/ymodel.js bookie/static/js/build/bookie/
cp bookie/static/js/bookie/ytagcontrol.js bookie/static/js/build/bookie/
cp bookie/static/js/bookie/yview.js bookie/static/js/build/bookie/
scripts/js/jsmin_all.py bookie/static/js/build/bookie
scripts/js/generate_meta.py -n YUI_MODULES -s bookie/static/js/bookie/y* -o bookie/static/js/build/bookie/meta.js

I'd like to see only the cp of the changed files.

share|improve this question
up vote 3 down vote accepted

I think you intended to make a pattern rule but used the wrong syntax. For example, this:

$(BOOKIE_JS)/y*-min.js: $(BOOKIE_JS)/y*.js
    scripts/js/jsmin_all.py $(JS_BUILD_PATH)/bookie

means each of the $(BOOKIE_JS)/y*-min.js files depends on the $(BOOKIE_JS)/y*.js files -- all of them, not just the one with a similar name. If you do this:

$(BOOKIE_JS)/y%-min.js: $(BOOKIE_JS)/y%.js
    scripts/js/jsmin_all.py $(JS_BUILD_PATH)/bookie

then the % must be replaced with the same string on each side, so for example $(BOOKIE_JS)/yapi-min.js depends only on $(BOOKIE_JS)/yapi.js

share|improve this answer
    
thanks, completely missed the * vs % – Rick Jan 25 '12 at 21:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.