From ea19382b3f9ba74456b49e8a8323a7a528227c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 21 Jul 2020 23:11:28 -0600 Subject: Implement get_os() --- fpm/src/fpm.f90 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index 85597c0..d9d1bac 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -3,8 +3,25 @@ implicit none private public :: print_help, cmd_build +integer, parameter :: os_linux = 1 +integer, parameter :: os_macos = 2 +integer, parameter :: os_windows = 3 + contains +integer function get_os() result(r) +#ifdef _WIN32 + r = os_windows +#elif defined __APPLE__ + r = os_macos +#elif defined __linux__ + r = os_linux +#else + ! Unsupported platform + error stop +#endif +end function + subroutine print_help() print *, "Fortran Package Manager (fpm)" end subroutine -- cgit v1.2.3 From 2990fe5a66f960a97fb8dff266b724b5314b220a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 21 Jul 2020 23:11:56 -0600 Subject: Rename fpm.f90 to fpm.F90 --- fpm/src/fpm.F90 | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fpm/src/fpm.f90 | 60 --------------------------------------------------------- 2 files changed, 60 insertions(+), 60 deletions(-) create mode 100644 fpm/src/fpm.F90 delete mode 100644 fpm/src/fpm.f90 diff --git a/fpm/src/fpm.F90 b/fpm/src/fpm.F90 new file mode 100644 index 0000000..789df8d --- /dev/null +++ b/fpm/src/fpm.F90 @@ -0,0 +1,60 @@ +module fpm +implicit none +private +public :: print_help, cmd_build + +integer, parameter :: os_linux = 1 +integer, parameter :: os_macos = 2 +integer, parameter :: os_windows = 3 + +contains + +integer function get_os() result(r) +#ifdef _WIN32 + r = os_windows +#elif defined __APPLE__ + r = os_macos +#elif defined __linux__ + r = os_linux +#else + ! Unsupported platform + error stop +#endif +end function + +subroutine print_help() +print *, "Fortran Package Manager (fpm)" +end subroutine + +subroutine run(cmd) +character(len=*), intent(in) :: cmd +integer :: stat +print *, "+ ", cmd +call execute_command_line(cmd, exitstat=stat) +if (stat /= 0) then + print *, "Command failed" + error stop +end if +end subroutine + +logical function exists(filename) result(r) +character(len=*), intent(in) :: filename +inquire(file=filename, exist=r) +end function + +subroutine cmd_build() +logical :: src +print *, "# Building project" +src = exists("src/fpm.F90") +if (src) then + call run("gfortran -c src/fpm.F90 -o fpm.o") +end if +call run("gfortran -c app/main.f90 -o main.o") +if (src) then + call run("gfortran main.o fpm.o -o fpm") +else + call run("gfortran main.o -o hello_world") +end if +end subroutine + +end module fpm diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 deleted file mode 100644 index d9d1bac..0000000 --- a/fpm/src/fpm.f90 +++ /dev/null @@ -1,60 +0,0 @@ -module fpm -implicit none -private -public :: print_help, cmd_build - -integer, parameter :: os_linux = 1 -integer, parameter :: os_macos = 2 -integer, parameter :: os_windows = 3 - -contains - -integer function get_os() result(r) -#ifdef _WIN32 - r = os_windows -#elif defined __APPLE__ - r = os_macos -#elif defined __linux__ - r = os_linux -#else - ! Unsupported platform - error stop -#endif -end function - -subroutine print_help() -print *, "Fortran Package Manager (fpm)" -end subroutine - -subroutine run(cmd) -character(len=*), intent(in) :: cmd -integer :: stat -print *, "+ ", cmd -call execute_command_line(cmd, exitstat=stat) -if (stat /= 0) then - print *, "Command failed" - error stop -end if -end subroutine - -logical function exists(filename) result(r) -character(len=*), intent(in) :: filename -inquire(file=filename, exist=r) -end function - -subroutine cmd_build() -logical :: src -print *, "# Building project" -src = exists("src/fpm.f90") -if (src) then - call run("gfortran -c src/fpm.f90 -o fpm.o") -end if -call run("gfortran -c app/main.f90 -o main.o") -if (src) then - call run("gfortran main.o fpm.o -o fpm") -else - call run("gfortran main.o -o hello_world") -end if -end subroutine - -end module fpm -- cgit v1.2.3 From f98d13bfde648bda2496c938eb113472f50df0a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 21 Jul 2020 23:14:52 -0600 Subject: Use get_os() --- fpm/src/fpm.F90 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fpm/src/fpm.F90 b/fpm/src/fpm.F90 index 789df8d..05a02e8 100644 --- a/fpm/src/fpm.F90 +++ b/fpm/src/fpm.F90 @@ -18,12 +18,16 @@ integer function get_os() result(r) r = os_linux #else ! Unsupported platform + r = -1 error stop #endif end function subroutine print_help() +integer :: ostype +ostype = get_os() print *, "Fortran Package Manager (fpm)" +print *, ostype end subroutine subroutine run(cmd) -- cgit v1.2.3 From f6f67d7e33c9c717ed96e35bb823b732b156d5f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 21 Jul 2020 23:22:26 -0600 Subject: Use () --- fpm/src/fpm.F90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fpm/src/fpm.F90 b/fpm/src/fpm.F90 index 05a02e8..fa40912 100644 --- a/fpm/src/fpm.F90 +++ b/fpm/src/fpm.F90 @@ -12,9 +12,9 @@ contains integer function get_os() result(r) #ifdef _WIN32 r = os_windows -#elif defined __APPLE__ +#elif defined(__APPLE__) r = os_macos -#elif defined __linux__ +#elif defined(__linux__) r = os_linux #else ! Unsupported platform -- cgit v1.2.3 From 93a9735cb8874d248cd3bfab760f5df05cfc97d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 08:57:40 -0600 Subject: Rework the macros --- fpm/src/fpm.F90 | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/fpm/src/fpm.F90 b/fpm/src/fpm.F90 index fa40912..617d5d9 100644 --- a/fpm/src/fpm.F90 +++ b/fpm/src/fpm.F90 @@ -12,22 +12,21 @@ contains integer function get_os() result(r) #ifdef _WIN32 r = os_windows -#elif defined(__APPLE__) + return +#endif +#ifdef __APPLE__ r = os_macos -#elif defined(__linux__) - r = os_linux -#else - ! Unsupported platform - r = -1 - error stop + return #endif + ! Assuming Linux here, as gfortran does not specify any macro for Linux + r = os_linux end function subroutine print_help() integer :: ostype ostype = get_os() print *, "Fortran Package Manager (fpm)" -print *, ostype +print *, "OS Type: ", ostype end subroutine subroutine run(cmd) -- cgit v1.2.3 From 46c839b3b05259252287a661b8e7d2a354976a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 09:20:41 -0600 Subject: Use $HOME to determine the OS type --- fpm/src/fpm.F90 | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/fpm/src/fpm.F90 b/fpm/src/fpm.F90 index 617d5d9..a68a0b9 100644 --- a/fpm/src/fpm.F90 +++ b/fpm/src/fpm.F90 @@ -10,16 +10,24 @@ integer, parameter :: os_windows = 3 contains integer function get_os() result(r) -#ifdef _WIN32 - r = os_windows - return -#endif -#ifdef __APPLE__ - r = os_macos - return -#endif - ! Assuming Linux here, as gfortran does not specify any macro for Linux +character(len=100) :: val +integer stat +call get_environment_variable("HOME", val, status=stat) +if (stat == 1) then + print *, "$HOME does not exist" + error stop +end if +if (stat /= 0) then + print *, "get_environment_variable() failed" + error stop +end if +if (val(1:5) == "/home") then r = os_linux +else if (val(1:6) == "/Users") then + r = os_macos +else + r = os_windows +end if end function subroutine print_help() -- cgit v1.2.3 From a1dc068e0881a134dd6472618409f758bfe492d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 09:40:03 -0600 Subject: Polish the code, add comments --- fpm/src/fpm.F90 | 27 ++++++++++++++++++++++++--- 1 file 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 -- cgit v1.2.3 From ef865577b7d04737afb5d1ba9ebbb150230e198d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 09:45:49 -0600 Subject: Rename fpm.F90 back to fpm.f90 --- fpm/src/fpm.F90 | 92 --------------------------------------------------------- fpm/src/fpm.f90 | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 92 deletions(-) delete mode 100644 fpm/src/fpm.F90 create mode 100644 fpm/src/fpm.f90 diff --git a/fpm/src/fpm.F90 b/fpm/src/fpm.F90 deleted file mode 100644 index c93e3aa..0000000 --- a/fpm/src/fpm.F90 +++ /dev/null @@ -1,92 +0,0 @@ -module fpm -implicit none -private -public :: print_help, cmd_build - -integer, parameter :: os_linux = 1 -integer, parameter :: os_macos = 2 -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" - error stop -end if -if (stat /= 0) then - print *, "get_environment_variable() failed" - error stop -end if -if (val(1:6) == "/home/") then - r = os_linux -else if (val(1:7) == "/Users/") then - r = os_macos -else - ! 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 - -subroutine print_help() -integer :: ostype -ostype = get_os() -print *, "Fortran Package Manager (fpm)" -print *, "OS Type: ", ostype -end subroutine - -subroutine run(cmd) -character(len=*), intent(in) :: cmd -integer :: stat -print *, "+ ", cmd -call execute_command_line(cmd, exitstat=stat) -if (stat /= 0) then - print *, "Command failed" - error stop -end if -end subroutine - -logical function exists(filename) result(r) -character(len=*), intent(in) :: filename -inquire(file=filename, exist=r) -end function - -subroutine cmd_build() -logical :: src -print *, "# Building project" -src = exists("src/fpm.F90") -if (src) then - call run("gfortran -c src/fpm.F90 -o fpm.o") -end if -call run("gfortran -c app/main.f90 -o main.o") -if (src) then - call run("gfortran main.o fpm.o -o fpm") -else - call run("gfortran main.o -o hello_world") -end if -end subroutine - -end module fpm diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 new file mode 100644 index 0000000..33d52ee --- /dev/null +++ b/fpm/src/fpm.f90 @@ -0,0 +1,92 @@ +module fpm +implicit none +private +public :: print_help, cmd_build + +integer, parameter :: os_linux = 1 +integer, parameter :: os_macos = 2 +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" + error stop +end if +if (stat /= 0) then + print *, "get_environment_variable() failed" + error stop +end if +if (val(1:6) == "/home/") then + r = os_linux +else if (val(1:7) == "/Users/") then + r = os_macos +else + ! 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 + +subroutine print_help() +integer :: ostype +ostype = get_os() +print *, "Fortran Package Manager (fpm)" +print *, "OS Type: ", ostype +end subroutine + +subroutine run(cmd) +character(len=*), intent(in) :: cmd +integer :: stat +print *, "+ ", cmd +call execute_command_line(cmd, exitstat=stat) +if (stat /= 0) then + print *, "Command failed" + error stop +end if +end subroutine + +logical function exists(filename) result(r) +character(len=*), intent(in) :: filename +inquire(file=filename, exist=r) +end function + +subroutine cmd_build() +logical :: src +print *, "# Building project" +src = exists("src/fpm.f90") +if (src) then + call run("gfortran -c src/fpm.f90 -o fpm.o") +end if +call run("gfortran -c app/main.f90 -o main.o") +if (src) then + call run("gfortran main.o fpm.o -o fpm") +else + call run("gfortran main.o -o hello_world") +end if +end subroutine + +end module fpm -- cgit v1.2.3 From 155e312152229fe3b3e5f5c55d6ccdb7a8181d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 09:48:34 -0600 Subject: Use uppercase for constants --- fpm/src/fpm.f90 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index 33d52ee..6670f78 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -3,9 +3,9 @@ implicit none private public :: print_help, cmd_build -integer, parameter :: os_linux = 1 -integer, parameter :: os_macos = 2 -integer, parameter :: os_windows = 3 +integer, parameter :: OS_LINUX = 1 +integer, parameter :: OS_MACOS = 2 +integer, parameter :: OS_WINDOWS = 3 contains @@ -24,7 +24,7 @@ integer stat ! or macOS, then this will be wrong): call get_environment_variable("HOMEPATH", val, status=stat) if (stat == 0) then - r = os_windows + r = OS_WINDOWS return end if @@ -40,14 +40,14 @@ if (stat /= 0) then error stop end if if (val(1:6) == "/home/") then - r = os_linux + r = OS_LINUX else if (val(1:7) == "/Users/") then - r = os_macos + r = OS_MACOS else ! 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 + r = OS_LINUX end if end function -- cgit v1.2.3 From 06edcbd3eb2c78808becb75b4524b9860f802904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 09:48:53 -0600 Subject: Print full OS name as a string --- fpm/src/fpm.f90 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index 6670f78..a6c5a18 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -52,10 +52,15 @@ end if end function subroutine print_help() -integer :: ostype -ostype = get_os() print *, "Fortran Package Manager (fpm)" -print *, "OS Type: ", ostype +select case (get_os()) + case (OS_LINUX) + print *, "OS Type: Linux" + case (OS_MACOS) + print *, "OS Type: macOS" + case (OS_WINDOWS) + print *, "OS Type: Windows" +end select end subroutine subroutine run(cmd) -- cgit v1.2.3 From e2e2d9c254dd1649a9c431588a056bb2c8fd33b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 09:51:52 -0600 Subject: Name the function get_os_type() --- fpm/src/fpm.f90 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index a6c5a18..d151da9 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -9,7 +9,7 @@ integer, parameter :: OS_WINDOWS = 3 contains -integer function get_os() result(r) +integer function get_os_type() result(r) ! Determines the OS type. ! ! Currently we use the $HOMEPATH and $HOME environment variables to determine @@ -53,7 +53,7 @@ end function subroutine print_help() print *, "Fortran Package Manager (fpm)" -select case (get_os()) +select case (get_os_type()) case (OS_LINUX) print *, "OS Type: Linux" case (OS_MACOS) -- cgit v1.2.3 From bfd90a604a51ae8daea01744f860cb1c25494f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 09:56:31 -0600 Subject: Only use the $HOME env variable for all OS types --- fpm/src/fpm.f90 | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/fpm/src/fpm.f90 b/fpm/src/fpm.f90 index d151da9..74015f3 100644 --- a/fpm/src/fpm.f90 +++ b/fpm/src/fpm.f90 @@ -10,30 +10,26 @@ integer, parameter :: OS_WINDOWS = 3 contains integer function get_os_type() result(r) -! Determines the OS type. +! Determine 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: +! 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: ! ! 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. +! we assume Linux if $HOME is defined, otherwise Windows. 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" - error stop + ! $HOME does not exist, we assume Windows + r = OS_WINDOWS + return end if if (stat /= 0) then print *, "get_environment_variable() failed" -- cgit v1.2.3 From 82cc08cde5ccda4266726a765fadaeba05b460fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Wed, 22 Jul 2020 10:19:43 -0600 Subject: Use $HOMEPATH on Windows --- fpm/src/fpm.f90 | 22 ++++++++++++++-------- 1 file 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" -- cgit v1.2.3