pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
[PATCH] Make pkg-config files cross-compile friendly
2+ messages / 2 participants
[nested] [flat]

Commits from this thread:
  2021-09-03 6588d8416e  Make pkg-config files cross-compile friendly
* [PATCH] Make pkg-config files cross-compile friendly
@ 2020-03-05 21:38 Sebastian Kemper <sebastian_ml@gmx.net>
  2021-09-03 14:58 ` Re: [PATCH] Make pkg-config files cross-compile friendly Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Sebastian Kemper @ 2020-03-05 21:38 UTC (permalink / raw)
  To: pgsql-hackers

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=libdir=/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=prefix=${STAGING_PREFIX} \
       --define-variable=exec_prefix=${STAGING_PREFIX} \
       --define-variable=bindir=${STAGING_PREFIX}/bin $@

Example #1: user calls ./configure with "--libdir=/some/lib" and
"--includedir=/some/include":

  prefix=/usr/local/pgsql
  exec_prefix=/usr/local/pgsql
  includedir=/some/include
  libdir=/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=/usr/local/pgsql
  exec_prefix=/usr/local/pgsql
  includedir=${prefix}/include
  libdir=${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/openwrt/staging_dir/target-mips_24kc_musl/usr/lib

Signed-off-by: Sebastian Kemper <sebastian_ml@gmx.net>
---
 src/Makefile.shlib | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

inline patch 1: src/Makefile.shlib (+16/-3 lines) download inline-1.patchdiff --git a/src/Makefile.shlib b/src/Makefile.shlib index 29a7f6d38c..33c23dabdd 100644 --- a/src/Makefile.shlib +++ b/src/Makefile.shlib @@ -387,14 +387,27 @@ endif # PORTNAME == cygwin || PORTNAME == win32 %.pc: $(MAKEFILE_LIST) - echo 'Name: lib$(NAME)' >$@ + echo 'prefix=$(prefix)' >$@ + echo 'exec_prefix=$(exec_prefix)' >>$@ +ifeq ($(patsubst $(prefix)/%,,$(includedir)),) + echo 'includedir=$${prefix}/$(patsubst $(prefix)/%,%,$(includedir))' >>$@ +else + echo 'includedir=$(includedir)' >>$@ +endif +ifeq ($(patsubst $(exec_prefix)/%,,$(libdir)),) + echo 'libdir=$${exec_prefix}/$(patsubst $(exec_prefix)/%,%,$(libdir))' >>$@ +else + echo 'libdir=$(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
-- 2.24.1 ^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: [PATCH] Make pkg-config files cross-compile friendly
  2020-03-05 21:38 [PATCH] Make pkg-config files cross-compile friendly Sebastian Kemper <sebastian_ml@gmx.net>
@ 2021-09-03 14:58 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Eisentraut @ 2021-09-03 14:58 UTC (permalink / raw)
  To: Sebastian Kemper <sebastian_ml@gmx.net>; pgsql-hackers

On 05.03.20 22:38, Sebastian Kemper wrote:
> 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=libdir=/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:

Committed.  I simplified your code a little bit, and I also made it so 
that exec_prefix is set to ${prefix} by default.  That way it matches 
what most other .pc files I have found do.





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-09-03 14:58 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-05 21:38 [PATCH] Make pkg-config files cross-compile friendly Sebastian Kemper <sebastian_ml@gmx.net>
2021-09-03 14:58 ` Peter Eisentraut <peter.eisentraut@enterprisedb.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox