[PATH] sysroot handling

xyz jlm_devel at laposte.net
Sun Oct 30 09:16:40 PST 2005

> * malet jean-luc alias cityhunter 
> | I saw that my patch wasn't included in last release.....
can someone
> | explain me why it has been rejected? or if it is still
under review?
> It hasn't been rejected, but I haven't decided on how to do
> sysroot/cross-compilation with pkg-config yet.
> There is already a suggestion on
> http://pkgconfig.freedesktop.org/wiki/CrossCompileProposal .
 It would
> be useful if you could comment on that and how sysroot
support relates
> to cross-compilation.

I've no rights to edit the wiki so I'll post my comments here:

I think that the proposal is TOO complex and TOO much bound to
the author tinks that all packages use uptodate autoconf
configuration file which is not the case. 
he assumes in "default search path" that the files are located
in the same tree in case of x86_64 which is not obviously the
case (I use some devel x386 box to crosscompile for the x86_64
section "Identifying Host Type for .pc Files" is already
implemented via the $PKG_CONFIG_LIBDIR $PKG_CONFIG_PATH. when
crosscompiling you often need to setup the env so that the
rights compilers are used.... so 'crosscompiler SA' are
already aware of those variables....

anyway to let you understand what is the mater let's take an
exemple :

in one project I've worked on, we had a crosscompiler provided
by a third party, a crosscompiler is often build to use a
single "sysroot" (system root) for testing purpose and because
we required it for various reason, boxes often had 2 to 5
"sysroot" (imagine a sysroot as a "chroot point" ie if the
arch were compatible you can do a chroot $SYSROOT and have
everything working) each sysroot have a whole workable tree,
including pkg-config .pc file....

so let's take an autoconf exemple :
export SYSROOT=/var/some/sysroot/point
export DESTDIR=/var/some/sysroot/point
export PATH=...
export CC=....
export CXX=....
export LDFLAGS=.....
export CPPFLAGS=.....
export .... 
#this is to be sure to use the target .pc and not the host ones
#DESTDIR can point elsewhere if you want to package thing but I'll
#make it short here

./configure --prefix=/usr --target=XXXX
#this is because the package is intendent to run in /usr but
will be 
#installed elsewhere (we can't polute the / of the
crosscompile box)
#some user user --target to use the right compiler.... I'm not
found of
#this methods which has the desavantage to be bound to
#where export CC is widely used....

make install
ok then let's see the problems :
1) .pc file are created using the --prefix value, which should
be the "running directory tree" (/usr) and not the "sysroot
directory" (/var/some/sysroot/point) a common mistake is to
confuse both.... this means that .pc are created and returns
-I to /usr/include 
you may say "then do a --prefix=/var/...." MISTAKE! because
some packages (and they are right) use this variable to know
where they will be installed, then where they will found
configuration file, or some dynamic libraries they've created....
2)so .pc have to be seded before they can be used replacing
prefix or other variables.... this leads to another trouble :
if you share some tree over nfs, a tree usable on one box
can't be on another : imagine the user made a symlink from
/var/some/ to /home/sysroots.... all .pc are usable.... I
prefer to let user be "flexible" then not to hardcode some
things (for exemple the kernel team of 2 people can share a
tree for the, testing things in it, and may not want to use
network space which migth not be able to store 5000000000

the best solution is to have a tool that setup correctly the
env according to user choices and then crosscompile....
the sed is not a really good solution (on .la this works fine
because .la use the env.... so we can sed /usr to
${SYSROOT}/usr before creating a package and then have no
trouble) but in case of .pc we must have a sed per
configuration choices because .pc don't use env.....

my patch is here to solve this issue : by providing an
environment variable that tell to pkg-config how to modify the
output then we can have a flexible way to handle sysroot issue....
the variable that REQUIRE to be modified are all PATHS (-I -L
and so on) because we require to say to the package we are
crosscompiling "use the header located there and not the host
headers" (idem for the libraries) else the autotools will do
horrible things (oh! there is a gstreamer there, but in the
sysroot tree there aren't any....)

at this time writing the only solution regarding headers is to
export CFLAGS="$CFLAGS --no-stdinc"  to prevent cpp/cc to use
standard include directories" and after to setup correctly the
-I.... a pain in the ass when you find pkg-config based

Accédez au courrier électronique de La Poste : www.laposte.net ; 
3615 LAPOSTENET (0,34€/mn) ; tél : 08 92 68 13 50 (0,34€/mn)

More information about the pkg-config mailing list