PATCH (trunk rev.119231): ability to disable an option at configure time

Basile STARYNKEVITCH basile@starynkevitch.net
Sun Nov 26 22:49:00 GMT 2006


Hello

As I proposed on http://gcc.gnu.org/ml/gcc/2006-11/msg00803.html and
http://gcc.gnu.org/ml/gcc/2006-11/msg00804.html it could be useful to
propose some options (flags at GCC runtime) which can be fully
disabled at configure time.

Also the Condition keyword in *.opt file seems never used anymore, but
does not disable entirely an option when the preprocessor condition is
false. (the generated flag variables in $GCCBUILD/gcc/options.h still
exist, and the --help option mentions such a flag). Since Condition is
not used, I suggest to mark it as obsolete.

The motivation for such a feature is to permit some expensive
processing in GCC to be enabled or disabled at configure time, and
when it is enabled, to offer an additional GCC runtime flag which
triggers it. As a simplistic scenario, the --enable-check=tree
configure option enable the build of $GCCBUILD/gcc/tree-browser.o
(which is not even built from $GCCTOP/gcc/tree-browser.c without this
--enable-check!), this tree-browser.o offers a browse_tree function,
and we could in that case only propose a -fbrowse-tree flag which
calls this function at several interesting points in the compiler. If
configured without any --enable-check the compiler won't even accept
such a -fbrowse-tree flag

I intend to propose in the future another patch which make a real use
of the CppCondition offered here.

The attached patch to rev. 119231 of GCC trunk does only provide
option handling (and does not propose its use, as illustrated
above). In addition it changes the generted comment in generated
options.[ch] files (which mentions an opts.sh which don't exist
anymore). Bootstraped with --disable-multilib --enable-languages=c on
x86_64-unknown-linux-gnu (Debian/Sid/AMD64)

Regarding legalese: my copyright assignment (signed for CEA-LIST my
employer to FSF) has been sent and the FSF (J.Jacobson) should have
recieved it before monday 27th november 2006 evening. Jonas Jacobson
have all the relevant details.

Changelog follows my signature

Regards

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/ 
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359 
8, rue de la Faïencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***


*********************************** Changelog


2006-11-26  Basile Starynkevitch  <basile@starynkevitch.net>

	* gcc/doc/options.texi: Condition is marked as obsolete,
	and added a description of CppCondition for flags
	which can be entirely disabled at configure time.
	* gcc/optc-gen.awk: generated comment tells about optc-gen.awk.
	Added handling of CppCondition.
	* gcc/opth-gen.awk:  generated comment tells about opth-gen.awk.
	Added handling of CppCondition.
	
-------------- next part --------------
Index: gcc/doc/options.texi
===================================================================
--- gcc/doc/options.texi	(revision 119231)
+++ gcc/doc/options.texi	(working copy)
@@ -221,4 +221,21 @@ The option should only be accepted if pr
 option will be present even if @var{cond} is false; @var{cond} simply
 controls whether the option is accepted and whether it is printed in
 the @option{--help} output.
