aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fpm/src/fpm.f9022
1 files changed, 14 insertions, 8 deletions
diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90
index 74015f3..cc5666b 100644
--- a/fpm/src/fpm.f90
+++ b/fpm/src/fpm.f90
@@ -14,22 +14,28 @@ integer function get_os_type() result(r)
!
! Returns one of OS_LINUX, OS_MACOS, OS_WINDOWS.
!
-! Currently we use the $HOME environment variable 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:
+! Currently we use the $HOME and $HOMEPATH 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 and we test its value to improve the
+! chances of it working even if a user defines $HOMEPATH on Linux or macOS.
+call get_environment_variable("HOMEPATH", val, status=stat)
+if (stat == 0 .and. val(1:7) == "\Users\") then
+ r = OS_WINDOWS
+ return
+end if
+
! We assume that $HOME=/home/... is Linux, $HOME=/Users/... is macOS, otherwise
-! we assume Linux if $HOME is defined, otherwise Windows. This is only a
-! heuristic and can easily fail.
+! we assume Linux. This is only a heuristic and can easily fail.
call get_environment_variable("HOME", val, status=stat)
if (stat == 1) then
- ! $HOME does not exist, we assume Windows
- r = OS_WINDOWS
- return
+ print *, "$HOME does not exist"
+ error stop
end if
if (stat /= 0) then
print *, "get_environment_variable() failed"