Skip to content

Instantly share code, notes, and snippets.

@sv99
Last active October 22, 2015 10:55
Show Gist options
  • Save sv99/2eb366d1cd46a0086a95 to your computer and use it in GitHub Desktop.
Save sv99/2eb366d1cd46a0086a95 to your computer and use it in GitHub Desktop.
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