makefile - Make runs target with variable name regardless of whether file exists -


i'm using gnu make work data. when try run target variable name, make run target, regardless of whether target file exists. consider following makefile:

include config.mk  .phony : all : $(pg_db).db  $(pg_db).db :      createdb $(pg_db) -u $(pg_user)     touch $@ 

where config.mk contains:

makeflags += --warn-undefined-variables shell := bash .shellflags := -eu -o pipefail .default_goal := .delete_on_error: .suffixes:  pg_user="foo" pg_db="foo" 

when run make, make creates postgres database, , touches file foo.db. however, when run make again, output is:

createdb "foo" -u foo createdb: database creation failed: error: database "foo" exists make : *** ["foo".db] error 1 

this shouldn't have happened! expect make, in situation, check prerequisites phony target all, see foo.db exists, , exit without doing anything.

strangely, happens when rid of variables in target names:

include config.mk  .phony : all : foo.db  foo.db :     createdb $(pg_db) -u $(pg_user)     touch $@ 

when run make modified makefile, get:

make: nothing done `all`. 

which expect.

what's going on here?

the problem not come variable, comes quotation mark in variable value. make not remove quotation mark before checking dependency. checking file "foo".db quotation mark included. while command touch "foo".db gets interpreted shell removes quotation marks. make, file never there , have same problem. when put dependency explicitly, put foo.db not include quotation mark. makes difference.

in config.mk, turn

pg_db="foo" 

into

pg_db=foo 

it should work. guess createdb normal shell command not care quotation marks. otherwise need add before calling command.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -