Skip to contentSkip to conversation

pkgconfig support for libsepol, libselinux, and libsemanage

PATCH In review Eamon Walsh 3 participants 7 messages Oct 21, 2009 – Oct 29, 2009 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pkgconfig support for libsepol, libselinux, and libsemanage

Add pkgconfig files for libsepol, libselinux, and libsemanage.

Having a pkgconfig file allows the pkg-config(1) tool to be used to query the presence of the library (or a particular version of it), and to obtain the C flags and linker arguments required to use it.

Based on Debian patches by Manoj Srivastava<[email protected]>.

---

Note that the .pc.in files themselves could use some review to make sure the Requires and Libs lines are correct. The sepol and selinux ones are from the Debian repos; the semanage one I wrote myself.

 .gitignore                        |    1 +
 libselinux/src/Makefile           |   11 +++++++++--
 libselinux/src/libselinux.pc.in   |   13 +++++++++++++
 libsemanage/src/Makefile          |   11 +++++++++--
 libsemanage/src/libsemanage.pc.in |   12 ++++++++++++
 libsepol/src/Makefile             |   12 ++++++++++--
 libsepol/src/libsepol.pc.in       |   11 +++++++++++
 7 files changed, 65 insertions(+), 6 deletions(-)
 create mode 100644 libselinux/src/libselinux.pc.in
 create mode 100644 libsemanage/src/libsemanage.pc.in
 create mode 100644 libsepol/src/libsepol.pc.in
.gitignore +1 -0
index c0e010f..9b7ed83 100644
@@ -9,6 +9,7 @@
 *.a
 *.s
 *.mo
+*.pc
 
 # Misc
 *.patch
libselinux/src/Makefile +9 -2
index 74b1e6a..6623706 100644
@@ -12,10 +12,12 @@ RUBYPLATFORM ?= $(shell ruby -e 'print RUBY_PLATFORM')
 RUBYINC ?= $(LIBDIR)/ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
 RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
 
+VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
 
 LIBA=libselinux.a
 TARGET=libselinux.so
+LIBPC=libselinux.pc
 SWIGIF= selinuxswig_python.i selinuxswig_python_exception.i
 SWIGRUBYIF= selinuxswig_ruby.i
 SWIGCOUT= selinuxswig_wrap.c
@@ -56,7 +58,7 @@ SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
-all: $(LIBA) $(LIBSO)
+all: $(LIBA) $(LIBSO) $(LIBPC)
 
 pywrap: all $(SWIGSO) $(AUDIT2WHYSO)
 
@@ -82,6 +84,9 @@ $(LIBSO): $(LOBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
 	ln -sf $@ $(TARGET)
 
+$(LIBPC): $(LIBPC).in
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):'<  $<  >  $@
+
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
 	sh exception.sh>  $@
 
@@ -111,6 +116,8 @@ install: all
 	install -m 644 $(LIBA) $(LIBDIR)
 	test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
 	install -m 755 $(LIBSO) $(SHLIBDIR)
+	test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
+	install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
 	cd $(LIBDIR)&&  ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)
 
 install-pywrap: pywrap
@@ -127,7 +134,7 @@ relabel:
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
 
 clean:
-	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~
+	-rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~
 
 distclean: clean
 	rm -f $(GENERATED) $(SWIGFILES)
libselinux/src/libselinux.pc.in new file +13 -0
new file mode 100644
index 0000000..c9608d9
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libselinux
+Description: SELinux utility library
+Version: @VERSION@
+URL: http://www.nsa.gov/research/selinux/
+Requires.private: libsepol>= 1.12
+Libs: -L${libdir} -lselinux
+Libs.private: -pthread
+Cflags: -I${includedir}
libsemanage/src/Makefile +9 -2
index cfb9558..a249f0f 100644
@@ -23,10 +23,12 @@ LFLAGS = -s
 YACC = bison
 YFLAGS = -d
 
+VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
 
 LIBA=libsemanage.a
 TARGET=libsemanage.so
+LIBPC=libsemanage.pc
 SWIGIF= semanageswig_python.i
 SWIGRUBYIF= semanageswig_ruby.i
 SWIGCOUT= semanageswig_wrap.c
@@ -53,7 +55,7 @@ SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) $(wildcard conf-*.[ch])
 
-all: $(LIBA) $(LIBSO)
+all: $(LIBA) $(LIBSO) $(LIBPC)
 
 pywrap: all $(SWIGLOBJ) $(SWIGSO)
 
