aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOndřej Čertík <ondrej@certik.us>2020-07-22 10:19:43 -0600
committerOndřej Čertík <ondrej@certik.us>2020-07-22 10:21:27 -0600
commit82cc08cde5ccda4266726a765fadaeba05b460fa (patch)
treeb0dd384e26206a6bef7a8c59bcfb4e6913e8b643
parentbfd90a604a51ae8daea01744f860cb1c25494f8d (diff)
downloadfpm-82cc08cde5ccda4266726a765fadaeba05b460fa.tar.gz
fpm-82cc08cde5ccda4266726a765fadaeba05b460fa.zip
Use $HOMEPATH on Windows
-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"