> Date: Sat, 18 Jan 2025 12:53:40 +0100 > From: Patrice Dumas <pertu...@free.fr> > > Hello, > > To setup paths we need to known if a program (texi2any) is called > in-source/in-build or from the installation directory. Is there a way > to detect if a C program is called in-source/in-build or after > installation? For Perl we use mainly a trick that in-source scripts > have .pl and do not have configure values substituted (ie '@datadir@' is > still '@' .'datadir@') while installed scripts have configure values > substituted. We also can also use an environment variable to be able to > call the scripts with configure values substituted in-build/in-source, > which I will implement in C, but I would prefer to also have something > like the .pl trick, there is much less risks of mixing up the two > programs. > > The C program has always the configure values available, as it always > need to include config.h and the variables passed with -D are always set > too. > > I tried to search on the www, but did not find anything relevant. > > Any idea? Any example of how it is done in other projects?
The usual way is to find the absolute file name of the executable that runs, and then look for directories relative to that which only exists in the build tree.