0

I am facing the issue while accessing a variable from other makefile which is included.

i have test.mak which has variable LIBS32 := $(TESTLIBS)/$(NEW_PLAT32) i have included test.mak in other makefile and trying to assign that variable in one of the target.

extlib32: EXTLIBS = $(LIBS32)
extlib64: EXTLIBS = $(LIBS64)

The expected value of EXTLIBS should be '/home/testlib/extlibs/Linux' . But here when i print EXTLIBS the value which i am seeing is '/home/testlib/extlibs/'

Note:- When i jut print LIBS i can see the content as expected. But when i assigned to EXTLIBS and try to use it.. I can see word 'Linux' is missing.

Thanks!

santosh
  • 421
  • 1
  • 6
  • 14

1 Answers1

0

You set EXTLIBS as a target-specific variable for target extlib32. Such variables are non-global and their value is only available in the target recipe and target's prerequisites, rather than globally (this is why $(info $(EXTLIBS)) doesn't print the expected value).

To print its value you need to print it from the recipe of target extlib32, e.g.:

extlib32:
    @echo "EXTLIBS=${EXTLIBS}"

If extlib32 and extlib64 are .PHONY targets to build something then your original target-specific assignments should propagate to the dependencies and be available in their recipes. You just cannot print its value from the global makefile scope.


To have one makefile build both in 32 and 64-bit mode (as well as release and debug) you need to structure it differently and invoke make separately for each build mode. Example:

# User can overrided capitalized variables. E.g.
# make BUILD=release MODE=32 LDLIBS=-lrt
BUILD := debug
MODE := 64

build_dir := ${BUILD}/${MODE}

ldlibs.32 := my-32-bit-libs
ldlibs.64 := my-64-bit-libs
ldlibs := ${ldlibs.${MODE}} ${LDLIBS}

all :
    @echo "build_dir=${build_dir}"
    @echo "ldlibs=${ldlibs}"

Usage examples:

$ make 
build_dir=debug/64
ldlibs=my-64-bit-libs

$ make BUILD=release MODE=32
build_dir=release/32
ldlibs=my-32-bit-libs 

Another example for debug/release compiler options.

Maxim Egorushkin
  • 131,725
  • 17
  • 180
  • 271
  • Hi Maxim, I just print with $(info .$(EXTLIBS)) to check the value....BTW want to use that variable in my targets.. How can i use it? Is the assignment which i did above is not correct ? – santosh Mar 06 '19 at 13:15
  • @santosh Then just do `EXTLIBS := $(LIBS)` (nothing else on the line). – Maxim Egorushkin Mar 06 '19 at 13:17
  • Hi Maxim, LIBS value will change based on 32bit or 64 bit build. Sorry if my question was not clear... I am updating my question for clarity. – santosh Mar 06 '19 at 13:25
  • @santosh Updated for you. – Maxim Egorushkin Mar 06 '19 at 14:44
  • Hi Maxim, Thank you for the update... In my case how can i fix this.. Basically the requirement is if we are running 32bit build then EXTLIBS value should assign to $(LIBS32), If we are running 64bit build then EXTLIBS value should assign to $(LIBS64).. Thats why i had above seperate targets for 32bit & 64bit which is not working as expected. How can we make it global... Could you please help fixing this? – santosh Mar 07 '19 at 03:13
  • @santosh Updated the answer for you. – Maxim Egorushkin Mar 07 '19 at 14:28