diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
new file mode 100644
index 000000000..70b32e66b
--- /dev/null
+++ b/.github/workflows/build.yml
@@ -0,0 +1,98 @@
+name: Build
+
+on:
+ push:
+ tags:
+ - '*'
+
+jobs:
+ build:
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - os: macos-12
+ name: macos
+ qt_ver: 5
+ qt_host: mac
+ qt_version: '5.15.2'
+ qt_modules: ''
+ qt_tools: ''
+
+ runs-on: ${{ matrix.os }}
+
+ steps:
+ ##
+ # PREPARE
+ ##
+ - name: Checkout
+ uses: actions/checkout@v3
+ with:
+ submodules: 'true'
+
+ - name: Set short version
+ shell: bash
+ run: |
+ ver_short=`git rev-parse --short HEAD`
+ ver_novelwriter=`awk '/^__version__/{print substr($NF,2,length($NF)-2)}' novelwriter/__init__.py`
+ echo "VERSION=$ver_novelwriter" >> $GITHUB_ENV
+ echo "VERSION_SHORT=$ver_short" >> $GITHUB_ENV
+
+ - name: Install Qt (Linux)
+ if: runner.os == 'Linux' && matrix.qt_ver != 6
+ run: |
+ sudo apt-get -y install qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools libqt5core5a libqt5network5 libqt5gui5
+
+ - name: Install Qt (macOS, AppImage & Windows MSVC)
+ if: runner.os == 'Linux' && matrix.qt_ver == 6 || runner.os == 'macOS' || (runner.os == 'Windows' && matrix.msystem == '')
+ uses: jurplel/install-qt-action@v3
+ with:
+ version: ${{ matrix.qt_version }}
+ host: ${{ matrix.qt_host }}
+ target: 'desktop'
+ arch: ${{ matrix.qt_arch }}
+ modules: ${{ matrix.qt_modules }}
+ tools: ${{ matrix.qt_tools }}
+ cache: true
+
+ - name: Setup TeX Live
+ uses: teatimeguest/setup-texlive-action@v2
+ with:
+ packages: >-
+ scheme-basic
+ collection-latexextra
+ latexmk
+ tex-gyre
+
+ - name: Install Dependencies (macOS)
+ if: runner.os == 'macOS'
+ run: |
+ pip3 install sphinx
+
+ ##
+ # BUILD
+ ##
+
+ - name: Build (macOS)
+ if: runner.os == 'macOS'
+ run: |
+ ./setup/macos/build.sh
+
+ ##
+ # UPLOAD BUILDS
+ ##
+
+ - name: Upload binary zip (macOS)
+ if: runner.os == 'macOS'
+ uses: actions/upload-artifact@v3
+ with:
+ name: novelWriter-${{ env.VERSION }}-${{ matrix.name }}.app.zip
+ path: dist_macos/novelWriter-${{ env.VERSION }}.app.zip
+
+ - name: Upload dmg (macOS)
+ if: runner.os == 'macOS'
+ uses: actions/upload-artifact@v3
+ with:
+ name: novelWriter-${{ env.VERSION }}-${{ matrix.name }}.dmg
+ path: dist_macos/novelWriter-${{ env.VERSION }}.dmg
+
diff --git a/setup.py b/setup.py
index 75bcd2b13..574096ef3 100755
--- a/setup.py
+++ b/setup.py
@@ -71,6 +71,25 @@ def getValue(theString):
return numVers, hexVers, relDate
+def extractCopyright():
+ """Extract the novelWriter copyright notice without having to import
+ anything else from the main package.
+ """
+ copyright = "Unknown"
+ initFile = os.path.join("novelwriter", "__init__.py")
+ try:
+ with open(initFile, mode="r", encoding="utf-8") as inFile:
+ for aLine in inFile:
+ if aLine.startswith("__copyright__"):
+ copyright = (aLine).partition("=")[2].strip().strip('"')
+ except Exception as exc:
+ print("Could not read file: %s" % initFile)
+ print(str(exc))
+
+ print("novelWriter copyright: %s " % (copyright))
+
+ return copyright
+
def compactVersion(numVers):
"""Make the version number more compact."""
@@ -395,6 +414,102 @@ def buildQtI18nTS(sysArgs):
return
+##
+# Generage MacOS PList
+##
+
+def genMacOSPlist():
+
+ # Set Up Folder
+ # =============
+
+ numVers, _, _ = extractVersion()
+ pkgVers = compactVersion(numVers)
+
+ outDir = "setup/macos"
+
+ macosBundleName = "novelWriter"
+ macosBundleExeName = "novelWriter"
+ macosBundleInfo = "novelWriter: A markdown-like text editor for planning and writing novels."
+ macosBundleIcon = "novelwriter.icns"
+ macosBundleIdent = "io.novelwriter.novelWriter"
+ macosBundleSVers = pkgVers
+ macosBundleVers = numVers
+ macosBundleCopyright = extractCopyright()
+
+ # These keys are no longer used but are present for compatability
+ macosBundleVersMajor, macosBundleVersMinor, _ = pkgVers.split(".")
+
+
+ plistXML = (
+ "\n"
+ "\n"
+ "\n"
+ "\n"
+ "NSPrincipalClass\n"
+ "NSApplication\n"
+ "NSHighResolutionCapable\n"
+ "True\n"
+ "CFBundleDevelopmentRegion\n"
+ "English\n"
+ "CFBundleExecutable\n"
+ f"{macosBundleExeName}\n"
+ "CFBundleGetInfoString\n"
+ f"{macosBundleInfo}\n"
+ "CFBundleIconFile\n"
+ f"{macosBundleIcon}\n"
+ "CFBundleIdentifier\n"
+ f"{macosBundleIdent}\n"
+ "CFBundleName\n"
+ f"{macosBundleName}\n"
+ "CFBundleDisplayName\n"
+ f"{macosBundleName}\n"
+ "CFBundleInfoDictionaryVersion\n"
+ "6.0\n"
+ "CFBundleShortVersionString\n"
+ f"{macosBundleSVers}\n"
+ "CFBundleSignature\n"
+ "????\n"
+ "CFBundleVersion\n"
+ f"{macosBundleVers}\n"
+ "CFBundlePackageType\n"
+ "APPL\n"
+ "NSHumanReadableCopyright\n"
+ f"{macosBundleCopyright}\n"
+ "IFMajorVersion\n"
+ f"{macosBundleVersMajor}\n"
+ "IFMinorVersion\n"
+ f"{macosBundleVersMinor}\n"
+ "CFBundleDocumentTypes\n"
+ " \n"
+ " \n"
+ " CFBundleTypeExtensions\n"
+ " \n"
+ " nwx\n"
+ " \n"
+ " CFBundleTypeName\n"
+ " novelWriter Project\n"
+ " CFBundleTypeOSTypes\n"
+ " \n"
+ " TEXT\n"
+ " utxt\n"
+ " TUTX\n"
+ " ****\n"
+ " \n"
+ " CFBundleTypeRole\n"
+ " Viewer\n"
+ " LSHandlerRank\n"
+ " Alternate\n"
+ " \n"
+ " \n"
+ "\n"
+ "\n"
+ )
+
+ print(f"Writing Info.plist to {outDir}/Info.plist")
+
+ writeFile(f"{outDir}/Info.plist", plistXML)
+
##
# Sample Project ZIP File Builder (sample)
@@ -1862,6 +1977,7 @@ def winUninstall():
" The files to be updated must be provided as arguments.",
" qtlrelease Build the language files for internationalisation.",
" clean-assets Delete assets built by manual, sample and qtlrelease.",
+ " gen-plist Generates an Info.plist for use in a MacOS Bundle",
"",
"Python Packaging:",
"",
@@ -1943,6 +2059,10 @@ def winUninstall():
if "clean-assets" in sys.argv:
sys.argv.remove("clean-assets")
cleanBuiltAssets()
+
+ if "gen-plist" in sys.argv:
+ sys.argv.remove("gen-plist")
+ genMacOSPlist()
# Python Packaging
# ================
diff --git a/setup/macos/App.entitlements b/setup/macos/App.entitlements
new file mode 100644
index 000000000..40dc976ac
--- /dev/null
+++ b/setup/macos/App.entitlements
@@ -0,0 +1,10 @@
+
+
+
+
+ com.apple.security.cs.disable-library-validation
+
+ com.apple.security.cs.allow-dyld-environment-variables
+
+
+
\ No newline at end of file
diff --git a/setup/macos/build.sh b/setup/macos/build.sh
new file mode 100755
index 000000000..96e261c3a
--- /dev/null
+++ b/setup/macos/build.sh
@@ -0,0 +1,145 @@
+#! /bin/bash
+
+# use RAM disk if possible
+if [ -d /dev/shm ]; then
+ TEMP_BASE=/dev/shm
+else
+ TEMP_BASE=/tmp
+fi
+
+BUILD_DIR=$(mktemp -d "$TEMP_BASE/novelWriter-build-XXXXXX")
+
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+
+SRC_DIR="$SCRIPT_DIR/../.."
+
+RLS_DIR="$SRC_DIR/dist_macos"
+
+echo "Script Dir: $SCRIPT_DIR"
+
+cleanup () {
+ if [ -d "$BUILD_DIR" ]; then
+ rm -rf "$BUILD_DIR"
+ fi
+}
+
+trap cleanup EXIT
+
+echo "Building in: $BUILD_DIR"
+
+OLD_CWD="$(pwd)"
+
+VERSION="$(awk '/^__version__/{print substr($NF,2,length($NF)-2)}' $SRC_DIR/novelwriter/__init__.py)"
+
+pushd "$SRC_DIR" || exit 1
+
+python3 setup.py manual qtlrelease sample gen-plist
+
+ls -lah .
+
+popd || exit 1
+
+pushd "$BUILD_DIR"/ || exit 1
+
+echo "Downloading Miniconda ..."
+# install Miniconda, a self-contained Python distribution
+curl -LO https://repo.continuum.io/miniconda/Miniconda3-latest-MacOSX-x86_64.sh
+bash Miniconda3-latest-MacOSX-x86_64.sh -b -p ~/miniconda -f
+rm Miniconda3-latest-MacOSX-x86_64.sh
+export PATH="$HOME/miniconda/bin:$PATH"
+
+echo "Creating conda env ..."
+# create conda env
+conda create -n novelWriter -c conda-forge python=3.10 --yes
+source activate novelWriter
+
+echo "installing dictionaries ..."
+conda install -c conda-forge enchant hunspell-en --yes
+
+echo "installing python deps ..."
+# install dependencies
+pip install -r "$SRC_DIR/requirements.txt"
+
+# leave conda env
+conda deactivate
+
+echo "Building app bundle ..."
+# create .app Framework
+mkdir -p novelWriter.app/Contents/
+mkdir novelWriter.app/Contents/MacOS novelWriter.app/Contents/Resources novelWriter.app/Contents/Resources/novelWriter
+cp $SRC_DIR/setup/macos/Info.plist novelWriter.app/Contents/Info.plist
+
+echo "Copying miniconda env to bundle ..."
+# copy Miniconda env
+cp -R ~/miniconda/envs/novelWriter/* novelWriter.app/Contents/Resources/
+
+echo "Copying novelWriter to bundle ..."
+# copy novelWriter
+
+FILES_COPY=(
+ "CHANGELOG.md" "MANIFEST.in" "CREDITS.md" "LICENSE.md"
+ "CONTRIBUTING.md" "CODE_OF_CONDUCT.md" "i18n" "novelwriter"
+ "novelWriter.py"
+)
+
+for file in "${FILES_COPY[@]}"; do
+ echo "Copying $SRC_DIR/$file ..."
+ cp -R $SRC_DIR/$file novelWriter.app/Contents/Resources/novelWriter/
+done
+
+cp $SRC_DIR/setup/macos/novelwriter.icns novelWriter.app/Contents/Resources/
+
+# create entry script
+cat > novelWriter.app/Contents/MacOS/novelWriter <<\EOF
+#!/bin/bash
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+$DIR/../Resources/bin/python -sE $DIR/../Resources/novelWriter/novelWriter.py $@
+EOF
+
+# make executable
+chmod a+x novelWriter.app/Contents/MacOS/novelWriter
+
+#do codesigning
+#echo "Signing bundle ..."
+#sudo codesign --sign - --deep --force --entitlements "$SCRIPT_DIR/../macos/App.entitlements" --options runtime "novelWriter.app/Contents/MacOS/novelWriter"
+
+# remove bloat
+pushd novelWriter.app/Contents/Resources || exit 1
+
+echo "Cleaning unused files from bundle ..."
+# cleanup commands HERE
+find . -type d -iname '__pycache__' -print0 | xargs -0 rm -r
+
+rm -rf pkgs
+rm -rf cmake
+rm -rf share/{gtk-,}doc
+
+#remove web engine
+rm lib/python3.*/site-packages/PyQt5/QtWebEngine* || true
+rm -r lib/python3.*/site-packages/PyQt5/Qt/translations/qtwebengine* || true
+rm lib/python3.*/site-packages/PyQt5/Qt/resources/qtwebengine* || true
+rm -r lib/python3.*/site-packages/PyQt5/Qt/qml/QtWebEngine* || true
+rm -r lib/python3.*/site-packages/PyQt5/Qt/plugins/webview/libqtwebview* || true
+rm lib/python3.*/site-packages/PyQt5/Qt/libexec/QtWebEngineProcess* || true
+rm lib/python3.*/site-packages/PyQt5/Qt/lib/libQt5WebEngine* || true
+
+popd || exit 1
+popd || exit 1
+
+echo "Packageing App ..."
+
+mkdir -p $RLS_DIR
+
+# generate .dmg
+
+brew install create-dmg
+# "--skip-jenkins" is a temporary workaround for https://github.com/create-dmg/create-dmg/issues/72
+create-dmg --volname "novelWriter $VERSION" --volicon $SRC_DIR/setup/macos/novelwriter.icns \
+ --window-pos 200 120 --window-size 800 400 --icon-size 100 --icon novelWriter.app 200 190 --hide-extension novelWriter.app \
+ --app-drop-link 600 185 $RLS_DIR/novelWriter-"${VERSION}".dmg "$BUILD_DIR"/
+
+pushd $BUILD_DIR || exit 1
+zip -qr novelWriter.app.zip novelWriter.app
+popd || exit 1
+
+mv $BUILD_DIR/novelWriter.app.zip $RLS_DIR/novelWriter-"${VERSION}".app.zip
diff --git a/setup/macos/generate_icns.sh b/setup/macos/generate_icns.sh
new file mode 100755
index 000000000..0ca1d9c0e
--- /dev/null
+++ b/setup/macos/generate_icns.sh
@@ -0,0 +1,70 @@
+#! /usr/bin/env bash
+
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+
+function generate_linux () {
+ echo "Generating on Linux ..."
+ if ! command -v png2icns &> /dev/null
+ then
+ echo "png2icns cound not be found, it is required. Please install a package like icnsutils or libicns."
+ exit
+ fi
+
+ if ! command -v convert $> /dev/null
+ then
+ echo "convert could not be found, it is required. please install a imagemagick package."
+ exit
+ fi
+
+ mkdir -p $SCRIPT_DIR/icons
+
+ sizes=( 16 32 64 128 256 )
+ for base in "${sizes[@]}"; do
+ let basex2=${base}*2
+ size="${base}x${base}"
+ echo "Copying files for $size"
+ double=${basex2}x${basex2}
+ cp $SCRIPT_DIR/../data/hicolor/${size}/apps/novelwriter.png $SCRIPT_DIR/icons/icon_${size}.png
+ echo "Resizing ${size}@2x to $double from $size"
+ convert $SCRIPT_DIR/icons/icon_${size}.png -resize $double $SCRIPT_DIR/icons/icon_${size}@2x.png
+ done
+
+ png2icns $SCRIPT_DIR/novelwriter.icns $SCRIPT_DIR/icons/icon_*.png
+
+ rm -r $SCRIPT_DIR/icons
+
+ echo "Done"
+}
+
+function generate_macos () {
+ echo "Generating on MacOs ..."
+ mkdir -p $SCRIPT_DIR/icons
+
+ echo "Building Iconset ..."
+ sizes=( 16 32 64 128 256 )
+ for base in "${sizes[@]}"; do
+ let basex2=${base}*2
+ size="${base}x${base}"
+ echo "Copying files for $size"
+ double=${basex2}x${basex2}
+ cp $SCRIPT_DIR/../data/hicolor/${size}/apps/novelwriter.png $SCRIPT_DIR/icons/icon_${size}.png
+ cp $SCRIPT_DIR/../data/hicolor/${size}/apps/novelwriter.png $SCRIPT_DIR/icons/icon_${size}@2x.png
+ echo "Resizing ${size}@2x to $double from $size"
+ sips -Z $basex2 $SCRIPT_DIR/icons/icon_${size}@2x.png
+ done
+
+ rm -rf $SCRIPT_DIR/novelwriter.iconset
+ mv $SCRIPT_DIR/icons $SCRIPT_DIR/novelwriter.iconset
+
+ echo "Generating icns ..."
+ iconutil -c icns $SCRIPT_DIR/novelwriter.iconset
+
+ echo "Done"
+}
+
+unameOut="$(uname -s)"
+case "$unameOut" in
+ Linux*) generate_linux;;
+ Darwin*) generate_macos;;
+ *) echo "Unsupported OS"
+esac
diff --git a/setup/macos/novelwriter.icns b/setup/macos/novelwriter.icns
new file mode 100644
index 000000000..884347bf7
Binary files /dev/null and b/setup/macos/novelwriter.icns differ