How to make disk image with darktable application bundle from source (using Homebrew):

0). Install Homebrew (instructions and prerequisites can be found on official website https://brew.sh/), ideally use default installation path (/opt/homebrew for arm64, /usr/local for x86_64).

1). Install required homebrew packages:
     $ 1_install_hb_dependencies.sh

2). Optional step for GraphicsMagick:
     darktable can be build with either ImageMagick or GraphicsMagick. If you want to use GraphicsMagick you need to rebuild the homebrew package so it 
     can be packed into the macOS bundle. Open the terminal and perform the following steps:

     brew edit graphicsmagick
        This opens the GraphicsMagick homebrew recipe in your editor.
        Scroll down to find the install options (starting with 'def install').
        Find the line

        --with-modules

        and replace it with

        --disable-installed

        Save the file and execute the commands:

     export HOMEBREW_NO_INSTALL_FROM_API=1
     brew reinstall --build-from-source --force graphicsmagick

3). Build and install darktable using either option A or B:
     - Option A: Build using the default build.sh, which should work for most use cases 
     $ 2_build_hb_darktable_default.sh
     - Option B: Build using custom cmake options, edit according to your specific needs/environment
     $ 2_build_hb_darktable_custom.sh

4). Create application bundle from build files. To properly sign the app bundle you can optionally provide your developer certificate email/id by defining CODECERT:
     $ export CODECERT="your.developer@apple.id" # optional, not required
     $ 3_make_hb_darktable_package.sh

5). Generate DMG image from application bundle:
     $ 4_make_hb_darktable_dmg.sh

The final result is a DMG file: darktable-<current version>+<latest commit>-{arm64|x86_64}.dmg

All binaries, the MacOS app bundle and the DMG file are created in build/macosx.

LIMITATIONS:
- Created DMG will only be compatible to the macOS version it was created upon.
- Naturally the libraries that darktable is built upon will be as good as its currently provided homebrew packages. You might want to use "$ brew pin <package>" to lock your working/verified setup.
- As of today homebrew ships lensfun 0.3.3 that is the successor of the last stable release 0.3.2. It is expected to be compatible and should not break existing edits based on 0.3.2 or before.
- For now additional darktable tools like darktable-curve-tool or darktable-noiseprofile are not part of the default application bundle.

MACOS SECURITY:
- The DMG is not notarized with/at Apple by using this approach. If it is still required see the official BUILD.txt for further instructions.
- As the DMG is not notarized and the app bundle may not even be properly signed, it is still possible to install/run darktable at your own risk. To do so make sure to run "$ xattr -d com.apple.quarantine <darktable-app>.dmg" on the DMG before installing.

NOTES:
- It will be automatically build for the architecture you are currently on, either Apple Silicon (arm64) or Intel (x86_64).
- If you want to build for x86_64 on arm64 see https://stackoverflow.com/questions/64951024/how-can-i-run-two-isolated-installations-of-homebrew/68443301#68443301 about how to handle both environments in parallel.
- After creating the darktable application bundle (step 3) you can directly run the result by executing:
     $ build/macosx/package/darktable.app/Contents/MacOS/darktable --configdir .config/darktable/ --cachedir .cache/darktable/

REFERENCES:
This approach is heavily based on and inspired by:
- The official BUILD.txt instructions (MacPorts-based) by the darktable community
- http://clarkkromenaker.com/post/library-dynamic-loading-mac/
- https://gitlab.gnome.org/GNOME/gtk-mac-bundler
- https://github.com/auriamg/macdylibbundler/ 