@@ -79,6 +81,9 @@ $(LIBSO): $(LOBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -lsepol -lselinux -lbz2 -lustr -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
 	ln -sf $@ $(TARGET)
 
+$(LIBPC): $(LIBPC).in
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):'<  $<  >  $@
+
 conf-scan.c: conf-scan.l conf-parse.h
 	$(LEX) $(LFLAGS) -t $<  >  $@
 
@@ -119,6 +124,8 @@ install: all
 	install -m 644 $(LIBA) $(LIBDIR)
 	test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
 	install -m 755 $(LIBSO) $(SHLIBDIR)
+	test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
+	install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
 	test -f $(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D semanage.conf $(DEFAULT_SEMANAGE_CONF_LOCATION)
 	cd $(LIBDIR)&&  ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)
 
@@ -134,7 +141,7 @@ relabel:
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
 
 clean:
-	rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c
+	rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c
 
 distclean: clean
 	rm -f $(SWIGCOUT) $(SWIGFILES)
libsemanage/src/libsemanage.pc.in new file +12 -0
new file mode 100644
index 0000000..6d0024c
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libsemanage
+Description: SELinux management library
+Version: @VERSION@
+URL: http://www.nsa.gov/research/selinux/
+Requires: libselinux
+Libs: -L${libdir} -lsemanage
+Cflags: -I${includedir}
libsepol/src/Makefile +10 -2
index 608fe0b..3b19e37 100644
@@ -1,19 +1,22 @@
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
+INCLUDEDIR ?= $(PREFIX)/include
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 
+VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
 
 LIBA=libsepol.a
 TARGET=libsepol.so
+LIBPC=libsepol.pc
 LIBSO=$(TARGET).$(LIBVERSION)
 OBJS= $(patsubst %.c,%.o,$(wildcard *.c))
 LOBJS= $(patsubst %.c,%.lo,$(wildcard *.c))
 CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn -Wmissing-format-attribute
 override CFLAGS += -I. -I../include -D_GNU_SOURCE
 
-all: $(LIBA) $(LIBSO)
+all: $(LIBA) $(LIBSO) $(LIBPC)
 
 $(LIBA):  $(OBJS)
 	$(AR) rcs $@ $^
@@ -23,6 +26,9 @@ $(LIBSO): $(LOBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -Wl,-soname,$(LIBSO),--version-script=libsepol.map,-z,defs
 	ln -sf $@ $(TARGET)
 
+$(LIBPC): $(LIBPC).in
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):'<  $<  >  $@
+
 %.o:  %.c
 	$(CC) $(CFLAGS) -fPIC -c -o $@ $<
 
@@ -34,13 +40,15 @@ install: all
 	install -m 644 $(LIBA) $(LIBDIR)
 	test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
 	install -m 755 $(LIBSO) $(SHLIBDIR)
+	test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
+	install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
 	cd $(LIBDIR)&&  ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)
 
 relabel:
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
 
 clean:
-	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET)
+	-rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET)
 
 indent:
 	../../scripts/Lindent $(wildcard *.[ch])
libsepol/src/libsepol.pc.in new file +11 -0
new file mode 100644
index 0000000..53a6970
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libsepol
+Description: SELinux policy library
+Version: @VERSION@
+URL: http://www.nsa.gov/research/selinux/
+Libs: -L${libdir} -lsepol
+Cflags: -I${includedir}
Signature · 12 lines
1.6.5.rc2


-- 
Eamon Walsh<[email protected]>
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#1 lore raw
Quoted 6 lines · Eamon Walsh

Add pkgconfig files for libsepol, libselinux, and libsemanage.

Having a pkgconfig file allows the pkg-config(1) tool to be used to query the presence of the library (or a particular version of it), and to obtain the C flags and linker arguments required to use it.

Quoted 10 lines

Based on Debian patches by Manoj Srivastava<[email protected]>.

---

Note that the .pc.in files themselves could use some review to make sure the Requires and Libs lines are correct. The sepol and selinux ones are from the Debian repos; the semanage one I wrote myself.

Re-send with non-mangled patch (attached).

Signature · 2 lines
Eamon Walsh<[email protected]>
National Security Agency
#2 lore raw
In reply to Eamon Walsh
Quoted 24 lines · Eamon Walsh

Add pkgconfig files for libsepol, libselinux, and libsemanage.

Having a pkgconfig file allows the pkg-config(1) tool to be used to query the presence of the library (or a particular version of it), and to obtain the C flags and linker arguments required to use it.

Based on Debian patches by Manoj Srivastava<[email protected]>.

---

Note that the .pc.in files themselves could use some review to make sure the Requires and Libs lines are correct. The sepol and selinux ones are from the Debian repos; the semanage one I wrote myself.

libselinux/src/libselinux.pc.in new file +3 -0
new file mode 100644
index 0000000..c9608d9
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib

libselinux/src/libselinux.pc.in line 13

Quoted 10 lines
libselinux/src/libselinux.pc.in new file +10 -0
+includedir=@includedir@
+
+Name: libselinux
+Description: SELinux utility library
+Version: @VERSION@
+URL: http://www.nsa.gov/research/selinux/
+Requires.private: libsepol>= 1.12
+Libs: -L${libdir} -lselinux
+Libs.private: -pthread
+Cflags: -I${includedir}

Requires.private only applies to the static lib, right? In the shared lib, libsepol is dlopen'd on demand these days and is only needed if loading a policy file whose version is greater than the version supported by the kernel.

I'd drop the >= 1.12 or make it more current.

libpthread should not be necessary any longer (it was temporarily from libselinux 2.0.82 through 2.0.84); if the program is already linked with libpthread then libselinux will use pthread_once for lazy initialization; otherwise it will fall back to a simple test.

Not sure if you should specify libdl or if that is implicitly handled.

Quoted 8 lines
libsemanage/src/libsemanage.pc.in new file +2 -0
new file mode 100644
index 0000000..6d0024c
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=${prefix}

libsemanage/src/libsemanage.pc.in line 12

Quoted 10 lines
libsemanage/src/libsemanage.pc.in new file +10 -0
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libsemanage
+Description: SELinux management library
+Version: @VERSION@
+URL: http://www.nsa.gov/research/selinux/
+Requires: libselinux
+Libs: -L${libdir} -lsemanage
+Cflags: -I${includedir}

Modern libsemanage requires libsepol, libselinux, libbz2, and libustr.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#3 lore raw
Quoted 16 lines · Stephen Smalley
Quoted 14 lines · Eamon Walsh

Add pkgconfig files for libsepol, libselinux, and libsemanage.

Having a pkgconfig file allows the pkg-config(1) tool to be used to query the presence of the library (or a particular version of it), and to obtain the C flags and linker arguments required to use it.

Based on Debian patches by Manoj Srivastava<[email protected]>.

---

Note that the .pc.in files themselves could use some review to make sure the Requires and Libs lines are correct. The sepol and selinux ones are from the Debian repos; the semanage one I wrote myself.

Quoted 15 lines
Quoted 6 lines
libselinux/src/libselinux.pc.in new file +0 -0
new file mode 100644
index 0000000..c9608d9

libselinux/src/libselinux.pc.in line 9

Quoted 9 lines
libselinux/src/libselinux.pc.in new file +9 -0
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libselinux
+Description: SELinux utility library
+Version: @VERSION@
+URL: http://www.nsa.gov/research/selinux/

Also the URLs should now point to the userspace.selinuxproject.org site.

Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#6 lore raw
In reply to Stephen Smalley
Quoted 18 lines · Stephen Smalley
Quoted 10 lines · Eamon Walsh

Add pkgconfig files for libsepol, libselinux, and libsemanage.

Having a pkgconfig file allows the pkg-config(1) tool to be used to query the presence of the library (or a particular version of it), and to obtain the C flags and linker arguments required to use it.

Based on Debian patches by Manoj Srivastava<[email protected]>.

---

Requires.private only applies to the static lib, right? In the shared lib, libsepol is dlopen'd on demand these days and is only needed if loading a policy file whose version is greater than the version supported by the kernel.

Quoted 8 lines

I'd drop the >= 1.12 or make it more current.

libpthread should not be necessary any longer (it was temporarily from libselinux 2.0.82 through 2.0.84); if the program is already linked with libpthread then libselinux will use pthread_once for lazy initialization; otherwise it will fall back to a simple test.

Not sure if you should specify libdl or if that is implicitly handled.

It is implicitly handled.

Quoted 13 lines
Quoted 13 lines
libsemanage/src/libsemanage.pc.in new file +6 -0
new file mode 100644
index 0000000..6d0024c
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libsemanage
Quoted 8 lines

