Build libresprite for slackware

From Studiosg
Jump to navigationJump to search

Welcome to Simone Giustetti's wiki pages.


Languages: English - Italiano


How-to Build LibreSprite for Slackware Linux

LibreSprite is a bitmap editor capable to produce digital art and aimed towards pixel art. It can be used to design both static and animated sprites for 2-D video games, for example, and has the rich set of features one would expect from a modern application and some more meant specifically for sprites and backgrounds. The program offers among other features:

  • Real-time animation previews;
  • Onion skinning enabling any artist to retain a copy of the previous frame of an animation as a background while drawing the new one;
  • Multiple sprites can be edited at once;
  • The program offers some ready for use color palettes;
  • Create your own customized color palettes;
  • Sprites are composed of both layers and frames;
  • Create tiles and use them to produce tiled images;
  • Pixel precise drawing tools;
  • It supports several file formats for both sprites and animations.

One recently added functionality consists in scripting in JavaScript, but it requires NodeJS, the JavaScript interpreter built around the V8 Chromium engine, to be installed on your Linux box.

LibreSprite originated forking Aseprite in 2016 after its license was moved to a proprietary one. Development went on in parallel and the two projects are now unrelated. LibreSprite is made available for a multitude of UNIX like systems; among them: Linux, Android and, since release 1.1, MacOsX; a Windows version is available too. No official package for Slackware Linux exists as developers do not seem to favor any distro, but release an AppImage package instead, formally able to be run on any 64 bit Linux system. Sadly the lastly released package, LibreSprite 1.1, includes a dependency to a glibc library version incompatible with the Slackware 15.0 included one. Slackware users have no choice but to use older release 1.0, dating back to 2021 and lacking all of the added functionality. I wanted to play with the latest release and managed to build a working package and subsequently shared the used build script to allow other users to do the same. In the following page I'll provide some detailed information about the build process and the "tricks" used to write a working script.

Read the LibreSprite Source Code

The first step to the goal consisted in reading the LibreSprite source code to understand which programming language was used, the required dependencies and the tools to use in the process. All of the source code is available through GitHub, included in the project repository. You are strongly suggested to read the README.md and INSTALL.md files which both include a lot of information useful for the task at hand. Specifically:

  • The program is written in 2014 C++ or C++14.
  • The build system consists of a combination of CMake and Ninja. The former is used to produce the makefile for the latter, which instead is used to perform the building and installation.
  • Support for the lua scripting language, used in earlier releases to produce automation scripts and macros inside the program, was removed and JavaScript support introduced instead. Scripting requires a working NodeJS. NodeJS is optional and not officially supported by Slackware therefore I ignored it hoping to obtain a lighter package. Interested parties can use one of the many NodeJS packages available on-line. AlienBob provides a ready for use package through his blog. Whoever wishes to build her/his own package can use build scripts provided by the SlackBuils.org project.
  • It links to many libraries in order to support a large number of image and animation formats. Some of the linked libraries are part of the standard Slackware package set while others are available somewhere else. More detail will be provided in the next paragraph.
  • There are 2 versions of the LibreSprite source code archive. This is a somewhat obscure notion that I learned the hard way after a brief series of failed attempts at building. The LibreSprite-1.1.tar.gz archive includes the source code of the main program only, with no third party modules at all. Some third party modules are required by the build procedure that cannot work without. The SOURCE.CODE.+.submodules.tar.gz archive includes source code for the third party modules too and is the only fully whole one, able to build the program with no error whatsoever. Deceived by the name, believing the third party modules to be optional, I initially downloaded the first archive only to learn the hard way it is unsuitable to the task thorough many a failure signaling missing libraries. Using the second archive proved to be the right choice.

LibreSprite Dependencies

I'll provide a list of all the libraries LibreSprite requires in order to compile successfully and notes about where to find them:

  • curl: Standard Slackware Linux package;
  • duktape: Can be found inside the SOURCE.CODE.+.submodules.tar.gz archive, but not inside LibreSprite-1.1.tar.gz;
  • freetype: Standard Slackware Linux package;
  • giflib: Standard Slackware Linux package;
  • gtest: Is one of the Project SlackBuilds.org packages;
  • libjpeg: Standard Slackware Linux package;
  • libpng: Standard Slackware Linux package;
  • libwebp: Standard Slackware Linux package;
  • libX11: Standard Slackware Linux package;
  • libXcursor: Standard Slackware Linux package;
  • loadpng: I could not find anything about, but no alert was raised while building;
  • modp_b64: Can be found inside the SOURCE.CODE.+.submodules.tar.gz archive, but not inside LibreSprite-1.1.tar.gz;
  • pixman: Standard Slackware Linux package;
  • SDL2: Standard Slackware Linux package;
  • simpleini: Is one of the Project SlackBuilds.org packages, but some traces of it are included in the SOURCE.CODE.+.submodules.tar.gz archive;
  • tinyxml2: Is one of the Project SlackBuilds.org packages;
  • zlib: Standard Slackware Linux package.

Before starting any test, I checked for all of the Slackware Linux standard libraries to be installed, I downloaded and installed the SlackBuilds.org provided ones and I finally downloaded the SOURCE.CODE.+.submodules.tar.gz archive, providing the remaining ones.

