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