+
+@strong{Warning:} @emph{this option @samp{Condition} is rarely used and 
+may become obsolete.}
+
+@item CppCondition(@var{cond})
+The option should only be accepted if preprocessor condition
+@var{cond} -which should be an identifier optionally defined at
+configuration time- is defined and true. In contrast to the obsolete
+@samp{Condition} option, any C declarations associated with this
+option @samp{CppCondition} will be skipped by preprocessing when the
+preprocessor condition @var{cond} is false or missing, and more
+generally no GCC runtime flag and no (generated in GCC) code are
+available (not even help messages) when this preprocessor @var{cond}
+is false or missing. With this @samp{CppCondition}, some compilation
+features can be entirely disabled (and won't even be recognized) at
+configuration time.
+
 @end table
Index: gcc/optc-gen.awk
===================================================================
--- gcc/optc-gen.awk	(revision 119231)
+++ gcc/optc-gen.awk	(working copy)
@@ -54,7 +54,7 @@ BEGIN {
 
 # Dump that array of options into a C file.
 END {
-print "/* This file is auto-generated by opts.sh.  */"
+print "/* This file is auto-generated by awk with optc-gen.awk.  */"
 print ""
 n_headers = split(header_name, headers, " ")
 for (i = 1; i <= n_headers; i++)
@@ -87,6 +87,11 @@ for (i = 0; i < n_opts; i++) {
 			continue;
 		gcc_driver = 0
 	}
+        
+	# add handling of CppCondition option 
+	cppcond = opt_args("CppCondition", flags[i])
+	if (cppcond != "")
+	    print "\n#if defined(" cppcond ") && " cppcond " != 0 /*cppcond*/";
 
 	if (gcc_driver == 1)
 		print "#ifdef GCC_DRIVER"
@@ -95,6 +100,10 @@ for (i = 0; i < n_opts; i++) {
 	print var_type(flags[i]) name init ";"
 	if (gcc_driver == 1)
 		print "#endif /* GCC_DRIVER */"
+	
+	if (cppcond != "")
+	    print "#endif /*cppcond: " cppcond " */\n"
+	    
 	print ""
 
 	var_seen[name] = 1;
@@ -188,6 +197,11 @@ for (i = 0; i < n_opts; i++) {
 				idx = -1;
 		}
 	}
+	# add handling of CppCondition option 
+	cppcond = opt_args("CppCondition", flags[i])
+	if (cppcond != "")
+	    print "\n#if defined(" cppcond ") && " cppcond " != 0 /*cppcond*/";
+
 	printf("  { %c-%s%c,\n    %s,\n    %s, %u, %d,\n",
 	       quote, opts[i], quote, hlp, back_chain[i], len, idx)
 	condition = opt_args("Condition", flags[i])
@@ -203,6 +217,8 @@ for (i = 0; i < n_opts; i++) {
 		printf("    %s,\n", cl_flags)
 	printf("    %s, %s }%s\n", var_ref(opts[i], flags[i]),
 	       var_set(flags[i]), comma)
+	if (cppcond != "")
+	    print "#endif /*cppcond: " cppcond " */\n"
 }
 
 print "};"
Index: gcc/opth-gen.awk
===================================================================
--- gcc/opth-gen.awk	(revision 119231)
+++ gcc/opth-gen.awk	(working copy)
@@ -55,7 +55,7 @@ BEGIN {
 # Dump out an enumeration into a .h file.
 # Combine the flags of duplicate options.
 END {
-print "/* This file is auto-generated by opts.sh.  */"
+print "/* This file is auto-generated by awk with opth-gen.awk  */"
 print ""
 print "#ifndef OPTIONS_H"
 print "#define OPTIONS_H"
@@ -67,8 +67,15 @@ for (i = 0; i < n_opts; i++) {
 	name = var_name(flags[i]);
 	if (name == "")
 		continue;
+	# add handling of CppCondition option 
+	cppcond = opt_args("CppCondition", flags[i])
+	if (cppcond != "")
+	    print "\n#if defined(" cppcond ") && " cppcond " != 0 /*cppcond*/";
 
 	print "extern " var_type(flags[i]) name ";"
+
+	if (cppcond != "")
+	    print "#endif /*cppcond: " cppcond " */\n"
 }
 print ""
 
@@ -76,11 +83,17 @@ for (i = 0; i < n_opts; i++) {
 	name = opt_args("Mask", flags[i])
 	vname = var_name(flags[i])
 	mask = "MASK_"
+	cppcond = opt_args("CppCondition", flags[i])
 	if (vname != "") {
 		mask = "OPTION_MASK_"
 	}
-	if (name != "" && !flag_set_p("MaskExists", flags[i]))
-		print "#define " mask name " (1 << " masknum[vname]++ ")"
+	if (name != "" && !flag_set_p("MaskExists", flags[i])) {
+	if (cppcond != "")
+	    print "\n#if defined(" cppcond ") && " cppcond " != 0 /*cppcond*/";
+	print "#define " mask name " (1 << " masknum[vname]++ ")";
+	if (cppcond != "")
+	    print "#endif /*cppcond: " cppcond " */\n"
+	}
 }
 for (i = 0; i < n_extra_masks; i++) {
 	print "#define MASK_" extra_masks[i] " (1 << " masknum[""]++ ")"
@@ -99,6 +112,8 @@ print ""
 for (i = 0; i < n_opts; i++) {
 	name = opt_args("Mask", flags[i])
 	vname = var_name(flags[i])
+	# add handling of CppCondition option 
+	cppcond = opt_args("CppCondition", flags[i])
 	macro = "OPTION_"
 	mask = "OPTION_MASK_"
 	if (vname == "") {
@@ -106,9 +121,14 @@ for (i = 0; i < n_opts; i++) {
 		macro = "TARGET_"
 		mask = "MASK_"
 	}
-	if (name != "" && !flag_set_p("MaskExists", flags[i]))
-		print "#define " macro name \
-		      " ((" vname " & " mask name ") != 0)"
+	if (name != "" && !flag_set_p("MaskExists", flags[i])) {
+	    if (cppcond != "")
+		print "\n#if defined(" cppcond ") && " cppcond " != 0 /*cppcond*/";
+	    print "#define " macro name				\
+		" ((" vname " & " mask name ") != 0)";
+	if (cppcond != "")
+	    print "#endif /*cppcond: " cppcond " */\n"
+	}
 }
 for (i = 0; i < n_extra_masks; i++) {
 	print "#define TARGET_" extra_masks[i] \
@@ -183,8 +203,14 @@ for (i = 0; i < n_opts; i++) {
 		hlp = "0"
 	else
 		hlp = "N_(\"" help[i] "\")";
+	# add handling of CppCondition option 
+	cppcond = opt_args("CppCondition", flags[i])
+	if (cppcond != "")
+	    print "\n#if defined(" cppcond ") && " cppcond " != 0 /*cppcond*/";
 
-	print "  " enum "," s "/* -" opts[i] " */"
+	print "  " enum "," s "/* -" opts[i] " */";
+	if (cppcond != "")
+	    print "#endif /*cppcond: " cppcond " */\n"
 }
 
 print "  N_OPTS"


More information about the Gcc-patches mailing list