Skip to content

Commit

Permalink
Adjust build script to get paths from pg_config tool and some README …
Browse files Browse the repository at this point in the history
…information
  • Loading branch information
fabriziomello committed Sep 18, 2017
1 parent 16e03a3 commit 0914eed
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -3,6 +3,7 @@
*.dll
*.so
*.dylib
*.h

# Test binary, build with `go test -c`
*.test
Expand All @@ -11,4 +12,4 @@
*.out

# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
.glide/
17 changes: 15 additions & 2 deletions README.md
Expand Up @@ -5,7 +5,20 @@ Background Worker Processes for PostgreSQL written in Go

## Build

1) Make sure the 'pg\_config' tool is in your $PATH, if not then config like the example below:

```
export PATH=/usr/lib/postgresql/9.6/bin:$PATH
```

2) Build the library

```
./build.bash
```

## PostgreSQL Config (postgresql.conf)

```
go build -buildmode=c-shared -o prest.so
cp prest.so /usr/lib/postgresql/9.6/lib/prest
shared_preload_libraries = 'go_brackground_worker'
```
22 changes: 19 additions & 3 deletions build.bash
@@ -1,10 +1,26 @@
#!/bin/bash

PGROOT="/home/fabrizio/pgsql"
if [ ! $(which pg_config) ]; then
echo "ERROR: pg_config not found"
exit 1
fi

BUILDDIR=".build"

[ -d ${BUILDDIR} ] || mkdir ${BUILDDIR}

INCLUDEDIR=$(pg_config --includedir-server)
LIBDIR=$(pg_config --pkglibdir)
LIBNAME="go_background_worker.so"
LIBOUTPUT="${BUILDDIR}/${LIBNAME}"

export CGO_CFLAGS="-I ${PGROOT}/include/server"
export CGO_CFLAGS="-I ${INCLUDEDIR}"
export CGO_LDFLAGS="-shared"

go build -buildmode=c-shared -v -o ${PGROOT}/lib/${LIBNAME}
echo "Building ${LIBOUTPUT}"
go build -buildmode=c-shared -o ${LIBOUTPUT}

if [ $? -eq 0 ]; then
echo "Sending ${LIBOUTPUT} to ${LIBDIR}"
cp -p ${LIBOUTPUT} ${LIBDIR}
fi

0 comments on commit 0914eed

Please sign in to comment.