1# Support building the Python bindings multiple times, against various Python 2# runtimes (e.g. Python 2 vs Python 3) by optionally prefixing the build 3# targets with "PYPREFIX": 4PYTHON ?= python 5PYPREFIX ?= $(notdir $(PYTHON)) 6RUBY ?= ruby 7RUBYPREFIX ?= $(notdir $(RUBY)) 8 9# Installation directories. 10PREFIX ?= $(DESTDIR)/usr 11LIBDIR ?= $(PREFIX)/lib 12SHLIBDIR ?= $(DESTDIR)/lib 13INCLUDEDIR ?= $(PREFIX)/include 14PYLIBVER ?= $(shell $(PYTHON) -c 'import sys;print("python%d.%d" % sys.version_info[0:2])') 15PYINC ?= $(shell pkg-config --cflags $(PYPREFIX)) 16PYLIBDIR ?= $(LIBDIR)/$(PYLIBVER) 17RUBYLIBVER ?= $(shell $(RUBY) -e 'print RUBY_VERSION.split(".")[0..1].join(".")') 18RUBYPLATFORM ?= $(shell $(RUBY) -e 'print RUBY_PLATFORM') 19RUBYINC ?= $(shell pkg-config --cflags ruby) 20RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM) 21LIBBASE ?= $(shell basename $(LIBDIR)) 22 23VERSION = $(shell cat ../VERSION) 24LIBVERSION = 1 25 26LIBA=libselinux.a 27TARGET=libselinux.so 28LIBPC=libselinux.pc 29SWIGIF= selinuxswig_python.i selinuxswig_python_exception.i 30SWIGRUBYIF= selinuxswig_ruby.i 31SWIGCOUT= selinuxswig_wrap.c 32SWIGRUBYCOUT= selinuxswig_ruby_wrap.c 33SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT)) 34SWIGRUBYLOBJ:= $(patsubst %.c,%.lo,$(SWIGRUBYCOUT)) 35SWIGSO=$(PYPREFIX)_selinux.so 36SWIGFILES=$(SWIGSO) selinux.py 37SWIGRUBYSO=$(RUBYPREFIX)_selinux.so 38LIBSO=$(TARGET).$(LIBVERSION) 39AUDIT2WHYLOBJ=$(PYPREFIX)audit2why.lo 40AUDIT2WHYSO=$(PYPREFIX)audit2why.so 41 42ifeq ($(DISABLE_AVC),y) 43 UNUSED_SRCS+=avc.c avc_internal.c avc_sidtab.c mapping.c stringrep.c checkAccess.c 44endif 45ifeq ($(DISABLE_BOOL),y) 46 UNUSED_SRCS+=booleans.c 47endif 48 49GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) selinuxswig_python_exception.i 50SRCS= $(filter-out $(UNUSED_SRCS) $(GENERATED) audit2why.c, $(wildcard *.c)) 51 52MAX_STACK_SIZE=32768 53 54OBJS= $(patsubst %.c,%.o,$(SRCS)) 55LOBJS= $(patsubst %.c,%.lo,$(SRCS)) 56CFLAGS ?= -O -Wall -W -Wundef -Wformat-y2k -Wformat-security -Winit-self -Wmissing-include-dirs \ 57 -Wunused -Wunknown-pragmas -Wstrict-aliasing -Wshadow -Wpointer-arith \ 58 -Wbad-function-cast -Wcast-align -Wwrite-strings -Wlogical-op -Waggregate-return \ 59 -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes \ 60 -Wmissing-declarations -Wmissing-noreturn -Wmissing-format-attribute \ 61 -Wredundant-decls -Wnested-externs -Winline -Winvalid-pch -Wvolatile-register-var \ 62 -Wdisabled-optimization -Wbuiltin-macro-redefined -Wpacked-bitfield-compat \ 63 -Wsync-nand -Wattributes -Wcoverage-mismatch -Wmultichar -Wcpp \ 64 -Wdeprecated-declarations -Wdiv-by-zero -Wdouble-promotion -Wendif-labels -Wextra \ 65 -Wformat-contains-nul -Wformat-extra-args -Wformat-zero-length -Wformat=2 -Wmultichar \ 66 -Wnormalized=nfc -Woverflow -Wpointer-to-int-cast -Wpragmas -Wsuggest-attribute=const \ 67 -Wsuggest-attribute=noreturn -Wsuggest-attribute=pure -Wtrampolines \ 68 -Wno-missing-field-initializers -Wno-sign-compare -Wjump-misses-init \ 69 -Wno-format-nonliteral -Wframe-larger-than=$(MAX_STACK_SIZE) -Wp,-D_FORTIFY_SOURCE=2 \ 70 -fstack-protector-all --param=ssp-buffer-size=4 -fexceptions \ 71 -fasynchronous-unwind-tables -fdiagnostics-show-option -funit-at-a-time \ 72 -fipa-pure-const -Wno-suggest-attribute=pure -Wno-suggest-attribute=const \ 73 -Werror -Wno-aggregate-return -Wno-redundant-decls 74 75override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 $(EMFLAGS) 76 77SWIG_CFLAGS += -Wno-error -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-parameter \ 78 -Wno-shadow -Wno-uninitialized -Wno-missing-prototypes -Wno-missing-declarations 79 80RANLIB ?= ranlib 81 82ARCH := $(patsubst i%86,i386,$(shell uname -m)) 83ifneq (,$(filter i386,$(ARCH))) 84TLSFLAGS += -mno-tls-direct-seg-refs 85endif 86 87SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./ 88 89SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ 90 91all: $(LIBA) $(LIBSO) $(LIBPC) 92 93pywrap: all $(SWIGSO) $(AUDIT2WHYSO) 94 95rubywrap: all $(SWIGRUBYSO) 96 97$(SWIGLOBJ): $(SWIGCOUT) 98 $(CC) $(CFLAGS) $(SWIG_CFLAGS) $(PYINC) -fPIC -DSHARED -c -o $@ $< 99 100$(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) 101 $(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $< 102 103$(SWIGSO): $(SWIGLOBJ) 104 $(CC) $(CFLAGS) -shared -o $@ $< -L. -lselinux $(LDFLAGS) -L$(LIBDIR) 105 106$(SWIGRUBYSO): $(SWIGRUBYLOBJ) 107 $(CC) $(CFLAGS) -shared -o $@ $^ -L. -lselinux $(LDFLAGS) -L$(LIBDIR) 108 109$(LIBA): $(OBJS) 110 $(AR) rcs $@ $^ 111 $(RANLIB) $@ 112 113$(LIBSO): $(LOBJS) 114 $(CC) $(CFLAGS) -shared -o $@ $^ -lpcre -ldl $(LDFLAGS) -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro 115 ln -sf $@ $(TARGET) 116 117$(LIBPC): $(LIBPC).in ../VERSION 118 sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@ 119 120selinuxswig_python_exception.i: ../include/selinux/selinux.h 121 bash exception.sh > $@ 122 123$(AUDIT2WHYLOBJ): audit2why.c 124 $(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $< 125 126$(AUDIT2WHYSO): $(AUDIT2WHYLOBJ) 127 $(CC) $(CFLAGS) -shared -o $@ $^ -L. $(LDFLAGS) -lselinux $(LIBDIR)/libsepol.a -L$(LIBDIR) 128 129%.o: %.c policy.h 130 $(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $< 131 132%.lo: %.c policy.h 133 $(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $< 134 135$(SWIGCOUT): $(SWIGIF) 136 $(SWIG) $< 137 138$(SWIGRUBYCOUT): $(SWIGRUBYIF) 139 $(SWIGRUBY) $< 140 141swigify: $(SWIGIF) 142 $(SWIG) $< 143 144install: all 145 test -d $(LIBDIR) || install -m 755 -d $(LIBDIR) 146 install -m 644 $(LIBA) $(LIBDIR) 147 test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR) 148 install -m 755 $(LIBSO) $(SHLIBDIR) 149 test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig 150 install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig 151 ln -sf --relative $(SHLIBDIR)/$(LIBSO) $(LIBDIR)/$(TARGET) 152 153install-pywrap: pywrap 154 test -d $(PYLIBDIR)/site-packages/selinux || install -m 755 -d $(PYLIBDIR)/site-packages/selinux 155 install -m 755 $(SWIGSO) $(PYLIBDIR)/site-packages/selinux/_selinux.so 156 install -m 755 $(AUDIT2WHYSO) $(PYLIBDIR)/site-packages/selinux/audit2why.so 157 install -m 644 selinux.py $(PYLIBDIR)/site-packages/selinux/__init__.py 158 159install-rubywrap: rubywrap 160 test -d $(RUBYINSTALL) || install -m 755 -d $(RUBYINSTALL) 161 install -m 755 $(SWIGRUBYSO) $(RUBYINSTALL)/selinux.so 162 163relabel: 164 /sbin/restorecon $(SHLIBDIR)/$(LIBSO) 165 166clean: 167 -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGRUBYLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~ 168 169distclean: clean 170 rm -f $(GENERATED) $(SWIGFILES) 171 172indent: 173 ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch])) 174 175.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean 176