diff --git a/Makefile b/Makefile index a41e3d3..33aa40d 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,13 @@ FFLAGS = $(RELEASE) LDFLAGS = -I$(PREFIX)/include -L$(PREFIX)/lib LDLIBS = -lpcre2-8 ARFLAGS = rcs +INCDIR = $(PREFIX)/include/libfortran-pcre2 +LIBDIR = $(PREFIX)/lib +MODULE = pcre2.mod TARGET = libfortran-pcre2.a TEST = test_pcre2 -.PHONY: all clean test +.PHONY: all clean install test all: $(TARGET) @@ -22,6 +25,14 @@ $(TARGET): src/pcre2.f90 $(FC) $(FFLAGS) -c src/pcre2.f90 $(AR) $(ARFLAGS) $(TARGET) pcre2.o +install: $(TARGET) + @echo "--- Installing $(TARGET) to $(LIBDIR)/ ..." + install -d $(LIBDIR) + install -m 644 $(TARGET) $(LIBDIR)/ + @echo "--- Installing module files to $(INCDIR)/ ..." + install -d $(INCDIR) + install -m 644 $(MODULE) $(INCDIR)/ + test: $(FC) $(FFLAGS) $(LDFLAGS) -o $(TEST) test/test_pcre2.f90 $(TARGET) $(LDLIBS) diff --git a/README.md b/README.md index 08f65e1..f6a7b5c 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ # fortran-pcre2 + A work-in-progress collection of Fortran 2018 ISO_C_BINDING interfaces to Perl-compatible Regular Expressions 2 ([PCRE2](https://www.pcre.org/current/doc/html/)). The library is also available on [MacPorts](https://ports.macports.org/port/fortran-pcre2/). ## Build Instructions + You will need *libpcre2* with development headers. On FreeBSD, run: ``` @@ -26,16 +28,23 @@ $ cd fortran-pcre2/ $ make ``` +Install the library and the modules files system-wide to `/opt`: + +``` +$ make install PREFIX=/opt +``` + Instead of `make`, you may want to build the library using the Fortran Package Manager: ``` -$ fpm build --profile=release +$ fpm build --profile release ``` Link your Fortran programs against `libfortran-pcre2.a` and `-lpcre2-8`. ## Example + The following program just compiles and executes a basic regular expression. ```fortran @@ -99,15 +108,17 @@ program main end program main ``` -Compile, link, and run the program with, for example: +If the library is installed to `/opt`, then compile, link, and run the program +with: ``` -$ gfortran -o example example.f90 libfortran-pcre2.a -lpcre2-8 +$ gfortran -I/opt/include/libfortran-pcre2 -o example example.f90 /opt/lib/libfortran-pcre2.a -lpcre2-8 $ ./example ``` -## fpm -You can add *fortran-pcre2* as an [fpm](https://github.com/fortran-lang/fpm) +## Fortran Package Manager + +You can add *fortran-pcre2* as an [FPM](https://github.com/fortran-lang/fpm) dependency: ```toml @@ -116,6 +127,7 @@ fortran-pcre2 = { git = "https://github.com/interkosmos/fortran-pcre2.git" } ``` ## Compatibility + It is not necessary to null-terminate character strings given to the procedures of *fortran-pcre2*. In contrast to the C API of PCRE2, you must not free substrings with `pcre2_substring_free()`, as this will be done by the wrapper @@ -142,4 +154,5 @@ functions. | `pcre2_substring_number_from_name_8` | `pcre2_substring_number_from_name` | ## Licence + ISC