# Building

## Prerequisites

* Installed [Leptonica](http://www.leptonica.org/) including development parts (e.g. libleptonica-dev) - Meson will download and build it if necessary
* Installed [cmake](https://cmake.org/) or [autotools](https://www.gnu.org/software/automake/manual/html_node/Autotools-Introduction.html) or [Meson](https://mesonbuild.com/)
* Installed C++ compiler (GCC, Clang, or MSVC)
* Installed [git](https://git-scm.com/)



## Unix-like OS

If you're running a Unix-like system such as Linux, BSD, macOS, or MSYS, run:

```
./autogen.sh
./configure
make
make install (or: sudo make install)
```


Make sure packages such as `automake`, ` libtool`, `make`, `pkg-config` and `autoconf-archive` are installed before executing the commands above.

## Meson

The usual way on most operating systems is:

```sh
meson setup build
meson compile -C build
meson install -C build
```

This will set up a build directory (called `build`), compile and install the software. Meson will ask for elevated user privileges as needed.

### IDEs

Some IDEs, like KDevelop, already support Meson.

VSCode has an extension you can install from the marketplace. Once that is set up, you can simply open the source directory in VSCode and everything will be configured automatically.

### Distributions with older Meson versions

If your OS distribution does not package a new enough version of Meson, you can also use Python tools to install it:

#### uv (recommended)

```sh
uv tool install meson
```

### pip

```sh
pip3 install --user meson
```

You may have to add `~/.local/bin` to your `$PATH` for it to be recognized.


## CMake

CMake requires a CMake-based build installation of Leptonica.


### Windows


*Note*: `cat`, `rm` and `dos2unix` tool are part of [git for windows](https://gitforwindows.org/). You can add them to your path with `set PATH=%PATH%;C:\Program Files\Git\usr\bin`. Adjust path `f:\win64` to your Leptonica installation.

```
"c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" x64
set INSTALL_DIR=f:\win64
set INCLUDE_DIR=f:\win64\include
set LIB_DIR=f:\win64\lib
set PATH=%PATH%;%INSTALL_DIR%\bin
```

### Configuration

```
git clone --depth 1 https://github.com/agl/jbig2enc
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DCMAKE_PREFIX_PATH=%INSTALL_DIR%
cmake --build build --config Release
```

### Install

```
cmake --build build --config Release --target install
```

### Uninstall

```
cat build/install_manifest.txt | dos2unix | xargs rm

```

### Clean

```
rm -r build/*
```