[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Crossbuild with pkg-config



On Thu, Dec 14, 2023 at 09:46:54PM +0100, IOhannes m zmölnig (Debian/GNU) wrote:
> On 12/14/23 19:51, Randy Pfeifer wrote:
> > Hello,
> > I'm attempting to create and cross-build a package with a simple Makefile using pkg-config to set linking options. I found a solution in theCrossBuildPackagingGuidelines wiki page:
> > 
> > In Makefile:
> > include /usr/share/dpkg/buildtools.mk

This is supposed to go into the Debian packaging.

> > PKG_CONFIG?=pkg-config
> > LDLIBS += $(shell $(PKG_CONFIG) --libs <lib...>)

This is supposed to go into the upstream Makefile.

> > This works, but the include makes the upstream package (Makefile) non-portable (debian specific). Is there a better way to accomplish this ?
> 
> 
> i see two ways:
> 1. just patch the makefile for Debian packaging (it's a bit unclear whether
> your context is actually Debian packaging, but since you quote
> CrossBuildPackagingGuidelines, I assume it is)

Don't. You can never upstream your patch and there is no need for a
patch, because:

> 2. just pass the PKG_CONFIG manually when invoking 'make'. use the power of
> /usr/share/dpkg/buildtools.mk from within your meta-buildsystem (e.g.
> d/rules) and call the actual build with 'make PKG_CONFIG=$(PKG_CONFIG)' or
> similar.

This sounds cumbersome, but this is the way to do it. The contract for
simple Makefiles is that upstreams pick defaults for CC, PKG_CONFIG and
friends but a user may set them. In particular, cross building requires
setting all of them.

Did you know that dh_auto_build automatically sets these (including
PKG_CONFIG) when performing a cross build? As soon as your upstream
Makefile always invokes pkg-config as $(PKG_CONFIG), it'll automatically
just work with dh_auto_build.

Also note that this approach also automatically just works with
buildroot, ptxdist and yocto. :)

Would either of you extend the wiki page?

> 3. (as upstream) do an *optional* include if the buildtools.mk:
> 
> ```
> -include /usr/share/dpkg/buildtools.mk
> PKG_CONFIG?=pkg-config
> ```

Don't. This is Debian packaging infrastructure and has no business in
upstream build systems.

Helmut


Reply to: