Make it easier to build libminijail on Chromium Linux.

- Move libsyscalls.gen.c generation code out of the Makefile and into a
  script.
- Add SECURE_ALL_* defines for systems that do not linux/securebits.h.

BUG=chromium-os:35482
TEST=FEATURES=test emerge chromeos-minijail

Change-Id: I922c579f1fcf09db2379659dbde737f246200e51
Reviewed-on: https://gerrit.chromium.org/gerrit/35928
Reviewed-by: Jorge Lucangeli Obes <jorgelo@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Commit-Ready: Lei Zhang <thestig@chromium.org>
Tested-by: Lei Zhang <thestig@chromium.org>
diff --git a/Makefile b/Makefile
index b953b66..cd6b51c 100644
--- a/Makefile
+++ b/Makefile
@@ -8,6 +8,10 @@
 CFLAGS += -fPIC -Wall -Wextra -Werror -DPRELOADPATH="$(PRELOADPATH)"
 CFLAGS += -fvisibility=internal
 
+ifneq ($(HAVE_SECUREBITS_H),no)
+CFLAGS += -DHAVE_SECUREBITS_H
+endif
+
 all : minijail0 libminijail.so libminijailpreload.so
 
 tests : libminijail_unittest.wrapper syscall_filter_unittest
@@ -59,43 +63,11 @@
 
 util.o : util.c util.h
 
-# sed expression which extracts system calls that are
-# defined via asm/unistd.h.  It converts them from:
-#  #define __NR_read
-# to:
-# #ifdef __NR_read
-#  { "read", __NR_read },
-# #endif
-# All other lines will not be emitted.  The sed expression lives in its
-# own macro to allow clean line wrapping.
-define sed-multiline
-	's/#define __\(ARM_\)\?\(NR_\)\([a-z0-9_]*\)$$/#ifdef __\1\2\3\n\
-	 { "\1\3", __\1\2\3 },\n#endif/g p;'
-endef
-
-# Generates a header file with a system call table made up of "name",
-# syscall_nr entries by including the build target <asm/unistd.h> and
-# emitting the list of defines.  Use of the compiler is needed to
-# dereference the actual provider of syscall definitions.
-#   E.g., asm/unistd_32.h or asm/unistd_64.h, etc.
-define gen_syscalls
-	(set -e; \
-	 echo '/* GENERATED BY MAKEFILE */'; \
-	 echo '#include <stddef.h>'; \
-	 echo '#include <asm/unistd.h>'; \
-	 echo '#include "libsyscalls.h"'; \
-	 echo "const struct syscall_entry syscall_table[] = {"; \
-	 echo "#include <asm/unistd.h>" | \
-	   $(CC) $(CFLAGS) -dN - -E | sed -ne $(sed-multiline); \
-	 echo "  { NULL, -1 },"; \
-	 echo "};" ) > $1
-endef
-
 # Only regenerate libsyscalls.gen.c if the Makefile or header changes.
 # NOTE! This will not detect if the file is not appropriate for the target.
 libsyscalls.gen.c : Makefile libsyscalls.h
 	@printf "Generating target-arch specific $@ . . . "
-	@$(call gen_syscalls,$@)
+	@./gen_syscalls.sh $@
 	@printf "done.\n"
 
 # Only clean up files affected by the CFLAGS change for testing.