0

I have several compilers with the same name but of different versions or location. The ./configure script seems to stop at the first it finds in PATH. How can I tell Automake to choose one of them according to a custom rule ? I already have a macro which can check the compiler version.

I would like to avoid setting the path by hand (with the FC variable) as it can be cumbersome to type each time the whole path.

In my case, several MPI wrapper compilers are located in different directories with the same name (and added to the PATH by the user).

The idea would be to use something like ./configure --with-intel to find and select the IntelMPI compiler.

alex_reader
  • 689
  • 1
  • 5
  • 22

2 Answers2

1

My solution is to set up CC and other "precious" variables via a shell script, lots of them for cross compilation. So I have a bunch of shell scripts sitting around with contents like:

export CROSS_COMPILE=arm-linux
export CC=${CROSS_COMPILE}-gcc
...
PATH=$PATH:/some/arm/compiler/bin:/some/arm/compiler/usr/bin # for arm compiler tools
export CFLAGS="..."

to set up the configure configuration. So at configure time I do:

source /path/to/configuration/some-arm-compiler.sh
./configure ...

It saves a lot of typing.

EDIT: So it could work for your particular case something like:

mpi-a.sh

export FC=mpif90
PATH=$PATH:/path/to/mpi-a/bin:/path/to/mpi-a/usr/bin

mpi-b.sh

export FC=mpif90
PATH=$PATH:/path/to/mpi-b/bin:/path/to/mpi-b/usr/bin

So for compiling with one of them:

source /path/to/mpi-a.sh
./configure ...

and the other:

source /path/to/mpi-b.sh
./configure ...
ldav1s
  • 15,885
  • 2
  • 53
  • 56
  • What if you have several compilers with the same name but on different locations ? – alex_reader Nov 09 '12 at 10:36
  • Make sure that `PATH` set up in the script is set up correctly to only find the one that's needed. This seems to be something that you're doing already. – ldav1s Nov 09 '12 at 19:19
  • I have taken the opposite approach : all possible paths must be appended to PATH by the user and `configure` chooses one of them according to its options. Your approach is interesting (and surely more in the UNIX spirit than mine) but you must have as many scripts as there are compilers. Also these scripts are machine-dependent, therefore not portable. – alex_reader Nov 10 '12 at 16:47
  • Rather than sourcing a file, it is often simpler to put the commands in a `config.site`. eg, rename `some-arm-compiler.sh` `/some/path/config.site` and it will be automatically sourced by `configure` when prefix is set to `/some/path`. – William Pursell Nov 13 '12 at 12:59
  • @WilliamPursell, Thanks for that info. I didn't know about that feature. I think the `CONFIG_SITE` method of doing the same thing might work out better for me. I'll have to think about it... – ldav1s Nov 13 '12 at 18:44
0

My solution : copy the search strategy of configure in a macro, with a custom matching criterion. Parsing PATH is done by setting the IFS variable (which is already defined in configure). In Bash, finding all the executables would be something like :

#!/bin/bash

IFS=":"
exe="mpif90"
for dir in $PATH
do
   if test -f "$dir/$exe"; then
     custom_test($dir/$exe)
   fi
done

Note: This is recommanded in the manual

If you need to check the behavior of a program as well as find out whether it is present, you have to write your own test for it.

alex_reader
  • 689
  • 1
  • 5
  • 22