diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-14 09:24:55 -0500 |
---|---|---|
committer | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-14 09:24:55 -0500 |
commit | b5b16cf826d468e79b4087500192a4a9e07c140f (patch) | |
tree | 1f615ee9ed6500bb1f6964ef2af0478b2fe51e4e /example_packages | |
parent | d3a65e36b28808c2c51ae41fc107f1179e27a08c (diff) | |
download | fpm-b5b16cf826d468e79b4087500192a4a9e07c140f.tar.gz fpm-b5b16cf826d468e79b4087500192a4a9e07c140f.zip |
Better organize example packages and bootstrap tests
Diffstat (limited to 'example_packages')
59 files changed, 501 insertions, 0 deletions
diff --git a/example_packages/README.md b/example_packages/README.md new file mode 100644 index 0000000..79fadb1 --- /dev/null +++ b/example_packages/README.md @@ -0,0 +1,20 @@ +# Example packages + +See the table below for a list of the example packages provided in this directory including +the features demonstrated in each package and which versions of fpm are supported. + + +| Name | Features | Bootstrap (Haskell) fpm | fpm | +|---------------------|---------------------------------------------------------------|:-----------------------:|:---:| +| auto_discovery_off | Default layout with auto-discovery disabled | N | Y | +| circular_example | Local path dependency; circular dependency | Y | N | +| circular_test | Local path dependency; circular dependency | Y | N | +| hello_complex | Non-standard directory layout; multiple tests and executables | Y | Y | +| hello_complex_2 | Auto-discovery of tests and executables with modules | N | Y | +| hello_fpm | App-only; local path dependency | Y | N | +| hello_world | App-only | Y | Y | +| makefile_complex | External build command (makefile); local path dependency | Y | N | +| program_with_module | App-only; module+program in single source file | Y | Y | +| submodules | Lib-only; submodules (3 levels) | N | Y | +| with_c | Compile with `c` source files | N | Y | +| with_makefile | External build command (makefile) | Y | N |
\ No newline at end of file diff --git a/example_packages/auto_discovery_off/app/main.f90 b/example_packages/auto_discovery_off/app/main.f90 new file mode 100644 index 0000000..8902dc6 --- /dev/null +++ b/example_packages/auto_discovery_off/app/main.f90 @@ -0,0 +1,6 @@ +program main +implicit none + +print *, "This program should run." + +end program main diff --git a/example_packages/auto_discovery_off/app/unused.f90 b/example_packages/auto_discovery_off/app/unused.f90 new file mode 100644 index 0000000..57d8153 --- /dev/null +++ b/example_packages/auto_discovery_off/app/unused.f90 @@ -0,0 +1,6 @@ +program unused +implicit none + +print *, "This program should NOT run." + +end program unused diff --git a/example_packages/auto_discovery_off/fpm.toml b/example_packages/auto_discovery_off/fpm.toml new file mode 100644 index 0000000..9a852df --- /dev/null +++ b/example_packages/auto_discovery_off/fpm.toml @@ -0,0 +1,12 @@ +name = "auto_discovery_off" + +[build] +auto-executables = false +auto-tests = false + + +[[test]] +name = "my_test" +source-dir="test" +main="my_test.f90" + diff --git a/example_packages/auto_discovery_off/test/my_test.f90 b/example_packages/auto_discovery_off/test/my_test.f90 new file mode 100644 index 0000000..fd59f9f --- /dev/null +++ b/example_packages/auto_discovery_off/test/my_test.f90 @@ -0,0 +1,6 @@ +program my_test +implicit none + +print *, "Test passed! That was easy!" + +end program my_test diff --git a/example_packages/auto_discovery_off/test/unused_test.f90 b/example_packages/auto_discovery_off/test/unused_test.f90 new file mode 100644 index 0000000..5c42611 --- /dev/null +++ b/example_packages/auto_discovery_off/test/unused_test.f90 @@ -0,0 +1,7 @@ +program unused_test +implicit none + +print *, "This program should NOT run." + +end program unused_test + diff --git a/example_packages/circular_example/.gitignore b/example_packages/circular_example/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/circular_example/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/circular_example/fpm.toml b/example_packages/circular_example/fpm.toml new file mode 100644 index 0000000..c524ce5 --- /dev/null +++ b/example_packages/circular_example/fpm.toml @@ -0,0 +1,4 @@ +name = "circular_example" + +[dev-dependencies] +circular_test = { path = "../circular_test" } diff --git a/example_packages/circular_example/src/greet_m.f90 b/example_packages/circular_example/src/greet_m.f90 new file mode 100644 index 0000000..2372f9a --- /dev/null +++ b/example_packages/circular_example/src/greet_m.f90 @@ -0,0 +1,13 @@ +module greet_m + implicit none + private + + public :: make_greeting +contains + function make_greeting(name) result(greeting) + character(len=*), intent(in) :: name + character(len=:), allocatable :: greeting + + greeting = "Hello, " // name // "!" + end function make_greeting +end module greet_m diff --git a/example_packages/circular_example/test/main.f90 b/example_packages/circular_example/test/main.f90 new file mode 100644 index 0000000..5b7d803 --- /dev/null +++ b/example_packages/circular_example/test/main.f90 @@ -0,0 +1,7 @@ +program run_tests + use hello_test, only: run_test + + implicit none + + call run_test +end program run_tests diff --git a/example_packages/circular_test/.gitignore b/example_packages/circular_test/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/circular_test/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/circular_test/fpm.toml b/example_packages/circular_test/fpm.toml new file mode 100644 index 0000000..56cfa2e --- /dev/null +++ b/example_packages/circular_test/fpm.toml @@ -0,0 +1,4 @@ +name = "circular_test" + +[dependencies] +circular_example = { path = "../circular_example"} diff --git a/example_packages/circular_test/src/hello_test.f90 b/example_packages/circular_test/src/hello_test.f90 new file mode 100644 index 0000000..5a591c6 --- /dev/null +++ b/example_packages/circular_test/src/hello_test.f90 @@ -0,0 +1,12 @@ +module hello_test + use greet_m, only: make_greeting + + implicit none + private + + public :: run_test +contains + subroutine run_test + print *, make_greeting("from test") + end subroutine run_test +end module hello_test diff --git a/example_packages/hello_complex/.gitignore b/example_packages/hello_complex/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/hello_complex/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/hello_complex/apps/say_goodbye/say_goodbye.f90 b/example_packages/hello_complex/apps/say_goodbye/say_goodbye.f90 new file mode 100644 index 0000000..6966e79 --- /dev/null +++ b/example_packages/hello_complex/apps/say_goodbye/say_goodbye.f90 @@ -0,0 +1,7 @@ +program say_goodbye + use farewell_m, only: make_farewell + + implicit none + + print *, make_farewell("World") +end program say_goodbye diff --git a/example_packages/hello_complex/apps/say_hello/say_Hello.f90 b/example_packages/hello_complex/apps/say_hello/say_Hello.f90 new file mode 100644 index 0000000..cf4a742 --- /dev/null +++ b/example_packages/hello_complex/apps/say_hello/say_Hello.f90 @@ -0,0 +1,7 @@ +program say_Hello + use greet_m, only: make_greeting + + implicit none + + print *, make_greeting("World") +end program say_Hello diff --git a/example_packages/hello_complex/fpm.toml b/example_packages/hello_complex/fpm.toml new file mode 100644 index 0000000..30ed293 --- /dev/null +++ b/example_packages/hello_complex/fpm.toml @@ -0,0 +1,24 @@ +name = "hello_complex" + +[library] +source-dir="source" + +[[executable]] +name="say_Hello" +source-dir="apps/say_hello" +main="say_Hello.f90" + +[[executable]] +name="say_goodbye" +source-dir="apps/say_goodbye" +main="say_goodbye.f90" + +[[test]] +name="greet_test" +source-dir="tests/greet" +main="greet_test.f90" + +[[test]] +name="farewell_test" +source-dir="tests/farewell" +main="farewell_test.f90" diff --git a/example_packages/hello_complex/source/farewell_m.f90 b/example_packages/hello_complex/source/farewell_m.f90 new file mode 100644 index 0000000..fbc45ed --- /dev/null +++ b/example_packages/hello_complex/source/farewell_m.f90 @@ -0,0 +1,14 @@ +module farewell_m + use subdir_constants, only: FAREWELL_STR + implicit none + private + + public :: make_farewell +contains + function make_farewell(name) result(greeting) + character(len=*), intent(in) :: name + character(len=:), allocatable :: greeting + + greeting = FAREWELL_STR // name // "!" + end function make_farewell +end module farewell_m diff --git a/example_packages/hello_complex/source/greet_m.f90 b/example_packages/hello_complex/source/greet_m.f90 new file mode 100644 index 0000000..38afd08 --- /dev/null +++ b/example_packages/hello_complex/source/greet_m.f90 @@ -0,0 +1,14 @@ +module greet_m + use subdir_constants, only: GREET_STR + implicit none + private + + public :: make_greeting +contains + function make_greeting(name) result(greeting) + character(len=*), intent(in) :: name + character(len=:), allocatable :: greeting + + greeting = GREET_STR // name // "!" + end function make_greeting +end module greet_m diff --git a/example_packages/hello_complex/source/subdir/constants.f90 b/example_packages/hello_complex/source/subdir/constants.f90 new file mode 100644 index 0000000..59d6e5f --- /dev/null +++ b/example_packages/hello_complex/source/subdir/constants.f90 @@ -0,0 +1,7 @@ +module subdir_constants +implicit none + +character(*), parameter :: GREET_STR = 'Hello, ' +character(*), parameter :: FAREWELL_STR = 'Goodbye, ' + +end module subdir_constants diff --git a/example_packages/hello_complex/tests/farewell/farewell_test.f90 b/example_packages/hello_complex/tests/farewell/farewell_test.f90 new file mode 100644 index 0000000..0f21b18 --- /dev/null +++ b/example_packages/hello_complex/tests/farewell/farewell_test.f90 @@ -0,0 +1,18 @@ +program farewell_test + use farewell_m, only: make_farewell + use iso_fortran_env, only: error_unit, output_unit + + implicit none + + character(len=:), allocatable :: farewell + + allocate(character(len=0) :: farewell) + farewell = make_farewell("World") + + if (farewell == "Goodbye, World!") then + write(output_unit, *) "Passed" + else + write(error_unit, *) "Failed" + call exit(1) + end if +end program farewell_test diff --git a/example_packages/hello_complex/tests/greet/greet_test.f90 b/example_packages/hello_complex/tests/greet/greet_test.f90 new file mode 100644 index 0000000..41fa508 --- /dev/null +++ b/example_packages/hello_complex/tests/greet/greet_test.f90 @@ -0,0 +1,18 @@ +program greet_test + use greet_m, only: make_greeting + use iso_fortran_env, only: error_unit, output_unit + + implicit none + + character(len=:), allocatable :: greeting + + allocate(character(len=0) :: greeting) + greeting = make_greeting("World") + + if (greeting == "Hello, World!") then + write(output_unit, *) "Passed" + else + write(error_unit, *) "Failed" + call exit(1) + end if +end program greet_test diff --git a/example_packages/hello_complex_2/.gitignore b/example_packages/hello_complex_2/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/hello_complex_2/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/hello_complex_2/app/app_mod.f90 b/example_packages/hello_complex_2/app/app_mod.f90 new file mode 100644 index 0000000..d69a228 --- /dev/null +++ b/example_packages/hello_complex_2/app/app_mod.f90 @@ -0,0 +1,5 @@ +module app_mod +implicit none + + +end module app_mod diff --git a/example_packages/hello_complex_2/app/say_goodbye.f90 b/example_packages/hello_complex_2/app/say_goodbye.f90 new file mode 100644 index 0000000..db12cbf --- /dev/null +++ b/example_packages/hello_complex_2/app/say_goodbye.f90 @@ -0,0 +1,8 @@ +program say_goodbye + use farewell_m, only: make_farewell + use app_mod + + implicit none + + print *, make_farewell("World") +end program say_goodbye diff --git a/example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 b/example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 new file mode 100644 index 0000000..5c426c8 --- /dev/null +++ b/example_packages/hello_complex_2/app/say_hello/app_hello_mod.f90 @@ -0,0 +1,4 @@ +module app_hello_mod +implicit none + +end module app_hello_mod diff --git a/example_packages/hello_complex_2/app/say_hello/say_Hello.f90 b/example_packages/hello_complex_2/app/say_hello/say_Hello.f90 new file mode 100644 index 0000000..3b69ba7 --- /dev/null +++ b/example_packages/hello_complex_2/app/say_hello/say_Hello.f90 @@ -0,0 +1,8 @@ +program say_Hello + use greet_m, only: make_greeting + use app_hello_mod + + implicit none + + print *, make_greeting("World") +end program say_Hello diff --git a/example_packages/hello_complex_2/fpm.toml b/example_packages/hello_complex_2/fpm.toml new file mode 100644 index 0000000..28c91d8 --- /dev/null +++ b/example_packages/hello_complex_2/fpm.toml @@ -0,0 +1,6 @@ +name = "hello_complex" + +[[executable]] +name="say_hello_world" +source-dir="app/say_hello" +main="say_Hello.f90" diff --git a/example_packages/hello_complex_2/src/farewell_m.f90 b/example_packages/hello_complex_2/src/farewell_m.f90 new file mode 100644 index 0000000..9fc75b9 --- /dev/null +++ b/example_packages/hello_complex_2/src/farewell_m.f90 @@ -0,0 +1,13 @@ +module farewell_m + implicit none + private + + public :: make_farewell +contains + function make_farewell(name) result(greeting) + character(len=*), intent(in) :: name + character(len=:), allocatable :: greeting + + greeting = "Goodbye, " // name // "!" + end function make_farewell +end module farewell_m diff --git a/example_packages/hello_complex_2/src/greet_m.f90 b/example_packages/hello_complex_2/src/greet_m.f90 new file mode 100644 index 0000000..2372f9a --- /dev/null +++ b/example_packages/hello_complex_2/src/greet_m.f90 @@ -0,0 +1,13 @@ +module greet_m + implicit none + private + + public :: make_greeting +contains + function make_greeting(name) result(greeting) + character(len=*), intent(in) :: name + character(len=:), allocatable :: greeting + + greeting = "Hello, " // name // "!" + end function make_greeting +end module greet_m diff --git a/example_packages/hello_complex_2/test/farewell_test.f90 b/example_packages/hello_complex_2/test/farewell_test.f90 new file mode 100644 index 0000000..dbe98d6 --- /dev/null +++ b/example_packages/hello_complex_2/test/farewell_test.f90 @@ -0,0 +1,19 @@ +program farewell_test + use farewell_m, only: make_farewell + use test_mod + use iso_fortran_env, only: error_unit, output_unit + + implicit none + + character(len=:), allocatable :: farewell + + allocate(character(len=0) :: farewell) + farewell = make_farewell("World") + + if (farewell == "Goodbye, World!") then + write(output_unit, *) "Passed" + else + write(error_unit, *) "Failed" + call exit(1) + end if +end program farewell_test diff --git a/example_packages/hello_complex_2/test/greet_test.f90 b/example_packages/hello_complex_2/test/greet_test.f90 new file mode 100644 index 0000000..38e9be0 --- /dev/null +++ b/example_packages/hello_complex_2/test/greet_test.f90 @@ -0,0 +1,19 @@ +program greet_test + use greet_m, only: make_greeting + use test_mod + use iso_fortran_env, only: error_unit, output_unit + + implicit none + + character(len=:), allocatable :: greeting + + allocate(character(len=0) :: greeting) + greeting = make_greeting("World") + + if (greeting == "Hello, World!") then + write(output_unit, *) "Passed" + else + write(error_unit, *) "Failed" + call exit(1) + end if +end program greet_test diff --git a/example_packages/hello_complex_2/test/test_mod.f90 b/example_packages/hello_complex_2/test/test_mod.f90 new file mode 100644 index 0000000..edb2626 --- /dev/null +++ b/example_packages/hello_complex_2/test/test_mod.f90 @@ -0,0 +1,5 @@ +module test_mod +implicit none + + +end module test_mod diff --git a/example_packages/hello_fpm/.gitignore b/example_packages/hello_fpm/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/hello_fpm/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/hello_fpm/app/main.f90 b/example_packages/hello_fpm/app/main.f90 new file mode 100644 index 0000000..5df6d64 --- /dev/null +++ b/example_packages/hello_fpm/app/main.f90 @@ -0,0 +1,9 @@ +program hello_fpm + use farewell_m, only: make_farewell + use greet_m, only: make_greeting + + implicit none + + print *, make_greeting("fpm") + print *, make_farewell("fpm") +end program hello_fpm diff --git a/example_packages/hello_fpm/fpm.toml b/example_packages/hello_fpm/fpm.toml new file mode 100644 index 0000000..d94d904 --- /dev/null +++ b/example_packages/hello_fpm/fpm.toml @@ -0,0 +1,4 @@ +name = "hello_fpm" + +[dependencies] +hello_complex = { path = "../hello_complex" } diff --git a/example_packages/hello_world/.gitignore b/example_packages/hello_world/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/hello_world/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/hello_world/app/main.f90 b/example_packages/hello_world/app/main.f90 new file mode 100644 index 0000000..d16022b --- /dev/null +++ b/example_packages/hello_world/app/main.f90 @@ -0,0 +1,3 @@ +program hello_world + print *, "Hello, World!" +end program hello_world diff --git a/example_packages/hello_world/fpm.toml b/example_packages/hello_world/fpm.toml new file mode 100644 index 0000000..b80e8d1 --- /dev/null +++ b/example_packages/hello_world/fpm.toml @@ -0,0 +1 @@ +name = "hello_world" diff --git a/example_packages/makefile_complex/.gitignore b/example_packages/makefile_complex/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/makefile_complex/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/makefile_complex/Makefile b/example_packages/makefile_complex/Makefile new file mode 100644 index 0000000..497c6b2 --- /dev/null +++ b/example_packages/makefile_complex/Makefile @@ -0,0 +1,9 @@ +INCLUDE_FLAGS = $(addprefix -I,$(INCLUDE_DIRS)) + +$(BUILD_DIR)/libmakefile_complex.a: $(BUILD_DIR)/wrapper_mod.o + ar rs $(@) $(^) + +$(BUILD_DIR)/wrapper_mod.mod: src/wrapper_mod.f90 + +$(BUILD_DIR)/wrapper_mod.o: src/wrapper_mod.f90 + $(FC) -c -J$(BUILD_DIR) $(INCLUDE_FLAGS) $(FFLAGS) -o $(@) $(<) diff --git a/example_packages/makefile_complex/app/main.f90 b/example_packages/makefile_complex/app/main.f90 new file mode 100644 index 0000000..ac9ed51 --- /dev/null +++ b/example_packages/makefile_complex/app/main.f90 @@ -0,0 +1,7 @@ +program makefile_complex + use wrapper_mod, only: do_stuff + + implicit none + + call do_stuff +end program makefile_complex diff --git a/example_packages/makefile_complex/fpm.toml b/example_packages/makefile_complex/fpm.toml new file mode 100644 index 0000000..3282cbe --- /dev/null +++ b/example_packages/makefile_complex/fpm.toml @@ -0,0 +1,8 @@ +name = "makefile_complex" + +[dependencies] +with_makefile = { path = "../with_makefile" } + +[library] +source-dir = "src" +build-script = "Makefile" diff --git a/example_packages/makefile_complex/src/wrapper_mod.f90 b/example_packages/makefile_complex/src/wrapper_mod.f90 new file mode 100644 index 0000000..e8028b5 --- /dev/null +++ b/example_packages/makefile_complex/src/wrapper_mod.f90 @@ -0,0 +1,12 @@ +module wrapper_mod + use hello_makefile, only: say_hello_from_makefile + + implicit none + private + + public :: do_stuff +contains + subroutine do_stuff + call say_hello_from_makefile + end subroutine do_stuff +end module wrapper_mod diff --git a/example_packages/program_with_module/app/main.f90 b/example_packages/program_with_module/app/main.f90 new file mode 100644 index 0000000..59441f0 --- /dev/null +++ b/example_packages/program_with_module/app/main.f90 @@ -0,0 +1,10 @@ +module greet_m + implicit none + character(*), parameter :: greeting = 'Hello, fpm!' +end module greet_m + +program program_with_module + use greet_m, only: greeting + implicit none + print *, greeting +end program program_with_module diff --git a/example_packages/program_with_module/fpm.toml b/example_packages/program_with_module/fpm.toml new file mode 100644 index 0000000..bce6aa2 --- /dev/null +++ b/example_packages/program_with_module/fpm.toml @@ -0,0 +1 @@ +name = "Program_with_module" diff --git a/example_packages/submodules/fpm.toml b/example_packages/submodules/fpm.toml new file mode 100644 index 0000000..cfc3d61 --- /dev/null +++ b/example_packages/submodules/fpm.toml @@ -0,0 +1 @@ +name = "submodules" diff --git a/example_packages/submodules/src/child1.f90 b/example_packages/submodules/src/child1.f90 new file mode 100644 index 0000000..dbd0fa5 --- /dev/null +++ b/example_packages/submodules/src/child1.f90 @@ -0,0 +1,16 @@ +submodule(parent) child1 +implicit none + +interface + module function my_fun() result (b) + integer :: b + end function my_fun +end interface + +contains + +module procedure my_sub1 + a = 1 +end procedure my_sub1 + +end submodule child1
\ No newline at end of file diff --git a/example_packages/submodules/src/child2.f90 b/example_packages/submodules/src/child2.f90 new file mode 100644 index 0000000..179cc32 --- /dev/null +++ b/example_packages/submodules/src/child2.f90 @@ -0,0 +1,10 @@ +submodule(parent) child2 +implicit none + +contains + +module procedure my_sub2 + a = 2 +end procedure my_sub2 + +end submodule child2
\ No newline at end of file diff --git a/example_packages/submodules/src/grandchild.f90 b/example_packages/submodules/src/grandchild.f90 new file mode 100644 index 0000000..8c5aa17 --- /dev/null +++ b/example_packages/submodules/src/grandchild.f90 @@ -0,0 +1,10 @@ +submodule(parent:child1) grandchild +implicit none + +contains + +module procedure my_fun + b = 2 +end procedure my_fun + +end submodule grandchild
\ No newline at end of file diff --git a/example_packages/submodules/src/parent.f90 b/example_packages/submodules/src/parent.f90 new file mode 100644 index 0000000..570827c --- /dev/null +++ b/example_packages/submodules/src/parent.f90 @@ -0,0 +1,15 @@ +module parent +implicit none + +interface + + module subroutine my_sub1(a) + integer, intent(out) :: a + end subroutine my_sub1 + + module subroutine my_sub2(a) + integer, intent(out) :: a + end subroutine my_sub2 +end interface + +end module parent
\ No newline at end of file diff --git a/example_packages/with_c/app/main.f90 b/example_packages/with_c/app/main.f90 new file mode 100644 index 0000000..4d3174b --- /dev/null +++ b/example_packages/with_c/app/main.f90 @@ -0,0 +1,10 @@ +program with_c_app +use with_c +implicit none + +write(*,*) "isdir('app') = ", system_isdir('app') +write(*,*) "isdir('src') = ", system_isdir('src') +write(*,*) "isdir('test') = ", system_isdir('test') +write(*,*) "isdir('bench') = ", system_isdir('bench') + +end program with_c_app
\ No newline at end of file diff --git a/example_packages/with_c/fpm.toml b/example_packages/with_c/fpm.toml new file mode 100644 index 0000000..97e3110 --- /dev/null +++ b/example_packages/with_c/fpm.toml @@ -0,0 +1 @@ +name = "with_c" diff --git a/example_packages/with_c/src/c_code.c b/example_packages/with_c/src/c_code.c new file mode 100644 index 0000000..44604f0 --- /dev/null +++ b/example_packages/with_c/src/c_code.c @@ -0,0 +1,10 @@ +#include <sys/stat.h> +/* + * Decides whether a given file name is a directory. + * return 1 if file exists and is a directory + * Source (Public domain): https://github.com/urbanjost/M_system + */ +int my_isdir (const char *path) { + struct stat sb; + return stat(path, &sb) == 0 && S_ISDIR (sb.st_mode); +}
\ No newline at end of file diff --git a/example_packages/with_c/src/with_c.f90 b/example_packages/with_c/src/with_c.f90 new file mode 100644 index 0000000..edd839e --- /dev/null +++ b/example_packages/with_c/src/with_c.f90 @@ -0,0 +1,26 @@ +module with_c + use iso_c_binding, only: c_char, c_int, c_null_char + implicit none + +contains + + function system_isdir(dirname) + ! Source (Public domain): https://github.com/urbanjost/M_system + ! + implicit none + character(len=*),intent(in) :: dirname + logical :: system_isdir + + interface + function c_isdir(dirname) bind (C,name="my_isdir") result (c_ierr) + import c_char,c_int + character(kind=c_char,len=1),intent(in) :: dirname(*) + integer(kind=c_int) :: c_ierr + end function c_isdir + end interface + + system_isdir= c_isdir(trim(dirname)//c_null_char) == 1 + + end function system_isdir + +end module with_c
\ No newline at end of file diff --git a/example_packages/with_makefile/.gitignore b/example_packages/with_makefile/.gitignore new file mode 100644 index 0000000..a007fea --- /dev/null +++ b/example_packages/with_makefile/.gitignore @@ -0,0 +1 @@ +build/* diff --git a/example_packages/with_makefile/Makefile b/example_packages/with_makefile/Makefile new file mode 100644 index 0000000..51e72d4 --- /dev/null +++ b/example_packages/with_makefile/Makefile @@ -0,0 +1,9 @@ +INCLUDE_FLAGS = $(addprefix -I,$(INCLUDE_DIRS)) + +$(BUILD_DIR)/libwith_makefile.a: $(BUILD_DIR)/hello_makefile.o + ar rs $(@) $(^) + +$(BUILD_DIR)/hello_makefile.mod: src/hello_makefile.f90 + +$(BUILD_DIR)/hello_makefile.o: src/hello_makefile.f90 + $(FC) -c -J$(BUILD_DIR) $(INCLUDE_FLAGS) $(FFLAGS) -o $(@) $(<) diff --git a/example_packages/with_makefile/fpm.toml b/example_packages/with_makefile/fpm.toml new file mode 100644 index 0000000..81dd02a --- /dev/null +++ b/example_packages/with_makefile/fpm.toml @@ -0,0 +1,5 @@ +name = "with_makefile" + +[library] +source-dir = "src" +build-script = "Makefile" diff --git a/example_packages/with_makefile/src/hello_makefile.f90 b/example_packages/with_makefile/src/hello_makefile.f90 new file mode 100644 index 0000000..2d4d1a2 --- /dev/null +++ b/example_packages/with_makefile/src/hello_makefile.f90 @@ -0,0 +1,10 @@ +module hello_makefile + implicit none + private + + public :: say_hello_from_makefile +contains + subroutine say_hello_from_makefile() + print *, "Hello from Makefile library!" + end subroutine say_hello_from_makefile +end module hello_makefile |