xref: /freebsd/contrib/capsicum-test/GNUmakefile (revision e17f5b1d)
1OS:=$(shell uname)
2
3# Set ARCH to 32 or x32 for i386/x32 ABIs
4ARCH?=64
5ARCHFLAG=-m$(ARCH)
6
7ifeq ($(OS),Linux)
8PROCESSOR:=$(shell uname -p)
9
10ifneq ($(wildcard /usr/lib/$(PROCESSOR)-linux-gnu),)
11# Can use standard Debian location for static libraries.
12PLATFORM_LIBDIR=/usr/lib/$(PROCESSOR)-linux-gnu
13else
14# Attempt to determine library location from gcc configuration.
15PLATFORM_LIBDIR=$(shell gcc -v 2>&1 | grep "Configured with:" | sed 's/.*--libdir=\(\/usr\/[^ ]*\).*/\1/g')
16endif
17
18# Override for explicitly specified ARCHFLAG.
19# Use locally compiled libcaprights in this case, on the
20# assumption that any installed version is 64-bit.
21ifeq ($(ARCHFLAG),-m32)
22PROCESSOR=i386
23PLATFORM_LIBDIR=/usr/lib32
24LIBCAPRIGHTS=./libcaprights.a
25endif
26ifeq ($(ARCHFLAG),-mx32)
27PROCESSOR=x32
28PLATFORM_LIBDIR=/usr/libx32
29LIBCAPRIGHTS=./libcaprights.a
30endif
31
32# Detect presence of libsctp in normal Debian location
33ifneq ($(wildcard $(PLATFORM_LIBDIR)/libsctp.a),)
34LIBSCTP=-lsctp
35CXXFLAGS=-DHAVE_SCTP
36endif
37
38ifneq ($(LIBCAPRIGHTS),)
39# Build local libcaprights.a (assuming ./configure
40# has already been done in libcaprights/)
41LOCAL_LIBS=$(LIBCAPRIGHTS)
42LIBCAPRIGHTS_OBJS=libcaprights/capsicum.o libcaprights/linux-bpf-capmode.o libcaprights/procdesc.o libcaprights/signal.o
43LOCAL_CLEAN=$(LOCAL_LIBS) $(LIBCAPRIGHTS_OBJS)
44else
45# Detect installed libcaprights static library.
46ifneq ($(wildcard $(PLATFORM_LIBDIR)/libcaprights.a),)
47LIBCAPRIGHTS=$(PLATFORM_LIBDIR)/libcaprights.a
48else
49ifneq ($(wildcard /usr/lib/libcaprights.a),)
50LIBCAPRIGHTS=/usr/lib/libcaprights.a
51endif
52endif
53endif
54
55endif
56
57# Extra test programs for arch-transition tests
58EXTRA_PROGS = mini-me.32 mini-me.64
59ifneq ($(wildcard /usr/include/gnu/stubs-x32.h),)
60EXTRA_PROGS += mini-me.x32
61endif
62
63# Chain on to the master makefile
64include makefile
65
66./libcaprights.a: $(LIBCAPRIGHTS_OBJS)
67	ar cr $@ $^
68
69# Small static programs of known architectures
70# These may require additional packages to be installed; for example, for Debian:
71#  - libc6-dev-i386 provides 32-bit headers for a 64-bit system
72#  - libc6-dev-x32 provides headers for the x32 ABI.
73mini-me.32: mini-me.c
74	$(CC) $(CFLAGS) -m32 -static -o $@ $<
75mini-me.x32: mini-me.c
76	$(CC) $(CFLAGS) -mx32 -static -o $@ $<
77mini-me.64: mini-me.c
78	$(CC) $(CFLAGS) -m64 -static -o $@ $<
79