aboutsummaryrefslogtreecommitdiff
path: root/src/fpm_environment.f90
diff options
context:
space:
mode:
authorCarlos Une <brocolis@eml.cc>2021-07-20 00:00:51 -0300
committerCarlos Une <brocolis@eml.cc>2021-07-20 00:00:51 -0300
commit1c6673c62523d7a3cf8bfa37e8997da8e76b7f9c (patch)
tree5848896b59745c473bd283dd3a24545eab181dfa /src/fpm_environment.f90
parente18017d155c7edb31a503203187c5d0bab20b846 (diff)
downloadfpm-1c6673c62523d7a3cf8bfa37e8997da8e76b7f9c.tar.gz
fpm-1c6673c62523d7a3cf8bfa37e8997da8e76b7f9c.zip
Cache get_os_type() return value using the save attribute
Diffstat (limited to 'src/fpm_environment.f90')
-rw-r--r--src/fpm_environment.f9020
1 files changed, 20 insertions, 0 deletions
diff --git a/src/fpm_environment.f90 b/src/fpm_environment.f90
index e9da3c7..a9f8c65 100644
--- a/src/fpm_environment.f90
+++ b/src/fpm_environment.f90
@@ -40,7 +40,16 @@ contains
character(len=32) :: val
integer :: length, rc
logical :: file_exists
+ logical, save :: first_run = .true.
+ integer, save :: ret = OS_UNKNOWN
+ !omp threadprivate(ret, first_run)
+ if (.not. first_run) then
+ r = ret
+ return
+ end if
+
+ first_run = .false.
r = OS_UNKNOWN
! Check environment variable `OS`.
@@ -48,6 +57,7 @@ contains
if (rc == 0 .and. length > 0 .and. index(val, 'Windows_NT') > 0) then
r = OS_WINDOWS
+ ret = r
return
end if
@@ -58,42 +68,49 @@ contains
! Linux
if (index(val, 'linux') > 0) then
r = OS_LINUX
+ ret = r
return
end if
! macOS
if (index(val, 'darwin') > 0) then
r = OS_MACOS
+ ret = r
return
end if
! Windows, MSYS, MinGW, Git Bash
if (index(val, 'win') > 0 .or. index(val, 'msys') > 0) then
r = OS_WINDOWS
+ ret = r
return
end if
! Cygwin
if (index(val, 'cygwin') > 0) then
r = OS_CYGWIN
+ ret = r
return
end if
! Solaris, OpenIndiana, ...
if (index(val, 'SunOS') > 0 .or. index(val, 'solaris') > 0) then
r = OS_SOLARIS
+ ret = r
return
end if
! FreeBSD
if (index(val, 'FreeBSD') > 0 .or. index(val, 'freebsd') > 0) then
r = OS_FREEBSD
+ ret = r
return
end if
! OpenBSD
if (index(val, 'OpenBSD') > 0 .or. index(val, 'openbsd') > 0) then
r = OS_OPENBSD
+ ret = r
return
end if
end if
@@ -103,6 +120,7 @@ contains
if (file_exists) then
r = OS_LINUX
+ ret = r
return
end if
@@ -111,6 +129,7 @@ contains
if (file_exists) then
r = OS_MACOS
+ ret = r
return
end if
@@ -119,6 +138,7 @@ contains
if (file_exists) then
r = OS_FREEBSD
+ ret = r
return
end if
end function get_os_type