Skip to content

Instantly share code, notes, and snippets.

@ryan-robeson
Last active September 1, 2024 19:31
Show Gist options
  • Save ryan-robeson/5841f712ff23c910bbbfac793c16bfad to your computer and use it in GitHub Desktop.
Save ryan-robeson/5841f712ff23c910bbbfac793c16bfad to your computer and use it in GitHub Desktop.
Building Resynthesizer for GIMP 2.10.10 on macOS

Building Resynthesizer for GIMP 2.10.10 on macOS - V2

Feedback is welcome and appreciated.

  • If you'd prefer to do things by hand check out Version 1 of this guide.

The following documents the steps I took to compile the latest version of Resynthesizer on macOS Sierra (10.12.6) for GIMP 2.10.10.

Homebrew was used to fulfill as many dependencies as possible.

After writing Version 1, I decided to make a Tap available which contains libgimp2.0. This should simplify the process of compiling GIMP plugins on macOS.

This guide assumes you'll be running Resynthesizer under GIMP 2.10.10 installed with brew cask install gimp.

Overview

  1. Setup build directory
  2. Acquire sources
  3. Install dependencies
  4. Compile Resynthesizer
  5. Install Resynthesizer

1 - Setup build directory

# I setup my build directory as recommended by [this howto](https://www.GIMP.org/source/howtos/GIMP-git-build.html) on GIMP.org.
# It allows us to keep things contained.

# You can put your build directory wherever is convenient.
# However, it's best if it's a new, empty directory unless you know what you're doing.

# We will assume that our build directory is '~/Code/build-gimp-plugins'.
# Let's refer to this directory with a variable
PREFIX=~/Code/build-gimp-plugins

# We need to create this directory if it does not exist.
mkdir -p $PREFIX

# We also need to create a couple other important directories.
mkdir -p $PREFIX/share # This is where config.site should be placed.
mkdir -p $PREFIX/bin

# In my case, I had installed perl from Homebrew at some point in the past.
# It did not come with a module Resynthesizer needed to compile, so rather than install
# that module which may have worked, I symlinked the system perl into $PREFIX/bin
# to make sure it was used instead of the Homebrew version.
# You may or may not have this issue.
# ln -s /usr/bin/perl $PREFIX/bin/perl

# Make sure you've placed 'config.site' in $PREFIX/share

2 - Acquire sources

# Now we're going to get the Resynthesizer source.
# Make sure we're in our build directory
cd $PREFIX

# Resynthesizer
git clone git://github.com/bootchk/resynthesizer.git

# Now's the time to `git checkout` a branch or tag if you don't want to compile
# Resynthesizer's latest code.

3 - Install dependencies

# Resynthesizer needs libgimp2.0 to compile
brew tap ryan-robeson/gimp
brew install libgimp2.0

4 - Compile Resynthesizer

# We're on the home stretch now
cd resynthesizer

# NOTE: @SimplyTheOther found the following change to be unnecessary on their system.
#       You should be able to skip editing the Resynthesizer source. I'm going to leave
#       the info here for now just in case.
#
# ** You can likely skip this ** #
# In order to get Resynthesizer to compile on macOS, I had to make a small change in the source.
# Open lib/engineTypes.h in your editor of choice.
# At the end of the file is the definition for swap_vector_elements.
# Add 'static' in front of 'inline void'.
# Save and exit.
# Without this change I was getting a 'symbol(s) not found' error.
# I got the idea to add 'static' from https://stackoverflow.com/a/19069107
# I do not know what the ramifications of this change are, I only know that it compiled and seems to work.
# ** end skip ** #

./autogen.sh --prefix=$PREFIX
make
# I don't believe `make install` will do what we want here, so skip it.

# If there are no errors, proceed to the next step.

5 - Install Resynthesizer

# You could copy the plugin files to one of GIMP's default plugin directories, 
# but I decided to put them in their own directory and tell GIMP about it.

