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