Difference between revisions of "Hacking:Building/Linux"

From GIMP Developer Wiki
Jump to: navigation, search
(Add new meson/ninja build instructions for babl.)
(Update the instructions to reflect some of the recent changes and to explain config.site. Still needs more updating, though.)
(One intermediate revision by the same user not shown)
Line 45: Line 45:
 
<pre>mkdir -p $INSTALL_PREFIX
 
<pre>mkdir -p $INSTALL_PREFIX
 
mkdir -p $SRC_DIR</pre>
 
mkdir -p $SRC_DIR</pre>
Now, remember the discussion we had about environment variables? Here are the updates we need to do:
+
 
 +
Now, remember the discussion we had about environment variables?  
 +
 
 +
Create a file called $INSTALL_PREFIX/share/config.site containing the following:
 
<pre>export PATH=$INSTALL_PREFIX/bin:$PATH
 
<pre>export PATH=$INSTALL_PREFIX/bin:$PATH
export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
+
export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig:$GIMP_PREFIX/share/pkgconfig:$PKG_CONFIG_PATH
 
export LD_LIBRARY_PATH=$INSTALL_PREFIX/lib:$LD_LIBRARY_PATH</pre>
 
export LD_LIBRARY_PATH=$INSTALL_PREFIX/lib:$LD_LIBRARY_PATH</pre>
 
In the first line, we update the PATH variable, so that looking for executables will begin in our installation directory (executables will be installed into the bin subdirectory).
 
In the first line, we update the PATH variable, so that looking for executables will begin in our installation directory (executables will be installed into the bin subdirectory).
Line 58: Line 61:
 
'''NOTE''': some distribution have more up-to-date versions of libraries, and therefore are more adapted for developers. For instance: Debian Testing, Fedora… In particular using some user-oriented distributions (for instance Ubuntu), you will have more dependencies to build yourself, and in worst cases, you may encounter dependency conflicts.
 
'''NOTE''': some distribution have more up-to-date versions of libraries, and therefore are more adapted for developers. For instance: Debian Testing, Fedora… In particular using some user-oriented distributions (for instance Ubuntu), you will have more dependencies to build yourself, and in worst cases, you may encounter dependency conflicts.
  
== Compiling libmypaint-gegl from source ==
+
Some packages you will probably need, if you don't already have them (install with apt install on Debian): build-essential meson libjson-c-dev gobject-introspection
This step is only needed if you're building GIMP git master. This library isn't available on most Linux distros, so you'll have to build it from source.
+
This is not a complete list: you will probably need other packages.
  
Note: the libmypaint master branch is currently subject to change, so GIMP requires v1.3.0. The commands below use git checkout to get the corresponding tag from the libmypaint repository.
+
== Compiling packages from source ==
 +
 
 +
If you're building GIMP git master, you'll need the latest version of libmypaint, mypaint-brushes, babl, and gegl, and you'll have to build those all from source. Babl uses meson for its builds; the other tools use autotools and make.
 +
 
 +
== babl ==
 +
 
 +
<pre>
 +
git clone https://gitlab.gnome.org/GNOME/babl.git
 +
SRCDIR=$(pwd)
 +
BUILD_DIR=$SRCDIR/obj-$(arch)
 +
mkdir -p $BUILD_DIR
 +
cd $BUILD_DIR
 +
meson -Dprefix=$INSTALL_PREFIX $SRCDIR && ninja && ninja install
 +
</pre>
 +
 
 +
== libmypaint ==
  
 
<pre>
 
<pre>
 
git clone https://github.com/mypaint/libmypaint.git
 
git clone https://github.com/mypaint/libmypaint.git
 
cd libmypaint/
 
cd libmypaint/
git checkout v1.3.0
+
git checkout -t origin/libmypaint-v1
sudo apt-get install libjson-c-dev
+
 
./autogen.sh && ./configure --prefix=$INSTALL_PREFIX && make && make install
 
./autogen.sh && ./configure --prefix=$INSTALL_PREFIX && make && make install
 
</pre>
 
</pre>
  
== Compiling babl, GEGL and GIMP from source ==
+
== libmypaint-brushes ==
The procedure for compiling babl, GEGL and GIMP is very easy once you have the dependencies. Note that the order here matters – we first need to have babl, then GEGL and finally GIMP.
+
 
