Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 100 lines (90 sloc) 2.206 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
require "mkmf"

def have_type(type, header=nil)
  printf "checking for %s... ", type
  STDOUT.flush
  src = <<"SRC"
#include <ruby.h>
SRC
  unless header.nil?
  src << <<"SRC"
#include <#{header}>
SRC
  end
  r = try_link(src + <<"SRC")
int main() { return 0; }
int t() { #{type} a; return 0; }
SRC
  unless r
    print "no\n"
    return false
  end
  $defs.push(format("-DHAVE_%s", type.upcase))
  print "yes\n"
  return true
end

def create_conf_h(file)
  print "creating #{file}\n"
  hfile = open(file, "w")
  for line in $defs
    line =~ /^-D(.*)/
    hfile.printf "#define %s 1\n", $1
  end
  hfile.close
end

if RUBY_VERSION < '1.8'
  alias __install_rb :install_rb
  def install_rb(mfile, dest, srcdir = nil)
    __install_rb(mfile, dest, srcdir)
    archdir = dest.sub(/sitelibdir/,"sitearchdir").sub(/rubylibdir/,"archdir")
    path = ['$(srcdir)/narray.h','narray_config.h']
    path << ['libnarray.a'] if /cygwin|mingw/ =~ RUBY_PLATFORM
    for f in path
      mfile.printf "\t@$(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0644, true)' %s %s\n", f, archdir
    end
  end
else
  $INSTALLFILES = [['narray.h', '$(archdir)'], ['narray_config.h', '$(archdir)']]
  if /cygwin|mingw/ =~ RUBY_PLATFORM
$INSTALLFILES << ['libnarray.a', '$(archdir)']
  end
end

if /cygwin|mingw/ =~ RUBY_PLATFORM
  if RUBY_VERSION >= '1.9.0'
    $DLDFLAGS << " -Wl,--export-all,--out-implib=libnarray.a"
  elsif RUBY_VERSION > '1.8.0'
    $DLDFLAGS << ",--out-implib=libnarray.a"
  elsif RUBY_VERSION > '1.8'
    CONFIG["DLDFLAGS"] << ",--out-implib=libnarray.a"
    system("touch libnarray.a")
  else
    CONFIG["DLDFLAGS"] << " --output-lib libnarray.a"
  end
end

#$DEBUG = true
#$CFLAGS = ["-Wall",$CFLAGS].join(" ")

srcs = %w(
narray
na_array
na_func
na_index
na_random
na_op
na_math
na_linalg
)

header = "stdint.h"
unless have_header(header)
  header = "sys/types.h"
  unless have_header(header)
    header = nil
  end
end

have_type("u_int8_t", header)
have_type("uint8_t", header)
have_type("int16_t", header)
have_type("int32_t", header)
have_type("u_int32_t", header)
have_type("uint32_t", header)

$objs = srcs.collect{|i| i+".o"}

create_conf_h("narray_config.h")
create_makefile("narray")
Something went wrong with that request. Please try again.