### Compilation

Home

Compilation should be working on Linux, Windows with MinGW and Mac OS X. You will need header files of Puredata, as well as libcurl, json-c, and liboauth.

The package build script is based on the Pd library template.

With version 0.11, json-c have changed the library path and name. If your system has an older version of json-c, you have to apply the patch `old-json-c-version.patch` via `patch -p1 < old-json-c-version.patch`.

When you use static versions of libcurl, i.e. on Windows and Mac OS X, you will need the file cacert.pem from the libcurl website. Put the downloaded file in the directory of PuREST JSON.

If you have gotten the source code from git, you will first have to init the uthash submodule by running `git submodule update --init`.

## Linux

You need build-essentials, header files for puredata, libjson0, libcurl4, liboauth. If you have Debian or a derivative (e.g. Ubuntu, Linux Mint), you can install the build utils and needed headers with `apt-get install build-essentials puredata-dev libjson0-dev libcurl4-openssl-dev liboauth-dev`. If you are not root, prefix the command with `sudo`.

Drop the sources in a directory and run `make`. You will get files with a suffix of pd_linux for each object (json-decode.pd_linux, json-encode.pd_linux, rest.pd_linux, oauth.pd_linux). These are needed to use the library.

### Building a deb package (Optional for Debian Based Distributions)

Install the package devscript with `apt-get install devscript`.

Run `make dpkg-deb`, you will get a deb file in the parent folder. The resulting package will have the following name structure: `pd-purest-json_{version}_{debian_architecture}.deb`, e.g. `pd-purest-json_0.11_i386.deb`. Install this file with `dpkg -i pd-purest-json_0.11_i386.deb`.

## Windows with MinGW

This section is outdated and probably will not work

You need to install MinGW on your computer. Follow the instructions on http://puredata.info/docs/developer/WindowsMinGW leaving out Cygwin. If you do not plan to compile Pd-extended, you may stop after following the instructions for "MinGW extras".

Install the additional packages: * pthreads-w32, from the MinGW shell via `mingw-get install pthreads-w32`.

- libcurl, from http://curl.haxx.se/download.html#Win32 Choose Win32 generic, libcurl

- json-c, from http://blog.stranadurakov.com/projects/mingw-libraries/ or use the latest json-c version from github (see above) and build it yourself.

- (TODO: how-to use liboauth)

Extract the latter zip files and put the contents in the correct MinGW folders.

If you encounter an error with two definition of boolean, delete the line `typedef int boolean;` from the file %MinGW%/include/json/json_object.h.

Navigate to the folder of purest_json in MinGW Shell and run `make`. You will get four dll files (json-decode.dll, json-encode.dll, rest-json.dll, libpurest_json.dll).

To use the library, you will also need the dll from the libcurl download, and rename libcurl.dll to libcurl-4.dll. This will not run on current releases (Pd-extended 0.42 or Pd vanilla 0.43), only on Pd-extended 0.43 auto-builds.

## Compilation on Mac OS X

I do not have a Mac available, so the following instructions are probably not entirely correct:

### Using Fink

You will need to install json-c, libcurl4 and libcurl4-shibs via Fink by running

`fink install json-c libcurl4 libcurl4-shibs`

You also need liboauth. Download the source code, extract the archive (e.g. from the command line with `tar -xf liboauth-1.0.0.tar.gz`) and run

`./configure`

`make`

`make install`

to build and install liboauth.

You will need to set up part of the Pd build environment on your computer

Run `make` in the purest_json folder.

If the build succeeded, run `./embed-MacOSX-dependencies.sh` to embed the dependencies in the shared library.

On the Mac OS X system that runs Pd, you will need SSL certificates to verify the signatures. You can download certificates in PEM format from cURL website. Copy the file `cacert.pem` in the same directory as rest.pd_darwin and oauth.pd_darwin, as the library expects the file to reside there.

### Using Homebrew

Homebrew looks like the newer and recommended way to get third party libraries on Mac OS X. This has not been tested, but the basic steps are outlined here anyway.

The dependencies should be installable by running

`brew install json-c curl liboauth`

After setting up the build environment for Pd, you should be able to build PuREST JSON by running `make` in the purest_json folder.

If the build succeeded, run `./embed-MacOSX-dependencies.sh` to embed the dependencies in the shared library.

## Cross-compilation for Windows on UNIX-like systems (Linux / *BSD / Mac OS X) with MXE

Get the development version of MXE from their Github repository and setup MXE, so that the cross compilation tools are in your PATH environmental variable.

Build the required libraries by running `make curl json-c liboauth pthreads`.

You will need a source of Pd, and pd.dll from a Windows version. Put them in folders with the following structure:

    pd/src/(source files including m_pd.h)
    pd/bin/pd.dll

Now run `make` with some environmental variables to tell the compiler to use the cross compiler, and where to find the Pd source and pd.dll. Here is an example from my setup:

    make \
    UNAME=MINGW \
    CROSS_PATH=/home/thomas/code/mxe/usr/ \
    CROSS=i686-pc-mingw32 \
    PD_PATH=/home/thomas/code/pd

Good luck.

On the Windows system that runs Pd, you will need SSL certificates to verify the signatures. You can download certificates in PEM format from cURL website. Copy the file `cacert.pem` in the same directory as rest.dll and oauth.dll, as the library expects the file to reside there.