Here's what I want to achieve (I'm working on Ubuntu 22):
1. Compile Harbour into *.a libraries with -fPIC flag to make the code position-independent.
2. Create a *.prg file with some code and compile it into *.so library with Harbour VM functions linked in (hbmk2 "-hbdynvm" compile flag).
The problem is with the first step - for the love of me I can't compile Harbour into PIC *.a libraries. Make builds all object files exclusively in the "no PIC" mode.
The HB_BUILD_DYN=yes env variable enables additional compilation of the libharbour.so library. And sure thing the make tool adds the gcc "-fPIC" flag to compile object files used to build the libharbour.so library, for example:
gcc -I. -I../../../../../include -W -Wall -O3 -ohvmall_dyn.o -DHB_DYNLIB -fPIC -c ../../../hvmall.c
... and later on:
gcc -shared -L../../../../../lib/linux/gcc -L/usr/X11R6/lib64 -L/usr/X11R6/lib -Wl,-soname,libharbour.so.3.2 -o ../../../../../lib/linux/gcc/libharbour.so.3.2.0 (...) ../../../../../src/vm/vmmt/obj/linux/gcc/hvmall_dyn.o (...)
The static libraries however remain in the "no PIC" mode and the object files get compiled without the -fPIC flag:
gcc -I. -I../../../../../include -W -Wall -O3 -ohvmall.o -c ../../../hvmall.c
There's also HB_BUILD_SHARED=yes/no env variable but I'm not sure what it's exactly used for. Either way it doesn't seem to be relevant in my case.
I've managed to cheese the compilation process using the HB_USER_CFLAGS="-fPIC" env variable and thus directly adding the gcc compilation flag. But it truly feels like a hack and I'm afraid it would break something in the future when I least expect it.
Why isn't there any formal way to compile Harbour into static *.a libraries in PIC mode? Is it intentional? Or perhaps I'm missing something?
Your truly,
Tom