Skip to contentSkip to conversation

: allow standard compilation of GIT development tree (was Re: [PATCH]: do not link static libraries from the system library directory)

PATCH In review Guido Trentalancia 3 participants 3 messages Jun 4, 2012 – Jun 6, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 : allow standard compilation of GIT development tree (was Re: [PATCH]: do not link static libraries from the system library directory)

Hello Eric !

Quoted 3 lines

At the moment, the sugggested way to do with is to use:

make DESTDIR=[some dir] install

That is not standard. Standard practice is to build first by typing "make" and only after the build has completed successfully eventually proceed with the installation by typing "make install" (with DESTDIR).

Quoted 5 lines

I've never really seen something which can get it right 'all the time'. Fedora, and I assume other distros actually just use the git tree subdirectories. I feel like any such patch to handle this is going to have to be something set in the top level Makefile and will have to cause no difficulties for other workflows....

You can build with virtually everything on automated build systems, as long as you can enter it once. But with humans, I suppose, you need something standard and easy to remember...

Here is the missing patch which complements the previous one (they were intentionally splitted):

Allow standard compilation with separate installation of the SELinux GIT development tree.

To build, just type "make".

To install (after successful build), just type "make install".

During installation, it is possible to pass the variables DESTDIR, LIBDIR and SHLIBDIR to GNU make in order to fine tune the results.

---
 Makefile |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
Makefile +12 -2
@@ -2,11 +2,21 @@ SUBDIRS=libsepol libselinux libsemanage
 PYSUBDIRS=libselinux libsemanage
 DISTCLEANSUBIDRS=libselinux libsemanage
 
+TOPDIR := $(shell pwd)
+
+CPPFLAGS ?= -I$(TOPDIR)/libselinux/include -I$(TOPDIR)/libsepol/include -I$(TOPDIR)/libsemanage/include
+LDFLAGS ?= -L$(TOPDIR)/libselinux/src -L$(TOPDIR)/libsepol/src -L$(TOPDIR)/libsemanage/src
+CFLAGS ?= $(CPPFLAGS)
+
 ifeq ($(DEBUG),1)
-	export CFLAGS = -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror
-	export LDFLAGS = -g
+	CFLAGS += -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror
+	LDFLAGS += -g
 endif
 
+export CPPFLAGS
+export CFLAGS
+export LDFLAGS
+
 all install relabel clean test indent:
 	@for subdir in $(SUBDIRS); do 
 		(cd $$subdir && $(MAKE) $@) || exit 1; 
Quoted 114 lines
Quoted 112 lines · Guido Trentalancia

Do not ever link GIT development sources against static SELinux libraries that are eventually already installed in the system library directory (LIBDIR), but instead source the "fresh" local versions from the GIT development tree itself.

This patch prevents build errors when SELinux is not already installed on a system or even worse it prevents linking against previous (obsolete, buggy or even insecure) versions of the libraries that might be found on the standard system library directory as defined by the Makefile variable LIBDIR.

It is intended only for the GIT development tree, therefore it should not be applied to the individually released libraries or userspace tools, as it would break their build (however, if released components are generated more or less directly from the GIT development tree, it shouldn't be too difficult or time consuming to process their Makefiles upon creation by using some sort of sed script to revert linking from LIBDIR instead of relative local GIT tree library subdirectories).

Please note that similar problems do arise for the header files and the shared libraries when building the GIT tree, although these problems can be avoided by passing the appropriate compiler/linker options in CPPFLAGS, CFLAGS and LDFLAGS to make so that the local headers and shared libraries files are used when compiling/linking.

---
 checkpolicy/Makefile                    |    2 +- checkpolicy/test/Makefile               |    2 +- libselinux/src/Makefile                 |    2 +- policycoreutils/mcstrans/src/Makefile   |    2 +- policycoreutils/mcstrans/utils/Makefile |    2 +- policycoreutils/semodule_deps/Makefile  |    2 +- policycoreutils/sepolgen-ifgen/Makefile |    2 +-

 7 files changed, 7 insertions(+), 7 deletions(-)

diff -pru selinux-04062012-original/checkpolicy/Makefile selinux-04062012/checkpolicy/Makefile

checkpolicy/Makefile       2012-06-04 14:04:44.954580741 +0200 renamed from checkpolicy/Makefile      2011-09-09 20:12:55.978662153 +0200 +0 -0
@@ -19,7 +19,7 @@ CHECKOBJS = y.tab.o lex.yy.o queue.o mod

 CHECKPOLOBJS = $(CHECKOBJS) checkpolicy.o
 CHECKMODOBJS = $(CHECKOBJS) checkmodule.o

checkpolicy/Makefile       2012-06-04 14:04:44.954580741 +0200 renamed from checkpolicy/Makefile      2011-09-09 20:12:55.978662153 +0200 +1 -1
-LDLIBS=$(LIBDIR)/libsepol.a -lfl
+LDLIBS=../libsepol/src/libsepol.a -lfl

 GENERATED=lex.yy.c y.tab.c y.tab.h

diff -pru selinux-04062012-original/checkpolicy/test/Makefile selinux-04062012/checkpolicy/test/Makefile

checkpolicy/test/Makefile  2012-06-04 14:01:39.788487811 +0200 renamed from checkpolicy/test/Makefile 2012-03-23 17:00:49.273045007 +0100 +0 -0
@@ -9,7 +9,7 @@ INCLUDEDIR ?= $(PREFIX)/include

 CFLAGS ?= -g -Wall -W -Werror -O2 -pipe
 override CFLAGS += -I$(INCLUDEDIR)

checkpolicy/test/Makefile  2012-06-04 14:01:39.788487811 +0200 renamed from checkpolicy/test/Makefile 2012-03-23 17:00:49.273045007 +0100 +1 -1
-LDLIBS=-lfl -lselinux $(LIBDIR)/libsepol.a -L$(LIBDIR)
+LDLIBS=-lfl -lselinux ../../libsepol/src/libsepol.a -L$(LIBDIR)

 all: dispol dismod

diff -pru selinux-04062012-original/libselinux/src/Makefile selinux-04062012/libselinux/src/Makefile

libselinux/src/Makefile    2012-06-04 14:02:48.398135397 +0200 renamed from libselinux/src/Makefile   2012-05-29 21:12:20.635265972 +0200 +0 -0
@@ -122,7 +122,7 @@ $(AUDIT2WHYLOBJ): audit2why.c

       $(CC) $(filter-out -Werror, $(CFLAGS)) $(PYINC) -fPIC -DSHARED -c -o $@ $<

 $(AUDIT2WHYSO): $(AUDIT2WHYLOBJ)
-       $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux $(LIBDIR)/libsepol.a -L$(LIBDIR) -Wl,-soname,$@
+       $(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ -L. -lselinux ../../libsepol/src/libsepol.a -L$(LIBDIR) -Wl,-soname,$@

 %.o:  %.c policy.h
       $(CC) $(CFLAGS) $(TLSFLAGS) -c -o $@ $<
diff -pru selinux-04062012-original/policycoreutils/mcstrans/src/Makefile selinux-04062012/policycoreutils/mcstrans/src/Makefile

policycoreutils/mcstrans/src/Makefile      2012-06-04 14:06:54.356297716 +0200 renamed from policycoreutils/mcstrans/src/Makefile     2011-09-09 20:12:56.040662607 +0200 +1 -1
@@ -28,7 +28,7 @@ override CFLAGS += -I../include -D_GNU_S
  all: $(PROG)
 
  $(PROG): $(PROG_OBJS)
-       $(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre $(LIBDIR)/libsepol.a
+       $(CC) $(LDFLAGS) -pie -o $@ $^ -lselinux -lcap -lpcre ../../../libsepol/src/libsepol.a
 

 %.o:  %.c
       $(CC) $(CFLAGS) -fPIE -c -o $@ $<
diff -pru selinux-04062012-original/policycoreutils/mcstrans/utils/Makefile selinux-04062012/policycoreutils/mcstrans/utils/Makefile

policycoreutils/mcstrans/utils/Makefile    2012-06-04 14:06:45.590585065 +0200 renamed from policycoreutils/mcstrans/utils/Makefile   2011-09-09 20:12:56.041662614 +0200 +0 -0
@@ -21,7 +21,7 @@ endif
 

 CFLAGS ?= -Wall
 override CFLAGS += -I../src -D_GNU_SOURCE

policycoreutils/mcstrans/utils/Makefile    2012-06-04 14:06:45.590585065 +0200 renamed from policycoreutils/mcstrans/utils/Makefile   2011-09-09 20:12:56.041662614 +0200 +1 -1
-LDLIBS += -L../src ../src/mcstrans.o ../src/mls_level.o -lselinux -lpcre $(LIBDIR)/libsepol.a
+LDLIBS += -L../src ../src/mcstrans.o ../src/mls_level.o -lselinux -lpcre ../../../libsepol/src/libsepol.a

 TARGETS=$(patsubst %.c,%,$(wildcard *.c))

diff -pru selinux-04062012-original/policycoreutils/semodule_deps/Makefile selinux-04062012/policycoreutils/semodule_deps/Makefile

policycoreutils/semodule_deps/Makefile     2012-06-04 14:06:38.284818580 +0200 renamed from policycoreutils/semodule_deps/Makefile    2011-11-15 00:32:56.867740958 +0100 +0 -0
@@ -7,7 +7,7 @@ MANDIR ?= $(PREFIX)/share/man
 

 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I$(INCLUDEDIR)

policycoreutils/semodule_deps/Makefile     2012-06-04 14:06:38.284818580 +0200 renamed from policycoreutils/semodule_deps/Makefile    2011-11-15 00:32:56.867740958 +0100 +1 -1
-LDLIBS = $(LIBDIR)/libsepol.a
+LDLIBS = ../../libsepol/src/libsepol.a

 all: semodule_deps

diff -pru selinux-04062012-original/policycoreutils/sepolgen-ifgen/Makefile selinux-04062012/policycoreutils/sepolgen-ifgen/Makefile

policycoreutils/sepolgen-ifgen/Makefile    2012-06-04 14:08:14.580334340 +0200 renamed from policycoreutils/sepolgen-ifgen/Makefile   2011-11-15 00:32:56.878741037 +0100 +0 -0
@@ -6,7 +6,7 @@ INCLUDEDIR ?= $(PREFIX)/include
 
Quoted 7 lines
Quoted 7 lines

 CFLAGS ?= -Werror -Wall -W
 override CFLAGS += -I$(INCLUDEDIR)

policycoreutils/sepolgen-ifgen/Makefile    2012-06-04 14:08:14.580334340 +0200 renamed from policycoreutils/sepolgen-ifgen/Makefile   2011-11-15 00:32:56.878741037 +0100 +1 -1
-LDLIBS = $(LIBDIR)/libsepol.a
+LDLIBS = ../../libsepol/src/libsepol.a

 all: sepolgen-ifgen-attr-helper

Of course, after the two patches have been applied, it would still work with the previous trick of doing just "make install" (not recommended).

Regards,

Guido

--
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 24 lines · Guido Trentalancia

Allow standard compilation with separate installation of the SELinux GIT development tree.

To build, just type "make".

To install (after successful build), just type "make install".

During installation, it is possible to pass the variables DESTDIR, LIBDIR and SHLIBDIR to GNU make in order to fine tune the results.

---
 Makefile |   14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
Makefile +2 -0
@@ -2,11 +2,21 @@ SUBDIRS=libsepol libselinux libsemanage
 PYSUBDIRS=libselinux libsemanage
 DISTCLEANSUBIDRS=libselinux libsemanage
 
+TOPDIR := $(shell pwd)
+

Makefile SUBDIRS=libsepol libselinux libsemanage · line 14

Quoted 10 lines
Makefile +6 -2
+CPPFLAGS ?= -I$(TOPDIR)/libselinux/include -I$(TOPDIR)/libsepol/include -I$(TOPDIR)/libsemanage/include
+LDFLAGS ?= -L$(TOPDIR)/libselinux/src -L$(TOPDIR)/libsepol/src -L$(TOPDIR)/libsemanage/src
+CFLAGS ?= $(CPPFLAGS)
+
 ifeq ($(DEBUG),1)
-	export CFLAGS = -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror
-	export LDFLAGS = -g
+	CFLAGS += -g3 -O0 -gdwarf-2 -fno-strict-aliasing -Wall -Wshadow -Werror
+	LDFLAGS += -g
 endif

My problem with this patch is that now all of the CFLAGS stuff we have lower in the tree (namely -W* stuff) is not going to get picked up since CFLAGS are already exported...

So how do we solve that one too?

--
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.

#2 lore raw
In reply to Guido Trentalancia
Quoted 5 lines · Guido Trentalancia
Quoted 5 lines

I've never really seen something which can get it right 'all the time'. Fedora, and I assume other distros actually just use the git tree subdirectories. I feel like any such patch to handle this is going to have to be something set in the top level Makefile and will have to cause no difficulties for other workflows....

See http://people.gnome.org/~walters/docs/build-api.txt

This patch looks roughly right to me, though it'd make me happier if you also added a configure script. (Note: configure script does not have to be implemented with autoconf; see
http://git.gnome.org/browse/gtk-doc-stub/tree/configure for a minimal plain sh one).

Quoted 6 lines

My problem with this patch is that now all of the CFLAGS stuff we have lower in the tree (namely -W* stuff) is not going to get picked up since
CFLAGS are already exported...

So how do we solve that one too?

The automake way is to have AM_CFLAGS, AM_CPPFLAGS which are build-internal (and always used). CFLAGS is then something that can be added by the builder.

--
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.