2

I use waf as my build system and I want to compile a small C program using Postgres. I have included postgres.h in my program so I need to find the path to it in my wscript file. I know that I can get the path I need by running:

pg_config --includedir-server

which gives me:

/usr/include/postgresql/9.3/server

So I thought I could use something like this:

cfg.check_cfg(
    path='pg_config',
    package='',
    uselib_store='PG',
    args='--includedir-server',
)

And then build my program by:

bld.program(
    source=['testpg.c'],
    target='testpg',
    includes=['.', '../src'],
    use=['PQ', 'PG'],
)

But this fails with postgres.h: No such file or directory. I ran ./waf -v and confirmed that the proper -I flag is not being passed to gcc. My guess is this happens because pg_config does not add a -I prefix to the path it returns. Is there a way I can make waf to add the prefix, or make pg_config to add it?

Elektito
  • 3,863
  • 8
  • 42
  • 72

1 Answers1

1

Should pg_config had the standard output of pkg_config like programs (ie outputs something like -Ixxx -Iyyy), your code would work, has check_cfg parse this kind of output.

As there is no complicated parsing, you can go for:

import subprocess

includes = subprocess.check_output(["pg_config", "--includedir-server"])
includes.replace("\n", "")

conf.env.INCLUDES_PG = [includes]

And then use it:

bld.program(
    source=['testpg.c'],
    target='testpg',
    use=['PG'],
)

See the library integration in the waf book. It explains the naming rule that make it works.

You can write a small plugin to ease the use :)

neuro
  • 14,948
  • 3
  • 36
  • 59
  • The man page says `--cflags` prints "the value of the CFLAGS variable that was used for building PostgreSQL". This is not the same as the CFLAGS we need to use in order to build our own programs. – Elektito Oct 02 '15 at 12:45
  • @Elektiko: You are right. pg_config does not follow the standard way of xxx_config utils which mistaken me ... See my edit – neuro Jan 08 '16 at 08:22