makefile - Make: stop compilation on error -


i'm starting use gnu make frontend build tool, , things work great. thing annoying compilation doesn't seem stop when 1 of steps reaches error. relevant portion of makefile:

js_files=$(filter-out $(ignore_js),$(wildcard \              js/ll/*.js js/ll/**/*.js)) ignore_js=js/ll/dist% js/ll/%.min.js  %.min.js: %.js     @echo ">>> uglifying $?"     @$(babeljs) $(babeljsflags) $? | $(uglifyjs) --source-map $(uglifyjsflags) > $@  min_js_files=$(js_files:%.js=%.min.js) main.js: $(min_js_files)     @echo ">>> concatenating javascript"     mkdir -p $(dist_dir)     cat $^ > $(dist_dir)$@  prod: main.js clean 

the output running make prod looks this:

>>> uglifying js/ll/dateex.js               syntaxerror: js/ll/dateex.js: invalid number (22:36)   20 |     day = today.getdate();             21 |   }                                  > 22 |   return new date(year, month, day, 01, 0, 0);      |                                     ^   23 | }   24 |   25 | function newdates(s) >>> uglifying js/ll/anonymization.js >>> uglifying js/ll/dummystorage.js (...) 

i have impression happens because steps run in parallel, know nothing make up. how can have compilation stop when 1 of steps returns non-zero?

what asking well-established default behavior of make. in build chain not setting nonzero exit code on failure, or masking out.

in particular, exit code shell pipeline exit code final command in pipeline. in other words, error babeljs in recipe lost.

maybe refactor not use pipe, perhaps this:

%.min.js: %.js.tmp     $(uglifyjs) --source-map $(uglifyjsflags) <$< >$@ %.js.tmp: %.js     $(babeljs) $(babeljsflags) $< >$@  .phony: clean clean:     rm *.js.tmp 

the use of temporary file bit of wart, , choice whether use separate recipe first step kind of arbitrary. prefer style because better adheres spirit of make (explicitly declare dependencies, let make keep track) if want fine-grained control on flow, go other way.

i removed @ prefix babeljs rule. bit of private crusade of mine -- littering makefile these makes debugging hard, , proper solution if want peace , quiet use make -s.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -