From 2cab2ce8855a47b64569f1cf37df75e8baf7b114 Mon Sep 17 00:00:00 2001
From: Nicolas Pierron <nicolas.b.pierron@gmail.com>
Date: Sun, 17 Apr 2011 08:27:22 +0000
Subject: [PATCH] Fuppes: Fix support of faad2, backward compatibility macros
 were not expanded in strings.

svn path=/nixpkgs/trunk/; revision=26864
---
 pkgs/tools/networking/fuppes/default.nix      |  9 ++
 ...-faad-exanpse-backward-symbols-macro.patch | 91 +++++++++++++++++++
 2 files changed, 100 insertions(+)
 create mode 100644 pkgs/tools/networking/fuppes/fuppes-faad-exanpse-backward-symbols-macro.patch

diff --git a/pkgs/tools/networking/fuppes/default.nix b/pkgs/tools/networking/fuppes/default.nix
index dca3b40ef5f4..711c3516bda2 100644
--- a/pkgs/tools/networking/fuppes/default.nix
+++ b/pkgs/tools/networking/fuppes/default.nix
@@ -8,6 +8,10 @@ stdenv.mkDerivation rec {
     sha256 = "1c385b29878927e5f1e55ae2c9ad284849d1522d9517a88e34feb92bd5195173";
   };
 
