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

megacmd: add ffmpeg and freeimage support; add darwin support #362308

Merged
merged 3 commits into from
Jan 4, 2025
Merged
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
49 changes: 49 additions & 0 deletions pkgs/by-name/me/megacmd/fix-darwin.patch
Original file line number Diff line number Diff line change
@@ -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<char*> 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
29 changes: 29 additions & 0 deletions pkgs/by-name/me/megacmd/fix-ffmpeg.patch
Original file line number Diff line number Diff line change
@@ -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<AVPixelFormat>(codecParm->format);
AVPixelFormat targetPixelFormat = AV_PIX_FMT_BGR24; //raw data expected by freeimage is in this format
141 changes: 88 additions & 53 deletions pkgs/by-name/me/megacmd/package.nix
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
];
};
}
Loading