diff options
author | Ondřej Čertík <ondrej@certik.us> | 2020-07-22 09:40:03 -0600 |
---|---|---|
committer | Ondřej Čertík <ondrej@certik.us> | 2020-07-22 09:41:02 -0600 |
commit | a1dc068e0881a134dd6472618409f758bfe492d1 (patch) | |
tree | 9fe8c1cd8e81225003b6c25e212081f50d1948e0 | |
parent | 46c839b3b05259252287a661b8e7d2a354976a23 (diff) | |
download | fpm-a1dc068e0881a134dd6472618409f758bfe492d1.tar.gz fpm-a1dc068e0881a134dd6472618409f758bfe492d1.zip |
Polish the code, add comments
-rw-r--r-- | fpm/src/fpm.F90 | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/fpm/src/fpm.F90 b/fpm/src/fpm.F90 index a68a0b9..c93e3aa 100644 --- a/fpm/src/fpm.F90 +++ b/fpm/src/fpm.F90 @@ -10,8 +10,26 @@ integer, parameter :: os_windows = 3 contains integer function get_os() result(r) +! Determines the OS type. +! +! Currently we use the $HOMEPATH and $HOME environment variables to determine +! the OS type. That is not 100% accurate in all cases, but it seems to be good +! enough for now. See the following issue for a more robust solution: +! +! https://github.com/fortran-lang/fpm/issues/144 +! character(len=100) :: val integer stat +! Only Windows define $HOMEPATH by default (if a user defines $HOMEPATH on Linux +! or macOS, then this will be wrong): +call get_environment_variable("HOMEPATH", val, status=stat) +if (stat == 0) then + r = os_windows + return +end if + +! We assume that $HOME=/home/... is Linux, $HOME=/Users/... is macOS, otherwise +! we assume Linux. This is only a heuristic and can easily fail. call get_environment_variable("HOME", val, status=stat) if (stat == 1) then print *, "$HOME does not exist" @@ -21,12 +39,15 @@ if (stat /= 0) then print *, "get_environment_variable() failed" error stop end if -if (val(1:5) == "/home") then +if (val(1:6) == "/home/") then r = os_linux -else if (val(1:6) == "/Users") then +else if (val(1:7) == "/Users/") then r = os_macos else - r = os_windows + ! This will happen on HPC systems that typically do not use either /home nor + ! /Users for $HOME. Those systems are typically Linux, so for now we simply + ! set Linux here. + r = os_linux end if end function |