blob: eb94b8609ef6e3c3cad806bf833317bce5f117f7 [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)"
Will Drewry6ac91122011-10-21 16:38:58 -05008CFLAGS += -fvisibility=internal
Elly Jonescd7a9042011-07-22 13:56:51 -04009
Ben Chan45397012011-08-23 08:15:03 -070010all : minijail0 libminijail.so libminijailpreload.so
Elly Jonescd7a9042011-07-22 13:56:51 -040011
Will Drewry6ac91122011-10-21 16:38:58 -050012tests : libminijail_unittest.wrapper
13
Will Drewry32ac9f52011-08-18 21:36:27 -050014minijail0 : libsyscalls.gen.o libminijail.o minijail0.c
Elly Jonescd7a9042011-07-22 13:56:51 -040015 $(CC) $(CFLAGS) -o $@ $^ -lcap
16
Will Drewry32ac9f52011-08-18 21:36:27 -050017libminijail.so : libminijail.o libsyscalls.gen.o
Ben Chan45397012011-08-23 08:15:03 -070018 $(CC) $(CFLAGS) -shared -o $@ $^ -lcap
19
Will Drewry6ac91122011-10-21 16:38:58 -050020# Allow unittests to access what are normally internal symbols.
21libminijail_unittest.wrapper :
22 $(MAKE) $(MAKEARGS) test-clean
23 $(MAKE) $(MAKEARGS) libminijail_unittest
24 $(MAKE) $(MAKEARGS) test-clean
25
26libminijail_unittest : CFLAGS := $(filter-out -fvisibility=%,$(CFLAGS))
Will Drewrydecdfdc2011-09-27 15:13:54 -050027libminijail_unittest : libminijail_unittest.o libminijail.o libsyscalls.gen.o
Will Drewry6ac91122011-10-21 16:38:58 -050028 $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(filter-out $(CFLAGS_FILE),$^) -lcap
Will Drewrydecdfdc2011-09-27 15:13:54 -050029
Will Drewry32ac9f52011-08-18 21:36:27 -050030libminijailpreload.so : libminijailpreload.c libsyscalls.gen.o libminijail.o
Elly Jonescd7a9042011-07-22 13:56:51 -040031 $(CC) $(CFLAGS) -shared -o $@ $^ -ldl -lcap
32
Thieu Lef0ef52e2011-09-14 14:03:09 -070033libminijail.o : libminijail.c libminijail.h
Will Drewry32ac9f52011-08-18 21:36:27 -050034
Will Drewrydecdfdc2011-09-27 15:13:54 -050035libminijail_unittest.o : libminijail_unittest.c test_harness.h
36 $(CC) $(CFLAGS) -c -o $@ $<
37
Will Drewry32ac9f52011-08-18 21:36:27 -050038libsyscalls.gen.o : libsyscalls.gen.c libsyscalls.h
39
40# sed expression which extracts system calls that are
41# defined via asm/unistd.h. It converts them from:
42# #define __NR_read
43# to:
44# #ifdef __NR_read
45# { "read", __NR_read },
46# #endif
47# All other lines will not be emitted. The sed expression lives in its
48# own macro to allow clean line wrapping.
49define sed-multiline
50 's/#define \(__NR_\)\([a-z0-9_]*\)$$/#ifdef \1\2\n\
51 { "\2", \1\2 },\n#endif/g p;'
52endef
53
54# Generates a header file with a system call table made up of "name",
55# syscall_nr entries by including the build target <asm/unistd.h> and
56# emitting the list of defines. Use of the compiler is needed to
57# dereference the actual provider of syscall definitions.
58# E.g., asm/unistd_32.h or asm/unistd_64.h, etc.
59define gen_syscalls
60 (set -e; \
61 echo '/* GENERATED BY MAKEFILE */'; \
62 echo '#include <stddef.h>'; \
63 echo '#include <asm/unistd.h>'; \
64 echo '#include "libsyscalls.h"'; \
65 echo "const struct syscall_entry syscall_table[] = {"; \
66 echo "#include <asm/unistd.h>" | \
67 $(CC) $(CFLAGS) -dN - -E | sed -ne $(sed-multiline); \
68 echo " { NULL, -1 },"; \
69 echo "};" ) > $1
70endef
71
72# Only regenerate libsyscalls.gen.c if the Makefile or header changes.
73# NOTE! This will not detect if the file is not appropriate for the target.
74libsyscalls.gen.c : Makefile libsyscalls.h
75 @printf "Generating target-arch specific $@ . . . "
76 @$(call gen_syscalls,$@)
77 @printf "done.\n"
78
Will Drewry6ac91122011-10-21 16:38:58 -050079# Only clean up files affected by the CFLAGS change for testing.
80test-clean :
81 @rm -f libminijail.o libminijail_unittest.o libsyscalls.gen.o
82
83clean : test-clean
Will Drewry32ac9f52011-08-18 21:36:27 -050084 @rm -f libminijail.o libminijailpreload.so minijail0
Will Drewry6ac91122011-10-21 16:38:58 -050085 @rm -f libminijail.so
86 @rm -f libminijail_unittest
87 @rm -f libsyscalls.gen.c