Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jA18B-0007Dz-KI for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2020 00:46:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jA189-00053T-GK for pgsql-hackers@arkaria.postgresql.org; Fri, 06 Mar 2020 00:46:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j9yCa-0002LO-A1 for pgsql-hackers@lists.postgresql.org; Thu, 05 Mar 2020 21:38:44 +0000 Received: from mout.gmx.net ([212.227.17.21]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1j9yCT-00037k-3j for pgsql-hackers@postgresql.org; Thu, 05 Mar 2020 21:38:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1583444312; bh=NeQ4b+jYcWG8fpgESLBCEwiysRUTV3DdqvpPVY6BD7E=; h=X-UI-Sender-Class:Date:From:To:Subject; b=MbEOVLYI83HmO5vex/dKavRG7Yz9C0ZGr2ZnKO+Py3DnTKoQIshQJVdo0ZFG3Zcx0 62fLDNZzBX4iQE+h+hmubYG/9pJxzRv9bLaTG53VhXWqipDInHoy79H4wUVP+GteFT 8j3A9dooQildiPZbQsEyhFk6LT4zdX2osYQs9fSA= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from darth.lan ([62.14.67.235]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MJVDM-1iuViC1M88-00Jpb4 for ; Thu, 05 Mar 2020 22:38:32 +0100 Date: Thu, 5 Mar 2020 22:38:29 +0100 From: Sebastian Kemper To: pgsql-hackers@postgresql.org Subject: [PATCH] Make pkg-config files cross-compile friendly Message-ID: <20200305213827.GA25135@darth.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Provags-ID: V03:K1:TfG8zU0leOu8b7MXGrbrh6oO/1lwQ58x5bNAgVWdEW2pxBHdCpm MVnkjP9FQblgemm3lGWh4/fpMMyZsWTotK8fgTnuPeAmNlTFVVJ73lSt0lNx1u9AJWzWyCM XpAu7s2/6tmCpClqAOXovOa9pzOB58dA+GOIL2CSoAtWhM0HpKzjkF51crYzhojvI8g7ziw 1i4BHG9nzHaxBBe1TqZuQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:1YJLqBLtWsU=:6Pkvr+bMrELN3lxYN7/yNA X7vG0YAO4i6rRckNgTc8ss5YRuBVu9gfFsE1t0S4RGhu1c+ITsHha/dZ0CWVfODkBGBBif2FL zcX7lIJj8FUhjXrUB2hAxh8fdvLV0eMhA3n1lhqgVUx8lOmeMeOHTdLmQZ9bXDQLH1wWlDjPK QShv6DDgj01zOG835vnpR/TlZ/ij6u56jxg3lmF2GUCe7Ia6GBPDqG5iZx19hmIAKdUDjgIec t/ev+V6/IEjvijO2GqazOGQAPMBETrbAGrqtBqF2MHbVOAvOD8dcg/gpoaaGRaM4BFmh9A6gW E1+Bvh7FiklWJ2BbNKsQqmwXqLrN4XUlPLIyK/wlbGS1j+BVHTgiJYX7xVNhVGHlp/gXx0BGQ P2QnNDxvl+rpthq4gukhgGp/wLnc+Wf8w6i32o1zs9QDFraTfVJ1hJPku+79Xtj/pISm+jS7M xC8HNwPSGtHARHcMe0dwLqlzXTmaWIzNPjFdxNkxCGBW0xUqLbaRhW6jR2lugSYmYMXJi+Xwn Kd5/d1Y1x+UCmGBer5aJFIOnJfZfhHbCTK3ApWMPRr5LJRCcm2toB5iGrz7u22QTMvrDmNCSx teIm6jZmQo1rkxOPffKitKudz+cLzLRDgrMVb1mrB4JopMCLPbNL7JyBLwdNo+kmz4cJ87q+g uvooFLAlzrIK80rGPXRMUUT4bwRe1D4QFHq+5WAZDOIXRe/teZ4yiAXAQRLSdKRS5xGJJJVLK v9WOe0brmCLX6/3gWd9J0AvCmSd04oWKW8smpYrWxQYOLdhkOa0Mb8VB9vWMDpgFz/dKtlgqH lkVdpBmTYu1NU0ATTcVn5oyloK0zM9PjJJw1fIjHl/PODThAFMSu/VV08Mm7LHb3J8c5BkLn7 Jjgnr+IT18i8lvwxZ2YvHtorGkU/0DYCsKnBMW3EYQ0d3uoWjKgJRlolYk1gOYTTXVsmuQU36 3fetnagRjChJCeA9I5AQZO/Ew01D/QkSbpovNtdPBi7uOvKmsqGZXvTZ4REZg8Gmn24Lix+QD 3aI18uUY4xGRhD9cFD9Z8BW/myb6G8g03IXD3BAxuZJ6gj1LcPHV1PTd7j4gN2OZiqtZyuPt5 zpor/RWqzBp+kaPdifgNKcFqzlXERUqfbu+9H7ptwkogoRcVB9MmqYBTaXuItx+qHpdXmtAS1 fDvqRoiXfTigTatQgVElYo6Bwd0yDGoV7YcB2Gy5Y7ZfEdprQJ0HIv3M1qa2SvWCt8yYMRdFn 6+eTBv8upBhUnmaOl Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Currently the pc files use hard coded paths for "includedir" and "libdir." Example: Cflags: -I/usr/include Libs: -L/usr/lib -lpq This is not very fortunate when cross compiling inside a buildroot, where the includes and libs are inside a staging directory, because this introduces host paths into the build: checking for pkg-config... /builder/shared-workdir/build/sdk/staging_dir= /host/bin/pkg-config checking for PostgreSQL libraries via pkg_config... -L/usr/lib <---- This commit addresses this by doing the following two things: 1. Instead of hard coding the paths in "Cflags" and "Libs" "${includedir}" and "${libdir}" are used. Note: these variables can be overriden on the pkg-config command line ("--define-variable=3Dlibdir=3D/some/path"). 2. Add the variables "prefix" and "exec_prefix". If "includedir" and/or "libdir" are using these then construct them accordingly. This is done because buildroots (for instance OpenWrt) tend to rename the real pkg-config and call it indirectly from a script that sets "prefix", "exec_prefix" and "bindir", like so: pkg-config.real --define-variable=3Dprefix=3D${STAGING_PREFIX} \ --define-variable=3Dexec_prefix=3D${STAGING_PREFIX} \ --define-variable=3Dbindir=3D${STAGING_PREFIX}/bin $@ Example #1: user calls ./configure with "--libdir=3D/some/lib" and "--includedir=3D/some/include": prefix=3D/usr/local/pgsql exec_prefix=3D/usr/local/pgsql includedir=3D/some/include libdir=3D/some/lib Name: libpq Description: PostgreSQL libpq library Url: http://www.postgresql.org/ Version: 12.1 Requires: Requires.private: Cflags: -I${includedir} Libs: -L${libdir} -lpq Libs.private: -lcrypt -lm Example #2: user calls ./configure with no arguments: prefix=3D/usr/local/pgsql exec_prefix=3D/usr/local/pgsql includedir=3D${prefix}/include libdir=3D${exec_prefix}/lib Name: libpq Description: PostgreSQL libpq library Url: http://www.postgresql.org/ Version: 12.1 Requires: Requires.private: Cflags: -I${includedir} Libs: -L${libdir} -lpq Libs.private: -lcrypt -lm Like this the paths can be forced into the staging directory when using a buildroot setup: checking for pkg-config... /home/sk/tmp/openwrt/staging_dir/host/bin/pkg= -config checking for PostgreSQL libraries via pkg_config... -L/home/sk/tmp/openw= rt/staging_dir/target-mips_24kc_musl/usr/lib Signed-off-by: Sebastian Kemper =2D-- src/Makefile.shlib | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Makefile.shlib b/src/Makefile.shlib index 29a7f6d38c..33c23dabdd 100644 =2D-- a/src/Makefile.shlib +++ b/src/Makefile.shlib @@ -387,14 +387,27 @@ endif # PORTNAME =3D=3D cygwin || PORTNAME =3D=3D wi= n32 %.pc: $(MAKEFILE_LIST) - echo 'Name: lib$(NAME)' >$@ + echo 'prefix=3D$(prefix)' >$@ + echo 'exec_prefix=3D$(exec_prefix)' >>$@ +ifeq ($(patsubst $(prefix)/%,,$(includedir)),) + echo 'includedir=3D$${prefix}/$(patsubst $(prefix)/%,%,$(includedir))' >= >$@ +else + echo 'includedir=3D$(includedir)' >>$@ +endif +ifeq ($(patsubst $(exec_prefix)/%,,$(libdir)),) + echo 'libdir=3D$${exec_prefix}/$(patsubst $(exec_prefix)/%,%,$(libdir))'= >>$@ +else + echo 'libdir=3D$(libdir)' >>$@ +endif + echo >>$@ + echo 'Name: lib$(NAME)' >>$@ echo 'Description: PostgreSQL lib$(NAME) library' >>$@ echo 'Url: $(PACKAGE_URL)' >>$@ echo 'Version: $(VERSION)' >>$@ echo 'Requires: ' >>$@ echo 'Requires.private: $(PKG_CONFIG_REQUIRES_PRIVATE)' >>$@ - echo 'Cflags: -I$(includedir)' >>$@ - echo 'Libs: -L$(libdir) -l$(NAME)' >>$@ + echo 'Cflags: -I$${includedir}' >>$@ + echo 'Libs: -L$${libdir} -l$(NAME)' >>$@ # Record -L flags that the user might have passed in to the PostgreSQL # build to locate third-party libraries (e.g., ldap, ssl). Filter out # those that point inside the build or source tree. Use sort to =2D- 2.24.1