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
This commit is contained in:
parent
253e45bb94
commit
6ff61909a9
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user