Open pcko1 opened 3 years ago
To compile on an M1 machine, with macOS 12.3, I had to do the following (It's a https://fish.sh script, not bash!!!):
#!/usr/bin/env fish
brew install cmake qt
git clone https://github.com/meganz/MEGAcmd.git
cd MEGAcmd
git submodule update --init --recursive
# cryptopp is not on Homebrew
git clone https://github.com/weidai11/cryptopp
pushd cryptopp
make
popd
# pdfium is not on HomeBrew, but we have arm64 binaries available
mkdir pdfium
pushd pdfium
curl -LO https://github.com/bblanchon/pdfium-binaries/releases/latest/download/pdfium-mac-arm64.tgz
tar -xf pdfium-mac-arm64.tgz
popd
# This project builds sqlite instead of using binaries
curl -LO https://www.sqlite.org/2022/sqlite-amalgamation-3380500.zip
unzip sqlite-amalgamation-3380500.zip
mkdir -p sdk/bindings/qt/3rdparty/{include,libs}
cp sqlite-amalgamation-3380500/sqlite3.c sdk/bindings/qt/3rdparty/sqlite3.c
cp sqlite-amalgamation-3380500/sqlite3.h sdk/bindings/qt/3rdparty/include/sqlite3.h
# We need static c-ares and homebrew only gives us a dynamic one
git clone https://github.com/c-ares/c-ares.git
pushd c-ares
mkdir build
pushd build
cmake .. -DCARES_STATIC=ON
make
popd
popd
set LIBS readline openssl@1.1 c-ares curl freeimage libsodium ffmpeg media-info pcre libuv libnghttp2 libssh2 openldap libidn2 krb5 brotli rtmpdump zstd
brew install $LIBS
# Patches FreeImage to turn typedef's into #define's
echo "
--- /opt/homebrew/opt/freeimage/include/FreeImage.h 2022-05-14 17:45:04.000000000 +0200
+++ FreeImage.h 2022-05-14 17:48:11.000000000 +0200
@@ -150,22 +150,22 @@
#ifndef _MSC_VER
// define portable types for 32-bit / 64-bit OS
#include <inttypes.h>
-typedef int32_t BOOL;
-typedef uint8_t BYTE;
-typedef uint16_t WORD;
-typedef uint32_t DWORD;
-typedef int32_t LONG;
-typedef int64_t INT64;
-typedef uint64_t UINT64;
+#define BOOL int32_t
+#define BYTE uint8_t
+#define WORD uint16_t
+#define DWORD uint32_t
+#define LONG int32_t
+#define FIINT64 int64_t
+#define FIUINT64 uint64_t
#else
// MS is not C99 ISO compliant
-typedef long BOOL;
-typedef unsigned char BYTE;
-typedef unsigned short WORD;
-typedef unsigned long DWORD;
-typedef long LONG;
-typedef signed __int64 INT64;
-typedef unsigned __int64 UINT64;
+#define BOOL long
+#define BYTE unsigned char
+#define WORD unsigned short
+#define DWORD unsigned long
+#define LONG long
+#define FIINT64 signed __int64
+#define FIUINT64 unsigned __int64
#endif // _MSC_VER
#if (defined(_WIN32) || defined(__WIN32__))" | patch -N (brew --prefix freeimage)/include/FreeImage.h
# Patches the SDK because it's calling a property which was hidden by the AVCodec guys.
echo "
--- sdk/src/gfx/freeimage.cpp 2022-05-14 18:47:50.000000000 +0200
+++ sdk/src/gfx/freeimage.cpp 2022-05-14 18:49:08.000000000 +0200
@@ -236,7 +236,7 @@
// Find decoder for video stream
AVCodecID codecId = codecParm->codec_id;
- AVCodec* decoder = avcodec_find_decoder(codecId);
+ const AVCodec* decoder = avcodec_find_decoder(codecId);
if (!decoder)
{
LOG_warn << "Codec not found: " << codecId;
@@ -253,7 +253,7 @@
// Force seeking to key frames
formatContext->seek2any = false;
- videoStream->skip_to_keyframe = true;
+ // videoStream->skip_to_keyframe = true;
if (decoder->capabilities & CAP_TRUNCATED)
{
codecContext->flags |= CAP_TRUNCATED;" | patch -N sdk/src/gfx/freeimage.cpp
# Patches installer_mac.sh to not build itself and to get the correct binaries.
echo '
--- /Users/alan/Developer/MEGAcmd/build/installer_mac.sh 2022-05-13 11:39:30.000000000 +0200
+++ installer_mac.sh 2022-05-14 23:23:57.000000000 +0200
@@ -7,17 +7,17 @@
APP_NAME=MEGAcmd
MOUNTDIR=tmp
RESOURCES=installer/resourcesDMG
-QTBASE=/QT/qt5/qtbase
+QTBASE=$(brew --prefix qt)
-AVCODEC_VERSION=libavcodec.57.dylib
-AVFORMAT_VERSION=libavformat.57.dylib
-AVUTIL_VERSION=libavutil.55.dylib
-SWSCALE_VERSION=libswscale.4.dylib
-
-AVCODEC_PATH=sdk/bindings/qt/3rdparty/libs/$AVCODEC_VERSION
-AVFORMAT_PATH=sdk/bindings/qt/3rdparty/libs/$AVFORMAT_VERSION
-AVUTIL_PATH=sdk/bindings/qt/3rdparty/libs/$AVUTIL_VERSION
-SWSCALE_PATH=sdk/bindings/qt/3rdparty/libs/$SWSCALE_VERSION
+AVCODEC_VERSION=$(basename $(ls $(brew --prefix ffmpeg)/lib/libavcodec.??.dylib))
+AVFORMAT_VERSION=$(basename $(ls $(brew --prefix ffmpeg)/lib/libavformat.??.dylib))
+AVUTIL_VERSION=$(basename $(ls $(brew --prefix ffmpeg)/lib/libavutil.??.dylib))
+SWSCALE_VERSION=$(basename $(ls $(brew --prefix ffmpeg)/lib/libswscale.?.dylib))
+
+AVCODEC_PATH=$(brew --prefix ffmpeg)/lib/$AVCODEC_VERSION
+AVFORMAT_PATH=$(brew --prefix ffmpeg)/lib/$AVFORMAT_VERSION
+AVUTIL_PATH=$(brew --prefix ffmpeg)/lib/$AVUTIL_VERSION
+SWSCALE_PATH=$(brew --prefix ffmpeg)/lib/$SWSCALE_VERSION
sign=0
createdmg=0
@@ -37,11 +37,11 @@
shift
done
-rm -rf Release_x64
-mkdir Release_x64
+# rm -rf Release_x64
+# mkdir Release_x64
cd Release_x64
-$QTBASE/bin/qmake -r ../../contrib/QtCreator/MEGAcmd/ -spec macx-g++ CONFIG+=release CONFIG+=x86_64 -nocache
-make -j$(sysctl -n hw.ncpu)
+# $QTBASE/bin/qmake -r ../../contrib/QtCreator/MEGAcmd/ -spec macx-g++ CONFIG+=release CONFIG+=x86_64 -nocache
+# make -j$(sysctl -n hw.ncpu)
#After building, we will have 5 folders (one per project: MEGAcmdServer, MEGAcmdClient, MEGAcmdLoader, MEGAcmdUpdater & MEGAcmdShell)
# we will include the stuff from the other 4 into MEGAcmdServer folder
@@ -98,10 +98,10 @@
mv MEGAcmdServer/MEGAcmd.app ./MEGAcmd.app
mkdir -p MEGAcmd.app/Contents/Frameworks
-cp -L ../../$AVCODEC_PATH MEGAcmd.app/Contents/Frameworks/
-cp -L ../../$AVFORMAT_PATH MEGAcmd.app/Contents/Frameworks/
-cp -L ../../$AVUTIL_PATH MEGAcmd.app/Contents/Frameworks/
-cp -L ../../$SWSCALE_PATH MEGAcmd.app/Contents/Frameworks/
+cp -L $AVCODEC_PATH MEGAcmd.app/Contents/Frameworks/
+cp -L $AVFORMAT_PATH MEGAcmd.app/Contents/Frameworks/
+cp -L $AVUTIL_PATH MEGAcmd.app/Contents/Frameworks/
+cp -L $SWSCALE_PATH MEGAcmd.app/Contents/Frameworks/
if [ ! -f MEGAcmd.app/Contents/Frameworks/$AVCODEC_VERSION ] \
|| [ ! -f MEGAcmd.app/Contents/Frameworks/$AVFORMAT_VERSION ] \
@@ -163,11 +163,4 @@
rmdir $MOUNTDIR
fi
-echo "Cleaning"
-rm -rf MEGAcmdServer
-rm -rf MEGAcmdClient
-rm -rf MEGAcmdShell
-rm -rf MEGAcmdLoader
-rm -rf MEGAcmdUpdater
-
echo "DONE"' | patch -N build/installer_mac.sh
sh autogen.sh
set LDFLAGS -L(pwd)/cryptopp -L(pwd)/pdfium/lib -lnghttp2 -lssh2 -lldap -llber -lidn2 -lgssapi_krb5 -lssl -lcrypto -lbrotli{common,dec,enc}-static -lrtmp -lzstd -lresolv
set CFLAGS -I(pwd) -I(pwd)/pdfium/include -I(pwd)/cryptopp
for lib in $LIBS
set -p LDFLAGS -L(brew --prefix $lib)/lib
set -p CFLAGS -I(brew --prefix $lib)/include
cp (brew --prefix $lib)/lib/*.a sdk/bindings/qt/3rdparty/libs
end
cp c-ares/build/lib/libcares_static.a sdk/bindings/qt/3rdparty/libs/libcares.a
cp pdfium/lib/* sdk/bindings/qt/3rdparty/libs
./configure LDFLAGS="$LDFLAGS" CXXFLAGS="-std=c++17 $CFLAGS" OBJCXXFLAGS="-std=c++17 $CFLAGS" CFLAGS="$CFLAGS" CPPFLAGS="$CFLAGS"
find contrib/QtCreator -type f -name '*.pr*' -exec sed -i '' -e "s/10.9/$(sw_vers -productVersion)/g" {} \;
mkdir -p build/Release_x64
pushd build/Release_x64
qmake ../../contrib/QtCreator/MEGAcmd QMAKE_CFLAGS_RELEASE="$CFLAGS" QMAKE_CXXFLAGS_RELEASE="-std=c++17 $CFLAGS" QMAKE_LFLAGS_RELEASE="$LDFLAGS"
make
for exe in */*.app/Contents/MacOS/*
install_name_tool -change ./libpdfium.dylib (pwd)/../../pdfium/lib/libpdfium.dylib $exe
end
cd ..
zsh installer_mac.sh
popd
However, mega-cmd SIGSEGV (Address boundary error), which is the same problem I have with the binaries I download from the site.
hello, how fix the issue on mac m1 ?
Platform:
macOS Big Sur v11.2.1 (M1 chip)
Steps: I have copied the 3rd-party dependencies into
sdk/bindings/qt/
andsdk/include/mega/config.h
. I have alsoexport LDFLAGS="-L/my_path_to_downloads_dir/MEGAcmd/sdk/bindings/qt/3rdparty/libs"
andexport CPPFLAGS="-I/my_path_to_downloads_dir/MEGAcmd/sdk/bindings/qt/3rdparty/include"
. Then I runsudo ./configure
.Error:
configure: error: readline library is required for the sample client.
Log: