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 
      9 # Installation directories.
     10 PREFIX ?= $(DESTDIR)/usr
     11 LIBDIR ?= $(PREFIX)/lib
     12 SHLIBDIR ?= $(DESTDIR)/lib
     13 INCLUDEDIR ?= $(PREFIX)/include
     14 PYLIBVER ?= $(shell $(PYTHON) -c 'import sys;print("python%d.%d" % sys.version_info[0:2])')
     15 PYINC ?= $(shell pkg-config --cflags $(PYPREFIX))
     16 PYLIBDIR ?= $(LIBDIR)/$(PYLIBVER)
     17 RUBYLIBVER ?= $(shell $(RUBY) -e 'print RUBY_VERSION.split(".")[0..1].join(".")')
     18 RUBYPLATFORM ?= $(shell $(RUBY) -e 'print RUBY_PLATFORM')
     19 RUBYINC ?= $(shell pkg-config --cflags ruby-$(RUBYLIBVER))
     20 RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
     21 
     22 LIBBASE=$(shell basename $(LIBDIR))
     23 
     24 DEFAULT_SEMANAGE_CONF_LOCATION=$(DESTDIR)/etc/selinux/semanage.conf
     25 
     26 ifeq ($(DEBUG),1)
     27 	export CFLAGS = -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror
     28 	export LDFLAGS = -g
     29 endif
     30 
     31 LEX = flex
     32 LFLAGS = -s
     33 YACC = bison
     34 YFLAGS = -d
     35 
     36 VERSION = $(shell cat ../VERSION)
     37 LIBVERSION = 1
     38 
     39 LIBA=libsemanage.a
     40 TARGET=libsemanage.so
     41 LIBPC=libsemanage.pc
     42 SWIGIF= semanageswig_python.i semanageswig_python_exception.i
     43 SWIGRUBYIF= semanageswig_ruby.i
     44 SWIGCOUT= semanageswig_wrap.c
     45 SWIGRUBYCOUT= semanageswig_ruby_wrap.c
     46 SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT))
     47 SWIGRUBYLOBJ:= $(patsubst %.c,$(RUBYPREFIX)%.lo,$(SWIGRUBYCOUT)) 
     48 SWIGSO=$(PYPREFIX)_semanage.so
     49 SWIGFILES=$(SWIGSO) semanage.py 
     50 SWIGRUBYSO=$(RUBYPREFIX)_semanage.so
     51 LIBSO=$(TARGET).$(LIBVERSION)
     52 
     53 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) semanageswig_python_exception.i
     54 SRCS= $(filter-out $(GENERATED),$(wildcard *.c))
     55 
     56 OBJS= $(patsubst %.c,%.o,$(SRCS)) conf-scan.o conf-parse.o
     57 LOBJS= $(patsubst %.c,%.lo,$(SRCS)) conf-scan.lo conf-parse.lo
     58 CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn -Wmissing-format-attribute
     59 
     60 SWIG_CFLAGS += -Wno-error -Wno-unused-but-set-variable -Wno-unused-variable -Wno-shadow \
     61 		-Wno-unused-parameter
     62 
     63 override CFLAGS += -I../include -I$(INCLUDEDIR) -D_GNU_SOURCE 
     64 RANLIB=ranlib
     65 
     66 SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
     67 
     68 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
     69 
     70 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) $(wildcard conf-*.[ch])
     71 
     72 all: $(LIBA) $(LIBSO) $(LIBPC)
     73 
     74 pywrap: all $(SWIGSO)
     75 
     76 rubywrap: 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 
    101 semanageswig_python_exception.i: ../include/semanage/semanage.h
    102 	bash exception.sh > $@
    103 
    104 conf-scan.c: conf-scan.l conf-parse.h
    105 	$(LEX) $(LFLAGS) -t $< > $@
    106 
    107 conf-parse.c: conf-parse.y
    108 	$(YACC) $(YFLAGS) -o $@ $<
    109 
    110 conf-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 
    118 conf-parse.o:  conf-parse.c
    119 	$(CC) $(filter-out -Werror, $(CFLAGS)) -c -o $@ $<
    120 
    121 conf-parse.lo:  conf-parse.c
    122 	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -DSHARED -c -o $@ $<
    123 
    124 conf-scan.o:  conf-scan.c
    125 	$(CC) $(filter-out -Werror, $(CFLAGS)) -c -o $@ $<
    126 
    127 conf-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 
    136 swigify: $(SWIGIF)
    137 	$(SWIG) $<
    138 
    139 install: 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 
    148 install-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 
    154 install-rubywrap: rubywrap
    155 	test -d $(RUBYINSTALL) || install -m 755 -d $(RUBYINSTALL) 
    156 	install -m 755 $(SWIGRUBYSO) $(RUBYINSTALL)/semanage.so
    157 
    158 relabel:
    159 	/sbin/restorecon $(LIBDIR)/$(LIBSO)
    160 
    161 clean: 
    162 	-rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c *.o *.lo *~
    163 
    164 distclean: clean
    165 	rm -f $(SWIGCOUT) $(SWIGFILES)
    166 
    167 indent:
    168 	../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
    169 
    170 .PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
    171