mirror of
https://github.com/SFML/SFML.git
synced 2024-12-01 15:51:04 +08:00
new directory structure for ruby binding should compile and link fine under windows
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1797 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
8675cb364c
commit
e63a8fe442
@ -15,6 +15,7 @@ SO_SRCS = {'audio' => FileList.new('sfml-audio/audio/*.cpp'),
|
||||
'window' => FileList.new('sfml-window/window/*.cpp'),
|
||||
'system' => FileList.new('sfml-system/system/*.cpp'),
|
||||
'all' => FileList.new('sfml-all/all/*.cpp') }
|
||||
OTHER_SRCS = FileList.new('shared/*.cpp')
|
||||
OBJDIR = 'obj'
|
||||
SODIR = 'sfml'
|
||||
|
||||
@ -54,11 +55,18 @@ SO_SRCS.each do |file, list|
|
||||
SO_OBJS[file] = list.collect { |fn| File.join("#{OBJDIR}/#{file}", File.basename(fn).ext('o')) }
|
||||
end
|
||||
|
||||
OTHER_OBJS = OTHER_SRCS.collect {|fn| File.join("#{OBJDIR}/shared/#{file}", File.basename(fn).ext('o')) }
|
||||
|
||||
SO_LIBS = []
|
||||
SO_SRCS.each_key {|file| SO_LIBS << "#{SODIR}/#{file}.so"}
|
||||
SO_SRCS.each_key {|dir| CLEAN.include("#{OBJDIR}/#{dir}")}
|
||||
SO_OBJS.each_value {|list| CLEAN.include(list)}
|
||||
CLEAN.include(OTHER_OBJS)
|
||||
CLEAN.include("#{OBJDIR}/shared")
|
||||
CLEAN.include(OBJDIR)
|
||||
|
||||
SO_LIBS.each {|so_file| CLOBBER.include(so_file)}
|
||||
CLOBBER.include(OBJDIR, SODIR)
|
||||
CLOBBER.include(SODIR)
|
||||
|
||||
|
||||
# Sets the default task to build
|
||||
@ -97,10 +105,11 @@ end
|
||||
|
||||
CFLAGS = CONFIG['CFLAGS']
|
||||
CC = CONFIG['CC']
|
||||
INSTALL = CONFIG['INSTALL_PROGRAM']
|
||||
# CONFIG['INSTALL_PROGRAM']
|
||||
INSTALL = "install"
|
||||
LOCATION = CONFIG['sitearchdir'] + '/sfml'
|
||||
|
||||
RUBYSFML_INC = "sfml-system/system"
|
||||
RUBYSFML_INC = "shared"
|
||||
SFML_INC = ENV.key?('SFML_INCLUDE') ? ENV['SFML_INCLUDE'] : '../../include'
|
||||
SFML_LIB = ENV.key?('SFML_LIB') ? ENV['SFML_LIB'] : '../../lib'
|
||||
SFML_LIBS = '-lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system'
|
||||
@ -108,14 +117,27 @@ RUBY_INC = CONFIG['rubyhdrdir']
|
||||
RUBY_LIB = (CONFIG['ENABLE_SHARED'] == 'yes' ? CONFIG['LIBRUBYARG_SHARED'] : CONFIG['LIBRUBYARG_STATIC']) + ' ' + CONFIG['SOLIBS']
|
||||
RUBY_LIB_PATH = CONFIG['libdir']
|
||||
LINK = CONFIG['LDSHAREDXX']
|
||||
# Windows screws up this variable...
|
||||
LINK.sub!("$(if $(filter-out -g -g0,#{CONFIG["debugflags"]}),,-s)", '')
|
||||
LINK_FLAGS = CONFIG['DLDFLAGS'] + " " + CONFIG['LDFLAGS']
|
||||
LINK_FLAGS.sub!("$(DEFFILE)", "")
|
||||
|
||||
SO_SRCS.each_key {|dir| directory "#{OBJDIR}/#{dir}"}
|
||||
directory "#{OBJDIR}/shared"
|
||||
directory SODIR
|
||||
directory LOCATION
|
||||
|
||||
OTHER_SRCS.each do |srcfile|
|
||||
objdir = "#{OBJDIR}/shared"
|
||||
objfile = File.join(objdir, File.basename(srcfile).ext('o'))
|
||||
file objfile => [srcfile, objdir] do
|
||||
puts "Compiling #{File.basename(srcfile)}"
|
||||
sh "#{CC} #{CFLAGS} -c #{srcfile} -o #{objfile} -I#{SFML_INC} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']} -I#{RUBYSFML_INC}"
|
||||
end
|
||||
end
|
||||
|
||||
task :shared => OTHER_OBJS
|
||||
|
||||
SO_SRCS.each do |so_file, list|
|
||||
begin
|
||||
list.each do |srcfile|
|
||||
@ -133,27 +155,32 @@ end
|
||||
|
||||
SO_OBJS.each do |so_file, objs|
|
||||
begin
|
||||
file "#{SODIR}/#{so_file}.so" => [*objs, SODIR] do
|
||||
prestep = "pre#{so_file}".to_sym
|
||||
task prestep do
|
||||
puts "Creating #{so_file}.so"
|
||||
end
|
||||
file "#{SODIR}/#{so_file}.so" => [prestep, :shared, SODIR, *objs] do
|
||||
puts "Linking files to create #{so_file}.so"
|
||||
#p "#{LINK} -o #{SODIR}/#{so_file}.so #{objs} -L. -L#{SFML_LIB} -L#{RUBY_LIB_PATH} #{LINK_FLAGS} #{RUBY_LIB} #{SFML_LIBS}"
|
||||
sh "#{LINK} -o #{SODIR}/#{so_file}.so #{objs} -L. -L#{SFML_LIB} -L#{RUBY_LIB_PATH} #{LINK_FLAGS} #{RUBY_LIB} #{SFML_LIBS}"
|
||||
sh "#{LINK} -o #{SODIR}/#{so_file}.so #{objs} #{OTHER_OBJS} -L. -L#{SFML_LIB} -L#{RUBY_LIB_PATH} #{LINK_FLAGS} #{RUBY_LIB} #{SFML_LIBS}"
|
||||
end
|
||||
rescue
|
||||
end
|
||||
end
|
||||
|
||||
task :install => [:build, LOCATION] do
|
||||
puts "Installing library"
|
||||
puts "Installing library to #{LOCATION}"
|
||||
begin
|
||||
SO_SRCS.each_key do |so_file|
|
||||
sh "#{INSTALL} #{SODIR}/#{so_file}.so #{LOCATION}"
|
||||
end
|
||||
rescue
|
||||
rescue Exception=>e
|
||||
p e
|
||||
end
|
||||
end
|
||||
|
||||
task :uninstall do
|
||||
puts "Uninstalling library"
|
||||
puts "Uninstalling library to #{LOCATION}"
|
||||
begin
|
||||
SO_SRCS.each_key do |so_file|
|
||||
sh "rm -f #{LOCATION}/#{so_file}.so"
|
||||
@ -163,5 +190,5 @@ task :uninstall do
|
||||
end
|
||||
end
|
||||
|
||||
task :build => SO_LIBS do
|
||||
task :build => [:shared, *SO_LIBS] do
|
||||
end
|
||||
|
@ -21,13 +21,10 @@
|
||||
*/
|
||||
|
||||
#include "main.hpp"
|
||||
|
||||
VALUE globalSFMLNamespace;
|
||||
|
||||
/* External classes */
|
||||
VALUE globalVector2Class;
|
||||
VALUE globalVector3Class;
|
||||
VALUE globalNonCopyableModule;
|
||||
#include "global.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
#include "NonCopyable.hpp"
|
||||
|
||||
static bool CheckDependencies( void )
|
||||
{
|
||||
@ -47,8 +44,8 @@ void Init_audio( void )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "This module depends on sfml-window" );
|
||||
}
|
||||
globalVector2Class = RetrieveSFMLClass( "Vector2" );
|
||||
/*globalVector2Class = RetrieveSFMLClass( "Vector2" );
|
||||
globalVector3Class = RetrieveSFMLClass( "Vector3" );
|
||||
globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" );
|
||||
globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" );*/
|
||||
rb_define_const(globalSFMLNamespace, "AudioLoaded", Qtrue);
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define SFML_RUBYEXT_AUDIO_MAIN_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
#include "../../sfml-system/system/main.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
// Ruby initiation function
|
||||
extern "C" void Init_audio( void );
|
||||
|
@ -21,6 +21,9 @@
|
||||
*/
|
||||
|
||||
#include "main.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
#include "NonCopyable.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Rect.hpp"
|
||||
#include "Drawable.hpp"
|
||||
@ -39,14 +42,10 @@
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
VALUE globalSFMLNamespace;
|
||||
VALUE globalBlendNamespace;
|
||||
|
||||
/* External classes */
|
||||
VALUE globalVector2Class;
|
||||
VALUE globalVector3Class;
|
||||
VALUE globalWindowClass;
|
||||
VALUE globalNonCopyableModule;
|
||||
|
||||
static bool CheckDependencies( void )
|
||||
{
|
||||
@ -71,15 +70,15 @@ static void CreateBlendEnum( void )
|
||||
void Init_graphics( void )
|
||||
{
|
||||
/* SFML namespace which contains the classes of this module. */
|
||||
globalSFMLNamespace = rb_define_module( "SFML" );
|
||||
/*globalSFMLNamespace = rb_define_module( "SFML" );*/
|
||||
if( CheckDependencies() == false )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "This module depends on sfml-window" );
|
||||
}
|
||||
globalVector2Class = RetrieveSFMLClass( "Vector2" );
|
||||
globalVector3Class = RetrieveSFMLClass( "Vector3" );
|
||||
/*globalVector2Class = RetrieveSFMLClass( "Vector2" );
|
||||
globalVector3Class = RetrieveSFMLClass( "Vector3" );*/
|
||||
globalWindowClass = RetrieveSFMLClass( "Window" );
|
||||
globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" );
|
||||
/*globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" );*/
|
||||
rb_define_const(globalSFMLNamespace, "GraphicsLoaded", Qtrue);
|
||||
|
||||
CreateBlendEnum();
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define SFML_RUBYEXT_GRAPHICS_MAIN_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
#include "../../sfml-system/system/main.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
// Ruby initiation function
|
||||
extern "C" void Init_graphics( void );
|
||||
|
@ -21,24 +21,12 @@
|
||||
*/
|
||||
|
||||
#include "main.hpp"
|
||||
#include "global.hpp"
|
||||
#include "Clock.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "Vector3.hpp"
|
||||
#include "NonCopyable.hpp"
|
||||
|
||||
VALUE globalSFMLNamespace;
|
||||
|
||||
VALUE RetrieveSFMLClass( const char * aName )
|
||||
{
|
||||
ID name = rb_intern( aName );
|
||||
if( rb_cvar_defined( globalSFMLNamespace, name ) == Qfalse )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "This module depends on SFML::%s", aName );
|
||||
}
|
||||
|
||||
return rb_cvar_get( globalSFMLNamespace, name );
|
||||
}
|
||||
|
||||
void Init_system( void )
|
||||
{
|
||||
/* SFML namespace which contains the classes of this module. */
|
||||
|
@ -21,6 +21,8 @@
|
||||
*/
|
||||
|
||||
#include "main.hpp"
|
||||
#include "Vector2.hpp"
|
||||
#include "NonCopyable.hpp"
|
||||
#include "Context.hpp"
|
||||
#include "ContextSettings.hpp"
|
||||
#include "Event.hpp"
|
||||
@ -33,15 +35,12 @@
|
||||
#include <iostream>
|
||||
|
||||
/* SFML Namespace which contains all classes in this module. */
|
||||
VALUE globalSFMLNamespace;
|
||||
VALUE globalKeyNamespace;
|
||||
VALUE globalMouseNamespace;
|
||||
VALUE globalJoyNamespace;
|
||||
VALUE globalStyleNamespace;
|
||||
|
||||
/* External classes */
|
||||
VALUE globalVector2Class;
|
||||
VALUE globalNonCopyableModule;
|
||||
extern VALUE globalVector2Class;
|
||||
extern VALUE globalNonCopyableModule;
|
||||
|
||||
static const char * keyNamesMisc[] =
|
||||
{
|
||||
@ -163,8 +162,9 @@ void Init_window( void )
|
||||
rb_raise( rb_eRuntimeError, "This module depends on sfml-system" );
|
||||
}
|
||||
|
||||
globalVector2Class = RetrieveSFMLClass( "Vector2" );
|
||||
globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" );
|
||||
|
||||
globalVector2Class = rb_define_class_under(globalSFMLNamespace, "Vector2", rb_cObject );
|
||||
globalNonCopyableModule = rb_define_module_under(globalSFMLNamespace, "NonCopyable");
|
||||
|
||||
rb_define_const( globalSFMLNamespace, "WindowLoaded", Qtrue );
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
#define SFML_RUBYEXT_WINDOW_MAIN_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
#include "../../sfml-system/system/main.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
// Ruby initiation function
|
||||
extern "C" void Init_window( void );
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "NonCopyable.hpp"
|
||||
#include "main.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
VALUE globalNonCopyableModule;
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include "main.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
VALUE globalVector2Class;
|
||||
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
#include "Vector3.hpp"
|
||||
#include "main.hpp"
|
||||
#include "global.hpp"
|
||||
|
||||
VALUE globalVector3Class;
|
||||
|
36
bindings/ruby/shared/global.cpp
Normal file
36
bindings/ruby/shared/global.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
/* rbSFML - Copyright (c) 2010 Henrik Valter Vogelius Hansson - groogy@groogy.se
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
#include "global.hpp"
|
||||
|
||||
VALUE globalSFMLNamespace;
|
||||
|
||||
VALUE RetrieveSFMLClass( const char * aName )
|
||||
{
|
||||
ID name = rb_intern( aName );
|
||||
if( rb_cvar_defined( globalSFMLNamespace, name ) == Qfalse )
|
||||
{
|
||||
rb_raise( rb_eRuntimeError, "This module depends on SFML::%s", aName );
|
||||
}
|
||||
|
||||
return rb_cvar_get( globalSFMLNamespace, name );
|
||||
}
|
49
bindings/ruby/shared/global.hpp
Normal file
49
bindings/ruby/shared/global.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
/* rbSFML - Copyright (c) 2010 Henrik Valter Vogelius Hansson - groogy@groogy.se
|
||||
* This software is provided 'as-is', without any express or
|
||||
* implied warranty. In no event will the authors be held
|
||||
* liable for any damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute
|
||||
* it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented;
|
||||
* you must not claim that you wrote the original software.
|
||||
* If you use this software in a product, an acknowledgment
|
||||
* in the product documentation would be appreciated but
|
||||
* is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such,
|
||||
* and must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any
|
||||
* source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SFML_RUBYEXT_GLOBAL_HEADER_
|
||||
#define SFML_RUBYEXT_GLOBAL_HEADER_
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
#define SFML_STATIC
|
||||
|
||||
extern VALUE globalSFMLNamespace;
|
||||
|
||||
VALUE RetrieveSFMLClass( const char * aName );
|
||||
|
||||
typedef VALUE ( *RubyFunctionPtr )( ... );
|
||||
|
||||
#define MAX( x, y ) ( ( x ) < ( y ) ? ( y ) : ( x ) )
|
||||
#define MIN( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
|
||||
|
||||
#define VALIDATE_CLASS( variable, type, name ) \
|
||||
if( rb_obj_is_kind_of( variable, type ) != Qtrue ) \
|
||||
{ \
|
||||
rb_raise( rb_eTypeError, "%s argument must be instance of %s", name, rb_string_value_cstr ( &type ) ); \
|
||||
}
|
||||
|
||||
#define rb_define_module_function( klass, name, func, argc, ... ) rb_define_module_function( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ )
|
||||
#define rb_define_singleton_method( klass, name, func, argc, ... ) rb_define_singleton_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ )
|
||||
#define rb_define_method( klass, name, func, argc, ... ) rb_define_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ )
|
||||
|
||||
#endif // SFML_RUBYEXT_SYSTEM_MAIN_HEADER_
|
Loading…
Reference in New Issue
Block a user