11! > This module contains procedures that interact with the programming environment.
2- ! !
2+ ! !
33! ! * [get_os_type] -- Determine the OS type
44! ! * [get_env] -- return the value of an environment variable
55module fpm_environment
@@ -9,6 +9,7 @@ module fpm_environment
99 public :: os_is_unix
1010 public :: run
1111 public :: get_env
12+ public :: get_archiver
1213
1314 integer , parameter , public :: OS_UNKNOWN = 0
1415 integer , parameter , public :: OS_LINUX = 1
@@ -110,7 +111,7 @@ integer function get_os_type() result(r)
110111 end if
111112 end function get_os_type
112113
113- ! > Compare the output of [[get_os_type]] or the optional
114+ ! > Compare the output of [[get_os_type]] or the optional
114115 ! ! passed INTEGER value to the value for OS_WINDOWS
115116 ! ! and return .TRUE. if they match and .FALSE. otherwise
116117 logical function os_is_unix (os ) result(unix)
@@ -150,7 +151,7 @@ end subroutine run
150151 function get_env (NAME ,DEFAULT ) result(VALUE)
151152 implicit none
152153 ! > name of environment variable to get the value of
153- character (len=* ),intent (in ) :: NAME
154+ character (len=* ),intent (in ) :: NAME
154155 ! > default value to return if the requested value is undefined or blank
155156 character (len=* ),intent (in ),optional :: DEFAULT
156157 ! > the returned value
@@ -182,4 +183,24 @@ function get_env(NAME,DEFAULT) result(VALUE)
182183 if (VALUE.eq. ' ' .and. present (DEFAULT))VALUE= DEFAULT
183184 end function get_env
184185
186+ function get_archiver () result(archiver)
187+ character (:), allocatable :: archiver
188+
189+ associate(os_type = > get_os_type())
190+ if (os_type /= OS_WINDOWS .and. os_type /= OS_UNKNOWN) then
191+ archiver = " ar -rs "
192+ else
193+ block
194+ integer :: estat
195+
196+ call execute_command_line(" ar --version" , exitstat= estat)
197+ if (estat /= 0 ) then
198+ archiver = " lib /OUT:"
199+ else
200+ archiver = " ar -rs "
201+ end if
202+ end block
203+ end if
204+ end associate
205+ end function
185206end module fpm_environment
0 commit comments