Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed OSX Support #446

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ downloads/
release/
*.bin
.version
nuitka.log
nuitka-crash-report.xml
autoortho/aoimage/main
autoortho/aoimage/*.dylib
37 changes: 35 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
2 changes: 2 additions & 0 deletions autoortho/aoimage/AoImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
34 changes: 34 additions & 0 deletions autoortho/aoimage/Makefile.osx
Original file line number Diff line number Diff line change
@@ -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__
8 changes: 8 additions & 0 deletions autoortho/autoortho.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("***************")
Expand Down
2 changes: 1 addition & 1 deletion autoortho/autoortho_fuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
28 changes: 10 additions & 18 deletions buildreqs.sh
Original file line number Diff line number Diff line change
@@ -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;
22 changes: 22 additions & 0 deletions buildreqs_lin.sh
Original file line number Diff line number Diff line change
@@ -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
83 changes: 83 additions & 0 deletions buildreqs_osx.sh
Original file line number Diff line number Diff line change
@@ -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/'

18 changes: 18 additions & 0 deletions conda_autoortho.yml
Original file line number Diff line number Diff line change
@@ -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