Skip to content

Commit

Permalink
Added install target.
Browse files Browse the repository at this point in the history
  • Loading branch information
interkosmos committed Mar 3, 2024
1 parent 139a1dd commit 59aa12d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@ 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)

$(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)

Expand Down
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:

```
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -142,4 +154,5 @@ functions.
| `pcre2_substring_number_from_name_8` | `pcre2_substring_number_from_name` |

## Licence

ISC

0 comments on commit 59aa12d

Please sign in to comment.