diff --git a/docs/developers/developers-setup.md b/docs/developers/developers-setup.md index ef09447..4b3b928 100644 --- a/docs/developers/developers-setup.md +++ b/docs/developers/developers-setup.md @@ -128,6 +128,25 @@ sudo rm -v /usr/local/share/locale/*/LC_MESSAGES/diffuse.mo Meson allows to change the default installation directories, see [command-line documentation](https://mesonbuild.com/Commands.html#configure). +## Setup on Mac OS + +Building on Mac OS is similar to building on Linux. To recap, these are +the steps needed to build and install Diffuse manually: + +```brew install meson python3 py3cairo pygobject3 gtk+3 + meson setup build + cd build + meson compile + meson test + meson install +``` + +After `meson install`, the `diffuse` command can be used to launch Diffuse +as a native Mac app that is installed into `/Applications/Diffuse.app`. + +The `diffuse` command is compatible with git. To use Diffuse as git's +`git difftool` run `git config --global diff.tool diffuse` + ## Setup on Windows _Note:_ The Windows port is not maintained and would need some love. diff --git a/src/diffuse/mac-os-app/Diffuse.app/Contents/Resources/diffuse.icns b/src/diffuse/mac-os-app/Diffuse.app/Contents/Resources/diffuse.icns new file mode 100644 index 0000000..03b345c Binary files /dev/null and b/src/diffuse/mac-os-app/Diffuse.app/Contents/Resources/diffuse.icns differ diff --git a/src/diffuse/mac-os-app/Info.plist.in b/src/diffuse/mac-os-app/Info.plist.in new file mode 100755 index 0000000..7e29659 --- /dev/null +++ b/src/diffuse/mac-os-app/Info.plist.in @@ -0,0 +1,22 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleExecutable + mac_launcher.sh + CFBundleIconFile + diffuse.icns + CFBundleIdentifier + io.github.mightycreak.Diffuse + CFBundleName + Diffuse + CFBundleShortVersionString + @VERSION@ + CFBundlePackageType + APPL + NSAppleScriptEnabled + NO + + diff --git a/src/diffuse/mac-os-app/diffuse-mac.in b/src/diffuse/mac-os-app/diffuse-mac.in new file mode 100755 index 0000000..e4bb412 --- /dev/null +++ b/src/diffuse/mac-os-app/diffuse-mac.in @@ -0,0 +1,14 @@ +#!/bin/bash +# +# This is the command-line entry point on Mac. +# +# We want to use Mac's `open` command for mainly two reasons; +# a) open lets us choose our own icon. +# b) open puts the app on top of the other windows, including the terminal we ran this from. +# +# --new lets us open multiple windows. +# --wait-apps lets Diffuse be a "git difftool", letting Diffuse run before git deletes its tmp files. +# +# We pass "pwd" because Mac's `open` command launches processes at '/'. +# "printf %q" escapes spaces and other characters so the complete dir is passed as one. +open /Applications/Diffuse.app --new --wait-apps --args $(printf %q "$(pwd)") $@ diff --git a/src/diffuse/mac-os-app/mac_launcher.sh.in b/src/diffuse/mac-os-app/mac_launcher.sh.in new file mode 100755 index 0000000..857811f --- /dev/null +++ b/src/diffuse/mac-os-app/mac_launcher.sh.in @@ -0,0 +1,7 @@ +#!/bin/bash + +# Mac's `open` command resets working dir. This extra script only +# does `cd` back to the dir from which `diffuse` was launched to +# allow Python to pick up any relative paths given by `git difftool`. +cd $1 +@BINDIR@/diffuse_impl ${@:2} diff --git a/src/diffuse/meson.build b/src/diffuse/meson.build index 6b27994..bb02d4c 100644 --- a/src/diffuse/meson.build +++ b/src/diffuse/meson.build @@ -9,15 +9,42 @@ conf.set('VERSION', meson.project_version()) conf.set('PKGDATADIR', pkgdatadir) conf.set('LOCALEDIR', join_paths(get_option('prefix'), get_option('localedir'))) conf.set('SYSCONFIGDIR', join_paths(get_option('prefix'), get_option('sysconfdir'))) +conf.set('BINDIR', join_paths(get_option('prefix'), get_option('bindir'))) configure_file( input: 'diffuse.in', - output: 'diffuse', + output: build_machine.system() == 'darwin' ? 'diffuse_impl' : 'diffuse', configuration: conf, install: true, install_dir: get_option('bindir') ) +if build_machine.system() == 'darwin' + install_subdir('mac-os-app/Diffuse.app', install_dir: '/Applications', strip_directory: false) + + configure_file( + input: 'mac-os-app/diffuse-mac.in', + output: 'diffuse', + configuration: conf, + install: true, + install_dir: get_option('bindir') + ) + configure_file( + input: 'mac-os-app/mac_launcher.sh.in', + output: 'mac_launcher.sh', + configuration: conf, + install: true, + install_dir: '/Applications/Diffuse.app/Contents/MacOS' + ) + configure_file( + input: 'mac-os-app/Info.plist.in', + output: 'Info.plist', + configuration: conf, + install: true, + install_dir: '/Applications/Diffuse.app/Contents' + ) +endif + diffuse_sources = [ '__init__.py', 'constants.py', diff --git a/utils/makemacicon.sh b/utils/makemacicon.sh new file mode 100755 index 0000000..35c5ac4 --- /dev/null +++ b/utils/makemacicon.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# Use this tool if you need to re-create +# Diffuse.app/Contents/Resources/diffuse.icns +# in case the icon changes (unlikely). + +sizes=(16 32 64 128 256 512) +for s in "${sizes[@]}"; do + echo $s + rsvg-convert -h $s "$1" > "icon_${s}x$s.png" +done + +cp 'icon_32x32.png' 'icon_16x16@2x.png' +cp 'icon_64x64.png' 'icon_32x32@2x.png' +cp 'icon_256x256.png' 'icon_128x128@2x.png' +cp 'icon_512x512.png' 'icon_256x256@2x.png' + +mkdir icon.iconset +mv icon_*x*.png icon.iconset +iconutil -c icns icon.iconset