blob: afde28275926b2238da9d15722fa7bacf8883279 [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 Drewrydecdfdc2011-09-27 15:13:54 -050016libminijail_unittest : libminijail_unittest.o libminijail.o libsyscalls.gen.o
17 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lcap
18
Will Drewry32ac9f52011-08-18 21:36:27 -050019libminijailpreload.so : libminijailpreload.c libsyscalls.gen.o libminijail.o
Elly Jonescd7a9042011-07-22 13:56:51 -040020 $(CC) $(CFLAGS) -shared -o $@ $^ -ldl -lcap
21
Thieu Lef0ef52e2011-09-14 14:03:09 -070022libminijail.o : libminijail.c libminijail.h
Will Drewry32ac9f52011-08-18 21:36:27 -050023
Will Drewrydecdfdc2011-09-27 15:13:54 -050024libminijail_unittest.o : libminijail_unittest.c test_harness.h
25 $(CC) $(CFLAGS) -c -o $@ $<
26
Will Drewry32ac9f52011-08-18 21:36:27 -050027libsyscalls.gen.o : libsyscalls.gen.c libsyscalls.h
28
29# sed expression which extracts system calls that are
30# defined via asm/unistd.h. It converts them from:
31# #define __NR_read
32# to:
33# #ifdef __NR_read
34# { "read", __NR_read },
35# #endif
36# All other lines will not be emitted. The sed expression lives in its
37# own macro to allow clean line wrapping.
38define sed-multiline
39 's/#define \(__NR_\)\([a-z0-9_]*\)$$/#ifdef \1\2\n\
40 { "\2", \1\2 },\n#endif/g p;'
41endef
42
43# Generates a header file with a system call table made up of "name",
44# syscall_nr entries by including the build target <asm/unistd.h> and
45# emitting the list of defines. Use of the compiler is needed to
46# dereference the actual provider of syscall definitions.
47# E.g., asm/unistd_32.h or asm/unistd_64.h, etc.
48define gen_syscalls
49 (set -e; \
50 echo '/* GENERATED BY MAKEFILE */'; \
51 echo '#include <stddef.h>'; \
52 echo '#include <asm/unistd.h>'; \
53 echo '#include "libsyscalls.h"'; \
54 echo "const struct syscall_entry syscall_table[] = {"; \
55 echo "#include <asm/unistd.h>" | \
56 $(CC) $(CFLAGS) -dN - -E | sed -ne $(sed-multiline); \
57 echo " { NULL, -1 },"; \
58 echo "};" ) > $1
59endef
60
61# Only regenerate libsyscalls.gen.c if the Makefile or header changes.
62# NOTE! This will not detect if the file is not appropriate for the target.
63libsyscalls.gen.c : Makefile libsyscalls.h
64 @printf "Generating target-arch specific $@ . . . "
65 @$(call gen_syscalls,$@)
66 @printf "done.\n"
67
68clean :
69 @rm -f libminijail.o libminijailpreload.so minijail0
Will Drewrydecdfdc2011-09-27 15:13:54 -050070 @rm -f libminijail_unittest libminijail_unittest.o
Will Drewry32ac9f52011-08-18 21:36:27 -050071 @rm -f libsyscalls.gen.c libsyscalls.gen.o