[Solved] compiling mythtv on Apple M1 silicon

For discussion of topics specific to MythTV on OSX
User avatar
jhoyt
Senior
Posts: 143
Joined: Thu Aug 27, 2015 10:11 am
United States of America

[Solved] compiling mythtv on Apple M1 silicon

Post by jhoyt »

Update 2/25: Cleaned up python install
Update 2/26: Remove libcec
Update 2/28: Point to updated build script

Recently there's been discussion of trying to compile mythtv / mythfrontend on Apple's new silicon. Unfortunately, we've found out that qtwebkit is not ready for Apple Silicon, so we'll have to install without the plugins.

This also means I'll need to modify the current ansible playbook and compile script some once we work out what's necessary to compile for the M1. The good news is we should be able to use the current compile script with some flags by installing the necessary ports manually. Here's my best guess on how to do that:

Install MacPorts https://www.macports.org/install.php
Update MacPorts

Code: Select all

sudo port selfupdate
Install python libraries

Code: Select all

sudo port install py38-future py38-requests py38-requests-cache py38-lxml py38-oauthlib py38-curl py38-simplejson py38-wheel py38-pip
Tell macOS to use Python 3.8 for python

Code: Select all

sudo port select python python38
sudo port select python3 python38
Install mythtv required ports

Code: Select all

sudo port install ccache nasm autoconf automake pkgconfig libxml2 taglib exiv2 libbluray lzo2 libsamplerate openssl libvpx x264 x265 XviD libvorbis flac faac freetype libxml2 fftw-3 libass x264 x265 libvpx minizip apache-ant hdhomerun libX11 liberation-fonts dejavu-fonts gmake libtool lame gnutls gsed
Install perl modules

Code: Select all

sudo port install perl5 p5-date-manip p5-datetime-format-iso8601 p5-dbi p5-image-size p5-io-socket-inet6 p5-json p5-libwww-perl p5-http-request-ascgi p5-net-upnp p5-soap-lite p5-xml-xpath p5-xml-simple
Install database relevant packages

Code: Select all

sudo port install mysql8 p5-dbd-mysql +mysql8 py38-mysqlclient +mysql8 py38-pymysql
Install minimal qt packages

Code: Select all

sudo port install qt5 qt5-qtscript qt5-mysql-plugin +mysql8
Then run the compile script with the following flags

Code: Select all

./compileMythfrontendAnsible.zsh --skip-ansible=true --database-version=mysql8 --build-plugins=false
This version of the compile script works on ARM builds: https://sourceforge.net/p/mythtvformaco ... ster/tree/

PRs have been issued on github for mythtv/ansible and mythtv/packaging to incorporated all of the necessary updates to build and codesign on arm64.

Binaries can be downloaded from here: https://sourceforge.net/projects/mythtvformacosx/files/
Last edited by jhoyt on Mon Mar 01, 2021 1:41 am, edited 5 times in total.
User avatar
pvr4me
Senior
Posts: 763
Joined: Fri Feb 07, 2014 7:25 pm
Location: near Toronto, Canada
Contact:
Canada

Re: compiling mythtv on Apple M1 silicon

Post by pvr4me »

jhoyt wrote:
Thu Feb 25, 2021 11:43 am

Install MacPorts https://www.macports.org/install.php
...
Install Python 3.8

Code: Select all

sudo port install python38
Tell macOS to use Python 3.8 for python

Code: Select all

sudo port select python python38
Tell macOS to use Python 3.8 for python3

Code: Select all

sudo port select python3 python38
Install additional python libraries

Code: Select all

sudo port install py38-future py38-requests py38-requests-cache py38-lxml py38-oauthlib py38-curl py38-simplejson py38-wheel py38-pip
...[/code]
Not a big deal, but I don't see why you are installing python38 first. Installing any one of the py38-blahbah ports will automatically install python38 as a dependency. Then do the port select commands.

Craig
Formerly the MacPorts guy.
User avatar
jhoyt
Senior
Posts: 143
Joined: Thu Aug 27, 2015 10:11 am
United States of America

Re: compiling mythtv on Apple M1 silicon

Post by jhoyt »

Python being installed first was more of an artifact of copying the install instructions needed for the compile script to work with ansible.

Basically, I needed a matching version of python and ansible installed before running the script so that the ansible playbook installs everything else including the py38-blahblah pieces.

I'll update this when I get back to a PC to combine/skip those steps.

