scripts: add a guard macro in generated .h files
PATCH 1/1 scripts: add a guard macro in generated .h files
To avoid redefinition warnings.
--- rules.mak | 2 +- scripts/create_config | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-)
rules.mak +1 -1
@@ -57,7 +57,7 @@ find-in-path = $(if $(find-string /, $1), \ @test -f $@ || cp $< $@ %.h-timestamp: %.mak - $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $*.h") + $(call quiet-command, sh $(SRC_PATH)/scripts/create_config $* < $< > $@, " GEN $*.h") @cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h # will delete the target of a rule if commands exit with a nonzero exit status
scripts/create_config +12 -0
@@ -1,7 +1,17 @@ #!/bin/sh +if [ $# -ne 1 ]; then + echo "Usage: $0 filename" 2>&1 + exit 1 +fi + +cond_macro=`echo $1 | tr a-z- A-Z_`_H + echo "/* Automatically generated by create_config - do not modify */" +echo "#ifndef $cond_macro" +echo "#define $cond_macro" + while read line; do case $line in
@@ -101,3 +111,5 @@ case $line in esac done # read + +echo "#endif /* $cond_macro */"
Signature · 1 line
1.7.3.GIT
Quoted 44 lines · Tristan Gingold
To avoid redefinition warnings.
Signed-off-by Tristan Gingold <[email protected]>--- rules.mak | 2 +- scripts/create_config | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-)rules.mak +1
-1@@ -57,7 +57,7 @@ find-in-path = $(if $(find-string /, $1), \ @test -f $@ || cp $< $@ %.h-timestamp: %.mak - $(call quiet-command, sh $(SRC_PATH)/scripts/create_config < $< > $@, " GEN $*.h") + $(call quiet-command, sh $(SRC_PATH)/scripts/create_config $* < $< > $@, " GEN $*.h") @cmp $@ $*.h >/dev/null 2>&1 || cp $@ $*.h # will delete the target of a rule if commands exit with a nonzero exit statusscripts/create_config +10
-0@@ -1,7 +1,17 @@ #!/bin/sh +if [ $# -ne 1 ]; then + echo "Usage: $0 filename" 2>&1 + exit 1 +fi + +cond_macro=`echo $1 | tr a-z- A-Z_`_H + echo "/* Automatically generated by create_config - do not modify */" +echo "#ifndef $cond_macro" +echo "#define $cond_macro" + while read line; do case $line in
scripts/create_config case $line in · line 115
Quoted 5 lines
scripts/create_config +2
-0@@ -101,3 +111,5 @@ case $line in esac done # read + +echo "#endif /* $cond_macro */"
config-host.h only contains #define entries, and GCC doesn't choke when as long as the definitions are the same. What is the use case of this patch?
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 5 lines · Aurelien Jarno
Quoted 1 line · Tristan Gingold
To avoid redefinition warnings.
config-host.honly contains #define entries, and GCC doesn't choke when as long as the definitions are the same. What is the use case of this patch?
Mostly a style issue. It is common to always protect header files against multiple inclusion, unless the header is meant to be included several times (which is not the case for these config files). I think this is a good practice.
I once got redefinition warnings for macros in config-host.h, but I agree that adding the guard macro doesn't fix this issue.
If you agree that adding guards is harmless and good style, I can change the comment.
Tristan.
Quoted 4 lines · Tristan Gingold
Mostly a style issue. It is common to always protect header files against multiple inclusion, unless the header is meant to be included several times (which is not the case for these config files). I think this is a good practice.
Traditionally, autoconf's config.h headers have no guards either. This can indeed cause some troubles. However, it also helps highlighting poor practices, such as libraries installing a config.h file including it from a public header.
Quoted 2 lines
I once got redefinition warnings for macros in
config-host.h, but I agree that adding the guard macro doesn't fix this issue.
config-host.h should always be the first included header (we are poor at this) and its macros should never conflict with anything else. I think we should rather fix the problems you've seen with config-host.h, if you can still reproduce them.
Paolo
Quoted 6 lines · Paolo Bonzini
Quoted 4 lines · Tristan Gingold
Mostly a style issue. It is common to always protect header files against multiple inclusion, unless the header is meant to be included several times (which is not the case for these config files). I think this is a good practice.
Quoted 6 lines
Traditionally, autoconf's
config.hheaders have no guards either. This can indeed cause some troubles. However, it also helps highlighting poor practices, such as libraries installing aconfig.hfile including it from a public header.Quoted 2 lines
I once got redefinition warnings for macros in
config-host.h, but I agree that adding the guard macro doesn't fix this issue.
config-host.hshould always be the first included header (we are poor at this) and its macros should never conflict with anything else. I think we should rather fix the problems you've seen withconfig-host.h, if you can still reproduce them.
Thank you. I will investigate the next time I have the issue and the time.
Tristan.