Skip to contentSkip to conversation

multilib_header: Place a #include guard to avoid infinite inclusion of headers

PATCH Superseded Khem Raj 1 participant 1 message Feb 1, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 multilib_header: Place a #include guard to avoid infinite inclusion of headers

In cases where extra preprocessing tools are used such as clang-tidy e.g. and these tools are not passed the knowledge about architecture then a corner case comes where we enter into include loop for bits/wordsize.h, since this template does explicitly include bits/wordsize.h

so it synthesized a guard out of file name e.g.

bits/wordsize.h -> __BITS_WORDSIZE_H__

and emits the guard at beginning of file

---
 meta/classes/multilib_header.bbclass | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
meta/classes/multilib_header.bbclass +7 -4
index e03f5b13b2..959e9cac74 100644
@@ -18,9 +18,9 @@ oe_multilib_header() {
         case ${TARGET_ARCH} in
         mips*)  case "${MIPSPKGSFX_ABI}" in
                 "-n32")
-                       ident=n32   
+                       ident=n32
                        ;;
-                *)     
+                *)
                        ident=${SITEINFO_BITS}
                        ;;
                 esac
@@ -33,10 +33,13 @@ oe_multilib_header() {
 	      continue
 	   fi
 	   stem=$(echo $each_header | sed 's#\.h$##')
+	   include_guard=$(echo $each_header | tr '/.' '_' | tr '[a-z]' '[A-Z]' | sed 's/^/__/' | sed 's/$/__/')
 	   # if mips64/n32 set ident to n32
 	   mv ${D}/${includedir}/$each_header ${D}/${includedir}/${stem}-${ident}.h
-
-	   sed -e "s#ENTER_HEADER_FILENAME_HERE#${stem}#g" ${COREBASE}/scripts/multilib_header_wrapper.h > ${D}/${includedir}/$each_header
+	   echo "#ifndef $include_guard" > ${D}/${includedir}/$each_header
+	   echo "#define $include_guard" >> ${D}/${includedir}/$each_header
+	   sed -e "s#ENTER_HEADER_FILENAME_HERE#${stem}#g" ${COREBASE}/scripts/multilib_header_wrapper.h >> ${D}/${includedir}/$each_header
+	   echo "#endif /* $include_guard */" > ${D}/${includedir}/$each_header
 	done
 }
 
Signature · 1 line
2.20.1