Jorge Lucangeli Obes | fc8ab53 | 2012-03-20 10:14:31 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
Sonny Rao | b5d537d | 2011-10-21 22:17:13 +0000 | [diff] [blame] | 5 | LIBDIR = lib |
| 6 | PRELOADPATH = \"/$(LIBDIR)/libminijailpreload.so\" |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 7 | CFLAGS += -fPIC -Wall -Wextra -Werror -DPRELOADPATH="$(PRELOADPATH)" |
Will Drewry | 6ac9112 | 2011-10-21 16:38:58 -0500 | [diff] [blame] | 8 | CFLAGS += -fvisibility=internal |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 9 | |
Ben Chan | 4539701 | 2011-08-23 08:15:03 -0700 | [diff] [blame] | 10 | all : minijail0 libminijail.so libminijailpreload.so |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 11 | |
Jorge Lucangeli Obes | fc8ab53 | 2012-03-20 10:14:31 -0700 | [diff] [blame] | 12 | tests : libminijail_unittest.wrapper syscall_filter_unittest |
Will Drewry | 6ac9112 | 2011-10-21 16:38:58 -0500 | [diff] [blame] | 13 | |
Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 14 | minijail0 : libsyscalls.gen.o libminijail.o syscall_filter.o bpf.o util.o \ |
| 15 | minijail0.c |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 16 | $(CC) $(CFLAGS) -o $@ $^ -lcap |
| 17 | |
Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 18 | libminijail.so : libminijail.o syscall_filter.o bpf.o util.o libsyscalls.gen.o |
Ben Chan | 4539701 | 2011-08-23 08:15:03 -0700 | [diff] [blame] | 19 | $(CC) $(CFLAGS) -shared -o $@ $^ -lcap |
| 20 | |
Will Drewry | 6ac9112 | 2011-10-21 16:38:58 -0500 | [diff] [blame] | 21 | # Allow unittests to access what are normally internal symbols. |
| 22 | libminijail_unittest.wrapper : |
| 23 | $(MAKE) $(MAKEARGS) test-clean |
| 24 | $(MAKE) $(MAKEARGS) libminijail_unittest |
| 25 | $(MAKE) $(MAKEARGS) test-clean |
| 26 | |
| 27 | libminijail_unittest : CFLAGS := $(filter-out -fvisibility=%,$(CFLAGS)) |
Jorge Lucangeli Obes | 524c040 | 2012-01-17 11:30:23 -0800 | [diff] [blame] | 28 | libminijail_unittest : libminijail_unittest.o libminijail.o \ |
Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 29 | syscall_filter.o bpf.o util.o libsyscalls.gen.o |
Will Drewry | 6ac9112 | 2011-10-21 16:38:58 -0500 | [diff] [blame] | 30 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter-out $(CFLAGS_FILE),$^) -lcap |
Will Drewry | decdfdc | 2011-09-27 15:13:54 -0500 | [diff] [blame] | 31 | |
Jorge Lucangeli Obes | 524c040 | 2012-01-17 11:30:23 -0800 | [diff] [blame] | 32 | libminijailpreload.so : libminijailpreload.c libminijail.o libsyscalls.gen.o \ |
Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 33 | syscall_filter.o bpf.o util.o |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 34 | $(CC) $(CFLAGS) -shared -o $@ $^ -ldl -lcap |
| 35 | |
Thieu Le | f0ef52e | 2011-09-14 14:03:09 -0700 | [diff] [blame] | 36 | libminijail.o : libminijail.c libminijail.h |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 37 | |
Will Drewry | decdfdc | 2011-09-27 15:13:54 -0500 | [diff] [blame] | 38 | libminijail_unittest.o : libminijail_unittest.c test_harness.h |
| 39 | $(CC) $(CFLAGS) -c -o $@ $< |
| 40 | |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 41 | libsyscalls.gen.o : libsyscalls.gen.c libsyscalls.h |
| 42 | |
Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 43 | syscall_filter_unittest : syscall_filter_unittest.o syscall_filter.o \ |
| 44 | bpf.o util.o libsyscalls.gen.o test_harness.h |
Jorge Lucangeli Obes | fc8ab53 | 2012-03-20 10:14:31 -0700 | [diff] [blame] | 45 | $(CC) $(CFLAGS) -o $@ $^ |
| 46 | |
| 47 | syscall_filter_unittest.o : syscall_filter_unittest.c test_harness.h |
| 48 | $(CC) $(CFLAGS) -c -o $@ $< |
| 49 | |
Jorge Lucangeli Obes | 524c040 | 2012-01-17 11:30:23 -0800 | [diff] [blame] | 50 | syscall_filter.o : syscall_filter.c syscall_filter.h |
Jorge Lucangeli Obes | fc8ab53 | 2012-03-20 10:14:31 -0700 | [diff] [blame] | 51 | |
Jorge Lucangeli Obes | 524c040 | 2012-01-17 11:30:23 -0800 | [diff] [blame] | 52 | bpf.o : bpf.c bpf.h |
Jorge Lucangeli Obes | fc8ab53 | 2012-03-20 10:14:31 -0700 | [diff] [blame] | 53 | |
Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 54 | util.o : util.c util.h |
| 55 | |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 56 | # sed expression which extracts system calls that are |
| 57 | # defined via asm/unistd.h. It converts them from: |
| 58 | # #define __NR_read |
| 59 | # to: |
| 60 | # #ifdef __NR_read |
| 61 | # { "read", __NR_read }, |
| 62 | # #endif |
| 63 | # All other lines will not be emitted. The sed expression lives in its |
| 64 | # own macro to allow clean line wrapping. |
| 65 | define sed-multiline |
Ben Chan | 6a82437 | 2012-07-21 16:30:52 -0700 | [diff] [blame] | 66 | 's/#define __\(ARM_\)\?\(NR_\)\([a-z0-9_]*\)$$/#ifdef __\1\2\3\n\ |
| 67 | { "\1\3", __\1\2\3 },\n#endif/g p;' |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 68 | endef |
| 69 | |
| 70 | # Generates a header file with a system call table made up of "name", |
| 71 | # syscall_nr entries by including the build target <asm/unistd.h> and |
| 72 | # emitting the list of defines. Use of the compiler is needed to |
| 73 | # dereference the actual provider of syscall definitions. |
| 74 | # E.g., asm/unistd_32.h or asm/unistd_64.h, etc. |
| 75 | define gen_syscalls |
| 76 | (set -e; \ |
| 77 | echo '/* GENERATED BY MAKEFILE */'; \ |
| 78 | echo '#include <stddef.h>'; \ |
| 79 | echo '#include <asm/unistd.h>'; \ |
| 80 | echo '#include "libsyscalls.h"'; \ |
| 81 | echo "const struct syscall_entry syscall_table[] = {"; \ |
| 82 | echo "#include <asm/unistd.h>" | \ |
| 83 | $(CC) $(CFLAGS) -dN - -E | sed -ne $(sed-multiline); \ |
| 84 | echo " { NULL, -1 },"; \ |
| 85 | echo "};" ) > $1 |
| 86 | endef |
| 87 | |
| 88 | # Only regenerate libsyscalls.gen.c if the Makefile or header changes. |
| 89 | # NOTE! This will not detect if the file is not appropriate for the target. |
| 90 | libsyscalls.gen.c : Makefile libsyscalls.h |
| 91 | @printf "Generating target-arch specific $@ . . . " |
| 92 | @$(call gen_syscalls,$@) |
| 93 | @printf "done.\n" |
| 94 | |
Will Drewry | 6ac9112 | 2011-10-21 16:38:58 -0500 | [diff] [blame] | 95 | # Only clean up files affected by the CFLAGS change for testing. |
| 96 | test-clean : |
| 97 | @rm -f libminijail.o libminijail_unittest.o libsyscalls.gen.o |
| 98 | |
| 99 | clean : test-clean |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 100 | @rm -f libminijail.o libminijailpreload.so minijail0 |
Will Drewry | 6ac9112 | 2011-10-21 16:38:58 -0500 | [diff] [blame] | 101 | @rm -f libminijail.so |
| 102 | @rm -f libminijail_unittest |
| 103 | @rm -f libsyscalls.gen.c |
Jorge Lucangeli Obes | a6b034d | 2012-08-07 15:29:20 -0700 | [diff] [blame^] | 104 | @rm -f syscall_filter.o bpf.o util.o |
Jorge Lucangeli Obes | fc8ab53 | 2012-03-20 10:14:31 -0700 | [diff] [blame] | 105 | @rm -f syscall_filter_unittest syscall_filter_unittest.o |