Skip to content
Snippets Groups Projects
Select Git revision
  • ecbcf70b2b6373c66370d46686788f5077f8648e
  • master default protected
  • rails-geocoder
  • rails2
  • v1.5.1
  • v1.5.0
  • v1.4.9
  • v1.4.8
  • v1.4.7
  • v1.4.6
  • v1.4.5
  • remove
  • v1.4.4
  • v1.4.3
  • v1.4.2
  • v1.4.1
  • v1.4.0
  • v1.3.7
  • v1.3.6
  • v1.3.5
  • v1.3.4
  • v1.3.3
  • v1.3.2
  • v1.3.1
24 results

README.md

Blame
  • Rakefile.cross 14.61 KiB
    # -*- coding: utf-8 -*-
    # -*- ruby -*-
    
    require 'rubygems'
    require 'hoe'
    require 'rake/extensiontask'
    require 'rake/extensioncompiler'
    require 'uri'
    require 'rbconfig'
    require 'pathname'
    
    ENV['RUBY_CC_VERSION'] ||= '1.8.7:1.9.3:2.0.0'
    
    NUM_CPUS = if File.exist?('/proc/cpuinfo')
        File.read('/proc/cpuinfo').scan('processor').length
    elsif RUBY_PLATFORM.include?( 'darwin' )
        `system_profiler SPHardwareDataType | grep 'Cores' | awk '{print $5}'`.chomp
    else
        1
    end
    
    class CrossLibrary < OpenStruct
      include Rake::DSL
    
      def initialize(ruby_platform)
        super()
    
        self.ruby_platform              = ruby_platform
    
        # Cross-compilation constants
        self.compile_home               = Pathname( "build" ).expand_path
        self.static_sourcesdir          = compile_home + 'sources'
        self.static_builddir            = compile_home + 'builds' + ruby_platform
        self.static_installdir          = compile_home + 'install' + ruby_platform
        self.ruby_build                 = RbConfig::CONFIG["host"]
    
        # Use rake-compilers config.yml to determine the toolchain that was used
        # to build Ruby for this platform.
        self.host_platform = begin
          config_file = YAML.load_file(File.expand_path("~/.rake-compiler/config.yml"))
          _, rbfile = config_file.find{|key, fname| key.start_with?("rbconfig-#{ruby_platform}-") }
          IO.read(rbfile).match(/CONFIG\["host"\] = "(.*)"/)[1]
        rescue
          nil
        end
    
        # Fetch zlib tarball
        self.libz_version            = ENV['libz_version'] || '1.2.7'
        self.libz_source_uri         = URI( "http://downloads.sourceforge.net/project/libpng/zlib/#{libz_version}/zlib-#{libz_version}.tar.bz2" )
        self.libz_tarball            = static_sourcesdir + File.basename( libz_source_uri.path )
        self.static_libz_builddir    = static_builddir + libz_tarball.basename(".tar.bz2")
        self.libz_makefile           = static_libz_builddir + 'Makefile'
        self.libz_a                  = static_libz_builddir + 'libz.a'
    
        # Fetch libpng tarball
        self.libpng_version            = ENV['libpng_version'] || '1.5.13'
        self.libpng_source_uri         = URI( "http://prdownloads.sourceforge.net/libpng/libpng-#{libpng_version}.tar.gz?download" )
        self.libpng_tarball            = static_sourcesdir + File.basename( libpng_source_uri.path )
        self.static_libpng_builddir    = static_builddir + libpng_tarball.basename(".tar.gz")
        self.libpng_makefile           = static_libpng_builddir + 'Makefile'
        self.libpng_a                  = static_libpng_builddir + '.libs' + 'libpng15.a'
    
    
        # Fetch libjpeg tarball
        self.libjpeg_version            = ENV['libjpeg_version'] || '8d'
        self.libjpeg_source_uri         = URI( "http://www.ijg.org/files/jpegsrc.v#{libjpeg_version}.tar.gz" )
        self.libjpeg_tarball            = static_sourcesdir + File.basename( libjpeg_source_uri.path )
        self.static_libjpeg_builddir    = static_builddir + "jpeg-#{libjpeg_version}"
        self.libjpeg_makefile           = static_libjpeg_builddir + 'Makefile'
        self.libjpeg_a                  = static_libjpeg_builddir + '.libs' + 'libjpeg.a'
    
    
        # Fetch libtiff tarball
        self.libtiff_version            = ENV['libtiff_version'] || '4.0.3'
        self.libtiff_source_uri         = URI( "http://download.osgeo.org/libtiff/tiff-#{libtiff_version}.tar.gz" )
        self.libtiff_tarball            = static_sourcesdir + File.basename( libtiff_source_uri.path )
        self.static_libtiff_builddir    = static_builddir + libtiff_tarball.basename(".tar.gz")
        self.libtiff_makefile           = static_libtiff_builddir + 'Makefile'
        self.libtiff_a                  = static_libtiff_builddir + 'libtiff' + '.libs' + 'libtiff.a'
    
    
        # Fetch libfox tarball
        self.libfox_version            = ENV['libfox_version'] || '1.6.49'
        self.libfox_source_uri         = URI( "http://ftp.fox-toolkit.org/pub/fox-#{libfox_version}.tar.gz" )
        self.libfox_tarball            = static_sourcesdir + File.basename( libfox_source_uri.path )
        self.static_libfox_builddir    = static_builddir + libfox_tarball.basename(".tar.gz")
        self.libfox_makefile           = static_libfox_builddir + 'Makefile'
        self.libfox_a                  = static_libfox_builddir + 'src' + '.libs' + 'libFOX-1.6.a'
    
        # Fetch fxscintilla tarball
        self.libfxscintilla_version            = ENV['libfxscintilla_version'] || '2.28.0'
        self.libfxscintilla_source_uri         = URI( "http://download.savannah.gnu.org/releases/fxscintilla/fxscintilla-#{libfxscintilla_version}.tar.gz" )
        self.libfxscintilla_tarball            = static_sourcesdir + File.basename( libfxscintilla_source_uri.path )
        self.static_libfxscintilla_builddir    = static_builddir + libfxscintilla_tarball.basename(".tar.gz")
        self.libfxscintilla_makefile           = static_libfxscintilla_builddir + 'Makefile'
        self.libfxscintilla_a                  = static_libfxscintilla_builddir + 'fox' + '.libs' + 'libfxscintilla.a'
    
    
    
        # clean intermediate files and folders
        CLEAN.include( static_builddir.to_s )
    
        #####################################################################
        ### C R O S S - C O M P I L A T I O N - T A S K S
        #####################################################################
    
        directory static_sourcesdir.to_s
    
        #
        # Static libz build tasks
        #
        directory static_libz_builddir.to_s
    
        # libz source file should be stored there
        file libz_tarball => static_sourcesdir do |t|
          # download the source file using wget or curl
          chdir File.dirname(t.name) do
            sh "wget '#{libz_source_uri}' -O #{libz_tarball}"
          end
        end
    
        # Extract the libz builds
        file static_libz_builddir => libz_tarball do |t|
          sh 'tar', '-xjf', libz_tarball.to_s, '-C', static_libz_builddir.parent.to_s
          rm libz_makefile
        end
    
        self.libz_env = [
          "CC=#{host_platform}-gcc",
          "AR=#{host_platform}-ar",
          "RANLIB=#{host_platform}-ranlib",
        ]
    
        # generate the makefile in a clean build location
        file libz_makefile => [static_libz_builddir] do |t|
          chdir( static_libz_builddir ) do
            options = [
              "--prefix=#{static_installdir}",
            ]
    
            configure_path = static_libz_builddir + 'configure'
            sh "env #{[libz_env, configure_path.to_s, *options].join(" ")}"
          end
        end
    
        # generate the makefile in a clean build location
        task libz_a => libz_makefile do |t|
          chdir( static_libz_builddir ) do
            sh "make -j#{NUM_CPUS} install 'LDSHAREDLIBC=-lmsvcrt'"
          end
        end
    
        #
        # Static libpng build tasks
        #
        directory static_libpng_builddir.to_s
    
        # libpng source file should be stored there
        file libpng_tarball => static_sourcesdir do |t|
          # download the source file using wget or curl
          chdir File.dirname(t.name) do
            sh "wget '#{libpng_source_uri}' -O #{libpng_tarball}"
          end
        end
    
        # Extract the libpng builds
        file static_libpng_builddir => libpng_tarball do |t|
          sh 'tar', '-xzf', libpng_tarball.to_s, '-C', static_libpng_builddir.parent.to_s
        end
    
        self.libpng_env = [
          # Use build directory instead of install, to avoid unnecessary rebuilds of libpng
          "'CPPFLAGS=-I#{static_libz_builddir}'",
          "'LDFLAGS=-L#{static_libz_builddir}'",
        ]
        # generate the makefile in a clean build location
        file libpng_makefile => [static_libpng_builddir, libz_a] do |t|
          chdir( static_libpng_builddir ) do
            options = [
              "--target=#{host_platform}",
              "--host=#{host_platform}",
              "--build=#{ruby_build}",
              "--prefix=#{static_installdir}",
              "--disable-shared",
            ]
    
            configure_path = static_libpng_builddir + 'configure'
            sh "env #{[libpng_env, configure_path.to_s, *options].join(" ")}"
          end
        end
    
        # generate the makefile in a clean build location
        task libpng_a => [libpng_makefile, libz_a] do |t|
          chdir( static_libpng_builddir ) do
            sh "make -j#{NUM_CPUS} install"
          end
        end
    
        #
        # Static libjpeg build tasks
        #
        directory static_libjpeg_builddir.to_s
    
        # libjpeg source file should be stored there
        file libjpeg_tarball => static_sourcesdir do |t|
          # download the source file using wget or curl
          chdir File.dirname(t.name) do
            sh "wget '#{libjpeg_source_uri}' -O #{libjpeg_tarball}"
          end
        end
    
        # Extract the libjpeg builds
        file static_libjpeg_builddir => libjpeg_tarball do |t|
          sh 'tar', '-xzf', libjpeg_tarball.to_s, '-C', static_libjpeg_builddir.parent.to_s
        end
    
        # generate the makefile in a clean build location
        file libjpeg_makefile => static_libjpeg_builddir do |t|
          chdir( static_libjpeg_builddir ) do
            options = [
              "--target=#{host_platform}",
              "--host=#{host_platform}",
              "--build=#{ruby_build}",
              "--prefix=#{static_installdir}",
              "--disable-shared",
            ]
    
            configure_path = static_libjpeg_builddir + 'configure'
            cmd = [ configure_path.to_s, *options ]
            sh *cmd
          end
        end
    
        # build libjpeg.a
        task libjpeg_a => [libjpeg_makefile] do |t|
          chdir( static_libjpeg_builddir ) do
            sh "make -j#{NUM_CPUS} install"
          end
        end
    
        #
        # Static libtiff build tasks
        #
        directory static_libtiff_builddir.to_s
    
        # libtiff source file should be stored there
        file libtiff_tarball => static_sourcesdir do |t|
          # download the source file using wget or curl
          chdir File.dirname(t.name) do
            sh "wget '#{libtiff_source_uri}' -O #{libtiff_tarball}"
          end
        end
    
        # Extract the libtiff builds
        file static_libtiff_builddir => libtiff_tarball do |t|
          sh 'tar', '-xzf', libtiff_tarball.to_s, '-C', static_libtiff_builddir.parent.to_s
        end
    
        self.libtiff_env = [
          "'CPPFLAGS=-I#{static_installdir}/include'",
          "'LDFLAGS=-L#{static_installdir}/lib'",
        ]
    
        # generate the makefile in a clean build location
        file libtiff_makefile => [static_libtiff_builddir, libjpeg_a, libz_a] do |t|
          chdir( static_libtiff_builddir ) do
            options = [
              "--target=#{host_platform}",
              "--host=#{host_platform}",
              "--build=#{ruby_build}",
              "--prefix=#{static_installdir}",
              "--disable-shared",
              "--with-zlib-include-dir=#{static_libz_builddir}",
              "--with-zlib-lib-dir=#{File.dirname(libz_a)}",
              "--with-jpeg-include-dir=#{static_libjpeg_builddir}",
              "--with-jpeg-lib-dir=#{File.dirname(libjpeg_a)}",
            ]
    
            configure_path = static_libtiff_builddir + 'configure'
            sh "env #{[libtiff_env, configure_path.to_s, *options].join(" ")}"
          end
        end
    
        # build libtiff.a
        task libtiff_a => [libtiff_makefile] do |t|
          chdir( static_libtiff_builddir ) do
            sh "make -j#{NUM_CPUS} install"
          end
        end
    
    
        #
        # Static libfox build tasks
        #
        directory static_libfox_builddir.to_s
    
        # libfox source file should be stored there
        file libfox_tarball => static_sourcesdir do |t|
          # download the source file using wget or curl
          chdir File.dirname(t.name) do
            sh "wget '#{libfox_source_uri}' -O #{libfox_tarball}"
          end
        end
    
        # Extract the libfox builds
        file static_libfox_builddir => libfox_tarball do |t|
          sh 'tar', '-xzf', libfox_tarball.to_s, '-C', static_libfox_builddir.parent.to_s
        end
    
        self.libfox_env = [
          "'CPPFLAGS=-I#{static_installdir}/include'",
          "'LDFLAGS=-L#{static_installdir}/lib'",
        ]
    
        # generate the makefile in a clean build location
        file libfox_makefile => [static_libfox_builddir, libjpeg_a, libz_a] do |t|
          chdir( static_libfox_builddir ) do
            options = [
              "--target=#{host_platform}",
              "--host=#{host_platform}",
              "--build=#{ruby_build}",
              "--prefix=#{static_installdir}",
              "--disable-shared",
              "--without-xft",
              "--without-x",
            ]
    
            configure_path = static_libfox_builddir + 'configure'
            sh "env #{[libfox_env, configure_path.to_s, *options].join(" ")}"
          end
        end
    
        # build libfox.a
        task libfox_a => [libfox_makefile] do |t|
          chdir( static_libfox_builddir ) do
            sh "make -j#{NUM_CPUS} #{fox_env.join(" ")} install"
          end
        end
    
    
        #
        # Static libfxscintilla build tasks
        #
        directory static_libfxscintilla_builddir.to_s
    
        # libfxscintilla source file should be stored there
        file libfxscintilla_tarball => static_sourcesdir do |t|
          # download the source file using wget or curl
          chdir File.dirname(t.name) do
            sh "wget '#{libfxscintilla_source_uri}' -O #{libfxscintilla_tarball}"
          end
        end
    
        # Extract the libfxscintilla builds
        file static_libfxscintilla_builddir => libfxscintilla_tarball do |t|
          sh 'tar', '-xzf', libfxscintilla_tarball.to_s, '-C', static_libfxscintilla_builddir.parent.to_s
        end
    
        self.fox_env = [
          "'CFLAGS=-I#{static_installdir}/include'",
          "'CPPFLAGS=-I#{static_installdir}/include'",
          "'LDFLAGS=-L#{static_installdir}/lib'",
          "'FOX_CFLAGS=-I#{static_installdir}/include/fox-1.6 -DFOX_1_6'",
          "'FOX_LIBS=-L#{static_installdir}/lib -lFOX-1.6'",
        ]
    
        # generate the makefile in a clean build location
        file libfxscintilla_makefile => [static_libfxscintilla_builddir, libfox_a] do |t|
          chdir( static_libfxscintilla_builddir ) do
            options = [
              "--target=#{host_platform}",
              "--host=#{host_platform}",
              "--build=#{ruby_build}",
              "--prefix=#{static_installdir}",
              "--disable-shared",
            ]
    
            configure_path = static_libfxscintilla_builddir + 'configure'
            sh "env #{[fox_env, configure_path.to_s, *options].join(" ")}"
          end
        end
    
        # build libfxscintilla.a
        task libfxscintilla_a => [libfxscintilla_makefile] do |t|
          chdir( static_libfxscintilla_builddir ) do
            sh "make -j#{NUM_CPUS} #{fox_env.join(" ")} install"
          end
        end
    
        desc "compile static libz libraries"
        task :static_libs => [ libz_a, libpng_a, libjpeg_a, libtiff_a, libfox_a, libfxscintilla_a ]
      end
    end
    
    if File.exist?(File.expand_path("~/.rake-compiler/config.yml"))
      CrossLibraries = [
        'i386-mingw32',
        'x64-mingw32',
      ].map do |platform|
        CrossLibrary.new platform
      end
    else
      $stderr.puts "Cross-compilation disabled -- rake-compiler not properly installed"
      CrossLibraries = []
    end
    
    
    desc 'cross compile required libs for win32'
    task :cross => [ :mingw32, :static_libs ]
    
    task :mingw32 do
      # Use Rake::ExtensionCompiler helpers to find the proper host
      unless Rake::ExtensionCompiler.mingw_host then
        warn "You need to install mingw32 cross compile functionality to be able to continue."
        warn "Please refer to your distribution/package manager documentation about installation."
        fail
      end
    end
    
    
    # vim: syntax=ruby