Bug 16905 - --cflags request incomplete if the var. PKG_CONFIG_SYSROOT_DIR is set
Summary: --cflags request incomplete if the var. PKG_CONFIG_SYSROOT_DIR is set
Status: RESOLVED FIXED
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: Tollef Fog Heen
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-30 07:20 UTC by Giorgio
Modified: 2009-12-06 13:41 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
patch to fix bug (550 bytes, patch)
2008-12-16 10:35 UTC, Jon Dufresne
Details | Splinter Review

Description Giorgio 2008-07-30 07:20:53 UTC
Take a xtrans.pc file like:

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: XTrans
Description: Abstract network code for X
Version: 1.2.1
Cflags: -I${includedir} -D_BSD_SOURCE -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT

and call pkg-config from a bash like (all on one line):

PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_PATH=/sources/emb_prj/dest/usr/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=/sources/emb_prj/dest  pkg-config --cflags "xtrans"

than all I get is:
   -I/sources/emb_prj/dest/usr/include

instead of the expected:
-D_BSD_SOURCE -DHAS_FCHOWN -DHAS_STICKY_DIR_BIT -I/sources/emb_prj/dest/usr/include

The three preprocessor variable defs are missing.

The problem does NOT occur if the env. var. PKG_CONFIG_SYSROOT_DIR is not defined.

I could trace down the bug in the function 'string_list_to_string()' defined in pkg.c:

static char *
string_list_to_string (GSList *list)
{
  GSList *tmp;
  GString *str = g_string_new ("");
  char *retval;
  
  tmp = list;
  while (tmp != NULL)
    {
      char *tmpstr = (char*) tmp->data;
      if (pcsysrootdir != NULL)
        {
          if (tmpstr[0] == '-' &&
              (tmpstr[1] == 'I' ||
               tmpstr[1] == 'L'))
            {
              g_string_append_c (str, '-');
              g_string_append_c (str, tmpstr[1]);
              g_string_append (str, pcsysrootdir);
              g_string_append (str, tmpstr+2);
            }
        }
      else 
        {
          g_string_append (str, tmpstr);
        }
      g_string_append_c (str, ' ');
      
      tmp = g_slist_next (tmp);
    }

  retval = str->str;
  g_string_free (str, FALSE);

  return retval;
}

If the var. 'pcsysrootdir' is not NULL *and* the 'tmpstr' does not start with '-I' or '-L' then the string 'tmpstr' won't be appended to the result 'str'.
Comment 1 Jon Dufresne 2008-12-16 10:35:22 UTC
Created attachment 21210 [details] [review]
patch to fix bug

This patch combines the two nested if statements in the above post. If -I or -L is not found, then the entire string is appended as one would expect. This has been tested and works on my system. I am now able to use pkg-config with a sysroot directory.
Comment 2 Alejandro Mery 2009-07-27 09:44:12 UTC
this one, and not the previously accepted http://lists.freedesktop.org/archives/pkg-config/2008-January/000255.html fixes SYSROOT support.
Comment 3 Tollef Fog Heen 2009-12-06 13:41:00 UTC
Fixed in 66d49f1.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.