blob: 37e99d9883a5c79059d5774395cd65aa9852d7f8 [file] [log] [blame]
Elly Jonescd7a9042011-07-22 13:56:51 -04001# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5PRELOADPATH ?= \"/lib/libminijailpreload.so\"
6CFLAGS += -fPIC -Wall -Wextra -Werror -DPRELOADPATH="$(PRELOADPATH)"
7
Ben Chan45397012011-08-23 08:15:03 -07008all : minijail0 libminijail.so libminijailpreload.so
Elly Jonescd7a9042011-07-22 13:56:51 -04009
Will Drewry32ac9f52011-08-18 21:36:27 -050010minijail0 : libsyscalls.gen.o libminijail.o minijail0.c
Elly Jonescd7a9042011-07-22 13:56:51 -040011 $(CC) $(CFLAGS) -o $@ $^ -lcap
12
Will Drewry32ac9f52011-08-18 21:36:27 -050013libminijail.so : libminijail.o libsyscalls.gen.o
Ben Chan45397012011-08-23 08:15:03 -070014 $(CC) $(CFLAGS) -shared -o $@ $^ -lcap
15
Will Drewry32ac9f52011-08-18 21:36:27 -050016libminijailpreload.so : libminijailpreload.c libsyscalls.gen.o libminijail.o
Elly Jonescd7a9042011-07-22 13:56:51 -040017 $(CC) $(CFLAGS) -shared -o $@ $^ -ldl -lcap
18
Thieu Lef0ef52e2011-09-14 14:03:09 -070019libminijail.o : libminijail.c libminijail.h
Will Drewry32ac9f52011-08-18 21:36:27 -050020
21libsyscalls.gen.o : libsyscalls.gen.c libsyscalls.h
22
23# sed expression which extracts system calls that are
24# defined via asm/unistd.h. It converts them from:
25# #define __NR_read
26# to:
27# #ifdef __NR_read
28# { "read", __NR_read },
29# #endif
30# All other lines will not be emitted. The sed expression lives in its
31# own macro to allow clean line wrapping.
32define sed-multiline
33 's/#define \(__NR_\)\([a-z0-9_]*\)$$/#ifdef \1\2\n\
34 { "\2", \1\2 },\n#endif/g p;'
35endef
36
37# Generates a header file with a system call table made up of "name",
38# syscall_nr entries by including the build target <asm/unistd.h> and
39# emitting the list of defines. Use of the compiler is needed to
40# dereference the actual provider of syscall definitions.
41# E.g., asm/unistd_32.h or asm/unistd_64.h, etc.
42define gen_syscalls
43 (set -e; \
44 echo '/* GENERATED BY MAKEFILE */'; \
45 echo '#include <stddef.h>'; \
46 echo '#include <asm/unistd.h>'; \
47 echo '#include "libsyscalls.h"'; \
48 echo "const struct syscall_entry syscall_table[] = {"; \
49 echo "#include <asm/unistd.h>" | \
50 $(CC) $(CFLAGS) -dN - -E | sed -ne $(sed-multiline); \
51 echo " { NULL, -1 },"; \
52 echo "};" ) > $1
53endef
54
55# Only regenerate libsyscalls.gen.c if the Makefile or header changes.
56# NOTE! This will not detect if the file is not appropriate for the target.
57libsyscalls.gen.c : Makefile libsyscalls.h
58 @printf "Generating target-arch specific $@ . . . "
59 @$(call gen_syscalls,$@)
60 @printf "done.\n"
61
62clean :
63 @rm -f libminijail.o libminijailpreload.so minijail0
64 @rm -f libsyscalls.gen.c libsyscalls.gen.o