Custom options for building extensions with --with--llvm

Started by Konstantin Knizhnikover 5 years ago3 messages
#1Konstantin Knizhnik
k.knizhnik@postgrespro.ru

Hi,

In my extension I want to define some custom options for compiler.
I do it in the following way:

ifdef USE_DISK
CUSTOM_COPT += -DIMCS_DISK_SUPPORT
endif

So if I want to enable disk support, I am building my extension as

make USE_DISK=1 clean all install

and it normally works... unless Postgres is built with --enable-llvm.
In this case it tries to build llvm code using clang and is not using
CUSTOM_COPTS:

gcc -Wall -Wmissing-prototypes -Wpointer-arith
-Wdeclaration-after-statement -Werror=vla -Wendif-labels
-Wmissing-format-attribute -Wformat-security -fno-strict-aliasing
-fwrapv -fexcess-precision=standard -g -O3 -Wall -pthread
-DIMCS_DISK_SUPPORT -fPIC -I. -I. -I../../src/include -D_GNU_SOURCE   -c
-o disk.o disk.c

vs.

/usr/bin/clang -Wno-ignored-attributes -fno-strict-aliasing -fwrapv -O2 
-I. -I. -I../../src/include  -D_GNU_SOURCE  -flto=thin -emit-llvm -c -o
disk.bc disk.c

I wonder is there any way to pass custom compile options to clang?
Thanks in advance,

--
Konstantin Knizhnik
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

#2Andres Freund
andres@anarazel.de
In reply to: Konstantin Knizhnik (#1)
Re: Custom options for building extensions with --with--llvm

Hi,

On 2020-09-24 19:15:22 +0300, Konstantin Knizhnik wrote:

In my extension I want to define some custom options for compiler.
I do it in the following way:

ifdef USE_DISK
CUSTOM_COPT += -DIMCS_DISK_SUPPORT
endif

Why aren't you adding it to PG_CPPFLAGS? That should work, and I think
that's what several contrib modules are using.

My understanding of CUSTOM_COPT is that it's for use in Makefile.custom,
not for contrib modules etc?

I wonder is there any way to pass custom compile options to clang?
Thanks in advance,

It probably wouldn't hurt to add COPT that to the respective rules in
Makefile.global.in in some way. Shouldn't be too hard to do, if you want
to write a patch. Probably just apply it to BITCODE_CFLAGS as well.

Greetings,

Andres Freund

#3Konstantin Knizhnik
k.knizhnik@postgrespro.ru
In reply to: Andres Freund (#2)
Re: Custom options for building extensions with --with--llvm

On 24.09.2020 21:37, Andres Freund wrote:

Hi,

On 2020-09-24 19:15:22 +0300, Konstantin Knizhnik wrote:

In my extension I want to define some custom options for compiler.
I do it in the following way:

ifdef USE_DISK
CUSTOM_COPT += -DIMCS_DISK_SUPPORT
endif

Why aren't you adding it to PG_CPPFLAGS? That should work, and I think
that's what several contrib modules are using.

Thank you.
PG_CPPFLAGS works correctly.