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