Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pkg-config: platform-neutral way to find out where to install my .pc file?

How do I know where to install my .pc file? These files are put in different places on different operating systems. The goal is to be able to use something like $(INSTALL) mylib.pc $$(pkg-config --pcdir) in the install target. I thought pkg-config would be able to tell me somehow, but can't find anything.

I'm looking for a "standalone" solution usable in plain Makefile (must not require support from autotools or similar).

like image 226
just somebody Avatar asked Feb 05 '10 18:02

just somebody


People also ask

Where does pkg-config look for files?

By default, pkg-config looks in the directory prefix/lib/pkgconfig for these files; it will also look in the colon-separated (on Windows, semicolon-separated) list of directories specified by the PKG_CONFIG_PATH environment variable.

What is a pkg-config file?

pkg-config is a useful tool for making sure compiler options are correct when compiling and linking software. Very often with compilers, you will need to determine the proper paths to library header files and code in order to link them to your software project.

What is pkg-config in Windows?

pkg-config is a computer program that defines and supports a unified interface for querying installed libraries for the purpose of compiling software that depends on them. It allows programmers and installation scripts to work without explicit knowledge of detailed library path information.

What is a .PC file Linux?

pc files include compiler and linker flags necessary to use a given library, as well as any other relevant metadata. These . pc files are processed by a utility called pkg-config, of which pkgconf is an implementation.


2 Answers

As of pkg-config 0.24, you can do "pkg-config --variable=pc_path pkg-config".

https://bugs.freedesktop.org/show_bug.cgi?id=14975

like image 106
scop Avatar answered Jan 03 '23 18:01

scop


UPDATE: Evidently there is now a way to do this:

pkg-config --variable pc_path pkg-config

Found in this bug report (see comment #4). The current man page appears to document this.

Original answer:

Horrible hackish solution (assuming bourne shell):

pkg-config --debug 2>&1 |grep Scanning | sed -e 's/Scanning directory //' -e "s/'//g"

This may give you more than one location.

edit by @just somebody

shorter version

pkg-config --debug 2>&1 | sed -ne '/Scanning directory /s///p'

and to stop after the first directory:

pkg-config --debug 2>&1 | sed -ne '/Scanning directory /{s///p;q;}'
like image 20
Craig Avatar answered Jan 03 '23 17:01

Craig