Skip to content

Instantly share code, notes, and snippets.

@tinchodias
Last active August 5, 2022 13:49
Show Gist options
  • Save tinchodias/904675d22288cbb126eaabaf75aeb88c to your computer and use it in GitHub Desktop.
Save tinchodias/904675d22288cbb126eaabaf75aeb88c to your computer and use it in GitHub Desktop.
Unofficial notes

Building Pharo's Third-Party Graphics Libraries

I'm only learning to do this stuff, not an expert!

Pharo has FFI bindings to freetype, cairo and SDL. Such bindings talk to dynamic libraries depending on the running platform:

  • Tha Mac VM provides dylibs for all of them.
  • The Win VM provides dlls. Must CHECK
  • The Linux VM does provide a .so for SDL, but doesn't for freetype and cairo. In such cases, Pharo looks at system's shared libraries.

Download and build

The following steps work on Mac, but had issues on Linux (an Ubuntu 22.04). See inlined comments.

  1. Change directory to a temporary location such as /tmp/pharoVmLibs
  2. Set a build BUILD_DIR env variable where the libraries will be installed, for example:
BUILD_DIR=/tmp/pharoVmLib/build
  1. Execute next script:
# png uses zlib
ZLIB_FILENAME=zlib-1.2.12
wget https://zlib.net/${ZLIB_FILENAME}.tar.gz
tar xvf ${ZLIB_FILENAME}.tar.gz
cd ${ZLIB_FILENAME}
./configure --prefix=${BUILD_DIR}
make install
cd ..

# freetype uses png (bitmap fonts such as emojis)
LIBPNG_FILENAME=libpng-1.6.37
wget https://download.sourceforge.net/libpng/${LIBPNG_FILENAME}.tar.gz
tar xvf ${LIBPNG_FILENAME}.tar.gz
cd ${LIBPNG_FILENAME}
# PKG_CONFIG_PATH="$PKG_CONFIG_PATH:${BUILD_DIR}/lib/pkgconfig" cmake . -DCMAKE_PREFIX_PATH=${BUILD_DIR}/ -DCMAKE_INSTALL_PREFIX:PATH=${BUILD_DIR}/
./configure --prefix=${BUILD_DIR}
make install
cd ..

FT_FILENAME=freetype-2.12.1
wget https://download.savannah.gnu.org/releases/freetype/${FT_FILENAME}.tar.gz
tar xvf ${FT_FILENAME}.tar.gz
cd ${FT_FILENAME}
./configure --prefix=${BUILD_DIR}
make install
cd ..

# cairo uses pixman
PIXMAN_FILENAME=pixman-0.40.0
wget https://www.cairographics.org/releases/${PIXMAN_FILENAME}.tar.gz
tar xvf ${PIXMAN_FILENAME}.tar.gz
cd ${PIXMAN_FILENAME}
./configure --prefix=${BUILD_DIR}
make install
cd ..

CAIRO_FILENAME=cairo-1.17.4
wget https://www.cairographics.org/snapshots/${CAIRO_FILENAME}.tar.xz
tar xvf ${CAIRO_FILENAME}.tar.xz
cd ${CAIRO_FILENAME}
# Disable platform-specific backends that Pharo vindings do not use
./configure --prefix=${BUILD_DIR} --disable-fc --disable-xlib --disable-xcb
make install
cd ..
#
# TO BE FIXED (linux):
# ldd ${BUILD_DIR}/lib/libcairo.so
# --> it links the new libcairo to system's pixman, freetype, png and libz. 
# ----> It should link to the libs in ${BUILD_DIR}
#

# this build is independent of previous builds
SDL_VERSION=2.0.22
wget https://libsdl.org/release/SDL2-${SDL_VERSION}.tar.gz
tar xvf SDL2-${SDL_VERSION}.tar.gz
cd SDL2-${SDL_VERSION}
./configure --prefix=${BUILD_DIR}/
make install
cd ..
# 
# Question (linux): Why is it so different the result of:
#   ldd ${BUILD_DIR}/lib/libSDL2.so
# versus:
#   ldd /lib/x86_64-linux-gnu/libSDL2-2.0.so
# and is it a problem?
#

Install built libs on Pharo VM

MacOS

  1. Change to the Plugins directory of a VM
  2. Ensure BUILD_DIR env var is set, and execute:

//TO DO: add libSDL2 and test

for LIB_PREFIX in libfreetype libpixman- libz libpng libcairo.
do 
  echo
  echo --- Updating ${LIB_PREFIX} ---
  echo
  echo Removing:
  echo
  rm -v ${LIB_PREFIX}*dylib  
  cp -a ${BUILD_DIR}/lib/${LIB_PREFIX}*dylib . 
  echo
  echo Copying:
  echo
  ls -lah ${LIB_PREFIX}*dylib 
done

Linux

  1. Change to the libs directory of a VM
  2. Ensure BUILD_DIR env var is set, and execute:
for LIB_PREFIX in libfreetype libpixman libz libpng libcairo libSDL2
do 
  echo
  echo --- Updating ${LIB_PREFIX} ---
  echo
  echo Removing:
  echo
  rm -v ${LIB_PREFIX}*so*
  cp -a ${BUILD_DIR}/lib/${LIB_PREFIX}*so* .
  echo
  echo Copying:
  echo
  ls -lah ${LIB_PREFIX}*so*
done

Windows

// TO DO

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment