<commit_before>require 'mkmf'
require 'rbconfig'

$stdout.sync = true
pkg = "jemalloc-3.0.0"

# monfigure and copy sources to cur_dir
cur_dir = Dir.pwd
Dir.chdir File.dirname(__FILE__) do
  # cleanup
  puts `rm -fR #{pkg}`
  puts `tar vjxf #{pkg}.tar.bz2`
  Dir.chdir(pkg) do
    # configure
    puts `./configure`
    # zone.c is only for Mac OS X
    if RbConfig::CONFIG['target_vendor'] != "apple"
      puts `rm -fR src/zone.c`
    end
    # mkmf only allows *.c files on current dir
    puts `cp src/*.c #{cur_dir}`
  end
end
Dir.chdir cur_dir

include_dir= File.dirname(__FILE__) + "/#{pkg}/include/"
$CFLAGS << %[ -std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -D_GNU_SOURCE -D_REENTRANT -I.. -I#{include_dir}]

create_makefile('jemalloc')

# modify Makefile to create .dylib, instead of .bundle
# NOTICE: Mac OS X only
if RbConfig::CONFIG['target_vendor'] == "apple"
  makefile = open('Makefile').read
  makefile.gsub!(/-dynamic\ -bundle/, '-shared')
  makefile.gsub!(/-flat_namespace/, '-dylib_install_name')
  #,-dylib_install_name
  open('Makefile', 'w'){ |f| f.write(makefile) }
end<commit_msg>more robust error logic at compile time<commit_after>require 'mkmf'
require 'rbconfig'

$stdout.sync = true
pkg = "jemalloc-3.0.0"

# monfigure and copy sources to cur_dir
cur_dir = Dir.pwd
Dir.chdir File.dirname(__FILE__) do
  # cleanup
  puts `rm -fR #{pkg}`
  puts `tar vjxf #{pkg}.tar.bz2`
  Dir.chdir(pkg) do
    # configure
    puts `./configure`
    # zone.c is only for Mac OS X
    if RbConfig::CONFIG['target_vendor'] != "apple"
      puts `rm -fR src/zone.c`
    end
    # mkmf only allows *.c files on current dir
    puts `cp src/*.c #{cur_dir}`
  end
end
Dir.chdir cur_dir

include_dir= File.dirname(__FILE__) + "/#{pkg}/include/"
$CFLAGS << %[ -std=gnu99 -Wall -pipe -g3 -fvisibility=hidden -O3 -funroll-loops -D_GNU_SOURCE -D_REENTRANT -I.. -I#{include_dir}]

create_makefile('jemalloc')

# modify Makefile to create .dylib, instead of .bundle
# NOTICE: Mac OS X only
if RbConfig::CONFIG['target_vendor'] == "apple"
  makefile = open('Makefile').read
  if makefile =~ /-dynamic\ -bundle/ && makefile =~ /-flat_namespace/
    makefile.gsub!(/-dynamic\ -bundle/, '-shared')
    makefile.gsub!(/-flat_namespace/, '-dylib_install_name')
  else
    raise 'Your platform is not supported. Please report to http://github.com/treasure-data/je'
  end
  open('Makefile', 'w'){ |f| f.write(makefile) }
end
{'fraction_non_alphanumeric': 0.15564681724845997, 'fraction_numerical': 0.006570841889117043, 'mean_word_length': 3.5703564727954973, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4002440', 'n_tokens_mistral': 913, 'n_tokens_neox': 914, 'n_words': 240}