Index: gcc/opth-gen.awk
===================================================================
--- gcc/opth-gen.awk	(revision 192400)
+++ gcc/opth-gen.awk	(working copy)
@@ -332,10 +332,9 @@ for (i = 0; i < n_opts; i++) {
 	if (name != "" && mask_bits[name] == 0) {
 		mask_bits[name] = 1
 		vname = var_name(flags[i])
-		mask = "MASK_"
+		mask = opt_prefix_mask(flags[i])
 		mask_1 = "1"
 		if (vname != "") {
-			mask = "OPTION_MASK_"
 			if (host_wide_int[vname] == "yes")
 				mask_1 = "HOST_WIDE_INT_1"
 		} else
@@ -375,14 +374,13 @@ for (i = 0; i < n_opts; i++) {
 	if (name != "" && mask_macros[name] == 0) {
 		mask_macros[name] = 1
 		vname = var_name(flags[i])
-		macro = "OPTION_"
-		mask = "OPTION_MASK_"
+		macro = opt_prefix_target(name)
+		mask = opt_prefix_mask(name)
 		if (vname == "") {
 			vname = "target_flags"
-			macro = "TARGET_"
-			mask = "MASK_"
 			extra_mask_macros[name] = 1
 		}
+
 		print "#define " macro name \
 		      " ((" vname " & " mask name ") != 0)"
 	}
@@ -398,13 +396,12 @@ for (i = 0; i < n_opts; i++) {
 	opt = opt_args("InverseMask", flags[i])
 	if (opt ~ ",") {
 		vname = var_name(flags[i])
-		macro = "OPTION_"
-		mask = "OPTION_MASK_"
+		macro = opt_prefix_target(flags[i])
+		mask = opt_prefix_mask(flags[i])
 		if (vname == "") {
 			vname = "target_flags"
-			macro = "TARGET_"
-			mask = "MASK_"
 		}
+
 		print "#define " macro nth_arg(1, opt) \
 		      " ((" vname " & " mask nth_arg(0, opt) ") == 0)"
 	}
Index: gcc/opt-functions.awk
===================================================================
--- gcc/opt-functions.awk	(revision 192400)
+++ gcc/opt-functions.awk	(working copy)
@@ -242,18 +242,14 @@ function var_set(flags)
 	s = opt_args("Mask", flags);
 	if (s != "") {
 		vn = var_name(flags);
-		if (vn)
-			return "0, CLVC_BIT_SET, OPTION_MASK_" s
-		else
-			return "0, CLVC_BIT_SET, MASK_" s
+		mask = opt_prefix_mask(flags)
+		return "0, CLVC_BIT_SET, " mask s
 	}
 	s = nth_arg(0, opt_args("InverseMask", flags));
 	if (s != "") {
 		vn = var_name(flags);
-		if (vn)
-			return "0, CLVC_BIT_CLEAR, OPTION_MASK_" s
-		else
-			return "0, CLVC_BIT_CLEAR, MASK_" s
+		mask = opt_prefix_mask(flags)
+		return "0, CLVC_BIT_CLEAR, " mask s
 	}
 	if (flag_set_p("Enum.*", flags)) {
 		en = opt_args("Enum", flags);
@@ -297,3 +293,25 @@ function lang_sanitized_name(name)
     gsub( "[^" alnum "_]", "X", name )
     return name
 }
+
+# Given the option called NAME which is a mask argument, return the prefix for
+# the option (i.e. TARGET_ or OPTION_).
+function opt_prefix_target(name)
+{
+	variable = var_name(name)
+	if (variable == "" || flag_set_p("TargetName", name))
+		return "TARGET_";
+	else
+		return "OPTION_";
+}
+
+# Given the option called NAME which is a mask argument, return the prefix for
+# the mask name (i.e. MASK_ or OPTION_MASK_).
+function opt_prefix_mask(name)
+{
+	variable = var_name(name)
+	if (variable == "" || flag_set_p("TargetName", name))
+		return "MASK_";
+	else
+		return "OPTION_MASK_";
+}
Index: gcc/doc/options.texi
===================================================================
--- gcc/doc/options.texi	(revision 192400)
+++ gcc/doc/options.texi	(working copy)
@@ -339,12 +339,14 @@ You may also specify @code{Var} to selec
 @code{target_flags}.
 
 The options-processing script will automatically allocate a unique bit
-for the option.  If the option is attached to @samp{target_flags},
-the script will set the macro @code{MASK_@var{name}} to the appropriate
-bitmask.  It will also declare a @code{TARGET_@var{name}} macro that has
-the value 1 when the option is active and 0 otherwise.  If you use @code{Var}
-to attach the option to a different variable, the associated macros are
-called @code{OPTION_MASK_@var{name}} and @code{OPTION_@var{name}} respectively.
+for the option.  If the option is attached to @samp{target_flags}, the
+script will set the macro @code{MASK_@var{name}} to the appropriate
+bitmask.  It will also declare a @code{TARGET_@var{name}} macro that
+has the value 1 when the option is active and 0 otherwise.  If you use
+@code{Var} to attach the option to a different variable and do not
+used the @code{TargetName} opiton, the associated macros are called
+@code{OPTION_MASK_@var{name}} and @code{OPTION_@var{name}}
+respectively.
 
 @item InverseMask(@var{othername})
 @itemx InverseMask(@var{othername}, @var{thisname})
@@ -472,4 +474,10 @@ format}.
 @item NoDWARFRecord
 The option is omitted from the producer string written by
 @option{-grecord-gcc-switches}.
+
+@item TargetName
+If the option was declared with @code{Mask} or @code{InverseMask} and
+also @code{Var} to specify an alternative flag word, the
+@code{TARGET_@var{name}} and @code{MASK_@var{name}} macros will be
+created of @code{OPTION_@var{name}} and @code{OPTION_MASK_@var{name}}.
 @end table
