Skip to content

Instantly share code, notes, and snippets.

@sv99
Last active October 22, 2015 10:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
eval loaded from file lines in the gnu make

Gnu make shell command replace \n with space in the result.

Trick - replace \n in the file with replacer and after loading subst revert \n befor eval.

define newline


endef


newline-stub = __NEWLINE_STUB__

# package-overlay -- load and eval makefile in place
#
#  argument 1 directory packacge_overlay
#  argument 2 relative path to the make fil
#
# example:
#   $(eval $(call package-overlay,$(call qstrip,$(BR2_PACKAGE_OVERLAY_DIR)),RELATIVE_PATH_TO_THE_FILE))
define package-overlay
ifneq ("$(1)","")
ifneq ($$(wildcard $(1)/$(2)),)
$$(eval $$(subst $$(newline-stub),$$(newline),$$(shell perl -p -e 's/\n/$$(newline-stub)/' $(1)/$(2))))
endif
endif
endef
  1. perl read makefile and replace \n with newline-stub
  2. subst revert this operation preparing data for eval

Made for buildroot project - package overlay in the extern project, without patchiing base tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment