diff --git a/.gitignore b/.gitignore index 7be77e47..f8a77d52 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,7 @@ downloads/ release/ *.bin .version +nuitka.log +nuitka-crash-report.xml +autoortho/aoimage/main +autoortho/aoimage/*.dylib \ No newline at end of file diff --git a/Makefile b/Makefile index c672c4b7..26a6904f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,8 @@ ZIP?=zip VERSION?=0.0.0 +AOIMAGE_DIR=autoortho/aoimage +BUILD_OUTPUT_FILES=autoortho_win_$(VERSION).zip AutoOrtho_win_$(VERSION).exe \ + autoortho_lin_$(VERSION).bin autoortho_osx_$(VERSION).bin autoortho.pyz: mkdir -p build/autoortho @@ -12,6 +15,31 @@ autoortho_lin_$(VERSION).bin: autoortho/*.py docker run --rm -v `pwd`:/code ubuntu:focal /bin/bash -c "cd /code; ./buildreqs.sh; time make bin VERSION=$(VERSION)" mv autoortho_lin.bin $@ + +$(AOIMAGE_DIR)/aoimage.dylib: + $(MAKE) -C $(AOIMAGE_DIR) --file Makefile.osx + +# +# --include-data-file=./autoortho/lib/darwin/*.dylib=lib/darwin/ \ +# Superfluous --enable-plugin=eventlet \ +# + +osx_bin: autoortho_osx_$(VERSION).bin +autoortho_osx_$(VERSION).bin: $(AOIMAGE_DIR)/aoimage.dylib autoortho/*.py + python3 -m nuitka --verbose --verbose-output=nuitka.log \ + --macos-app-icon=autoortho/imgs/ao-icon.ico \ + --disable-ccache \ + --include-package=geocoder \ + --enable-plugin=tk-inter \ + --tcl-library-dir=/usr/local/lib/tcl8.6 \ + --tk-library-dir=/usr/local/lib/tk8.6 \ + --include-data-file=./autoortho/.version*=. \ + --include-data-file=./autoortho/templates/*.html=templates/ \ + --include-data-file=./autoortho/aoimage/*.dylib=aoimage/ \ + --include-data-dir=./autoortho/imgs=imgs \ + --onefile \ + ./autoortho/__main__.py -o $@ + enter: docker run --rm -it -v `pwd`:/code ubuntu:focal /bin/bash @@ -85,8 +113,13 @@ testperf: serve_docs: docker run -p 8000:8000 -v `pwd`:/docs squidfunk/mkdocs-material -clean: +.PHONY: clean_osx +clean_osx: clean + $(MAKE) -C $(AOIMAGE_DIR) --file makefile.osx clean + +.PHONY: clean +clean: clean_osx -rm -rf build -rm -rf __main__.dist -rm -rf __main__.build - + -rm $(BUILD_OUTPUT_FILES) \ No newline at end of file diff --git a/autoortho/aoimage/AoImage.py b/autoortho/aoimage/AoImage.py index 3e3adc47..9735a101 100755 --- a/autoortho/aoimage/AoImage.py +++ b/autoortho/aoimage/AoImage.py @@ -149,6 +149,8 @@ def open(filename): _aoi_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),'aoimage.so') elif platform.system().lower() == 'windows': _aoi_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),'aoimage.dll') +elif platform.system().lower() == 'darwin': + _aoi_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),'aoimage.dylib') else: log.error("System is not supported") exit() diff --git a/autoortho/aoimage/Makefile.osx b/autoortho/aoimage/Makefile.osx new file mode 100644 index 00000000..00014f2e --- /dev/null +++ b/autoortho/aoimage/Makefile.osx @@ -0,0 +1,34 @@ +.SUFFIXES: .obj + +TARGET=main +INC_DIR=$(CONDA_PREFIX)/include +LIB_DIR=$(CONDA_PREFIX)/lib + +JPGT=$(CONDA_PREFIX)/lib/libturbojpeg.a +HEADERS=$(wildcard *.h) +OBJECTS=aoimage.o + +CC=gcc +LD=gcc + +CFLAGS+=-O2 -Wall -fPIC -fdiagnostics-color -fvisibility=hidden -I$(INC_DIR) \ + $(DEFINES) + +LDFLAGS=-shared -rdynamic -nodefaultlibs -lpthread +LIBS=$(LIB_DIR)/libturbojpeg.a + +all: $(TARGET) + +.c.o: $(HEADERS) + $(CC) $(CFLAGS) -c $< + +main: main.c aoimage.dylib $(HEADERS) + $(CC) $(CFLAGS) -o main \ + main.c aoimage.c $(LIBS) + +aoimage.dylib: $(OBJECTS) + $(LD) -o aoimage.dylib $(LDFLAGS) $(OBJECTS) $(LIBS) + +clean: + rm -f $(OBJECTS) $(TARGET) aoimage.dylib test*.jpg + -rm -rf __pycache__ diff --git a/autoortho/autoortho.py b/autoortho/autoortho.py index 5ab0fe54..1b9066ea 100644 --- a/autoortho/autoortho.py +++ b/autoortho/autoortho.py @@ -140,6 +140,14 @@ def diagnose(CFG): log.warning(f" Maptype: {maptype} FAILED!") failed = True + log.info(f"Checking DDS file compression:") + dds_compressor = CFG.pydds.compressor.upper() + if dds_compressor != "ISPC" and platform.system().lower() == 'darwin': + log.warning(f" {dds_compressor} FAILED! Not supported on MacOS, use ISPC instead!") + failed = True + else: + log.info(f" {dds_compressor} OK!") + log.info("------------------------------------") if failed: log.warning("***************") diff --git a/autoortho/autoortho_fuse.py b/autoortho/autoortho_fuse.py index aab9b05a..ce418c54 100644 --- a/autoortho/autoortho_fuse.py +++ b/autoortho/autoortho_fuse.py @@ -283,7 +283,7 @@ def statfs(self, path): # return dict((key, getattr(st, key)) for key in ('f_bavail', 'f_bfree', # 'f_blocks', 'f_bsize', 'f_favail', 'f_ffree', 'f_files', 'f_flag', # 'f_frsize', 'f_namemax')) - elif platform.system() == 'Linux': + else: # Linux or Darwin stv = os.statvfs(full_path) #log.info(stv) return dict((key, getattr(stv, key)) for key in ('f_bavail', 'f_bfree', diff --git a/buildreqs.sh b/buildreqs.sh index 7784aed8..1551585f 100755 --- a/buildreqs.sh +++ b/buildreqs.sh @@ -1,18 +1,10 @@ -#!/bin/bash - -export DEBIAN_FRONTEND=noninteractive -export TZ=America/New_York - -apt-get update -apt-get install software-properties-common -y -add-apt-repository ppa:deadsnakes/ppa -y -apt-get update -apt-get install -y make curl patchelf python3.10 python3.10-tk zlib1g-dev \ - ccache python3.10-distutils python3.10-dev libjpeg-dev libturbojpeg0-dev build-essential - -curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10 - -python3.10 -m pip install -U pip -python3.10 -m pip install setuptools -python3.10 -m pip install -r requirements-build.txt --no-use-pep517 -python3.10 -m pip install -r requirements.txt +#!/bin/sh +UNAME_OUT="$(uname -s)" + +case "${UNAME_OUT}" in + Linux*) ./buildreqs_lin.sh;; + Darwin*) ./buildreqs_osx.sh;; + *) echo "System $UNAME_OUT not supported by buildreqs.sh."; + exit 1;; +esac +exit 0; \ No newline at end of file diff --git a/buildreqs_lin.sh b/buildreqs_lin.sh new file mode 100755 index 00000000..60e4b243 --- /dev/null +++ b/buildreqs_lin.sh @@ -0,0 +1,22 @@ +#!/bin/bash +UNAME_OUT="$(uname -s)" +if [[ ! $UNAME_OUT == 'Linux'* ]]; then + echo "buildreqs_lin.sh: This script is for Linux only."; + exit 1; +fi +export DEBIAN_FRONTEND=noninteractive +export TZ=America/New_York + +apt-get update +apt-get install software-properties-common -y +add-apt-repository ppa:deadsnakes/ppa -y +apt-get update +apt-get install -y make curl patchelf python3.10 python3.10-tk zlib1g-dev \ + ccache python3.10-distutils python3.10-dev libjpeg-dev libturbojpeg0-dev build-essential + +curl -sS https://bootstrap.pypa.io/get-pip.py | python3.10 + +python3.10 -m pip install -U pip +python3.10 -m pip install setuptools +python3.10 -m pip install -r requirements-build.txt --no-use-pep517 +python3.10 -m pip install -r requirements.txt diff --git a/buildreqs_osx.sh b/buildreqs_osx.sh new file mode 100755 index 00000000..b7775d63 --- /dev/null +++ b/buildreqs_osx.sh @@ -0,0 +1,83 @@ +#!/bin/sh +# Installs required environment for OSX + +# Check this is run on a Mac +if [[ ! $OSTYPE == 'darwin'* ]]; then + echo "buildreqs_osx.sh: This script is for OSX (Mac) only."; + exit 1; +fi + +if [[ $(sysctl -n machdep.cpu.brand_string) =~ "Apple" ]]; then + CPU_ARCH="Apple"; +else + CPU_ARCH="Intel"; +fi; + +echo "Configuring build environment for Macintosh with an $CPU_ARCH CPU." + +# First make sure homebrew is installed +# and updated + +#if [[ $(command -v brew) == "" ]]; then +# # Prompt for installation +# while true; do +# read -p "Homebrew not installed. Install [y/n]? " yn +# case $yn in +# [yY] ) echo "Installing Homebrew..."; +# break;; +# [nN] ) echo "Exiting..."; +# exit;; +# * ) echo "Invalid choice ($yn).";; +# esac +# done +# /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" +#else +# echo "Updating Homebrew" +# brew update +#fi + +# Install brew packages needed +# Currently no brew packages needed + +# Make sure Miniforge3 or is installed +if [[ $(command -v conda) == "" ]]; then + # Prompt for installation + while true; do + read -p "Miniforge3 not installed. Install [y/n]? " yn + case $yn in + [yY] ) echo "OK, preparing to download Miniforge3..."; + if [[ $CPU_ARCH=="Apple" ]]; then + MF_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-arm64.sh"; + else + MF_URL="https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-x86_64.sh"; + fi; + break;; + [nN] ) echo "Exiting..."; + exit;; + * ) echo "Invalid choice ($yn).";; + esac + done + curl -LJ0 "$MF_URL" --output mf3_installer.sh; + echo "Downloaded mf3_installer.sh. Starting installer..." + echo bash mf3_installer.sh + echo "Removing Miniforge3 installer" + rm mf3_installer.sh + echo "Miniforge3 install complete." + echo "\nClose terminal window, start a new terminal window and re-run buildreqs.sh to continue." + exit 0 +fi + +# Activate +echo "Creating Miniforge3 or Conda environment autoortho..." +conda env create -f conda_autoortho.yml + +echo "Activating autoortho environment" +conda activate autoortho + +# Installing modules not available from conda-forge +echo "Installing python package refuse..." +pip install refuse + +echo 'System setup for Macintosh is complete.\n\nTo compile:\ns1. conda activate autoortho.\n2. make osx_bin\n' +echo 'To run without compiling:\n1. conda activate autoortho\n2. python3 autoortho/' + diff --git a/conda_autoortho.yml b/conda_autoortho.yml new file mode 100644 index 00000000..d98067c9 --- /dev/null +++ b/conda_autoortho.yml @@ -0,0 +1,18 @@ +name: autoortho +channels: + - conda-forge +dependencies: + - python=3.11 + - certifi + - nuitka + - zstandard + - ordered-set + - pysimplegui + - eventlet + - packaging + - Flask + - flask-socketio + - psutil + - geocoder + - imageio + - libjpeg-turbo \ No newline at end of file