FluffyStuff / OpenRiichi

An open source riichi mahjong client
GNU General Public License v3.0
107 stars 17 forks source link

Building .app on Mac #22

Closed nikhiljha closed 5 years ago

nikhiljha commented 5 years ago

I built the executable with...

brew install vala lcsfml sfml csfml libgee libffi git
# replace the value of libffi with your actual libffi
# find it like this
# brew ls libffi
export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.2.1/lib/pkgconfig/
git clone https://github.com/FluffyStuff/OpenRiichi.git
git clone https://github.com/FluffyStuff/Engine.git
cd OpenRiichi
make mac

... and it works fine, but how do I make an actual packaged application to give to my friends?

FluffyStuff commented 5 years ago

The package is just a regular folder which contains an .icns icon file and an Info.plist file. You will need to place the built executable and the data folder into the root of the folder. Apart from that the only additional thing you need to do is place the sfml/csfml dylib files into the root. You can find them here.

You can also see the structure of the package I deploy here.

nikhiljha commented 5 years ago
Screen Shot 2019-03-10 at 4 32 30 PM

Unfortunately, that doesn't seem to work. (For that matter, your .app doesn't work either, which is why I was building it in the first place.) If I replace just the binary in your package then it runs, but only on my system. Everyone else has the same error as above.

nikhiljha commented 5 years ago

I took your folder, updated csfml dylibs (to match the newer ones I compiled against), put in my new binary and Data folder, and it works on my computer now.

Other people are getting

Dyld Error Message:
  Library not loaded: /usr/local/opt/glib/lib/libgio-2.0.0.dylib
  Referenced from: /Applications/OpenRiichi.app/OpenRiichi
  Reason: image not found
nikhiljha commented 5 years ago

I couldn't find an actual solution so I decided to just hack the binary. The following fish script should be run from the bin directory of the project, and assumes that the app folder is in downloads. Just unlink the system dependencies from local when it's done.

function mvx
      cp $argv ~/Downloads/OpenRiichi.app/
end

function brel
      install_name_tool -change $argv @executable_path/(basename $argv) OpenRiichi
end

for x in (otool -L ./OpenRiichi | cut -d' ' -f1 | cut -c2-)
      mvx $x[1]
end

for x in (otool -L ./OpenRiichi | cut -d' ' -f1 | cut -c2-)
     brel $x[1]
end

(Yes, I know this is a terrible solution, but I wanna play Mahjong :P)

nikhiljha commented 5 years ago

Apparently that didn't work either. The binary still tries to install stuff from cellar :/

FluffyStuff commented 5 years ago

Seems like the package is just missing a few dylibs. I'll take a look into this once I can.

nikhiljha commented 5 years ago

From looking at the logs, I think...

It's not so much that they're missing, but that MacOS tries to load them from the wrong place. (It's looking in /usr/local/ instead of the .application folder itself.)

nikhiljha commented 5 years ago
#!/usr/bin/env bash

# Verify homebrew.
echo "Verifying if you have homebrew installed..."
if hash brew 2>/dev/null; then
    brew update
else
    echo "You need to install brew. Get it from https://brew.sh"
    exit 1
fi

# Grab dependencies.
echo "Installing dependencies..."
xcode-select --install
brew install vala sfml csfml libgee libffi git jq pkg-config sdl2 sdl2_image glew pango

# Check what version of libffi was installed and link that.
echo "Finding libffi..."
export FFI_VER=$(brew info --json=v1 libffi | jq -r '.[0].installed[0].version')
export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/$FFI_VER/lib/pkgconfig/

# Download files to preset directory.
echo "Installing to ~/Documents/Games/"
mkdir -p ~/Documents/Games/
cd ~/Documents/Games/
echo "Downloading game..."
git clone https://github.com/FluffyStuff/OpenRiichi.git
git clone https://github.com/FluffyStuff/Engine.git

# Compile game.
echo "Compiling..."
cd OpenRiichi
make mac

# Create desktop shortcut.
echo "Creating desktop shortcut..."
ln -s ~/Documents/Games/OpenRiichi/bin/OpenRiichi ~/Desktop/OpenRiichi

# All done!
echo "Success! To uninstall just delete your desktop shortcut and the folders in ~/Documents/Games."

This doesn't set -e to keep things short but it shouldn't be destructive... in theory....