Skip to content

Instantly share code, notes, and snippets.

@nikkon-dev
Created March 20, 2019 01:59
Show Gist options
  • Save nikkon-dev/2d26ea9fc08824a282fcb0dc6891a758 to your computer and use it in GitHub Desktop.
Save nikkon-dev/2d26ea9fc08824a282fcb0dc6891a758 to your computer and use it in GitHub Desktop.
Pass a variable to submake process
# We need to properly escape DCGM_GLOBAL_CFLAGS and DCGM_GLOBAL_LDFLAGS
# in a way that neither submake nor shell breake them due to substitutions rules.
#
# Here is the example of what is going on:
# This makefile:
# DCGM_GLOBAL_LDFLAGS := '-Wl,-rpath,$$ORIGIN/'
# DCGM_GLOBAL_LDFALGS += '-Wl,-static'
#
# To allow another make process to see this variable in exacly the same way, it should be quoted:
# make DCGM_GLOBAL_LDFLAGS=$'\'-Wl,-rpath,\$\$ORIGIN/\' \'-Wl,-static\''
#
DCGM_GLOBAL_LDFLAGS_T := $(foreach v, $(DCGM_GLOBAL_LDFLAGS), $(subst $$,\$$\$$,$(v)))
DCGM_GLOBAL_LDFLAGS_S := $$"$(foreach v, $(DCGM_GLOBAL_LDFLAGS_T), '$(shell echo $(v))' )"
DCGM_GLOBAL_CFLAGS_T := $(foreach v, $(DCGM_GLOBAL_CFLAGS), $(subst $$,\$$\$$,$(v)))
DCGM_GLOBAL_CFLAGS_S := $$"$(foreach v, $(DCGM_GLOBAL_CFLAGS_T), '$(shell echo $(v))' )"
all:
make DCGM_GLOBAL_LDFLAGS=$(DCGM_GLOBAL_LDFLAGS_S) -f anothermake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment