Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 1 | # 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 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)" |
| 8 | |
Ben Chan | 4539701 | 2011-08-23 08:15:03 -0700 | [diff] [blame] | 9 | all : minijail0 libminijail.so libminijailpreload.so |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 10 | |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 11 | minijail0 : libsyscalls.gen.o libminijail.o minijail0.c |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 12 | $(CC) $(CFLAGS) -o $@ $^ -lcap |
| 13 | |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 14 | libminijail.so : libminijail.o libsyscalls.gen.o |
Ben Chan | 4539701 | 2011-08-23 08:15:03 -0700 | [diff] [blame] | 15 | $(CC) $(CFLAGS) -shared -o $@ $^ -lcap |
| 16 | |
Will Drewry | decdfdc | 2011-09-27 15:13:54 -0500 | [diff] [blame] | 17 | libminijail_unittest : libminijail_unittest.o libminijail.o libsyscalls.gen.o |
| 18 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -lcap |
| 19 | |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 20 | libminijailpreload.so : libminijailpreload.c libsyscalls.gen.o libminijail.o |
Elly Jones | cd7a904 | 2011-07-22 13:56:51 -0400 | [diff] [blame] | 21 | $(CC) $(CFLAGS) -shared -o $@ $^ -ldl -lcap |
| 22 | |
Thieu Le | f0ef52e | 2011-09-14 14:03:09 -0700 | [diff] [blame] | 23 | libminijail.o : libminijail.c libminijail.h |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 24 | |
Will Drewry | decdfdc | 2011-09-27 15:13:54 -0500 | [diff] [blame] | 25 | libminijail_unittest.o : libminijail_unittest.c test_harness.h |
| 26 | $(CC) $(CFLAGS) -c -o $@ $< |
| 27 | |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 28 | libsyscalls.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. |
| 39 | define sed-multiline |
| 40 | 's/#define \(__NR_\)\([a-z0-9_]*\)$$/#ifdef \1\2\n\ |
| 41 | { "\2", \1\2 },\n#endif/g p;' |
| 42 | endef |
| 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. |
| 49 | define 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 |
| 60 | endef |
| 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. |
| 64 | libsyscalls.gen.c : Makefile libsyscalls.h |
| 65 | @printf "Generating target-arch specific $@ . . . " |
| 66 | @$(call gen_syscalls,$@) |
| 67 | @printf "done.\n" |
| 68 | |
| 69 | clean : |
| 70 | @rm -f libminijail.o libminijailpreload.so minijail0 |
Will Drewry | decdfdc | 2011-09-27 15:13:54 -0500 | [diff] [blame] | 71 | @rm -f libminijail_unittest libminijail_unittest.o |
Will Drewry | 32ac9f5 | 2011-08-18 21:36:27 -0500 | [diff] [blame] | 72 | @rm -f libsyscalls.gen.c libsyscalls.gen.o |