mkdir plug-ins
cp src/resynthesizer/resynthesizer plug-ins/
cp src/resynthesizer-gui/resynthesizer_gui plug-ins/
cp PluginScripts/*.py plug-ins/
chmod a+x plug-ins/*.py

# Now open your system's copy of GIMP (installed by Homebrew Cask in my case),
# open Preferences, expand the folders dropdown, select Plug-ins, and add the plug-ins folder
# we just created to the list.
# Click OK. Then restart GIMP.

# Filters > Enhance > Heal Selection and several others should now be available.
# This is an example config.site for building plugins manually after
# installing libgimp2.0.
# It should be placed in $PREFIX/share/
# It may need to be adjusted based on your plugin's dependencies.
# A convenient reference for our Homebrew install dir
: ${HOMEBREW_ROOT:=$(brew --prefix)}
export PATH="$PREFIX/bin:$HOMEBREW_ROOT/opt/gettext/bin:$PATH"
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PREFIX/share/pkgconfig:$HOMEBREW_ROOT/lib/pkgconfig:$HOMEBREW_ROOT/opt/gegl/lib/pkgconfig:$HOMEBREW_ROOT/opt/libffi/lib/pkgconfig:$PKG_CONFIG_PATH"
export LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"
export ACLOCAL_FLAGS="-I $PREFIX/share/aclocal -I $HOMEBREW_ROOT/opt/gettext/share/aclocal/ -I $HOMEBREW_ROOT/share/aclocal $ACLOCAL_FLAGS"
export LDFLAGS="-L$HOMEBREW_ROOT/opt/gettext/lib -L$HOMEBREW_ROOT/lib $LDFLAGS"
export CPPFLAGS="-I$HOMEBREW_ROOT/opt/gettext/include -I$HOMEBREW_ROOT/include $CPPFLAGS"
@flyisland
Copy link

Hi @ryan-robeson, thanks for your quick response!

Please check the blow output, it seems that there're still some components missing due to the python 3.

$ brew update
Updated 3 taps (homebrew/core, homebrew/cask and ryan-robeson/gimp).
==> New Formulae
ryan-robeson/gimp/pygtk
==> Updated Formulae
azure-cli ✔                  dmd                          docker-compose               dub                          ejdb                         icecast                      mercurial                    pipx

$ brew install --build-from-source libgimp2.0
==> Installing libgimp2.0 from ryan-robeson/gimp
Error: No available formula with the name "pygobject" (dependency of ryan-robeson/gimp/libgimp2.0)
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow

pygobject was deleted from homebrew/core in commit fcfa254fcf:
  pygobject: delete
  Does not support Python 3, and needs pygtk which has been removed.

To show the formula before removal run:
  git -C "$(brew --repo homebrew/core)" show fcfa254fcf^:Formula/pygobject.rb

If you still use this formula consider creating your own tap:
  https://docs.brew.sh/How-to-Create-and-Maintain-a-Tap

@ryan-robeson
Copy link
Author

@flyisland, I've now added pygobject to my Tap as well.

Hopefully that will get things working.

I tried to check for other dependencies being removed, and couldn't find any, but I may have missed something.

@flyisland
Copy link

hi @ryan-robeson, please check ryan-robeson/homebrew-gimp#2 , thanks.

@rljhaines
Copy link

rljhaines commented Oct 25, 2020

Are you doing all this as root? When I begin to follow your guide as User, which from my home directory is the most natural jumping-off point, I end up with an undesirable directory (for building gimp plugins) under my home path of "~" (such that when I'm in build-gimp-plugins, it's ~/~/Code/build-gimp-plugins). Then, when attempting to proceed from / as User in the interest of creating the Code directly into the user path (~, to realize ~/Code/build-gimp-plugins), I'm advised / is a read-only directory (for User). The first reality all this seems to suggest is that this process is being done as root. Please advise. Thank you!

@ryan-robeson
Copy link
Author

Hi @rljhaines, all of this is done with a standard user account. Root should not be necessary.

It sounds like an issue of quoting if you are ending up with a directory structure like:

- ~
  |- ~
    |- Code
      |- build-gimp-plugins

Please post the commands you are using.

@rljhaines
Copy link

Here's a screenshot (maybe).

Screen Shot 2020-10-25 at 2 24 38 PM

@ryan-robeson
Copy link
Author

It is a quoting issue. Thanks for catching that.

Try PREFIX=~/Code/build-gimp-plugins instead. I'll update the instructions accordingly

@rljhaines
Copy link

Thank you! I should maybe have guessed as much, but I sometimes become linear in my thinking when following instruction :-D

@rljhaines
Copy link

Do you have guidance to offer regarding my failed autogen.sh? I have all the files in a few different places on my Catalina machine, but I don't know what 'autoconf macro directory' refers to. And I don't know if I can set the ACLOCAL_FLAGS -I [eye] /some/dir twice, as glib-gettext.m4 and intltool.m4 are in different places. Please advise. Thank you!

Screen Shot 2020-10-25 at 5 04 09 PM

Screen Shot 2020-10-25 at 5 03 42 PM

@ryan-robeson
Copy link
Author

Did you add the config.site above to $PREFIX/share?

It also looks like you are using perl from Homebrew. I had to link the system perl into the $PREFIX/bin directory to get the build to succeed.

ln -s /usr/bin/perl $PREFIX/bin/perl

@rljhaines
Copy link

Crud. I always do intend to be more careful. I'd made a mental note to attempt using the link to /usr/bin/perl if I didn't have success without it, but I guess when those other error messages seemed to indicate more it slipped my mind.

Anyway, that didn't cut it, and I'm getting the same error messages, including the Parser Perl Module error.

Yes, I have the config.site in the share directory, copied and pasted. I made it executable, not knowing if that was necessary, and still no luck.

It feels like the next step is to link all the requisite m4 files to the proper directory, but I don't know what that directory is :-(

Screen Shot 2020-10-26 at 11 26 10 AM

@ryan-robeson
Copy link
Author

Ok, for the Perl error, let's verify that XML::Parser is not installed for the system Perl:

/usr/bin/perl -MXML::Parser -e 1

If that returns an error (it likely will), then you can try cpan XML::Parser. Assuming that works, you can delete the symlink rm $PREFIX/bin/perl as the previous command should have installed the module under your Homebrew install of Perl.

For the aclocal errors:

First, make sure you have glib, gettext, and intltool installed: brew info gettext, brew info intltool, brew info glib. Then, if necessary, you can modify the ACLOCAL_FLAGS variable inconfig.site to include their aclocal directories. However once installed, on my machine at least, the relevant files were automatically symlinked into $(brew --prefix)/share/aclocal which is already included in config.site as $HOMEBREW_ROOT/share/aclocal. So, you may only need to install the missing formula.

@rljhaines
Copy link

Hello, Ryan. The /usr/bin/perl -MXML::Parser -e 1 command returned nothing whatsoever, and the cpan XML::Parser command seems to have put my perl aright. I now have Resynthesizer compiled and installed.

The compile complained about the aclocal files again as shown in the attached image, but I have confirmed that I do have functional Enhance > Heal Selection in gimp.

As to the aclocal files, I do have them on my system and prior to compiling I symlinked them all to $PREFIX/share/aclocal, which you have included in config.site. So, the fact that I have Heal Selection (etc) doesn't make a whole lot of sense to me, and raises some concern that I'm missing some functionality.

If I'm in the mood sometime, can I symlink those files (shown in the image) to $(brew —prefix)/share/aclocal and compile again to see if I'm greeted with the same message?

Thank you.

Screen Shot 2020-10-27 at 6 47 32 PM

Screen Shot 2020-10-27 at 7 07 01 PM

@ryan-robeson
Copy link
Author

Glad you've gotten it working for the most part.

If I'm in the mood sometime, can I symlink those files (shown in the image) to $(brew —prefix)/share/aclocal and compile again to see if I'm greeted with the same message?

I would guess that it would be equivalent to what you've already done, but may be worth a shot.

I did notice that some of your links point to /opt/local instead of /usr/local. That leads me to believe you're also using MacPorts. Combining files from MacPorts and Homebrew can occasionally lead to strange problems.

@rljhaines
Copy link

Thank you for Resynthesizer and the assistance!

@ryan-robeson
Copy link
Author

Happy to help! Can't take credit for Resynthesizer though. I've just tried to make compiling GIMP plugins for macOS a little more straightforward.

@51ngul4r1ty
Copy link

@ryan-robeson I just installed the dependencies using brew install libgimp2.0 and ran into an error:

==> Pouring [email protected]_1.catalina.bottle.tar.gz
tar: Error opening archive: Failed to open '/Users/kevin/Library/Caches/Homebrew/downloads/323d92a2d15821382d03c20caaadab64fed10ad8f0d0da64ddccea6326ce4a6a--python@2-2.7.17_1.catalina.bottle.tar.gz'
Error: Failure while executing; `tar xof /Users/kevin/Library/Caches/Homebrew/downloads/323d92a2d15821382d03c20caaadab64fed10ad8f0d0da64ddccea6326ce4a6a--python@2-2.7.17_1.catalina.bottle.tar.gz -C /var/folders/r5/6pm7b2214wb6km4nvfb39nfw0000gn/T/d20210201-7614-vk1yt9` exited with 1. Here's the output:
tar: Error opening archive: Failed to open '/Users/kevin/Library/Caches/Homebrew/downloads/323d92a2d15821382d03c20caaadab64fed10ad8f0d0da64ddccea6326ce4a6a--python@2-2.7.17_1.catalina.bottle.tar.gz'

Warning: Bottle installation failed: building from source.
==> ./configure --prefix=/usr/local/Cellar/python@2/2.7.17_1 --enable-ipv6 --datarootdir=/usr/local/Cellar/python@2/2.7.17_1/share --datadir=/usr/local/Cellar/python@2/2.7.17_1/share --enable-framew
==> make
Last 15 lines from /Users/kevin/Library/Logs/Homebrew/python@2/02.make:
    cmd_obj.run()
  File "/private/tmp/python-2-20210201-13470-bhg0mw/Python-2.7.17/Lib/distutils/command/build.py", line 127, in run
    self.run_command(cmd_name)
  File "/private/tmp/python-2-20210201-13470-bhg0mw/Python-2.7.17/Lib/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/private/tmp/python-2-20210201-13470-bhg0mw/Python-2.7.17/Lib/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/private/tmp/python-2-20210201-13470-bhg0mw/Python-2.7.17/Lib/distutils/command/build_ext.py", line 340, in run
    self.build_extensions()
  File "./setup.py", line 228, in build_extensions
    missing = self.detect_modules()
  File "./setup.py", line 805, in detect_modules
    (tuple(int(n) for n in dep_target.split('.')[0:2])
AttributeError: 'int' object has no attribute 'split'
make: *** [sharedmods] Error 1

I'm running Big Sur- so I figured that's why I'm seeing this error. How's the best way to address this?

@beebird
Copy link

beebird commented Feb 25, 2021

@ryan-robeson I have successfully built Resynthesizer and get the plugin loaded by gimp-2.10.22 which is installed via brew.

However, every time when I select an area and run "Heal selection", gimp throws a RuntimeError: The texture source is empty. Does any selection include non-transparent pixels?

Do you have any idea? I'm running Big Sur.

@yorkshirelandscape
Copy link

yorkshirelandscape commented Jan 3, 2023

Hi @ryan-robeson - Looks like it's been a little while since people have tried this, but in case there's life in it...
I'm running into trouble at installing libgimp2.0 under MacOS Ventura on Apple Silicon. I consistently get:
Error: [email protected]: undefined method 'cellar' for #<BottleSpecification:0x0000000147d15d10>

Any thoughts? Any help you can offer is much appreciated, as is putting all this together to begin with.

@rljacobson
Copy link

I consistently get: Error: [email protected]: undefined method 'cellar' for #<BottleSpecification:0x0000000147d15d10>

I am getting the same error.

@davegoldin
Copy link

I am on Sonoma 14.1.2 and Homebrew 4.1.25 on Apple Silicon. Following these two commands – brew tap ryan-robeson/gimp and brew install [email protected] – I am getting the same error as prior two posters. @ryan-robeson Any guidance you can provide? Thanks.

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