diff --git a/pkgs/by-name/me/megacmd/fix-darwin.patch b/pkgs/by-name/me/megacmd/fix-darwin.patch new file mode 100644 index 0000000000000..7fa87b43163a0 --- /dev/null +++ b/pkgs/by-name/me/megacmd/fix-darwin.patch @@ -0,0 +1,49 @@ +--- a/Makefile.am ++++ b/Makefile.am +@@ -25,6 +25,11 @@ AM_CPPFLAGS = \ + + AM_CPPFLAGS+=-I$(top_srcdir)/src -I$(top_srcdir)/sdk/include + ++if DARWIN ++AM_LIBTOOLFLAGS="--tag=CXX" ++AM_CPPFLAGS+=-I$(top_srcdir)/include/mega/osx -I$(top_srcdir)/sdk/include/mega/osx ++endif ++ + if WIN32 + AM_CPPFLAGS+=-I$(top_srcdir)/sdk/include/mega/win32 + else +--- a/src/megacmdshell/megacmdshellcommunications.cpp ++++ b/src/megacmdshell/megacmdshellcommunications.cpp +@@ -306,10 +306,6 @@ SOCKET MegaCmdShellCommunications::createSocket(int number, bool initializeserve + #endif + const char executable2[] = "./mega-cmd-server"; + #else +- #ifdef __MACH__ +- const char executable[] = "/Applications/MEGAcmd.app/Contents/MacOS/mega-cmd"; +- const char executable2[] = "./mega-cmd"; +- #else + const char executable[] = "mega-cmd-server"; + #ifdef __linux__ + char executable2[PATH_MAX]; +@@ -317,7 +313,6 @@ SOCKET MegaCmdShellCommunications::createSocket(int number, bool initializeserve + #else + const char executable2[] = "./mega-cmd-server"; + #endif +- #endif + #endif + + std::vector argsVector{ +--- a/sdk/Makefile.am ++++ b/sdk/Makefile.am +@@ -27,6 +27,11 @@ AM_CPPFLAGS = \ + + include m4/aminclude.am + ++if DARWIN ++AM_LIBTOOLFLAGS="--tag=CXX" ++AM_CPPFLAGS+=-I$(top_srcdir)/include/mega/osx ++endif ++ + if WIN32 + AM_CPPFLAGS+=-I$(top_srcdir)/include/mega/win32 + else diff --git a/pkgs/by-name/me/megacmd/fix-ffmpeg.patch b/pkgs/by-name/me/megacmd/fix-ffmpeg.patch new file mode 100644 index 0000000000000..45d6e85b373c8 --- /dev/null +++ b/pkgs/by-name/me/megacmd/fix-ffmpeg.patch @@ -0,0 +1,29 @@ +--- a/sdk/src/gfx/freeimage.cpp ++++ b/sdk/src/gfx/freeimage.cpp +@@ -216,11 +216,13 @@ bool GfxProviderFreeImage::readbitmapFreeimage(const LocalPath& imagePath, int s + + #ifdef HAVE_FFMPEG + ++#if LIBAVCODEC_VERSION_MAJOR < 60 + #ifdef AV_CODEC_CAP_TRUNCATED + #define CAP_TRUNCATED AV_CODEC_CAP_TRUNCATED + #else + #define CAP_TRUNCATED CODEC_CAP_TRUNCATED + #endif ++#endif + + const char *GfxProviderFreeImage::supportedformatsFfmpeg() + { +@@ -323,10 +325,12 @@ bool GfxProviderFreeImage::readbitmapFfmpeg(const LocalPath& imagePath, int size + + // Force seeking to key frames + formatContext->seek2any = false; ++#if LIBAVCODEC_VERSION_MAJOR < 60 + if (decoder->capabilities & CAP_TRUNCATED) + { + codecContext->flags |= CAP_TRUNCATED; + } ++#endif + + AVPixelFormat sourcePixelFormat = static_cast(codecParm->format); + AVPixelFormat targetPixelFormat = AV_PIX_FMT_BGR24; //raw data expected by freeimage is in this format diff --git a/pkgs/by-name/me/megacmd/package.nix b/pkgs/by-name/me/megacmd/package.nix index 3e2625e9a7a89..ea68f8fa84cee 100644 --- a/pkgs/by-name/me/megacmd/package.nix +++ b/pkgs/by-name/me/megacmd/package.nix @@ -1,66 +1,85 @@ -{ lib -, stdenv -, autoreconfHook -, c-ares -, cryptopp -, curl -, fetchFromGitHub - # build fails with latest ffmpeg, see https://github.com/meganz/MEGAcmd/issues/523. - # to be re-enabled when patch available - # , ffmpeg -, gcc-unwrapped -, icu -, libmediainfo -, libraw -, libsodium -, libuv -, libzen -, pcre-cpp -, pkg-config -, readline -, sqlite +{ + lib, + stdenv, + autoreconfHook, + c-ares, + cryptopp, + curl, + fetchFromGitHub, + ffmpeg, + freeimage, + gcc-unwrapped, + icu, + libmediainfo, + libraw, + libsodium, + libuv, + libzen, + pcre-cpp, + pkg-config, + readline, + sqlite, + withFreeImage ? false, # default to false because freeimage is insecure }: -stdenv.mkDerivation rec { +let pname = "megacmd"; version = "1.7.0"; + srcOptions = + if stdenv.isLinux then + { + tag = "${version}_Linux"; + hash = "sha256-UlSqwM8GQKeG8/K0t5DbM034NQOeBg+ujNi/MMsVCuM="; + } + else + { + tag = "${version}_macOS"; + hash = "sha256-UlSqwM8GQKeG8/K0t5DbM034NQOeBg+ujNi/MMsVCuM="; + }; +in +stdenv.mkDerivation { + inherit pname version; - src = fetchFromGitHub { - owner = "meganz"; - repo = "MEGAcmd"; - rev = "${version}_Linux"; - hash = "sha256-UlSqwM8GQKeG8/K0t5DbM034NQOeBg+ujNi/MMsVCuM="; - fetchSubmodules = true; - }; + src = fetchFromGitHub ( + srcOptions + // { + owner = "meganz"; + repo = "MEGAcmd"; + fetchSubmodules = true; + } + ); enableParallelBuilding = true; - nativeBuildInputs = [ autoreconfHook pkg-config ]; - - buildInputs = [ - c-ares - cryptopp - curl - # ffmpeg - icu - gcc-unwrapped - libmediainfo - libraw - libsodium - libuv - libzen - pcre-cpp - readline - sqlite + nativeBuildInputs = [ + autoreconfHook + pkg-config ]; + buildInputs = + lib.optionals stdenv.isLinux [ gcc-unwrapped ] # fix: ld: cannot find lib64/libstdc++fs.a + ++ [ + c-ares + cryptopp + curl + ffmpeg + icu + libmediainfo + libraw + libsodium + libuv + libzen + pcre-cpp + readline + sqlite + ] + ++ lib.optionals withFreeImage [ freeimage ]; + configureFlags = [ - "--disable-curl-checks" "--disable-examples" "--with-cares" "--with-cryptopp" "--with-curl" - # "--with-ffmpeg" - "--without-freeimage" # disabled as freeimage is insecure + "--with-ffmpeg" "--with-icu" "--with-libmediainfo" "--with-libuv" @@ -69,13 +88,29 @@ stdenv.mkDerivation rec { "--with-readline" "--with-sodium" "--with-termcap" + ] ++ (if withFreeImage then [ "--with-freeimage" ] else [ "--without-freeimage" ]); + + # On darwin, some macros defined in AssertMacros.h (from apple-sdk) are conflicting. + postConfigure = '' + echo '#define __ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES 0' >> sdk/include/mega/config.h + ''; + + patches = [ + ./fix-ffmpeg.patch # https://github.com/meganz/sdk/issues/2635#issuecomment-1495405085 + ./fix-darwin.patch # fix: libtool tag not found; MacFileSystemAccess not declared; server cannot init ]; - meta = with lib; { + meta = { description = "MEGA Command Line Interactive and Scriptable Application"; homepage = "https://mega.io/cmd"; - license = with licenses; [ bsd2 gpl3Only ]; - platforms = [ "i686-linux" "x86_64-linux" ]; - maintainers = with maintainers; [ lunik1 ]; + license = with lib.licenses; [ + bsd2 + gpl3Only + ]; + platforms = lib.platforms.linux ++ lib.platforms.darwin; + maintainers = with lib.maintainers; [ + lunik1 + ulysseszhan + ]; }; }