Permalink
Browse files

Added checks for location of include files

  • Loading branch information...
1 parent 70f11be commit d9580783e0043f648e11b9c48e32af10b9467732 @wedesoft committed Oct 8, 2010
Showing with 73 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +47 −2 Rakefile
  3. +1 −0 ext/.gitignore
  4. +12 −0 ext/avinput.hh
  5. +12 −0 ext/avoutput.hh
View
@@ -5,4 +5,5 @@ pkg
*~
*.gem
*.swp
+*.log
View
@@ -28,7 +28,7 @@ HOMEPAGE = %q{http://wedesoft.github.com/hornetseye-ffmpeg/}
OBJ = CC_FILES.ext 'o'
$CXXFLAGS = ENV[ 'CXXFLAGS' ] || ''
-$CXXFLAGS = "#{$CXXFLAGS} -fPIC -DNDEBUG"
+$CXXFLAGS = "#{$CXXFLAGS} -fPIC -DNDEBUG -DHAVE_CONFIG_H"
if RbConfig::CONFIG[ 'rubyhdrdir' ]
$CXXFLAGS = "#{$CXXFLAGS} -I#{RbConfig::CONFIG[ 'rubyhdrdir' ]} " +
"-I#{RbConfig::CONFIG[ 'rubyhdrdir' ]}/#{RbConfig::CONFIG[ 'arch' ]}"
@@ -73,6 +73,51 @@ task :uninstall do
end
end
+desc 'Create config.h'
+task :config_h => 'ext/config.h'
+
+def check_program
+ f_base_name = 'rakeconf'
+ begin
+ File.open( "#{f_base_name}.cc", 'w' ) { |f| yield f }
+ `#{CXX} -S #{$CXXFLAGS} -c -o #{f_base_name}.o #{f_base_name}.cc 2>&1 >> rake.log`
+ $?.exitstatus == 0
+ ensure
+ File.delete *Dir.glob( "#{f_base_name}.*" )
+ end
+end
+
+file 'ext/config.h' do |t|
+ s = "/* config.h. Generated from Rakefile by rake. */\n"
+ libswscale_incdir = check_program do |c|
+ c.puts <<EOS
+extern "C" {
+ #include <libswscale/swscale.h>
+}
+int main(void) { return 0; }
+EOS
+ end
+ if libswscale_incdir
+ s << "#define HAVE_LIBSWSCALE_INCDIR 1\n"
+ else
+ s << "#undef HAVE_LIBSWSCALE_INCDIR\n"
+ end
+ libavformat_incdir = check_program do |c|
+ c.puts <<EOS
+extern "C" {
+ #include <libavformat/avformat.h>
+}
+int main(void) { return 0; }
+EOS
+ end
+ if libavformat_incdir
+ s << "#define HAVE_LIBAVFORMAT_INCDIR 1\n"
+ else
+ s << "#undef HAVE_LIBAVFORMAT_INCDIR\n"
+ end
+ File.open( t.name, 'w' ) { |f| f.puts s }
+end
+
Rake::TestTask.new do |t|
t.libs << 'ext'
t.test_files = TC_FILES
@@ -170,7 +215,7 @@ rule '.o' => '.cc' do |t|
sh "#{CXX} #{$CXXFLAGS} -c -o #{t.name} #{t.source}"
end
-file ".depends.mf" do |t|
+file ".depends.mf" => :config_h do |t|
sh "g++ -MM #{$CXXFLAGS} #{CC_FILES.join ' '} | " +
"sed -e :a -e N -e 's/\\n/\\$/g' -e ta | " +
"sed -e 's/ *\\\\\\$ */ /g' -e 's/\\$/\\n/g' | sed -e 's/^/ext\\//' > #{t.name}"
View
@@ -1,4 +1,5 @@
*~
*.o
*.so
+config.h
View
@@ -16,10 +16,22 @@
#ifndef AVINPUT_HH
#define AVINPUT_HH
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <boost/shared_ptr.hpp>
extern "C" {
+#ifdef HAVE_LIBSWSCALE_INCDIR
#include <libswscale/swscale.h>
+#else
+ #include <ffmpeg/swscale.h>
+#endif
+#ifdef HAVE_LIBAVFORMAT_INCDIR
#include <libavformat/avformat.h>
+#else
+ #include <ffmpeg/avformat.h>
+#endif
}
#include "rubyinc.hh"
#include "error.hh"
View
@@ -16,10 +16,22 @@
#ifndef AVOUTPUT_HH
#define AVOUTPUT_HH
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <boost/shared_ptr.hpp>
extern "C" {
+#ifdef HAVE_LIBSWSCALE_INCDIR
#include <libswscale/swscale.h>
+#else
+ #include <ffmpeg/swscale.h>
+#endif
+#ifdef HAVE_LIBAVFORMAT_INCDIR
#include <libavformat/avformat.h>
+#else
+ #include <ffmpeg/avformat.h>
+#endif
}
#include "rubyinc.hh"
#include "error.hh"

0 comments on commit d958078

Please sign in to comment.