I'm also going to add another flag to ansible playbook that skips the qtwebkit install. That mod will take a bit to work through. The good news is the compile script already has a --build-plugins flag so I just have to feed that into ansible (similar to the database-version flag).
ILMostro
Newcomer
Posts: 7
Joined: Fri Feb 26, 2021 5:11 am
Canada

Re: compiling mythtv on Apple M1 silicon

Post by ILMostro »

Thanks for starting this discussion here.

At this time, there's a failure during build time related to ffmpeg (libavcodec) and libcec. There are two symlinks (libcec.6.dylib, libcec.dylib) that point to a non-existent location for the libcec libs.

These are the outstanding issues when qtwebkit is disregarded as a blocker for compilation on arm64.

Code: Select all

/var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/libcec.dylib --> /var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/Contents/Frameworks/libcec.6.0.2.dylib
I suspect that the issue with the symlinks might be resolved if the build succeeds without causing libavcodec errors. I've tried using ffmpeg+gpl as well as ffmpeg+nonfree variants from the macports with the same result.
ILMostro
Newcomer
Posts: 7
Joined: Fri Feb 26, 2021 5:11 am
Canada

Re: compiling mythtv on Apple M1 silicon

Post by ILMostro »

This is where the failure occurs at the moment on arm64 using the zshell script.

Code: Select all

/opt/local/libexec/qt5/bin/qmake -install qinstall /private/var/root/mythtv-31/mythtv/mythtv/libs/libmythupnp/serializers/jsonSerializer.h /var/root/mythtv-31/31-osx-64bit/include/mythtv/upnp/jsonSerializ
er.h                                                                                                                                                                                                        
/opt/local/libexec/qt5/bin/qmake -install qinstall /private/var/root/mythtv-31/mythtv/mythtv/libs/libmythupnp/serializers/soapSerializer.h /var/root/mythtv-31/31-osx-64bit/include/mythtv/upnp/soapSerializ
er.h                                                                                                                                                                                                        
cd libmyth/ && ( test -e Makefile || /opt/local/libexec/qt5/bin/qmake -o Makefile /private/var/root/mythtv-31/mythtv/mythtv/libs/libmyth/libmyth.pro QMAKE=/opt/local/libexec/qt5/bin/qmake ) && /Applicatio
ns/Xcode.app/Contents/Developer/usr/bin/make -f Makefile install                                                                                                                                            
ccache clang++ -c -pipe -stdlib=libc++ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DPIC -I /var/root/mythtv-31/mythtv/mythtv/external -I /opt/local/include -std=c++11 -DNDEBUG -fomit-frame-pointer -fPIC -
DQT_DISABLE_DEPRECATED_BEFORE=0x050700 -pthread -g -Wall -Wextra -Wpointer-arith -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -Wno-constant-logical-operand -Wno-unused-value -Qunused-arguments -Wimplici
t-fallthrough -std=gnu++11  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.13 -fPIC -DUSING_APPLEREMOTE -D
using_libcec -D_GNU_SOURCE -DMYTH_API -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_XML_LIB -DQT_SQL_LIB -DQT_SCRIPT_LIB -DQT_DBUS_LIB -DQT_CORE_LIB -I. -I/opt/local/include -I/opt/loc
al/include/libxml2 -I../../external/libmythsoundtouch -I../libmythfreesurround -I../libmythbase -I../.. -I.. -I. -I../libmythupnp -I../libmythui -I../.. -I../../external/FFmpeg -I../libmythservicecontract
s -I/opt/local/libexec/qt5/lib/QtWidgets.framework/Headers -I/opt/local/libexec/qt5/lib/QtGui.framework/Headers -I/opt/local/libexec/qt5/lib/QtNetwork.framework/Headers -I/opt/local/libexec/qt5/lib/QtXml.
framework/Headers -I/opt/local/libexec/qt5/lib/QtSql.framework/Headers -I/opt/local/libexec/qt5/lib/QtScript.framework/Headers -I/opt/local/libexec/qt5/lib/QtDBus.framework/Headers -I/opt/local/libexec/qt
5/lib/QtCore.framework/Headers -Imoc -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications
/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/AGL.framework/Headers -I/opt/local/libexec/qt5/mkspecs/macx-clang -F/opt/local/libexec/qt5/l
ib -o obj/audiooutput.o audio/audiooutput.cpp                                                                                                                                                               
ccache clang++ -c -pipe -stdlib=libc++ -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DPIC -I /var/root/mythtv-31/mythtv/mythtv/external -I /opt/local/include -std=c++11 -DNDEBUG -fomit-frame-pointer -fPIC -
DQT_DISABLE_DEPRECATED_BEFORE=0x050700 -pthread -g -Wall -Wextra -Wpointer-arith -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS -Wno-constant-logical-operand -Wno-unused-value -Qunused-arguments -Wimplici
t-fallthrough -std=gnu++11  -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk -mmacosx-version-min=10.13 -fPIC -DUSING_APPLEREMOTE -D
using_libcec -D_GNU_SOURCE -DMYTH_API -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_XML_LIB -DQT_SQL_LIB -DQT_SCRIPT_LIB -DQT_DBUS_LIB -DQT_CORE_LIB -I. -I/opt/local/include -I/opt/loc
al/include/libxml2 -I../../external/libmythsoundtouch -I../libmythfreesurround -I../libmythbase -I../.. -I.. -I. -I../libmythupnp -I../libmythui -I../.. -I../../external/FFmpeg -I../libmythservicecontract
s -I/opt/local/libexec/qt5/lib/QtWidgets.framework/Headers -I/opt/local/libexec/qt5/lib/QtGui.framework/Headers -I/opt/local/libexec/qt5/lib/QtNetwork.framework/Headers -I/opt/local/libexec/qt5/lib/QtXml.
framework/Headers -I/opt/local/libexec/qt5/lib/QtSql.framework/Headers -I/opt/local/libexec/qt5/lib/QtScript.framework/Headers -I/opt/local/libexec/qt5/lib/QtDBus.framework/Headers -I/opt/local/libexec/qt
5/lib/QtCore.framework/Headers -Imoc -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications
/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/AGL.framework/Headers -I/opt/local/libexec/qt5/mkspecs/macx-clang -F/opt/local/libexec/qt5/l
ib -o obj/audiooutputbase.o audio/audiooutputbase.cpp                                                                                                                                                       
audio/audiooutputbase.cpp:630:18: error: use of undeclared identifier 'ff_codec_id_string'                                                                                                                  
            .arg(ff_codec_id_string(m_codec))                                                                                                                                                               
                 ^                                                                                                                                                                                          
