Conditional compilation based on environment variables

Since the definition is forced in the make compilation command, the first branch is always compiled. I agree the logic is a bit faulty. It looks to me as if written by a PhD student who never came back to complete it. If you look into configure.sh, you’ll find

#!/bin/bash
echo "export IRVSPDATA="`pwd` >> ~/.bashrc

I guess what you could do instead is use the status variable of get_environment_variable:

call get_environment_variable('IRVSPDATA',spgpath,status=stat)
if (stat == 1) then
   write(6,*) "Environment variable 'IRVSPDATA' must be provided."
   write(6,*) "Please run the following commands to make the library:"
   write(6,*) "./configure.sh"
   write(6,*) "source ~/.bashrc"
   write(6,*) "make"
   stop
end if

Ideally, you’d wrap get_environment_variable in a fail-safe function, which also checked the other conditions (sufficient string length, processor support) and gave you the option to provide a default value. An example would be get_env used in the Fortran package manager.

Using get_env you might write:

character(len=:), allocatable :: spgpath

spgpath = get_env('IRVSPDATA')
if (spgpath == '') then
   write(6,*) "Environment variable 'IRVSPDATA' must be provided."
   ! ...
end if