| 1 |
|
| 2 |
|
| 3 |
require "rbconfig" |
| 4 |
|
| 5 |
if ARGV.delete("--help") |
| 6 |
print(<<~TEXT) |
| 7 |
USAGE: ruby #{$PROGRAM_NAME} [options] |
| 8 |
|
| 9 |
Flags that are always valid: |
| 10 |
|
| 11 |
--enable-build-debug |
| 12 |
Enable debug build. |
| 13 |
You may also set the PRISM_BUILD_DEBUG environment variable. |
| 14 |
|
| 15 |
--enable-build-minimal |
| 16 |
Enable minimal build. |
| 17 |
You may also set the PRISM_BUILD_MINIMAL environment variable. |
| 18 |
|
| 19 |
--help |
| 20 |
Display this message. |
| 21 |
|
| 22 |
Environment variables used: |
| 23 |
|
| 24 |
PRISM_BUILD_DEBUG |
| 25 |
Equivalent to `--enable-build-debug` when set, even if nil or blank. |
| 26 |
|
| 27 |
PRISM_BUILD_MINIMAL |
| 28 |
Equivalent to `--enable-build-minimal` when set, even if nil or blank. |
| 29 |
|
| 30 |
TEXT |
| 31 |
exit!(0) |
| 32 |
end |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
def generate_templates |
| 38 |
Dir.chdir(File.expand_path("../..", __dir__)) do |
| 39 |
if !File.exist?("include/prism/ast.h") && Dir.exist?(".git") |
| 40 |
system(RbConfig.ruby, "templates/template.rb", exception: true) |
| 41 |
end |
| 42 |
end |
| 43 |
end |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
def make(env, target) |
| 49 |
puts "Running make #{target} with #{env.inspect}" |
| 50 |
Dir.chdir(File.expand_path("../..", __dir__)) do |
| 51 |
system( |
| 52 |
env, |
| 53 |
RUBY_PLATFORM.match?(/openbsd|freebsd/) ? "gmake" : "make", |
| 54 |
target, |
| 55 |
exception: true |
| 56 |
) |
| 57 |
end |
| 58 |
end |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
if RUBY_ENGINE != "ruby" |
| 65 |
generate_templates |
| 66 |
soext = RbConfig::CONFIG["SOEXT"] |
| 67 |
|
| 68 |
make({ "SOEXT" => soext }, "build/libprism.#{soext}") |
| 69 |
File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n") |
| 70 |
return |
| 71 |
end |
| 72 |
|
| 73 |
require "mkmf" |
| 74 |
|
| 75 |
|
| 76 |
generate_templates |
| 77 |
unless find_header("prism.h", File.expand_path("../../include", __dir__)) |
| 78 |
raise "prism.h is required" |
| 79 |
end |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
unless find_header("prism/extension.h", File.expand_path("..", __dir__)) |
| 86 |
raise "prism/extension.h is required" |
| 87 |
end |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
if enable_config("build-debug", ENV["PRISM_BUILD_DEBUG"] || false) |
| 95 |
append_cflags("-DPRISM_BUILD_DEBUG") |
| 96 |
end |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
if enable_config("build-minimal", ENV["PRISM_BUILD_MINIMAL"] || false) |
| 104 |
append_cflags("-DPRISM_BUILD_MINIMAL") |
| 105 |
end |
| 106 |
|
| 107 |
|
| 108 |
append_cflags("-fvisibility=hidden") |
| 109 |
|
| 110 |
def src_list(path) |
| 111 |
srcdir = path.dup |
| 112 |
RbConfig.expand(srcdir) |
| 113 |
Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")] |
| 114 |
end |
| 115 |
|
| 116 |
def add_libprism_source(path) |
| 117 |
$VPATH << path |
| 118 |
src_list path |
| 119 |
end |
| 120 |
|
| 121 |
$srcs = src_list("$(srcdir)") + |
| 122 |
add_libprism_source("$(srcdir)/../../src") + |
| 123 |
add_libprism_source("$(srcdir)/../../src/util") |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
create_makefile("prism/prism") |