Framework for exporting system header to user space (#59)
[lunaix-os.git] / lunaix-os / scripts / gen-syscall-header
diff --git a/lunaix-os/scripts/gen-syscall-header b/lunaix-os/scripts/gen-syscall-header
new file mode 100755 (executable)
index 0000000..b32a52d
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+outfile="$1"
+
+read -d '' payload <<EOF
+#define SYSCALL(x) __NR##x __COUNTER__
+#include <asm/syscall_nr.inc>
+EOF
+
+body=$(echo "$payload" \
+      | gcc $CFLAGS -x none -E - -o- -nostdlib -P \
+      | sed -e 's/^__NR__/#define __NR__/' \
+      | sed -e '/#define/!d')
+
+cat <<EOF > "$outfile" 
+#ifndef __LUNAIX_SYSCALL_H
+#define __LUNAIX_SYSCALL_H
+
+$body
+
+#endif
+EOF
\ No newline at end of file