scripts: gen_syscalls: Add compiler check to pragma.
This commit addresses the following portability issues:
1. gen_syscalls incorrectly assumes that the compiler is always GCC.
2. pragma GCC diagnostic push and pop are not supported in GCC < 4.6.
Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
diff --git a/scripts/gen_syscalls.py b/scripts/gen_syscalls.py
index beffaf7..3fc9f09 100755
--- a/scripts/gen_syscalls.py
+++ b/scripts/gen_syscalls.py
@@ -80,8 +80,13 @@
#include <syscall_list.h>
#include <syscall_macros.h>
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic push
+#endif
+
+#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
+#endif
#ifdef __cplusplus
extern "C" {
@@ -93,7 +98,9 @@
}
#endif
+#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic pop
+#endif
#endif
#endif /* include guard */
@@ -411,12 +418,18 @@
with open(mrsh_fn, "w") as fp:
fp.write("/* auto-generated by gen_syscalls.py, don't edit */\n")
+ fp.write("#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)\n")
fp.write("#pragma GCC diagnostic push\n")
+ fp.write("#endif\n")
+ fp.write("#ifdef __GNUC__\n")
fp.write("#pragma GCC diagnostic ignored \"-Wstrict-aliasing\"\n")
+ fp.write("#endif\n")
fp.write(mrsh_includes[fn] + "\n")
fp.write("\n")
fp.write(mrsh_defs[fn] + "\n")
+ fp.write("#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)\n")
fp.write("#pragma GCC diagnostic pop\n")
+ fp.write("#endif\n")
if __name__ == "__main__":
main()