The Linux kernel has an existing script to sanitize headers which
uses more steps to clean up the header file. Make the DPDK header
import script use the same regular expression. The kernel script
is GPL-2.0 so ok.

Not necessary for current vduse.h header only but useful if more
headers are added later. Want the distro and DPDK header to
be exact match.

Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
 devtools/linux-uapi.sh | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/devtools/linux-uapi.sh b/devtools/linux-uapi.sh
index ccd8b6816e..e739bdb1f4 100755
--- a/devtools/linux-uapi.sh
+++ b/devtools/linux-uapi.sh
@@ -79,9 +79,21 @@ import_header()
 fixup_includes()
 {
        local path=$1
+       local tmpfile=$path.tmp
 
-       sed -i "s|^#include <linux/compiler.h>||g" $path
-       sed -i "s|\<__user[[:space:]]||" $path
+       # script to sanitize see kernel script
+       # 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/scripts/headers_install.sh
+
+       sed -E -e '
+            s/([[:space:](])(__user|__force|__iomem)[[:space:]]/\1/g
+            s/__attribute_const__([[:space:]]|$)/\1/g
+            s@^#include <linux/compiler(|_types).h>@@
+            
s/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g
+            
s/(^|[[:space:](])(inline|asm|volatile)([[:space:](]|$)/\1__\2__\3/g
+           s@#(ifndef|define|endif[[:space:]]*/[*])[[:space:]]*_UAPI@#\1 @' 
$path >$tmpfile
+
+       unifdef -U__KERNEL__ -D__EXPORTED_HEADERS $tmpfile >$path
+       rm $tmpfile
 
        # Prepend include path with "uapi/" if the header is imported
        for include in $(sed -ne 's/^#include <\(.*\)>$/\1/p' $path); do
-- 
2.47.2

Reply via email to