=== Getting the sources ===
+
If you're building GIMP from git master, you'll probably also need to build libmypaint-brushes.
You can download the source tarballs of all 3 from the [http://download.gimp.org/pub/ GIMP.org]:
+
Sorry, there are no explicit instructions for that here yet.
<pre>http://download.gimp.org/pub/babl/
+
 
http://download.gimp.org/pub/gegl/
+
== GEGL and GIMP  ==
http://download.gimp.org/pub/gimp/</pre>
+
Or you can download the sources from Git (you'll need to have git installed):
+
<pre>git clone git@gitlab.gnome.org:GNOME/babl.git
+
git clone git@gitlab.gnome.org:GNOME/gegl.git
+
git clone git@gitlab.gnome.org:GNOME/gimp.git</pre>
+
  
If you are behind a corporate firewall, you can also try Git over HTTPS:
 
<pre>git clone https://gitlab.gnome.org/GNOME/babl.git
 
 
git clone https://gitlab.gnome.org/GNOME/gegl.git
 
git clone https://gitlab.gnome.org/GNOME/gegl.git
git clone https://gitlab.gnome.org/GNOME/gimp.git</pre>
+
git clone https://gitlab.gnome.org/GNOME/gimp.git
If you downloaded the source tarballs (the filename will end with .tar.gz or .tar.bz2), you'll need to extract them by executing
+
<pre>tar -xf FILE -C DIR</pre>
+
Where FILE should be the path to the file you want to extract and DIR is the directory into which you wish to extract the sources.
+
  
=== Actual Building ===
+
The instructions for the two directories are the same. Build gegl first, then gimp.
BABL now uses Meson and Ninja. To build BABL:
+
 
<pre>
+
# If you downloaded a source Tarball, run the configure script with our desired install prefix
SRCDIR=$(PWD)
+
 
BUILD_DIR=$SRCDIR/obj-$(arch)
+
<pre>./configure --prefix=$INSTALL_PREFIX</pre>
mkdir -p $BUILD_DIR
+
 
cd $BUILD_DIR
+
Otherwise, if you downloaded the source from git, run the autogen script with same argument:
meson -Dprefix=$INSTALL_PREFIX $SRCDIR && ninja && ninja install
+
 
</pre>
+
<pre>./autogen.sh --prefix=$INSTALL_PREFIX</pre>
  
GEGL and GIMP still use autotools. For GEGL, then GIMP (in that order!) do:
+
If you encounter errors about missing dependancies, look at these suggestions:
# Enter the source directory<pre>cd PATH/TO/DIRECTORY</pre>Replace with apropriate path
+
# If you downloaded a source Tarball, run the configure script with our desired install prefix<pre>./configure --prefix=$INSTALL_PREFIX</pre> Ohterwise, if you downloaded the source from git, run the autogen script with same argument<pre>./autogen.sh --prefix=$INSTALL_PREFIX</pre>If you encounter errors about missing dependancies, look at these suggestions:
+
 
#* When running it for GIMP, if you don't have Python and PyGtk, you'll need to disable them explicitly by appending the following argument to the command above<pre>--disable-python</pre>
 
#* When running it for GIMP, if you don't have Python and PyGtk, you'll need to disable them explicitly by appending the following argument to the command above<pre>--disable-python</pre>
 
#* When running it for GIMP, if you don't have gtk-doc, you'll need to disable it explicitly by appending the following argument to the command above<pre>--disable-gtk-doc</pre>
 
#* When running it for GIMP, if you don't have gtk-doc, you'll need to disable it explicitly by appending the following argument to the command above<pre>--disable-gtk-doc</pre>

Revision as of 21:59, 9 August 2019

This guide will explain you how to install GIMP, even without root/admin permissions/privileges. It will explain how to install GIMP to a custom location so that it won’t conflict with your existing GIMP installation. Through this guide, I’m going to use the bash shell for executing stuff from the command line – it’s usually located in /bin/bash.

Perquisites:

  • You should know roughly what is a command-line/terminal/shell. You should also know how to open the command-line/terminal/shell.
  • You should know roughly what are environment variables.
  • You should read and understand Hacking:Building

Note: This page is heavily based on this guide

DO NOT BUILD GIMP OR ITS DEPENDENCIES IN PREFIX /usr/local

Just don't. Start a new prefix either in /opt or /home/yourusername/blah. If you do and you run into problems, feel free to clean up and start over elsewhere. As a general rule, it is better to never use the root user except you know what you are doing. For this reason, we will assume you will set the prefix in a directory with write rights for your user (for instance under their $HOME directory). In particular it means that the `make install` steps will never need any root rights (i.e. no `sudo` needed).

If you know what you are doing and want to install in a directory with administrative rights, then… well you know what you are doing.

The Basics - Environment Variables

The main "problem" (don't worry, it's solvable) with compiling gimp on Linux, is environment variables. There are 3 environment variables which we should get to know when compiling things on Linux, and we’ll now present them:

PATH

First of all, this environment variable specifies where to look for executables. When you type "gimp" in the command line, all the directories inside the path will be searched.

lightning@nova:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games:/usr/local32/bin:.

As you can see, the path is composed out of a list of paths to directories, separated by ':' signs. The order of directories inside the path does matter! Directories which are listed first, are searched first!

PKG_CONFIG_PATH

This environment variable tells the pkg-config tool (a tool which is used to resolve most dependencies in GIMP’s compilation) where to look for the config files (which are used by pkg-config) for installed libraries.

LD_LIBRARY_PATH

Many executables used files which are called shared libraries – these files contain functionality that should be shared between executables. One example which you should know (if you are a Linux user) is Gtk+ – the library which is used by many applications (including GIMP) to create the user interface.

The executables search for these libraries inside some directories which are considered as “default”. So, in order for us to install and use libraries in other locations we need to update this variable to point to the directory leading to these libraries.

CFLAGS, CPPFLAGS, LIBS

These variables are used to specify additional arguments to the C compiler (CFLAGS), the C Pre-Processor (CPPFLAGS) and the linker (LIBS). Since we install things in paths other than the default, we will possibly need to use them to specify the tools where to look for our installed stuff.

What’s the problem with environment variables?

We don’t want to compile GIMP and install it in the default location, because then it may conflict with our existing installation. But if we install GIMP at a different location, we need to configure the environment variables so that the correct versions of libraries will be found and used, both for compilation and for running GIMP.

Preparing for compilation

First of all, we need to decide where do we want to install the alternative version of GIMP. To make it easy to remember and use, we’ll define an environment variable containing that path:

export INSTALL_PREFIX=$HOME/dev/gimp-prefix/

We will also need a directory to download the sources to; this is the directory I used. Change it to your own:

export SRC_DIR=/vol/scratch/gimp-beta/src

You’ll need to make sure both of these directories actually exist, and if not, create them. You can do it by running following commands:

mkdir -p $INSTALL_PREFIX
mkdir -p $SRC_DIR

Now, remember the discussion we had about environment variables?

Create a file called $INSTALL_PREFIX/share/config.site containing the following:

export PATH=$INSTALL_PREFIX/bin:$PATH
export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig:$GIMP_PREFIX/share/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=$INSTALL_PREFIX/lib:$LD_LIBRARY_PATH

In the first line, we update the PATH variable, so that looking for executables will begin in our installation directory (executables will be installed into the bin subdirectory). In the second line, we tell pkg-config that it should begin searching for library config files in our installation directory. This will resolve many compilation issues! For example, this will allow us to compile plug-ins against our updated version of the GIMP libraries, even if we have the old ones installed. In the third line, we tell the library loader that it should first of all try to look for libraries in our installation directory – this will prevent it from loading the libraries of other GIMP versions (that can cause trouble...).

Dependencies

Since you already read about GIMP's dependencies in Hacking:Building, you should already know roughly what does GIMP rely on. Any recent linux distribution should have most dependencies listed in the previous page, except for babl and GEGL. If you'll encounter errors in the process, about missing dependencies or too old versions of dependencies, see the troubleshooting section at the bottom of this page.

NOTE: some distribution have more up-to-date versions of libraries, and therefore are more adapted for developers. For instance: Debian Testing, Fedora… In particular using some user-oriented distributions (for instance Ubuntu), you will have more dependencies to build yourself, and in worst cases, you may encounter dependency conflicts.

Some packages you will probably need, if you don't already have them (install with apt install on Debian): build-essential meson libjson-c-dev gobject-introspection This is not a complete list: you will probably need other packages.

Compiling packages from source

If you're building GIMP git master, you'll need the latest version of libmypaint, mypaint-brushes, babl, and gegl, and you'll have to build those all from source. Babl uses meson for its builds; the other tools use autotools and make.

babl

git clone https://gitlab.gnome.org/GNOME/babl.git
SRCDIR=$(pwd)
BUILD_DIR=$SRCDIR/obj-$(arch)
mkdir -p $BUILD_DIR
cd $BUILD_DIR
meson -Dprefix=$INSTALL_PREFIX $SRCDIR && ninja && ninja install

libmypaint

git clone https://github.com/mypaint/libmypaint.git
cd libmypaint/
git checkout -t origin/libmypaint-v1
./autogen.sh && ./configure --prefix=$INSTALL_PREFIX && make && make install

libmypaint-brushes

If you're building GIMP from git master, you'll probably also need to build libmypaint-brushes. Sorry, there are no explicit instructions for that here yet.

GEGL and GIMP

git clone https://gitlab.gnome.org/GNOME/gegl.git git clone https://gitlab.gnome.org/GNOME/gimp.git

The instructions for the two directories are the same. Build gegl first, then gimp.

  1. If you downloaded a source Tarball, run the configure script with our desired install prefix
./configure --prefix=$INSTALL_PREFIX

Otherwise, if you downloaded the source from git, run the autogen script with same argument:

./autogen.sh --prefix=$INSTALL_PREFIX

If you encounter errors about missing dependancies, look at these suggestions:

    • When running it for GIMP, if you don't have Python and PyGtk, you'll need to disable them explicitly by appending the following argument to the command above
      --disable-python
    • When running it for GIMP, if you don't have gtk-doc, you'll need to disable it explicitly by appending the following argument to the command above
      --disable-gtk-doc
    • When running it for GIMP, if you got some error message about some missing libraries, and they weren't listed as the core dependancies of GIMP in Hacking:Building, you can try to disable them. You can list the options that the configure script accepts by running
      ./configure --help
      You can do the same with the autogen script (since it passes it's flags to the configure script!)
      Now, look for some option which is called --disable-XXX or --without-XXX, where XXX is the thing which causes your problem. If you found such an option, simply append it to the list of arguments (without the --help) and try again.
  1. Run make
    make
  2. Run make install
    make install

Running our compiled version of GIMP

Now, we should be careful before running GIMP. Our compilation was done with some very specific environment variables, and running GIMP will depend on them! So, let’s save our environment variables into a script that runs GIMP:

echo "#! /bin/bash

# set the path to the installation directory
export INSTALL_PREFIX=$INSTALL_PREFIX

# set the path to the directory into which we download the sources
export SRC_DIR=$SRC_DIR

# Now, set mandatory enviroment variables
export PATH=\$INSTALL_PREFIX/bin:\$PATH
export LD_LIBRARY_PATH=\$INSTALL_PREFIX/lib:\$LD_LIBRARY_PATH

# Not needed for running GIMP directly, but needed if you want to compile anything against our
# builds (think of plug-ins, etc.)
export PKG_CONFIG_PATH=\$INSTALL_PREFIX/lib/pkgconfig:\$PKG_CONFIG_PATH

# Now you can run executables our other stuff depending on our environment
# Here we run GIMP, and pass it any arguments given to this script
\$INSTALL_PREFIX/bin/gimp-2.10 \$@

# If you want to run something else, copy paste into bash everything before the line that
# runs GIMP, and then run it
" > $INSTALL_PREFIX/run-gimp.sh

chmod +x $INSTALL_PREFIX/run-gimp.sh

This command creates a script file called run-gimp.sh (inside our installation directory), which sets our environment variables, and then runs GIMP. The script will also contain instructions about running things other than GIMP using our environment. If you finished this step without errors, you should now have a working build of GIMP! Note: If you compiled a gimp version other than 2.10, replace the 2.10 with the correct version.

Troubleshooting

  • I’m getting an error about a too low of GTK+/GLib while compiling XXX
    You can either update your version of GTK+/GLib using your system’s package manager, or compile GTK+/GLib from source! Compiling these is done exactly like we compiled babl – download the source (either the latest from Git, or a package from the official site), compile and install. You may also need to do something like this to a library called ATK.
  • I’m getting some error about relative path in the prefix
    The installation directory of libraries/executables must be specified in an absolute path and not in a relative path. If you got this error, it means that one of the paths in your environment variables is relative and not absolute – fix that!
  • I'm getting errors about missing/old version of Gtk+/Glib/etc.
    The 3/4 step process described in Hacking:Building for building should work for building most if not all of GIMP's dependancies. Like we compiled GIMP, you should download the sources, run configure then make and finally make install. Use Google or some other search engine to find the website of the package and download it's source from it. Of course that if possible, you should try to install these dependencies through your system's package manager (if you have root permissions) and by that you'll save the time and effort of the compilation.


Building the Documentation

To build the documentation

git clone --depth=0 git@gitlab.gnome.org:GNOME/gimp-help.git
cd gimp-help
./autogen.sh [--without-gimp ALL_LINGUAS="en"]
LINGUAS=en make
LINGUAS=en make pdf-local

Substitute your language options in the above.

Notes
The production of the documentation requires docbook and ancillary programs. Here are some of the other programs;
gettext
automake
docbook2odf
pngcrush
pngnq
docbook-xsl
docbook-utils
dblatex
Which may or may not already installed. Running autogen will stop at the failed dependency, so install and repeat the process till autogen finishes.


It is recommended that you read the README.