1 error generated.                                                                                                                                                                                          
make[2]: *** [obj/audiooutputbase.o] Error 1                                                                                                                                                                
make[1]: *** [sub-libmyth-install_subtargets] Error 2                                                                                                                                                       
make: *** [libs_install] Error 2                                                                                                                                                                            
------------ Skipping Mythplugins Compile ------------                                                                                                                                                      
------------ Deploying QT to Mythfrontend Executable ------------                                                                                                                                           
Error: Could not find app bundle "/var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app"                                                                                                 
------------ Update Mythfrontend.app to use internal dylibs ------------                                                                                                                                    
osx-bundler: Couldn't locate /var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/Contents/MacOS/mythfrontend
------------ Installing libcec into Mythfrontend.app ------------                                     
./compileMythfrontendAnsible.zsh:cd:379: no such file or directory: /var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/Contents/Frameworks
cp: /var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/Contents/Frameworks/libcec.6.0.2.dylib: No such file or directory
ln: libcec.dylib: File exists
ln: libcec.6.dylib: File exists
osx-bundler: Couldn't locate /var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/Contents/Frameworks/libcec.6.0.2.dylib
error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/install_name_tool: can't open file: /var/root/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/C
ontents/MacOS/mythfrontend (No such file or directory)
------------ Installing additional mythtv utility executables into Mythfrontend.app  ------------
./compileMythfrontendAnsible.zsh:402: no matches found: /var/root/mythtv-31/31-osx-64bit/bin/*.app
Last edited by Steve Goodey on Fri Feb 26, 2021 7:33 am, edited 1 time in total.
Reason: libmythDOTPRO changed to libmyth.pro
ILMostro
Newcomer
Posts: 7
Joined: Fri Feb 26, 2021 5:11 am
Canada

Re: compiling mythtv on Apple M1 silicon

Post by ILMostro »

Please note, the forum software wouldn't let me post the previous message unless I removed "libmyth.pro" from the pre-formatted text. So, that was replaced by "libmythDOTPRO" instead.
User avatar
Steve Goodey
Moderator
Posts: 219
Joined: Fri Feb 07, 2014 6:30 pm
Location: Colchester, England
Great Britain

Re: compiling mythtv on Apple M1 silicon

Post by Steve Goodey »

libmythDOTPRO changed to libmyth.pro in pre-formatted text.
Don't forget the Wiki.
User avatar
jhoyt
Senior
Posts: 143
Joined: Thu Aug 27, 2015 10:11 am
United States of America

Re: compiling mythtv on Apple M1 silicon

Post by jhoyt »

@ILMostro - a big thank you for helping out!

The libcec error is not a big deal. I've actually had constant issues trying to get it to link in the app bundle and have been considering removing it as a required port. It really doesn't buy you much unless you're using HDMI to connect to a TV/monitor. I've removed it from the install instructions and will update the compilescipt this weekend to either remove any of the llibcec linking lines or fix the linking issue. Would you mind running a port contents on libcec and post the results for me?

Code: Select all

port contents libcec
The FFmpeg line is a bit more troubling. I previously would get a build failure at the exact same place when I had ffmpeg installed alongside a mythtv build. One of the more recent changes to linking order fixed that on intel. The core problem is that mythtv does a custom ffmpeg compile then links in the header/library. For some reason either the linker is picking up another ffmpeg header file or not finding the one it built. Any chance you port the full log somewhere?

When I have a little more time, I'll see what I can dig up on the macports sites to see if anyone has figured out a fix for this issue.
User avatar
jhoyt
Senior
Posts: 143
Joined: Thu Aug 27, 2015 10:11 am
United States of America

Re: compiling mythtv on Apple M1 silicon

Post by jhoyt »

@ILMostro - also would you mind trying this version of the compile script

https://github.com/MythTV/packaging/blo ... nsible.zsh

It's an older version (commit ccf3e92) that had a different way of linking in the mythtv ffmpeg goodies. I'm curious if it gives your different results. You' probably need to deactivate any ffmpeg install you have to prevent the linker bug I tried to squash:

Code: Select all

 sudo port deactivate ffmpeg
You can reactivate ffmpeg after testing with:

Code: Select all

 sudo port activate ffmpeg
ILMostro
Newcomer
Posts: 7
Joined: Fri Feb 26, 2021 5:11 am
Canada

Re: compiling mythtv on Apple M1 silicon

Post by ILMostro »

Sure thing,

Here are the files from libcec:

Code: Select all

port contents libcec
Port libcec contains:
  /opt/local/bin/cec-client
  /opt/local/bin/cec-client-6.0.2
  /opt/local/bin/cecc-client
  /opt/local/bin/cecc-client-6.0.2
  /opt/local/bin/pyCecClient
  /opt/local/include/libcec/cec.h
  /opt/local/include/libcec/cecc.h
  /opt/local/include/libcec/ceccloader.h
  /opt/local/include/libcec/cecloader.h
  /opt/local/include/libcec/cectypes.h
  /opt/local/include/libcec/version.h
  /opt/local/lib/libcec.6.0.2.dylib
  /opt/local/lib/libcec.6.dylib
  /opt/local/lib/libcec.dylib
  /opt/local/lib/pkgconfig/libcec.pc
  /opt/local/lib/python3.8/site-packages/_cec.so
  /opt/local/lib/python3.8/site-packages/cec.py
  /opt/local/share/doc/libcec/AUTHORS
  /opt/local/share/doc/libcec/COPYING
  /opt/local/share/doc/libcec/README.md
  /opt/local/share/doc/libcec/changelog.in
I've attached the output of the zshell script, as requested, with the following config options:

Code: Select all

# setup default variables
BUILD_PLUGINS=false
PYTHON_VERS="38"
UPDATE_PORTS=false
MYTHTV_VERS="fixes/31"
UPDATE_GIT=true
SKIP_BUILD=true
SKIP_ANSIBLE=true
APPLY_PATCHES=false
MYTHTV_PATCH_DIR=""
PACK_PATCH_DIR=""
PLUGINS_PATCH_DIR=""
I'll try the other version of the script next.

Thank you.
Attachments
compileMythfrontendAnsible.output.log
(71.08 KiB) Downloaded 126 times
ILMostro
Newcomer
Posts: 7
Joined: Fri Feb 26, 2021 5:11 am
Canada

Re: compiling mythtv on Apple M1 silicon

Post by ILMostro »

All right,

Using that older zshell script, it shows the ffmpeg compilation, at least. In the end, though, there is still an error about missing target "mythavtest", which may or may not be necessary. Attaching the output here is refused, as the file is 1.3MB in size. So, I've uploaded it to https://file.io/HSirJubuhUOU

For what it's worth, sha256sum is

Code: Select all

a297b866b369ca2d32270616e9f83d59e51d52cc8ef365334216087c2e713a8b
ILMostro
Newcomer
Posts: 7
Joined: Fri Feb 26, 2021 5:11 am
Canada

Re: compiling mythtv on Apple M1 silicon

Post by ILMostro »

Rerunning that script after I've removed /var/root/mythtv-31/ to get a clean start results in failure with py2app not having a precompiled apptemplate for arm64.

https://file.io/YEhWVCp9woLh

Code: Select all

31b867cc35a55f5f549563db40bba13b79dc189047f0654b748d91fb1e19a0a2  compileMythfrontendAnsible-older.output2.log
User avatar
jhoyt
Senior
Posts: 143
Joined: Thu Aug 27, 2015 10:11 am
United States of America

Re: compiling mythtv on Apple M1 silicon

Post by jhoyt »

Wow - that second log file looks promising. You made it through the entire compile and got tripped up in packaging. You were only a couple steps away from generating the .dmg file.

You should be able to run the mythfrontend executable from the command line it'll be installed in ~/mythtv-31/31-osx-64bit/bin/mythfrontend.app

Also - it should be executable in ~/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/Contents/MacOS/mythfrontend
or ~/mythtv-31/mythtv/mythtv/programs/mythfrontend/mythfrontend.app/Contents/MacOS/mythfrontend.real (depending on how far the compile script really got)

I'm curious it if loads :)

As for the py2app issue - I use py2app to bundle a working python installation into the application bundle. The error in the compile script is from it trying to find the correct prebuilt python profile. Doing an ls of the directory on my computer shows:

Code: Select all

% ls /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/py2app/apptemplate/prebuilt/
main-fat            main-i386           main-ppc            main-universal      secondary-fat       secondary-i386      secondary-ppc       secondary-universal
main-fat3           main-intel          main-ppc64          main-x86_64         secondary-fat3      secondary-intel     secondary-ppc64     secondary-x86_64
The key is it's missing something for main-arm64 (as the error message states). I just checked and its missing in the python29 version as well.

Can you run the following and post your results?

Code: Select all

 ls /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/py2app/apptemplate/prebuilt/
The real fix is to get the port updated (we can work on that later...)

A faster solution is we can modify py2app to use the "main-universal" base directory by issuing a -b switch to py2applet in the script, i.e. change the following line

Code: Select all

$PY2APPLET_BIN -p $PYTHON_RUNTIME_PKGS --site-packages --use-pythonpath --make-setup $INSTALL_DIR/share/mythtv/metadata/Television/ttvdb.py
to

Code: Select all

$PY2APPLET_BIN -p $PYTHON_RUNTIME_PKGS -b /opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/py2app/apptemplate/prebuilt/main-universal --site-packages --use-pythonpath --make-setup $INSTALL_DIR/share/mythtv/metadata/Television/ttvdb.py
If that works, I can come up with a switch in the compile script that auto path's to universal for arm64 / x86_64 for intel.

Let me know if your comfortable editing the compile script or if it's easier on you for me to post a modified compile script to test
User avatar
jhoyt
Senior
Posts: 143
Joined: Thu Aug 27, 2015 10:11 am
United States of America

Re: compiling mythtv on Apple M1 silicon

Post by jhoyt »

looking into the py2app issue, it looks like they added arm support in v0.22 (and are up to v0.24) https://py2app.readthedocs.io/en/latest ... y2app-0-24.

ARM support is also in the git repo https://github.com/ronaldoussoren/py2ap ... e/prebuilt

Macports is up to v0.23, but doesn't install the arm bits - wonder if this was intentional or just an oversight by the port maintainer.
User avatar
pvr4me
Senior
Posts: 763
Joined: Fri Feb 07, 2014 7:25 pm
Location: near Toronto, Canada
Contact:
Canada

Re: compiling mythtv on Apple M1 silicon

Post by pvr4me »

jhoyt wrote:
Sat Feb 27, 2021 12:15 am
looking into the py2app issue, it looks like they added arm support in v0.22 (and are up to v0.24) https://py2app.readthedocs.io/en/latest ... y2app-0-24.

ARM support is also in the git repo https://github.com/ronaldoussoren/py2ap ... e/prebuilt

Macports is up to v0.23, but doesn't install the arm bits - wonder if this was intentional or just an oversight by the port maintainer.
Py2app doesn't look like they've released 0.24. Also, from a quick look at the port file, it doesn't not like there is any special handling for these templates. Possibly upstream needs to fix something.

Craig
Formerly the MacPorts guy.
Post Reply