Skip to content

Commit 657b312

Browse files
committed
added interfaces and necessary build stuff
1 parent 30ccd9d commit 657b312

File tree

4 files changed

+109
-4
lines changed

4 files changed

+109
-4
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VER
3131
message(FATAL_ERROR "GCC Version 9 or newer required")
3232
endif()
3333

34+
# Convert CMAKE_SYSTEM_NAME to uppercase
35+
string(TOUPPER "${CMAKE_SYSTEM_NAME}" SYSTEM_NAME_UPPER)
36+
37+
# Pass the uppercase system name as a macro
38+
add_compile_options(-D${SYSTEM_NAME_UPPER})
39+
3440
# --- compiler feature checks
3541
include(CheckFortranSourceCompiles)
3642
include(CheckFortranSourceRuns)

config/fypp_deployment.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import platform
23
import fypp
34
import argparse
45
from joblib import Parallel, delayed
@@ -115,6 +116,7 @@ def fpm_build(args,unknown):
115116
for idx, arg in enumerate(unknown):
116117
if arg.startswith("--flag"):
117118
flags= flags + unknown[idx+1]
119+
flags = flags + "-D{}".format(platform.system().upper())
118120
#==========================================
119121
# build with fpm
120122
subprocess.run("fpm build"+

src/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ set(fppFiles
3232
stdlib_linalg_kronecker.fypp
3333
stdlib_linalg_cross_product.fypp
3434
stdlib_linalg_eigenvalues.fypp
35-
stdlib_linalg_solve.fypp
35+
stdlib_linalg_solve.fypp
3636
stdlib_linalg_determinant.fypp
3737
stdlib_linalg_qr.fypp
3838
stdlib_linalg_inverse.fypp
3939
stdlib_linalg_pinv.fypp
4040
stdlib_linalg_norms.fypp
4141
stdlib_linalg_state.fypp
42-
stdlib_linalg_svd.fypp
42+
stdlib_linalg_svd.fypp
4343
stdlib_linalg_cholesky.fypp
4444
stdlib_linalg_schur.fypp
4545
stdlib_optval.fypp
@@ -94,6 +94,7 @@ set(cppFiles
9494

9595
stdlib_linalg_blas.fypp
9696
stdlib_linalg_lapack.fypp
97+
stdlib_system.F90
9798
)
9899

99100
add_subdirectory(blas)
@@ -116,7 +117,7 @@ set(SRC
116117
stdlib_sorting_radix_sort.f90
117118
stdlib_system_subprocess.c
118119
stdlib_system_subprocess.F90
119-
stdlib_system.F90
120+
stdlib_system_path.f90
120121
stdlib_sparse.f90
121122
stdlib_specialfunctions_legendre.f90
122123
stdlib_quadrature_gauss.f90

src/stdlib_system.F90

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,22 @@ module stdlib_system
8383
public :: kill
8484
public :: elapsed
8585
public :: is_windows
86-
86+
87+
!! Public path related functions and interfaces
88+
#ifdef WINDOWS
89+
character(len=1), parameter, public :: pathsep = '\'
90+
logical, parameter, public :: ISWIN = .true.
91+
#else
92+
character(len=1), parameter, public :: pathsep = '/'
93+
logical, parameter, public :: ISWIN = .false.
94+
#endif
95+
96+
public :: joinpath
97+
public :: operator(/)
98+
public :: splitpath
99+
public :: basename
100+
public :: dirname
101+
87102
!! version: experimental
88103
!!
89104
!! Tests if a given path matches an existing directory.
@@ -550,6 +565,87 @@ end function process_get_ID
550565

551566
end interface
552567

568+
interface joinpath
569+
!! version: experimental
570+
!!
571+
!!### Summary
572+
!! join the paths provided according to the OS-specific path-separator
573+
!! ([Specification](../page/specs/stdlib_system.html#joinpath))
574+
!!
575+
module pure function join2(p1, p2) result(path)
576+
character(:), allocatable :: path
577+
character(*), intent(in) :: p1, p2
578+
end function join2
579+
580+
module pure function joinarr(p) result(path)
581+
character(:), allocatable :: path
582+
character(*), intent(in) :: p(:)
583+
end function joinarr
584+
end interface joinpath
585+
586+
interface operator(/)
587+
!! version: experimental
588+
!!
589+
!!### Summary
590+
!! A binary operator to join the paths provided according to the OS-specific path-separator
591+
!! ([Specification](../page/specs/stdlib_system.html#operator(/)))
592+
!!
593+
module pure function join_op(p1, p2) result(path)
594+
character(:), allocatable :: path
595+
character(*), intent(in) :: p1, p2
596+
end function join_op
597+
end interface operator(/)
598+
599+
interface splitpath
600+
!! version: experimental
601+
!!
602+
!!### Summary
603+
!! splits the path immediately following the final path-separator
604+
!! separating into typically a directory and a file name.
605+
!! ([Specification](../page/specs/stdlib_system.html#splitpath))
606+
!!
607+
!!### Description
608+
!! If the path is empty `head`='.' and tail=''
609+
!! If the path only consists of separators, `head` is set to the separator and tail is empty
610+
!! If the path is a root directory, `head` is set to that directory and tail is empty
611+
!! `head` ends with a path-separator iff the path appears to be a root directory
612+
module subroutine splitpath(p, head, tail)
613+
character(*), intent(in) :: p
614+
character(:), allocatable, intent(out) :: head, tail
615+
end subroutine splitpath
616+
end interface splitpath
617+
618+
interface basename
619+
!! version: experimental
620+
!!
621+
!!### Summary
622+
!! returns the basename (last component) of the provided path
623+
!! ([Specification](../page/specs/stdlib_system.html#basename))
624+
!!
625+
!!### Description
626+
!! The value returned is the `tail` of the interface `splitpath`
627+
module function basename(p) result(base)
628+
character(:), allocatable :: base
629+
character(*), intent(in) :: p
630+
end function basename
631+
end interface basename
632+
633+
interface dirname
634+
!! version: experimental
635+
!!
636+
!!### Summary
637+
!! returns everything but the last component of the provided path
638+
!! ([Specification](../page/specs/stdlib_system.html#dirname))
639+
!!
640+
!!### Description
641+
!! The value returned is the `head` of the interface `splitpath`
642+
module function dirname(p) result(base)
643+
character(:), allocatable :: base
644+
character(*), intent(in) :: p
645+
end function dirname
646+
end interface dirname
647+
648+
553649
contains
554650

555651
integer function get_runtime_os() result(os)

0 commit comments

Comments
 (0)