libsemanage/src/libsemanage.pc.in line 12

Quoted 6 lines
libsemanage/src/libsemanage.pc.in new file +6 -0
+Description: SELinux management library
+Version: @VERSION@
+URL: http://www.nsa.gov/research/selinux/
+Requires: libselinux
+Libs: -L${libdir} -lsemanage
+Cflags: -I${includedir}

Modern libsemanage requires libsepol, libselinux, libbz2, and libustr.

I need to update that, thanks.

Also, I have patches now to libselinux/src/Makefile to use
pkg-config to look for the location of libsepol.a.

manoj

[topic--debian]: Add support for cross compilation

The Python bindings are always linked against /usr/lib/libsepol.a. This patch allows the specification of the directory one may find libsepol.a in.

libselinux/src/Makefile +6 -1
index b68d586..ac4f467 100644
@@ -52,6 +52,11 @@ ifneq (,$(filter i386,$(ARCH)))
 TLSFLAGS += -mno-tls-direct-seg-refs
 endif
 
+LIBSEPOLDIR=$(shell pkg-config --variable=libdir libsepol)
+ifeq (,$(strip $(LIBSEPOLDIR)))
+LIBSEPOLDIR=$(LIBDIR)
+endif
+
 SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
@@ -86,7 +90,7 @@ audit2why.lo: audit2why.c
 	$(CC) $(CFLAGS) -I$(PYINC) -fPIC -DSHARED -c -o $@ $<
 
 $(AUDIT2WHYSO): audit2why.lo
-	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux ${LIBDIR}/libsepol.a -L$(LIBDIR) -Wl,-soname,$@
+	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux $(LIBSEPOLDIR)/libsepol.a -L$(LIBDIR) -Wl,-soname,$@
 
 %.o:  %.c policy.h
 	$(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
Signature · 7 lines
Manoj Srivastava <[email protected]> <http://www.golden-gryphon.com/>  
1024D/BF24424C print 4966 F272 D093 B493 410B  924B 21BA DABB BF24 424C

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#4 lore raw

PATCH 1/1 pkgconfig support for libsepol, libselinux, and libsemanage

In reply to Stephen Smalley

Add pkgconfig files for libsepol, libselinux, and libsemanage.

Having a pkgconfig file allows the pkg-config tool to be used to query the presence of the library (or a particular version of it), and to obtain the C flags and linker arguments to build with it.

Based on Debian patches by Manoj Srivastava <[email protected]>.

-v2: Corrected URL, fixed requirements for libselinux and libsemanage.

---

Notes: Requires.private applies to static linking only, but it will pull in CFLAGS from dependencies. This is not very well documented. My main source for information here is a bug report:
https://bugzilla.redhat.com/show_bug.cgi?id=224148
http://wiki.mandriva.com/en/Overlinking

As far as I can tell, a shared library shouldn't have anything listed in "Requires" or "Libs". The only difference between Required.private and Libs.private I can tell is that the former takes pkgconfig file names as arguments and the latter actual -lfoo directives.

 .gitignore                        |    1 +
 libselinux/src/Makefile           |   11 +++++++++--
 libselinux/src/libselinux.pc.in   |   12 ++++++++++++
 libsemanage/src/Makefile          |   11 +++++++++--
 libsemanage/src/libsemanage.pc.in |   13 +++++++++++++
 libsepol/src/Makefile             |   12 ++++++++++--
 libsepol/src/libsepol.pc.in       |   11 +++++++++++
 7 files changed, 65 insertions(+), 6 deletions(-)
 create mode 100644 libselinux/src/libselinux.pc.in
 create mode 100644 libsemanage/src/libsemanage.pc.in
 create mode 100644 libsepol/src/libsepol.pc.in
.gitignore +1 -0
index c0e010f..9b7ed83 100644
@@ -9,6 +9,7 @@
 *.a
 *.s
 *.mo
+*.pc
 
 # Misc
 *.patch
libselinux/src/Makefile +9 -2
index 74b1e6a..6623706 100644
@@ -12,10 +12,12 @@ RUBYPLATFORM ?= $(shell ruby -e 'print RUBY_PLATFORM')
 RUBYINC ?= $(LIBDIR)/ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
 RUBYINSTALL ?= $(LIBDIR)/ruby/site_ruby/$(RUBYLIBVER)/$(RUBYPLATFORM)
 
+VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
 
 LIBA=libselinux.a 
 TARGET=libselinux.so
+LIBPC=libselinux.pc
 SWIGIF= selinuxswig_python.i selinuxswig_python_exception.i
 SWIGRUBYIF= selinuxswig_ruby.i
 SWIGCOUT= selinuxswig_wrap.c
@@ -56,7 +58,7 @@ SWIG = swig -Wall -python -o $(SWIGCOUT) -outdir ./
 
 SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
-all: $(LIBA) $(LIBSO) 
+all: $(LIBA) $(LIBSO) $(LIBPC)
 
 pywrap: all $(SWIGSO) $(AUDIT2WHYSO)
 
@@ -82,6 +84,9 @@ $(LIBSO): $(LOBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -ldl -L$(LIBDIR) -Wl,-soname,$(LIBSO),-z,defs,-z,relro
 	ln -sf $@ $(TARGET) 
 
+$(LIBPC): $(LIBPC).in
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
+
 selinuxswig_python_exception.i: ../include/selinux/selinux.h
 	sh exception.sh > $@ 
 
@@ -111,6 +116,8 @@ install: all
 	install -m 644 $(LIBA) $(LIBDIR)
 	test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
 	install -m 755 $(LIBSO) $(SHLIBDIR)
+	test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
+	install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
 	cd $(LIBDIR) && ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)
 
 install-pywrap: pywrap
@@ -127,7 +134,7 @@ relabel:
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
 
 clean: 
-	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~ 
+	-rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) $(AUDIT2WHYSO) *.o *.lo *~
 
 distclean: clean
 	rm -f $(GENERATED) $(SWIGFILES)
