diff options
| author | Tom Black <[email protected]> | 2016-04-19 22:21:55 -0400 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2016-04-19 22:21:55 -0400 |
| commit | 809160eb205b26f9723a5252a8ae477762921f1a (patch) | |
| tree | 7237c71fc02ec6d901c641551163daa0603b7777 /ext | |
| parent | c0db462af1ffba389c865efefd5f0344879387ba (diff) | |
| download | ruby2d-809160eb205b26f9723a5252a8ae477762921f1a.tar.gz ruby2d-809160eb205b26f9723a5252a8ae477762921f1a.zip | |
Updating extconf.rb
- Adding minimum required Simple 2D version
- Better control flow checking whether Homebrew and Simple 2D are
installed
- Added -std=c99 to CFLAGS for GCC
- Removed mingw case, since we’re not officially supporting Windows
(yet)
- General clean up
Diffstat (limited to 'ext')
| -rw-r--r-- | ext/ruby2d/extconf.rb | 103 |
1 files changed, 51 insertions, 52 deletions
diff --git a/ext/ruby2d/extconf.rb b/ext/ruby2d/extconf.rb index 721c4fb..d4c620f 100644 --- a/ext/ruby2d/extconf.rb +++ b/ext/ruby2d/extconf.rb @@ -1,84 +1,83 @@ require 'mkmf' +S2D_VERSION = '0.2.1' # Simple 2D version required +$errors = [] + class String def colorize(c); "\e[#{c}m#{self}\e[0m" end - def error; colorize('1;31') end - def bold; colorize('1') end + def bold; colorize('1') end + def red; colorize('1;31') end end -def print_errors(errors) +def print_errors puts " -#{"== Ruby 2D Installation Errors =============================".bold} - - #{"Ruby 2D found some problems and was not installed:".error} - - #{errors.join("\n ")} - -#{"============================================================".bold}" +#{"== #{"Ruby 2D Installation Errors".red} =====================================\n"} + #{$errors.join("\n ")}\n +#{"===================================================================="}" +end + +def check_s2d_version + unless Gem::Version.new(`simple2d --version`) >= Gem::Version.new(S2D_VERSION) + $errors << "Simple 2D needs to be updated for this version of Ruby 2D." << + "Run the following, then try reinstalling this gem:\n" << + " simple2d update".bold + print_errors + exit + end end -errors = [] # Install Simple 2D on supported platforms # OS X if RUBY_PLATFORM =~ /darwin/ - unless ARGV.include? "--no-brew" - # Simple 2D not installed - if `which simple2d`.empty? - # Homebrew not installed, print and quit - if `which brew`.empty? - errors << "Ruby 2D uses a library called Simple 2D." << - "On OS X, this can be installed using Homebrew." << - "Install Homebrew, then try installing this gem again.\n" << - "Learn more at http://brew.sh" - print_errors(errors) - exit - # Install Simple 2D using Homebrew - else - `brew tap simple2d/tap` - `brew install simple2d` - end + + # Simple 2D not installed + if `which simple2d`.empty? + + # Homebrew not installed + if `which brew`.empty? + $errors << "Ruby 2D uses a native library called Simple 2D." << + "On OS X, this can be installed using Homebrew.\n" << + "First, install #{"Homebrew".bold}. See instructions at #{"http://brew.sh".bold}" << + "Then, run the following:\n" << + " brew tap simple2d/tap".bold << + " brew install simple2d".bold + print_errors + exit - # Simple 2D installed, update to latest version + # Homebrew installed, instruct to install Simple 2D else - # Homebrew not installed - if `which brew`.empty? - # TODO: Check for latest version manually and update - # Homebrew installed, get latest version of Simple 2D - else - # An alternative, but slower and updates all formulas: - # `brew update` - # `brew upgrade simple2d` - - `brew untap simple2d/tap` - `brew tap simple2d/tap` - `brew upgrade simple2d` - end + $errors << "Ruby 2D uses a native library called Simple 2D." << + "Install with Homebrew using:\n" << + " brew tap simple2d/tap".bold << + " brew install simple2d".bold + print_errors + exit end end # Linux elsif RUBY_PLATFORM =~ /linux/ - # If Simple 2D not installed + + # Simple 2D not installed if `which simple2d`.empty? - errors << "Ruby 2D uses a library called Simple 2D." << - "There's a script to make installation easy on Linux.\n" << - "Follow the instructions in the README to get started:" << - " https://github.com/simple2d/simple2d" - print_errors(errors) + $errors << "Ruby 2D uses a native library called Simple 2D.\n" << + "To install Simple 2D on Linux, follow the instructions" << + "in the README: #{"https://github.com/simple2d/simple2d".bold}" + print_errors exit end -# Windows -elsif RUBY_PLATFORM =~ /mingw/ - puts "Ruby 2D doesn't support Windows yet :(" - exit + $CFLAGS << ' -std=c99' end +# Simple 2D installed, check version +check_s2d_version + # Configure Simple 2D and create Makefile $LDFLAGS << ' ' << `simple2d --libs` -$LDFLAGS.gsub!(/\n/, ' ') # remove newlines in flags, they cause problems +$LDFLAGS.gsub!(/\n/, ' ') # Remove newlines in flags, they cause problems create_makefile('ruby2d/ruby2d') |
