Previously I had a directive pictDBM
that was something like this:
all: pictDBM
pictDBM : db_list.o db_delete.o db_utils.o error.o pictDBM.o
db_create.o dedup.o image_content.o pictDBM_tools.o db_read.o
gcc $(CFLAGS) -o $@ $^ $(LDLIBS)
This part worked very well.
Then I thought I wanted to be able to add an optional argument given from the command line. This option would then go into the gcc
command line that I execute in the pictDBM
subpart.
I approched the problem by using a OPTS=""
variable that I declare in my code(at the beginning of the makefile before any directive). My aim is to call make like this:
make all OPT='-g'
.
Then I declared a variable base=gcc $(CFLAGS) -o $@ $^ $(LDLIBS)
Part of my solution was to use a if else construct to include or not my option variable ${OPT}
to the ${base}
gcc
command that I execute in pictDBM.
I red this topic, that helped build my multi-line if else construct:
pictDBM : db_list.o db_delete.o db_utils.o error.o pictDBM.o
db_create.o dedup.o image_content.o pictDBM_tools.o db_read.o
if [ ! -z "$$OPT" ]; \
then \
echo "$$base $$OPT" ; \ #for debugging purposes
eval "$$base $$OPT" ; \
else \
eval "$$base" ; \
fi ;
When I simply execute make all
everything seems to be ok with make, and the output program works well.
but when I execute make all OPTS='-g'
I get the following output:
-g
/bin/sh: 1: eval: -g: not found
makefile:16: recipe for target 'pictDBM' failed
make: *** [pictDBM] Error 127
you can see echo prints only -g, how can I fix this?
`CFLAGS += $$(pkg-config vips --cflags)`
`LDLIBS += $$(pkg-config vips --libs) -lm -lssl -lcrypto`
`override CFLAGS+=`
`override LDFLAGS+=`
`all : pictDBM`
`pictDBM : db_list.o db_delete.o db_utils.o error.o pictDBM.o db_create.o`
`dedup.o image_content.o pictDBM_tools.o db_read.o`
but when I do `make all CFLAGS=-g`
I get: – Simonlbc May 16 '16 at 10:19