name: compile_mac

on: [push]

env:
  BUILD_TYPE: Release

permissions:
  contents: read
  
jobs:
  # Commented out, because github has no ARM runners
  #
  # compile_Ninja_ARM:
  #   runs-on: osx-arm64
  #   steps:
  #     - name: Checkout wxMaxima from git
  #       uses: actions/checkout@v4
  #       with:
  #         # We must fetch at least the immediate parents so that if this is
  #         # a pull request then we can checkout the head.
  #         fetch-depth: 15
  #     - name: Install the dependencies
  #       run: |
  #            export PATH=$PATH:/usr/local/opt/gettext/bin
  #            export HOMEBREW_NO_AUTO_UPDATE=1
  #            set -e
  #            brew install gettext ninja pandoc wxwidgets
  #            set +e
  #     - name: Configure wxMaxima
  #       run: |
  #            mkdir ../build-wxm
  #            cmake -S . -B ../build-wxm -G Ninja -DCMAKE_INSTALL_PREFIX=. -DWXM_UNIT_TESTS=YES

  #     - name: Check Info.plist
  #       run: |
  #            ls -l ../build-wxm/src/Info.plist
  #     - name: Compile wxMaxima
  #       run: |
  #            cmake --build ../build-wxm
  #     - name: Install wxMaxima
  #       run: |
  #            cmake --install ../build-wxm
  #     - name: Package wxMaxima
  #       run: |
  #            cd ../build-wxm
  #             cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop

  compile_Ninja:
    runs-on: macos-latest

    steps:
      - name: Checkout wxMaxima from git
        uses: actions/checkout@v4
        with:
          # We must fetch at least the immediate parents so that if this is
          # a pull request then we can checkout the head.
          fetch-depth: 15
      - name: Install the dependencies
        run: |
             export PATH=$PATH:/usr/local/opt/gettext/bin
             export HOMEBREW_NO_AUTO_UPDATE=1
             set -e
             brew install gettext ninja pandoc wxwidgets
             set +e
      - name: xcode-select
        run: |
             sudo xcode-select --reset
      - name: Configure wxMaxima
        run: |
             mkdir build-wxm
             cmake -S . -B build-wxm -G Ninja -DCMAKE_INSTALL_PREFIX=. -DWXM_UNIT_TESTS=YES -DCPACK_PACKAGE_CHECKSUM=SHA512
      - name: Check Info.plist
        run: |
             ls -l build-wxm/src/Info.plist
      - name: Compile wxMaxima
        run: |
             cmake --build build-wxm
      - name: Install wxMaxima
        run: |
             cmake --install build-wxm
      - name: Package wxMaxima
        run: |
             cd build-wxm
             cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop
             cd ..
             cp build-wxm/*.dmg wxMaxima.dmg
             cp build-wxm/*.sha512 wxMaxima.dmg.sha512
      - name: install
        run: |
             cmake --install build-wxm
             ls -lh build-wxm/src
             ls -lh build-wxm
      - name: Upload the dmg
        uses: actions/upload-artifact@v4
        with:
          name: wxMaxima_ia64.dmg
          path: wxMaxima.dmg
      - name: Upload the dmg checksum
        uses: actions/upload-artifact@v4
        with:
          name: wxMaxima_ia64.dmg.sha512
          path: wxMaxima.dmg.sha512
          
  compile_Make:
    runs-on: macos-latest

    steps:
      - name: Checkout_git
        uses: actions/checkout@v4
        with:
          # We must fetch at least the immediate parents so that if this is
          # a pull request then we can checkout the head.
          fetch-depth: 15
      - name: Install the Dependencies
        run: |
             export PATH=$PATH:/usr/local/opt/gettext/bin
             export HOMEBREW_NO_AUTO_UPDATE=1
             set -e
             brew install gettext pandoc wxwidgets
             set +e
      - name: configure
        run: |
             mkdir ../build-wxm
             cmake -S . -B ../build-wxm -DCMAKE_INSTALL_PREFIX=.
      - name: compile
        run: |
             cmake --build ../build-wxm
      - name: Install wxMaxima
        run: |
             cmake --install ../build-wxm
      - name: Package wxMaxima
        run: |
             cd ../build-wxm
             cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop

  compile_macports:
    runs-on: macos-latest

    steps:
      - name: Make MacPorts cachable
        run: |
             sudo mkdir /opt/local
             sudo chown -R 1001:1001 /opt/local
             sudo chmod a+rwx /opt/local
      - name: Cache MacPorts
        id: cache-macports
        uses: actions/cache@v4
        with:
          path: /opt/local/
          key: ${{ runner.os }}-macports-3-${{ hashFiles('macos_build.txt') }}
      - name: Checkout wxMaxima from git
        uses: actions/checkout@v4
        with:
          # We must fetch at least the immediate parents so that if this is
          # a pull request then we can checkout the head.
          fetch-depth: 15
      - name: Install macports
        run: | 
          if test -e "/opt/local/bin"; then echo Macports already installed; else aria2c https://github.com/macports/macports-base/releases/download/v2.9.3/MacPorts-2.9.3-14-Sonoma.pkg && sudo installer -pkg MacPorts-2.9.3-14-Sonoma.pkg -target /; fi
          echo "/opt/local/bin" >> $GITHUB_PATH
      - name: Update macports
        run: |
          set
          sudo port selfupdate
      - name: Install dependencies
        run: |
          sudo port install gettext ninja pandoc maxima gnuplot pkgconfig wxWidgets-3.2
          sudo port select wxWidgets wxWidgets-3.2
      - name: Configure wxMaxima
        run: |
             mkdir ../build-wxm
             export CXXFLAGS=-I/opt/local/include
             export LDFLAGS=-I/opt/local/lib
             cmake -S . -B ../build-wxm -G Ninja -DCMAKE_INSTALL_PREFIX=. -DWXM_UNIT_TESTS=YES -DWXM_DISABLE_WEBVIEW=YES
      - name: Compile wxMaxima
        run: |
             cmake --build ../build-wxm
      - name: Install wxMaxima
        run: |
             cmake --install ../build-wxm
      - name: Package wxMaxima
        run: |
             cd ../build-wxm
             cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop||cpack -G DragNDrop
      - name: Cleanup
        run: |
             port -f uninstall inactive || echo "No cleanup necessary"