+  patches = [
+    ./fuppes-faad-exanpse-backward-symbols-macro.patch
+  ];
+
   buildInputs = [
     pkgconfig pcre libxml2 sqlite ffmpeg imagemagick exiv2 mp4v2 lame
     libvorbis flac libmad faad2
@@ -26,6 +30,11 @@ stdenv.mkDerivation rec {
     "--enable-faad"
   ];
 
+  postFixup = ''
+    patchelf --set-rpath "$(patchelf --print-rpath $out/bin/fuppes):${faad2}/lib" $out/bin/fuppes
+    patchelf --set-rpath "$(patchelf --print-rpath $out/bin/fuppesd):${faad2}/lib" $out/bin/fuppesd
+  '';
+
   meta = {
     description = "UPnP A/V Media Server";
     longDescription = ''
diff --git a/pkgs/tools/networking/fuppes/fuppes-faad-exanpse-backward-symbols-macro.patch b/pkgs/tools/networking/fuppes/fuppes-faad-exanpse-backward-symbols-macro.patch
new file mode 100644
index 000000000000..c88a6fb4427e
--- /dev/null
+++ b/pkgs/tools/networking/fuppes/fuppes-faad-exanpse-backward-symbols-macro.patch
@@ -0,0 +1,91 @@
+diff -x _inst -x _build -x .svn -ur fuppes-0.660/src/lib/Transcoding/FaadWrapper.cpp fuppes-0.660.new/src/lib/Transcoding/FaadWrapper.cpp
+--- fuppes-0.660/src/lib/Transcoding/FaadWrapper.cpp	2009-11-19 10:16:25.000000000 +0100
++++ fuppes-0.660.new/src/lib/Transcoding/FaadWrapper.cpp	2011-01-30 22:25:34.171263052 +0100
+@@ -329,13 +329,19 @@
+   
+   CloseFile();
+ }
+-  
++
++// These macros are used to convert old function names to new ones based on
++// the #define declared in faad headers.  The two-level macro are used to
++// expanse the macro which are gave to to_str.
++#define to_str_(fun) #fun
++#define to_str(fun) to_str_(fun)
++
+ bool CFaadWrapper::LoadLib()
+ {
+   #ifdef WIN32 
+-  std::string sLibName = "libfaad-0.dll"; 
++  std::string sLibName = "libfaad-2.dll"; 
+   #else   
+-  std::string sLibName = "libfaad.so.0"; 
++  std::string sLibName = "libfaad.so.2"; 
+   #endif 
+    
+   if(!CSharedConfig::Shared()->FaadLibName().empty()) { 
+@@ -350,54 +356,54 @@
+     return false; 
+   }
+  
+-  m_faacDecOpen = (faacDecOpen_t)FuppesGetProcAddress(m_LibHandle, "faacDecOpen"); 
++  m_faacDecOpen = (faacDecOpen_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecOpen)); 
+   if(!m_faacDecOpen) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecOpen'", __FILE__, __LINE__);    
+     return false; 
+   }
+ 
+-  m_faacDecGetErrorMessage = (faacDecGetErrorMessage_t)FuppesGetProcAddress(m_LibHandle, "faacDecGetErrorMessage"); 
++  m_faacDecGetErrorMessage = (faacDecGetErrorMessage_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecGetErrorMessage)); 
+   if(!m_faacDecGetErrorMessage) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecGetErrorMessage'", __FILE__, __LINE__);    
+     return false; 
+   }
+   
+-  m_faacDecGetCurrentConfiguration = (faacDecGetCurrentConfiguration_t)FuppesGetProcAddress(m_LibHandle, "faacDecGetCurrentConfiguration"); 
++  m_faacDecGetCurrentConfiguration = (faacDecGetCurrentConfiguration_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecGetCurrentConfiguration)); 
+   if(!m_faacDecGetCurrentConfiguration) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecGetCurrentConfiguration'", __FILE__, __LINE__);    
+   } 
+ 
+-  m_faacDecSetConfiguration = (faacDecSetConfiguration_t)FuppesGetProcAddress(m_LibHandle, "faacDecSetConfiguration"); 
++  m_faacDecSetConfiguration = (faacDecSetConfiguration_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecSetConfiguration)); 
+   if(!m_faacDecSetConfiguration) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecSetConfiguration'", __FILE__, __LINE__);    
+   } 
+ 
+-  m_faacDecInit = (faacDecInit_t)FuppesGetProcAddress(m_LibHandle, "faacDecInit"); 
++  m_faacDecInit = (faacDecInit_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecInit)); 
+   if(!m_faacDecInit) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecInit'", __FILE__, __LINE__);    
+   } 
+ 
+-  m_faacDecInit2 = (faacDecInit2_t)FuppesGetProcAddress(m_LibHandle, "faacDecInit2"); 
++  m_faacDecInit2 = (faacDecInit2_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecInit2)); 
+   if(!m_faacDecInit2) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecInit2'", __FILE__, __LINE__);    
+     return false; 
+   }
+   
+-  m_faacDecDecode = (faacDecDecode_t)FuppesGetProcAddress(m_LibHandle, "faacDecDecode"); 
++  m_faacDecDecode = (faacDecDecode_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecDecode)); 
+   if(!m_faacDecDecode) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecDecode'", __FILE__, __LINE__);    
+     return false; 
+   } 
+ 
+-  m_faacDecClose = (faacDecClose_t)FuppesGetProcAddress(m_LibHandle, "faacDecClose"); 
++  m_faacDecClose = (faacDecClose_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecClose)); 
+   if(!m_faacDecClose) { 
+     CSharedLog::Shared()->Log(L_EXT, "cannot load symbol 'faacDecClose'", __FILE__, __LINE__);    
+     return false; 
+   } 
+ 
+-  m_AudioSpecificConfig = (AudioSpecificConfig_t)FuppesGetProcAddress(m_LibHandle, "AudioSpecificConfig"); 
++  m_AudioSpecificConfig = (AudioSpecificConfig_t)FuppesGetProcAddress(m_LibHandle, to_str(AudioSpecificConfig)); 
+   if(!m_AudioSpecificConfig) {
+-		m_AudioSpecificConfig = (AudioSpecificConfig_t)FuppesGetProcAddress(m_LibHandle, "faacDecAudioSpecificConfig"); 
++		m_AudioSpecificConfig = (AudioSpecificConfig_t)FuppesGetProcAddress(m_LibHandle, to_str(faacDecAudioSpecificConfig)); 
+ 		if(!m_AudioSpecificConfig) {  
+   	  CSharedLog::Shared()->Log(L_EXT, "cannot load symbol '(faacDec)AudioSpecificConfig'", __FILE__, __LINE__);    
+       return false;