Re: the ScriptingMojo

From: Chapman Flack <chap(at)anastigmatix(dot)net>
To: Kartik Ohri <kartikohri13(at)gmail(dot)com>
Cc: pljava-dev(at)lists(dot)postgresql(dot)org
Subject: Re: the ScriptingMojo
Date: 2020-08-26 05:09:19
Message-ID: 5F45EE7F.5020609@anastigmatix.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

On 08/26/20 00:44, Kartik Ohri wrote:

> Also, I had another question: is there any particular reason that compiling
> and linking should
> be two different commands. To me it appears to be another one of nar maven
> quirks.
> Compilers by default compile and link in a single step. It seems nar maven
> overrides it due to
> reason. Since, there is no configuration to suggest that this is desired I
> am a bit confused.
> Do we want to compile and link in different steps ?

Yes ... because not only is it done by the nar-maven-plugin (which is not
what we want to imitate), it is also done that way by the PGXS makefiles
(which are what we want to imitate). In fact it has been the usual practice
for about as long as there have been makefiles.

One reason is that compiling C programs is a kind of local activity.
Each .c file is transformed into a .o file, without needing to know
very much about the others. (What little it does need to know, it
gets from .h files.)

Conceptually, it's a different operation once you have all of those .o
files and you want to edit and link all of them together into some kind
of binary image with the references resolved. On top of that, there are
choices in what kind of result to produce. A standalone executable?
A static library? A dynamic library? A loadable plugin? (The Mac OS
linker really makes a distinction between a regular dynamic library
and a plugin. The unresolved references in a dynamic library have to
be findable in the other libraries given as its dependencies. For a
plugin, the assumption is they will be findable in the program that
the plugin gets loaded into. The Mac linker actually checks that at
link time, which is why there is a -bundle_loader option added in
the Mac OS profile in pljava-so.)

Even when you can just pile all the compiling and linking options onto
one gcc command line, that still is just the gcc wrapper command being
clever and sorting the options out and running the preprocessor and
compiler and then the linker. But for clarity in makefiles, it is very
common to separate the rules for compiling the components from the rules
for linking the final product.

Regards,
-Chap

In response to

Responses

Browse pljava-dev by date

  From Date Subject
Next Message Kartik Ohri 2020-08-26 16:55:08 Re: the ScriptingMojo
Previous Message Kartik Ohri 2020-08-26 04:44:45 Re: the ScriptingMojo