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