The SlackBuild Script

Once all of the libraries were in place, I moved to the build script. I wanted a simple script, the more standard the better, thus I adopted on of the templates provided by the SlackBuilds.org project and imposed myself to follow their guidelines as much as possible:

  • Here you can find the script template for a CMake build;
  • Here the related guidelines.

Every program has its distinctive traits and LibreSprite is not different. The template required some work: the added lines of code are presented in the following paragraph along with some commentary:

I obviously had to set the package name and its version:

   PRGNAM=libresprite
   VERSION=${VERSION:-1.1}

I added a variable for the source archive file name as it presented no relation to the package one:

   SRC="SOURCE.CODE.+.submodules"

I added a line tasked to create the libresprite-1.1 sub-directory where to save the compiled files as the source code archive is organized in a way that prevents the tar utility to do so while extracting, as is usually the case:

   mkdir ${PRGNAM}-${VERSION}

The SRC variable was used to decompress the source code tar archive:

   tar -xvf ${CWD}/${SRC}.tar.gz

I added a line to clean the CMake cache before starting the build. The script template had nothing of the sort, but previous experience taught me it's the sensible thing to do:

   # Clean cmake cache
   find . -name CMakeCache.txt -exec rm {} \;

CMake required some specific parameters and Ninja a directory where to copy install files:

   mkdir -p build
   cd build
   cmake \
      -DCMAKE_C_FLAGS:STRING="${SLKCFLAGS}" \
      -DCMAKE_CXX_FLAGS:STRING="${SLKCFLAGS}" \
      -DCMAKE_INSTALL_PREFIX=/usr \
      -DLIB_SUFFIX=${LIBDIRSUFFIX} \
      -G Ninja ..
   
   ninja libresprite
   
   DESTDIR=${PKG} ninja install

The source code includes no man pages nor any info ones, the documentation consists of some text files that need copying to the proper destination:

   # No man pages & no info ones
   
   # Copy program documentation into the package
   mkdir -p ${PKG}/usr/doc/${PRGNAM}-${VERSION}
   cp -a \
      ${TMP}/${PRGNAM}-${VERSION}/docs/* \
      ${PKG}/usr/doc/${PRGNAM}-${VERSION}
   cat ${CWD}/${PRGNAM}.SlackBuild > ${PKG}/usr/doc/${PRGNAM}-${VERSION}/${PRGNAM}.SlackBuild

At last, being a graphical application, LibreSprite requires some icons to show in the application bar and in menus of the supported desktop environments:

   # Copy some icons for the program
   mkdir -p ${PKG}/usr/share/applications/
   cp ${TMP}/${PRGNAM}-${VERSION}/desktop/libresprite.desktop ${PKG}/usr/share/applications/
   cp -r ${TMP}/${PRGNAM}-${VERSION}/desktop/icons ${PKG}/usr/share/
   mkdir -p ${PKG}/usr/share/pixmaps
   cp ${TMP}/${PRGNAM}-${VERSION}/desktop/icons/hicolor/48x48/apps/libresprite.png ${PKG}/usr/share/pixmaps/

That's it folks. The script can be downloaded form the following link. A second version with proper modifications was submitted to the SlackBuilds.org forum. It should become available once the project members will conclude the necessary review. Both versions share a lot of code and should work pretty much the same.

Using the SlackBuild Script

To build a working LibreSprite package you have to:

  • Download the SOURCE.CODE.+.submodules.tar.gz archive file in a local directory of your Linux box: /usr/src/libresprite-1.1 or /tmp, for example.
  • Copy the libresprite.SlackBuild script, thedoinstall.sh script and the slack-desc file in the directory were you located the source code.
  • Change script permissions making it executable with chmod:
   chmod u+rx libresprite.SlackBuild
  • Run the script through the shell:
   ./libresprite.SlackBuild

The script will do its thing extracting and building the source code. The task requires quite some time. The exact duration will vary based on your hardware: RAM, CPU, Hard drive and so on. The resulting package will be located in the /tmp directory; you can install it using the installpkg tool:

   installpkg /tmp/libresprite-1.1-x86_64-1_sg.txz

In the above example I installed a package for the Amd/Intel 64 bit architecture. Installing requires but a few instants. When done, LibreSprite will be immediately ready for use.

Some Screenshots

Libresprite splash screen.png

Fig: 1 - The program splash screen.

Libresprite new dark theme.png

Fig: 2 - The new optional dark theme.

Libresprite car animation.png

Fig: 3 - A simple 2-D race car.

Libresprite vase animation.png

Fig: 4 - A frame from a flying vase animation.

Libresprite soldier animation.png

Fig: 5 - An animated soldier (Volumes alone, no details).

Libresprite onion skinning.png

Fig: 6 - An "Onion Skinning" example.


CONCLUSIONS

This page introduces LibreSprite: an art oriented software useful to create pixel art and static and animated sprites. The software can work on Linux, but not Slackware nor any other distribution is actively supported. I presented a working build script, with full comments for the lines of code and some documentation for its use. Some screenshots, taken while using the software, were included as proof of what LibreSprite is capable of.


For any feedback, questions, errors and such, please e-mail me at studiosg [at] giustetti [dot] net


External links





Languages: English - Italiano