• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 ?= python3
5PYPREFIX ?= $(shell $(PYTHON) -c 'import sys;print("python-%d.%d" % sys.version_info[:2])')
6RUBY ?= ruby
7RUBYPREFIX ?= $(notdir $(RUBY))
8PKG_CONFIG ?= pkg-config
9
10# Installation directories.
11PREFIX ?= /usr
12LIBDIR ?= $(PREFIX)/lib
13INCLUDEDIR ?= $(PREFIX)/include
14PYINC ?= $(shell $(PKG_CONFIG) --cflags $(PYPREFIX))
15PYLIBS ?= $(shell $(PKG_CONFIG) --libs $(PYPREFIX))
16PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib(plat_specific=1, prefix='$(PREFIX)'))")
17PYCEXT ?= $(shell $(PYTHON) -c 'import imp;print([s for s,m,t in imp.get_suffixes() if t == imp.C_EXTENSION][0])')
18RUBYINC ?= $(shell $(RUBY) -e 'puts "-I" + RbConfig::CONFIG["rubyarchhdrdir"] + " -I" + RbConfig::CONFIG["rubyhdrdir"]')
19RUBYLIBS ?= $(shell $(RUBY) -e 'puts "-L" + RbConfig::CONFIG["libdir"] + " -L" + RbConfig::CONFIG["archlibdir"] + " " + RbConfig::CONFIG["LIBRUBYARG_SHARED"]')
20RUBYINSTALL ?= $(shell $(RUBY) -e 'puts RbConfig::CONFIG["vendorarchdir"]')
21
22DEFAULT_SEMANAGE_CONF_LOCATION=/etc/selinux/semanage.conf
23
24ifeq ($(DEBUG),1)
25	export CFLAGS ?= -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror
26	export LDFLAGS ?= -g
27endif
28
29LEX = flex
30LFLAGS = -s
31YACC = bison
32YFLAGS = -d
33
34VERSION = $(shell cat ../VERSION)
35LIBVERSION = 1
36
37LIBA=libsemanage.a
38TARGET=libsemanage.so
39LIBPC=libsemanage.pc
40SWIGIF= semanageswig_python.i semanageswig_python_exception.i
41SWIGRUBYIF= semanageswig_ruby.i
42SWIGCOUT= semanageswig_wrap.c
43SWIGRUBYCOUT= semanageswig_ruby_wrap.c
44SWIGLOBJ:= $(patsubst %.c,$(PYPREFIX)%.lo,$(SWIGCOUT))
45SWIGRUBYLOBJ:= $(patsubst %.c,$(RUBYPREFIX)%.lo,$(SWIGRUBYCOUT))
46SWIGSO=$(PYPREFIX)_semanage.so
47SWIGFILES=$(SWIGSO) semanage.py
48SWIGRUBYSO=$(RUBYPREFIX)_semanage.so
49LIBSO=$(TARGET).$(LIBVERSION)
50
51GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) semanageswig_python_exception.i $(sort $(wildcard conf-*.[ch]))
52SRCS= $(filter-out $(GENERATED),$(sort $(wildcard *.c)))
53
54OBJS= $(patsubst %.c,%.o,$(SRCS)) conf-scan.o conf-parse.o
55LOBJS= $(patsubst %.c,%.lo,$(SRCS)) conf-scan.lo conf-parse.lo
56CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn -Wmissing-format-attribute
57
58SWIG_CFLAGS += -Wno-error -Wno-unused-but-set-variable -Wno-unused-variable -Wno-shadow \
59		-Wno-unused-parameter
60
61override CFLAGS += -I../include -D_GNU_SOURCE
62RANLIB ?= ranlib
63
64SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
65
66SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
67
68all: $(LIBA) $(LIBSO) $(LIBPC)
69
70pywrap: all $(SWIGSO)
71
72rubywrap: 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
97semanageswig_python_exception.i: exception.sh $(wildcard ../include/semanage/*.h)
98	bash -e exception.sh > $@ || (rm -f $@ ; false)
99
100conf-scan.c: conf-scan.l conf-parse.h
101	$(LEX) $(LFLAGS) -o $@ $<
102
103conf-parse.c: conf-parse.y
104	$(YACC) $(YFLAGS) -o $@ $<
105
106conf-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
114conf-parse.o:  conf-parse.c
115	$(CC) $(filter-out -Werror, $(CFLAGS)) -c -o $@ $<
116
117conf-parse.lo:  conf-parse.c
118	$(CC) $(filter-out -Werror, $(CFLAGS)) -fPIC -DSHARED -c -o $@ $<
119
120conf-scan.o:  conf-scan.c
121	$(CC) $(filter-out -Werror, $(CFLAGS)) -c -o $@ $<
122
123conf-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
132swigify: $(SWIGIF)
133	$(SWIG) $<
134
135install: 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
144install-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
150install-rubywrap: rubywrap
151	test -d $(DESTDIR)$(RUBYINSTALL) || install -m 755 -d $(DESTDIR)$(RUBYINSTALL)
152	install -m 755 $(SWIGRUBYSO) $(DESTDIR)$(RUBYINSTALL)/semanage.so
153
154relabel:
155	/sbin/restorecon $(DESTDIR)$(LIBDIR)/$(LIBSO)
156
157clean:
158	-rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(SWIGRUBYSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c *.o *.lo *~
159
160distclean: clean
161	rm -f $(GENERATED) $(SWIGFILES)
162
163indent:
164	../../scripts/Lindent $(filter-out $(GENERATED),$(wildcard *.[ch]))
165
166.PHONY: all clean pywrap rubywrap swigify install install-pywrap install-rubywrap distclean
167