27
27
! >
28
28
module fpm_backend
29
29
30
- use fpm_environment, only: run
31
- use fpm_filesystem, only: dirname, join_path, exists, mkdir
30
+ use fpm_environment, only: run, get_os_type, OS_WINDOWS
31
+ use fpm_filesystem, only: dirname, join_path, exists, mkdir, unix_path
32
32
use fpm_model, only: fpm_model_t
33
33
use fpm_targets, only: build_target_t, build_target_ptr, FPM_TARGET_OBJECT, &
34
34
FPM_TARGET_C_OBJECT, FPM_TARGET_ARCHIVE, FPM_TARGET_EXECUTABLE
35
- use fpm_strings, only: string_cat
35
+ use fpm_strings, only: string_cat, string_t
36
36
37
37
implicit none
38
38
@@ -250,7 +250,16 @@ subroutine build_target(model,target)
250
250
// " " // target % link_flags// " -o " // target % output_file)
251
251
252
252
case (FPM_TARGET_ARCHIVE)
253
- call run(model% archiver // target % output_file // " " // string_cat(target % link_objects," " ))
253
+
254
+ select case (get_os_type())
255
+ case (OS_WINDOWS)
256
+ call write_response_file(target % output_file// " .resp" ,target % link_objects)
257
+ call run(model% archiver // target % output_file // " @" // target % output_file// " .resp" )
258
+
259
+ case default
260
+ call run(model% archiver // target % output_file // " " // string_cat(target % link_objects," " ))
261
+
262
+ end select
254
263
255
264
end select
256
265
@@ -262,4 +271,19 @@ subroutine build_target(model,target)
262
271
263
272
end subroutine build_target
264
273
274
+ ! > Response files allow to read command line options from files.
275
+ ! > Whitespace is used to separate the arguments, we will use newlines
276
+ ! > as separator to create readable response files which can be inspected
277
+ ! > in case of errors.
278
+ subroutine write_response_file (name , argv )
279
+ character (len=* ), intent (in ) :: name
280
+ type (string_t), intent (in ) :: argv(:)
281
+ integer :: iarg, io
282
+ open (file= name, newunit= io)
283
+ do iarg = 1 , size (argv)
284
+ write (io, ' (a)' ) unix_path(argv(iarg)% s)
285
+ end do
286
+ close (io)
287
+ end subroutine write_response_file
288
+
265
289
end module fpm_backend
0 commit comments