libselinux/src/libselinux.pc.in new file +12 -0
new file mode 100644
index 0000000..9b3808b
@@ -0,0 +1,12 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libselinux
+Description: SELinux utility library
+Version: @VERSION@
+URL: http://userspace.selinuxproject.org/
+Requires.private: libsepol
+Libs: -L${libdir} -lselinux
+Cflags: -I${includedir}
libsemanage/src/Makefile +9 -2
index cfb9558..a249f0f 100644
@@ -23,10 +23,12 @@ LFLAGS = -s
 YACC = bison
 YFLAGS = -d
 
+VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
 
 LIBA=libsemanage.a
 TARGET=libsemanage.so
+LIBPC=libsemanage.pc
 SWIGIF= semanageswig_python.i
 SWIGRUBYIF= semanageswig_ruby.i
 SWIGCOUT= semanageswig_wrap.c
@@ -53,7 +55,7 @@ SWIGRUBY = swig -Wall -ruby -o $(SWIGRUBYCOUT) -outdir ./
 
 GENERATED=$(SWIGCOUT) $(SWIGRUBYCOUT) $(wildcard conf-*.[ch])
 
-all: $(LIBA) $(LIBSO) 
+all: $(LIBA) $(LIBSO) $(LIBPC)
 
 pywrap: all $(SWIGLOBJ) $(SWIGSO) 
 
@@ -79,6 +81,9 @@ $(LIBSO): $(LOBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -lsepol -lselinux -lbz2 -lustr -L$(LIBDIR) -Wl,-soname,$(LIBSO),--version-script=libsemanage.map,-z,defs
 	ln -sf $@ $(TARGET)
 
+$(LIBPC): $(LIBPC).in
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
+
 conf-scan.c: conf-scan.l conf-parse.h
 	$(LEX) $(LFLAGS) -t $< > $@
 
@@ -119,6 +124,8 @@ install: all
 	install -m 644 $(LIBA) $(LIBDIR)
 	test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
 	install -m 755 $(LIBSO) $(SHLIBDIR)
+	test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
+	install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
 	test -f $(DEFAULT_SEMANAGE_CONF_LOCATION) || install -m 644 -D semanage.conf $(DEFAULT_SEMANAGE_CONF_LOCATION)
 	cd $(LIBDIR) && ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)
 
@@ -134,7 +141,7 @@ relabel:
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
 
 clean: 
-	rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c
+	rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(SWIGLOBJ) $(SWIGSO) $(TARGET) conf-parse.c conf-parse.h conf-scan.c
 
 distclean: clean
 	rm -f $(SWIGCOUT) $(SWIGFILES)
libsemanage/src/libsemanage.pc.in new file +13 -0
new file mode 100644
index 0000000..d0945f8
@@ -0,0 +1,13 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libsemanage
+Description: SELinux management library
+Version: @VERSION@
+URL: http://userspace.selinuxproject.org/
+Requires.private: libselinux libsepol ustr
+Libs: -L${libdir} -lsemanage
+Libs.private: -lbz2
+Cflags: -I${includedir}
libsepol/src/Makefile +10 -2
index 608fe0b..3b19e37 100644
@@ -1,19 +1,22 @@
 # Installation directories.
 PREFIX ?= $(DESTDIR)/usr
+INCLUDEDIR ?= $(PREFIX)/include
 LIBDIR ?= $(PREFIX)/lib
 SHLIBDIR ?= $(DESTDIR)/lib
 
+VERSION = $(shell cat ../VERSION)
 LIBVERSION = 1
 
 LIBA=libsepol.a 
 TARGET=libsepol.so
+LIBPC=libsepol.pc
 LIBSO=$(TARGET).$(LIBVERSION)
 OBJS= $(patsubst %.c,%.o,$(wildcard *.c))
 LOBJS= $(patsubst %.c,%.lo,$(wildcard *.c))
 CFLAGS ?= -Werror -Wall -W -Wundef -Wshadow -Wmissing-noreturn -Wmissing-format-attribute
 override CFLAGS += -I. -I../include -D_GNU_SOURCE
 
-all: $(LIBA) $(LIBSO)
+all: $(LIBA) $(LIBSO) $(LIBPC)
 
 $(LIBA):  $(OBJS)
 	$(AR) rcs $@ $^
@@ -23,6 +26,9 @@ $(LIBSO): $(LOBJS)
 	$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -Wl,-soname,$(LIBSO),--version-script=libsepol.map,-z,defs
 	ln -sf $@ $(TARGET) 
 
+$(LIBPC): $(LIBPC).in
+	sed -e 's/@VERSION@/$(VERSION)/; s:@prefix@:$(PREFIX):; s:@libdir@:$(LIBDIR):; s:@includedir@:$(INCLUDEDIR):' < $< > $@
+
 %.o:  %.c 
 	$(CC) $(CFLAGS) -fPIC -c -o $@ $<
 
@@ -34,13 +40,15 @@ install: all
 	install -m 644 $(LIBA) $(LIBDIR)
 	test -d $(SHLIBDIR) || install -m 755 -d $(SHLIBDIR)
 	install -m 755 $(LIBSO) $(SHLIBDIR)
+	test -d $(LIBDIR)/pkgconfig || install -m 755 -d $(LIBDIR)/pkgconfig
+	install -m 644 $(LIBPC) $(LIBDIR)/pkgconfig
 	cd $(LIBDIR) && ln -sf ../../`basename $(SHLIBDIR)`/$(LIBSO) $(TARGET)
 
 relabel:
 	/sbin/restorecon $(SHLIBDIR)/$(LIBSO)
 
 clean: 
-	-rm -f $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET) 
+	-rm -f $(LIBPC) $(OBJS) $(LOBJS) $(LIBA) $(LIBSO) $(TARGET)
 
 indent:
 	../../scripts/Lindent $(wildcard *.[ch])
libsepol/src/libsepol.pc.in new file +11 -0
new file mode 100644
index 0000000..bc7635c
@@ -0,0 +1,11 @@
+prefix=@prefix@
+exec_prefix=${prefix}
+libdir=${exec_prefix}/lib
+includedir=@includedir@
+
+Name: libsepol
+Description: SELinux policy library
+Version: @VERSION@
+URL: http://userspace.selinuxproject.org/
+Libs: -L${libdir} -lsepol
+Cflags: -I${includedir}
Signature · 14 lines
1.6.5.rc2



-- 

Eamon Walsh 
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
#5 lore raw
Quoted 6 lines · Eamon Walsh

Add pkgconfig files for libsepol, libselinux, and libsemanage.

Having a pkgconfig file allows the pkg-config tool to be used to query the presence of the library (or a particular version of it), and to obtain the C flags and linker arguments to build with it.

Quoted 9 lines

Based on Debian patches by Manoj Srivastava <[email protected]>.

-v2: Corrected URL, fixed requirements for libselinux and libsemanage.

---

I have pushed this and bumped the library versions. This will impact downstreams with pkgconfig files patched in themselves. If anything's seriously amiss let me know.

Signature · 8 lines
Eamon Walsh 
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.