Search code examples
configuration-filesconfigureconfigurationmanagerpkg-config

Is there any way to define own options in *.pc files except standard options


I am trying to make a .pc file and want to define a flag ldflags and use it something like this

pkg-config package --ldflags

but it's showing unknown option ldflags. Is there a way to define my own option in pc file.


Solution

  • .pc file has special format, check here:

    The file format contains predefined metadata keywords and freeform variables.

    keywords are fixed, e.g. Cflags and most of them correspond to pkg-config tool options e.g. --cflags. But variables:

    ... can be used by the keyword definitions for flexibility or to store data not covered by pkg-config

    So, it possible to add own, for example I created minimum possible one (Name, Version, Description are mandatory keywords):

    $ cat test.pc
    Name: test
    Version: 1
    Description: test
    aaa=bbb
    
    $ pkg-config --variable=aaa
    bbb
    

    It's possible to list all with --print-variables option (interestingly though that pcfiledir variable is added automatically):

    $ pkg-config --print-variables test.pc
    aaa
    pcfiledir
    
    $ pkg-config --variable=pcfiledir
    .
    

    It can even (re)define one variable using another:

    $ cat test.pc
    Name: test
    Version: 1
    Description: test
    aaa=bbb${ccc}
    
    $ pkg-config test.pc --variable=aaa --define-variable=ccc=xxx
    bbbxxx  
    

    Wonder about your use case? since contents of this file is just for keeping metadata about dependencies some package has. Maybe you should add instead these flags to Libs or Libs.private keywords?