From 672cd3689b322db968c7480f352194b03abd2741 Mon Sep 17 00:00:00 2001 From: Jannis Teunissen <jannis@delljannis.wlan.cwi.nl> Date: Tue, 2 Apr 2024 13:50:21 +0200 Subject: [PATCH 1/5] Add brief explanation on how to include stdlib in a Makefile --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.md b/README.md index 2a7f336ae..8e0ef757e 100644 --- a/README.md +++ b/README.md @@ -217,6 +217,8 @@ stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" } ## Using stdlib in your project +### Using stdlib with CMake + The stdlib project exports CMake package files and pkg-config files to make stdlib usable for other projects. The package files are located in the library directory in the installation prefix. @@ -235,6 +237,18 @@ target_link_libraries( To make the installed stdlib project discoverable add the stdlib directory to the ``CMAKE_PREFIX_PATH``. The usual install location of the package files is ``$PREFIX/lib/cmake/fortran_stdlib``. +### Using stdlib with a regular Makefile + +The library can be included in a regular Makefile, for example with +```make +STDLIB_PATH := path/to/build +LIBDIRS := $(STDLIB_PATH)/src +INCDIRS := $(STDLIB_PATH)/src/mod_files +... +``` +Here it is assumed that the compiler will look for libraries in `LIBDIRS` and for module files in `INCDIRS`. +A flag `-lfortran_stdlib` should be included to link against `libfortran_stdlib.a` or `libfortran_stdlib.so`. + ## Documentation Documentation is a work in progress (see issue [#4](https://github.com/fortran-lang/stdlib/issues/4)) but already available at [stdlib.fortran-lang.org](https://stdlib.fortran-lang.org). From 86c9bef942354f2c45568be21347039c18353ea7 Mon Sep 17 00:00:00 2001 From: Jannis Teunissen <jannis@delljannis.wlan.cwi.nl> Date: Tue, 2 Apr 2024 17:42:18 +0200 Subject: [PATCH 2/5] Move fpm usage description and include Cmake installation paths --- README.md | 49 ++++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 8e0ef757e..35648ec04 100644 --- a/README.md +++ b/README.md @@ -201,20 +201,6 @@ fpm run --example prog with `prog` being the name of the example program (e.g., `example_sort`). -To use `stdlib` within your `fpm` project, add the following lines to your `fpm.toml` file: -```toml -[dependencies] -stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" } -``` - -> **Warning** -> -> Fpm 0.9.0 and later implements stdlib as a *metapackage*. -> To include the standard library metapackage, change the dependency to: -> `stdlib = "*"`. -> -> [see also](https://fpm.fortran-lang.org/spec/metapackages.html) - ## Using stdlib in your project ### Using stdlib with CMake @@ -237,17 +223,38 @@ target_link_libraries( To make the installed stdlib project discoverable add the stdlib directory to the ``CMAKE_PREFIX_PATH``. The usual install location of the package files is ``$PREFIX/lib/cmake/fortran_stdlib``. +### Using stdlib with with fpm + +To use `stdlib` within your `fpm` project, add the following lines to your `fpm.toml` file: +```toml +[dependencies] +stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" } +``` + +> **Warning** +> +> Fpm 0.9.0 and later implements stdlib as a *metapackage*. +> To include the standard library metapackage, change the dependency to: +> `stdlib = "*"`. +> +> [see also](https://fpm.fortran-lang.org/spec/metapackages.html) + ### Using stdlib with a regular Makefile -The library can be included in a regular Makefile, for example with +After the library has been built, it can be included in a regular Makefile. +If the library has been installed in a directory inside the compiler's search path, +only a flag `-lfortran_stdlib` is required to link against `libfortran_stdlib.a` or `libfortran_stdlib.so`. +If the installation directory is not in the compiler's search path, one can add for example ```make -STDLIB_PATH := path/to/build -LIBDIRS := $(STDLIB_PATH)/src -INCDIRS := $(STDLIB_PATH)/src/mod_files -... +libdir=${install_dir}/lib +moduledir=${install_dir}/include/fortran_stdlib/<compiler name and version> +``` +Here it is assumed that the compiler will look for libraries in `libdir` and for module files in `moduledir`. +The library can also be included from a build directory without installation: +```make +libdir=$(build_dir)/src +moduledir=$(build_dir)/src/mod_files ``` -Here it is assumed that the compiler will look for libraries in `LIBDIRS` and for module files in `INCDIRS`. -A flag `-lfortran_stdlib` should be included to link against `libfortran_stdlib.a` or `libfortran_stdlib.so`. ## Documentation From 2a648a8d44d619b6e9534ac34d5c1e3457494388 Mon Sep 17 00:00:00 2001 From: Jannis Teunissen <jannis@teunissen.net> Date: Tue, 2 Apr 2024 20:06:01 +0200 Subject: [PATCH 3/5] Update README.md Co-authored-by: Federico Perini <federico.perini@gmail.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 35648ec04..073c71d4d 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,7 @@ target_link_libraries( To make the installed stdlib project discoverable add the stdlib directory to the ``CMAKE_PREFIX_PATH``. The usual install location of the package files is ``$PREFIX/lib/cmake/fortran_stdlib``. -### Using stdlib with with fpm +### Using stdlib with fpm To use `stdlib` within your `fpm` project, add the following lines to your `fpm.toml` file: ```toml From ecf85d0a5eb8e1d0022a1971c637ee5ad6415efa Mon Sep 17 00:00:00 2001 From: Jannis Teunissen <jannis@teunissen.net> Date: Thu, 4 Apr 2024 22:55:09 +0200 Subject: [PATCH 4/5] Add pkg-config usage in Makefile --- README.md | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 073c71d4d..f23859a85 100644 --- a/README.md +++ b/README.md @@ -242,18 +242,47 @@ stdlib = { git="https://github.com/fortran-lang/stdlib", branch="stdlib-fpm" } ### Using stdlib with a regular Makefile After the library has been built, it can be included in a regular Makefile. +The recommended way to do this is using the [pkg-config](https://www.freedesktop.org/wiki/Software/pkg-config/) tool, for which an example is shown below. +```make +# Necessary if the installation directory is not in PKG_CONFIG_PATH +install_dir := path/to/install_dir +export PKG_CONFIG_PATH := $(install_dir)/lib/pkgconfig:$(PKG_CONFIG_PATH) + +STDLIB_CFLAGS := `pkg-config --cflags fortran_stdlib` +STDLIB_LIBS := `pkg-config --libs fortran_stdlib` + +# Example definition of Fortran compiler and flags +FC := gfortran +FFLAGS := -O2 -Wall -g + +# Definition of targets etc. +... + +# Example rule to compile object files from .f90 files +%.o: %.f90 + $(FC) -c -o $@ $< $(FFLAGS) $(STDLIB_CFLAGS) + +# Example rule to link an executable from object files +%: %.o + $(FC) -o $@ $^ $(FFLAGS) $(STDLIB_LIBS) + +``` + +The same can also be achieved without pkg-config. If the library has been installed in a directory inside the compiler's search path, -only a flag `-lfortran_stdlib` is required to link against `libfortran_stdlib.a` or `libfortran_stdlib.so`. +only a flag `-lfortran_stdlib` is required. If the installation directory is not in the compiler's search path, one can add for example ```make -libdir=${install_dir}/lib -moduledir=${install_dir}/include/fortran_stdlib/<compiler name and version> +install_dir := path/to/install_dir +libdir := $(install_dir)/lib +moduledir := $(install_dir)/include/fortran_stdlib/<compiler name and version> ``` -Here it is assumed that the compiler will look for libraries in `libdir` and for module files in `moduledir`. -The library can also be included from a build directory without installation: +The linker should then look for libraries in `libdir` (using e.g.`-L$(libdir)`) and the compiler should look for module files in `moduledir` (using e.g. `-I$(moduledir)`). +Alternatively, the library can also be included from a build directory without installation with ```make -libdir=$(build_dir)/src -moduledir=$(build_dir)/src/mod_files +... +libdir := $(build_dir)/src +moduledir := $(build_dir)/src/mod_files ``` ## Documentation From d288010c8339191c56a9b537c48c662aef8aa90d Mon Sep 17 00:00:00 2001 From: Jannis Teunissen <jannis@teunissen.net> Date: Thu, 4 Apr 2024 22:57:59 +0200 Subject: [PATCH 5/5] Update line about build_dir --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f23859a85..6180bea0e 100644 --- a/README.md +++ b/README.md @@ -280,7 +280,7 @@ moduledir := $(install_dir)/include/fortran_stdlib/<compiler name and version> The linker should then look for libraries in `libdir` (using e.g.`-L$(libdir)`) and the compiler should look for module files in `moduledir` (using e.g. `-I$(moduledir)`). Alternatively, the library can also be included from a build directory without installation with ```make -... +build_dir := path/to/build_dir libdir := $(build_dir)/src moduledir := $(build_dir)/src/mod_files ```