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 b8116c3 commit feb5214
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
17 changes: 13 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,31 @@ PPFLAGS = -DSQLITE_ENABLE_COLUMN_METADATA=0
LDFLAGS = -I$(PREFIX)/include -L$(PREFIX)/lib
LDLIBS = -lsqlite3
ARFLAGS = rcs
TARGET = libfortran-sqlite3.a
SRC = src/sqlite3_macro.c src/sqlite3.F90 src/sqlite3_util.f90
INCDIR = $(PREFIX)/include/libfortran-sqlite3
LIBDIR = $(PREFIX)/lib
OBJ = sqlite3.o sqlite3_macro.o sqlite3_util.o
TARGET = libfortran-sqlite3.a

.PHONY: all clean test
.PHONY: all clean install test

all: $(TARGET)

test: test_sqlite3

$(TARGET): $(SRC)
$(TARGET): src/sqlite3_macro.c src/sqlite3.F90 src/sqlite3_util.f90
$(CC) $(CFLAGS) -c src/sqlite3_macro.c
$(FC) $(FFLAGS) -c src/sqlite3_util.f90
$(FC) $(FFLAGS) $(PPFLAGS) -c src/sqlite3.F90
$(AR) $(ARFLAGS) $(TARGET) $(OBJ)

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 *.mod $(INCDIR)/

test_sqlite3: $(TARGET) test/test_sqlite3.f90
$(FC) $(FFLAGS) $(LDFLAGS) -o test_sqlite3 test/test_sqlite3.f90 $(TARGET) $(LDLIBS)

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $ cd fortran-sqlite3/
Either build the library with `fpm` or `make`. Once compiled, link your Fortran
application against `libfortran-sqlite3.a` and `-lsqlite3`.

### fpm
### Fortran Package Manager

Simply execute the Fortran Package Manager:

Expand All @@ -54,7 +54,12 @@ $ make PPFLAGS="-DSQLITE_ENABLE_COLUMN_METADATA=1"
```

You may want to override the default compilers by passing the arguments `CC` (C
compiler) and `FC` (Fortran compiler).
compiler) and `FC` (Fortran compiler). To install the library and the module
files system-wide, for example, to `/opt`, run:

```
$ make install PREFIX=/opt
```

## Source-Code Documentation

Expand Down Expand Up @@ -161,15 +166,16 @@ contains
end program example
```

Compile, link, and run the example with:
If the library is installed to `/opt`, then compile, link, and run the example
with:

```
$ gfortran -o example example.f90 libfortran-sqlite3.a -lsqlite3
$ gfortran -I/opt/include/libfortran-sqlite3 -o example example.f90 /opt/lib/libfortran-sqlite3.a -lsqlite3
$ ./example
1 one 12345
```

## fpm
## Fortran Package Manager

You can add *fortran-sqlite3* as an [fpm](https://github.com/fortran-lang/fpm)
dependency to your `fpm.toml`:
Expand Down
13 changes: 6 additions & 7 deletions src/sqlite3.F90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
! Licence: ISC
module sqlite3
use, intrinsic :: iso_c_binding
use, intrinsic :: iso_fortran_env, only: i8 => int64
use :: sqlite3_util
implicit none (type, external)
private
Expand Down Expand Up @@ -945,14 +944,14 @@ end function sqlite3_bind_parameter_index
function sqlite3_bind_text(stmt, idx, val, destructor)
!! Binds text to column. This wrapper passes destructor
!! `SQLITE_TRANSIENT` by default!
type(c_ptr), intent(inout) :: stmt
integer, intent(in) :: idx
character(len=*), intent(in) :: val
integer(kind=i8), intent(in), optional :: destructor
integer :: sqlite3_bind_text
type(c_ptr), intent(inout) :: stmt
integer, intent(in) :: idx
character(len=*), intent(in) :: val
integer(kind=c_size_t), intent(in), optional :: destructor
integer :: sqlite3_bind_text

if (present(destructor)) then
sqlite3_bind_text = sqlite3_bind_text_(stmt, idx, val, len(val), int(destructor, kind=c_size_t))
sqlite3_bind_text = sqlite3_bind_text_(stmt, idx, val, len(val), destructor)
return
end if

Expand Down

0 comments on commit feb5214

Please sign in to comment.