Skip to content
Snippets Groups Projects
Unverified Commit 6ff61909 authored by David Griffith's avatar David Griffith Committed by Mike McQuaid
Browse files

Deal with Makefile conditional assignment operators.

Ordinarily variable assignments in Makefiles are done simply with an
unconditional assignment: the equals sign.  There are variants of this:

FOO := $(BAR)	Avoid recursively expand variables.
FOO ?= bar	Assign only if $(FOO) is not already set.
FOO += bar	Add more to a variable.
FOO != bar	Execute a shell script and assign result to $(FOO).

See also
https://www.gnu.org/software/make/manual/html_node/Conditional-Example.html
https://www.gnu.org/software/make/manual/html_node/Flavors.html
parent 253e45bb
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ module StringInreplaceExtension
# Looks for Makefile style variable definitions and replaces the
# value with "new_value", or removes the definition entirely.
def change_make_var!(flag, new_value)
return if gsub!(/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)
return if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*(.*)$/, "#{flag}=#{new_value}", false)
errors << "expected to change #{flag.inspect} to #{new_value.inspect}"
end
......@@ -50,12 +50,14 @@ module StringInreplaceExtension
def remove_make_var!(flags)
Array(flags).each do |flag|
# Also remove trailing \n, if present.
errors << "expected to remove #{flag.inspect}" unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=.*$\n?/, "", false)
if gsub!(/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=.*$\n?/, "", false)
errors << "expected to remove #{flag.inspect}"
end
end
end
# Finds the specified variable
def get_make_var(flag)
self[/^#{Regexp.escape(flag)}[ \t]*=[ \t]*(.*)$/, 1]
self[/^#{Regexp.escape(flag)}[ \t]*[\\?\+\:\!]?=[ \t]*(.*)$/, 1]
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment