Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Dec 2012 00:54:19 +0100
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        hackers@FreeBSD.org
Subject:   Fix overlinking in base aka import pkgconf
Message-ID:  <20121214235418.GF18884@ithaqua.etoilebsd.net>

next in thread | raw e-mail | index | archive | help

--ni93GHxFvA+th69W
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi,

Some of our binary are overlinked, the way we handle the linking doesn't he=
lp
for that.

On proposition could be to use pkgconf https://github.com/pkgconf/pkgconf w=
hich
is BSD license pkg-config implementation 100% compatible with pkg-config.

What I propose is to create a new PCADD variable for the Makefiles.

PCADD will invoke pkgconf to gather the libraries and the cflags for a given
project.

The second thing would be to create .pc files for all of our libraries.

for example:
usr.bin/fstat dynamic build is overlinked

With the following simple patch we can solve the problem:
Index: Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- Makefile    (revision 243899)
+++ Makefile    (working copy)
@@ -5,7 +5,7 @@
 SRCS=3D  fstat.c fuser.c main.c
 LINKS=3D ${BINDIR}/fstat ${BINDIR}/fuser
 DPADD=3D ${LIBKVM} ${LIBUTIL} ${LIBPROCSTAT}
-LDADD=3D -lkvm -lutil -lprocstat
+PCADD=3D procstat
=20
 MAN1=3D  fuser.1 fstat.1
=20

This requires the following .pc files quick and dirty ones:
- util.pc:

prefix=3D/usr
libdir=3D${prefix}/lib
includedir=3D${prefix}/include

Name:   util
Libs:   -L${libdir} -lutil
Cflags: -I${includedir}

- kvm.pc:

prefix=3D/usr
libdir=3D${prefix}/lib
includedir=3D${prefix}/include
Name:   kvm
Libs:   -L${libdir} -lkvm
Cflags: -I${includedir}

- procstat.pc:
prefix=3D/usr
libdir=3D${prefix}/lib
includedir=3D${prefix}/include
Name:   procstat
Requires.private: kvm util
Libs:   -L${libdir} -lprocstat
Cflags: -I${includedir}

The quick and dirty patch for our framework is:
Index: bsd.prog.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- bsd.prog.mk (revision 243899)
+++ bsd.prog.mk (working copy)
@@ -36,6 +36,18 @@
 LDFLAGS+=3D -static
 .endif
=20
+.if defined(PCADD)
+PCFLAGS!=3D      ${PKGCONF} --cflags ${PCADD}
+.if defined(NO_SHARED) && (${NO_SHARED} !=3D "no" && ${NO_SHARED} !=3D "NO=
")
+PCLIBS!=3D       ${PKGCONF} --libs --static ${PCADD}
+.else
+PCLIBS!=3D ${PKGCONF} --libs ${PCADD}
+.endif
+CFLAGS+=3D       ${PCFLAGS}
+CXXFLAGS+=3D     ${PCFLAGS}
+LDADD+=3D                ${PCLIBS}
+.endif
+
 .if defined(PROG_CXX)
 PROG=3D  ${PROG_CXX}
 .endif
Index: sys.mk
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- sys.mk      (revision 243899)
+++ sys.mk      (working copy)
@@ -137,6 +137,8 @@
 PC             ?=3D      pc
 PFLAGS         ?=3D
=20
+PKGCONF                ?=3D      pkgconf
+
 RC             ?=3D      f77
 RFLAGS         ?=3D
=20

Of course a lot of work is needed to get something really well integrated b=
ut
I wanted feedback first before working on anything like this :)

regards,
Bapt

--ni93GHxFvA+th69W
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (FreeBSD)

iEYEARECAAYFAlDLvCoACgkQ8kTtMUmk6EzbPACbB6cR+36w0Gv8sFW93J7EJTbi
k5QAnRpPMLDTjadalIT32dhOTjvjl7PX
=nloN
-----END PGP SIGNATURE-----

--ni93GHxFvA+th69W--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121214235418.GF18884>