variables - Conditional checks in makefile -


consider following makefile. intend call "make var=xxx" normal building, , "make help" or "make clean" or "make showvars" @ other times. when i'm doing actual build, need ensure 'var' variable passed @ commandline, not require present other targets such clean. currently, check bails out time var not specified, safe, annoying , unnecessary when cleaning or mucking around. how can run check build targets , not @ other times?

var=  $(if $(var),,$(error var not specified @ commandline!))  var_release=`echo $(var) | sed -e 's/-/_/g'`  .phony showvars clean prep rpm  all: prep rpm  prep: # prep work. requires valid var , var_release  rpm: # build rpm. requires valid var_release  help: # not require var , var_release  showvars: # display vars. requires valid var , var_release  clean: # not require var , var_release 

update:

per maxim's suggestion below, using $(makecmdgoals) check target specified , ignoring not require var set:

# check if var empty prep , rpm targets, bail out if so. ifneq ($(makecmdgoals),clean) ifneq ($(makecmdgoals),help) ifneq ($(makecmdgoals),showvars) $(if $(var),,$(error var not specified @ commandline! see 'make help')) endif endif endif 

it works, it's bit crude... possible streamline @ all?

you use makecmdgoals find out targets have been specified on command line:

make set special variable makecmdgoals list of goals specified on command line. if no goals given on command line, variable empty. note variable should used in special circumstances.

alternatively, can set variables default values in makefile. assignments variables on command line override values makefile. way user have specify values of variables if defaults not suitable.


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -