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-$(RUBYLIBVER)) 20RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM) 21 22LIBBASE=$(shell basename $(LIBDIR)) 23 24DEFAULT_SEMANAGE_CONF_LOCATION=$(DESTDIR)/etc/selinux/semanage.conf 25 26ifeq ($(DEBUG),1) 27 export CFLAGS = -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror 28 export LDFLAGS = -g 29endif 30 31LEX = flex 32LFLAGS = -s 33YACC = bison 34YFLAGS = -d 35 36VERSION = $(shell cat ../VERSION) 37LIBVERSION = 1 38 39LIBA=libsemanage.a 40TARGET=libsemanage.so 41LIBPC=libsemanage.pc 42SWIGIF= semanageswig_python.i semanageswig_python_exception.i 43SWIGRUBYIF= semanageswig_ruby.i 44SWIGCOUT= semanageswig_wrap.c 45SWIGRUBYCOUT= semanageswig_ruby_wrap.c 46SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT)) 47SWIGRUBYLOBJ:= $(patsubst %.c,$(RUBYPREFIX)%.lo,$(SWIGRUBYCOUT)) 48SWIGSO=$(PYPREFIX)_semanage.so 49SWIGFILES=$(SWIGSO) semanage.py 50SWIGRUBYSO=$(RUBYPREFIX)_semanage.so 51LIBSO=$(TARGET).$(LIBVERSION) 52 53GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) semanageswig_python_exception.i 54SRCS= $(filter-out $(GENERATED),$(wildcard *.c)) 55 56OBJS= $(patsubst %.c,%.o,$(SRCS)) conf-scan.o conf-parse.o 57LOBJS= $(patsubst %.c,%.lo,$(SRCS)) conf-scan.lo conf-parse.lo 58CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn -Wmissing-format-attribute 59 60SWIG_CFLAGS += -Wno-error -Wno-unused-but-set-variable -Wno-unused-variable -Wno-shadow \ 61 -Wno-unused-parameter 62 63override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE 64RANLIB=ranlib 65 66SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./ 67 68SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./ 69 70GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) $(wildcard conf-*.[ch]) 71 72all: $(LIBA) $(LIBSO) $(LIBPC) 73 74pywrap: all $(SWIGSO) 75 76rubywrap: all $(SWIGRUBYSO) 77 78$(SWIGLOBJ): $(SWIGCOUT) 79 $(CC) $(CFLAGS) $(SWIG_CFLAGS) $(PYINC) -fPIC -DSHARED -c -o $@ $< 80 81$(SWIGRUBYLOBJ): $(SWIGRUBYCOUT) 82 $(CC) $(CFLAGS) $(SWIG_CFLAGS) $(RUBYINC) -fPIC -DSHARED -c -o $@ $< 83 84$(SWIGSO): $(SWIGLOBJ) 85 $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $< -L. -lsemanage -L$(LIBDIR) 86 87$(SWIGRUBYSO): $(SWIGRUBYLOBJ) 88 $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lsemanage -L$(LIBDIR) 89 90$(LIBA): $(OBJS) 91 $(AR) rcs $@ $^ 92 $(RANLIB) $@ 93 94$(LIBSO): $(LOBJS) 95 $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -lsepol -laudit -lselinux -lbz2 -lustr -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs 96 ln -sf $@ $(TARGET) 97 98$(LIBPC): $(LIBPC).in ../VERSION 99 sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBBASE):; s:@includedir@:$(INCLUDEDIR):' < $< > $@ 100 101semanageswig_python_exception.i: ../include/semanage/semanage.h 102 bash exception.sh > $@ 103 104conf-scan.c: conf-scan.l conf-parse.h 105 $(LEX) $(LFLAGS) -t $< > $@ 106 107conf-parse.c: conf-parse.y 108 $(YACC) $(YFLAGS) -o $@ $< 109 110conf-parse.h: conf-parse.c 111 112%.o: %.c 113 $(CC) $(CFLAGS) -c -o $@ $< 114 115%.lo: %.c 116 $(CC) $(CFLAGS) -fPIC -DSHARED -c -o $@ $< 117 118conf-parse.o: conf-parse.c 119 $(CC) $(filter-out -Werror, $(CFLAGS)) -c -o $@ $< 120 121conf-parse.lo: conf-parse.c 122 $(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -DSHARED -c -o $@ $< 123 124conf-scan.o: conf-scan.c 125 $(CC) $(filter-out -Werror, $(CFLAGS)) -c -o $@ $< 126 127conf-scan.lo: conf-scan.c 128 $(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -DSHARED -c -o $@ $< 129 130$(SWIGCOUT): $(SWIGIF) 131 $(SWIG) $< 132 133$(SWIGRUBYCOUT): $(SWIGRUBYIF) 134 $(SWIGRUBY) $< 135 136swigify: $(SWIGIF) 137 $(SWIG) $< 138 139install: all 140 test -d $(LIBDIR) || install -m 755 -d $(LIBDIR) 141 install -m 644 $(LIBA) $(LIBDIR) 142 install -m 755 $(LIBSO) $(LIBDIR) 143 test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig 144 install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig 145 test -f $(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D semanage.conf $(DEFAULT_SEMANAGE_CONF_LOCATION) 146 cd $(LIBDIR) && ln -sf $(LIBSO) $(TARGET) 147 148install-pywrap: pywrap 149 test -d $(PYLIBDIR)/site-packages || install -m 755 -d $(PYLIBDIR)/site-packages 150 install -m 755 $(SWIGSO) $(PYLIBDIR)/site-packages/_semanage.so 151 install -m 755 semanage.py $(PYLIBDIR)/site-packages 152 153 154install-rubywrap: rubywrap 155 test -d $(RUBYINSTALL) || install -m 755 -d $(RUBYINSTALL) 156 install -m 755 $(SWIGRUBYSO) $(RUBYINSTALL)/semanage.so 157 158relabel: 159 /sbin/restorecon $(LIBDIR)/$(LIBSO) 160 161clean: 162 -rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c *.o *.lo *~ 163 164distclean: clean 165 rm -f $(SWIGCOUT) $(SWIGFILES) 166 167indent: 168 ../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch])) 169 170.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean 171