blob: e4633c415af167dc4de3e082a99728bc31a9bc61 (
plain)
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# -*- makefile -*-
V = 0
Q1 = $(V:1=)
Q = $(Q1:0=@)
ECHO1 = $(V:1=@:)
ECHO = $(ECHO1:0=@echo)
<%
require './rbconfig'
macros = {}
deps = []
note = []
rubies = []
exeext = RbConfig::CONFIG['EXEEXT']
gnumake = false
opt = OptionParser.new do |o|
o.on('--gnumake=BOOL') {|v| gnumake = v == 'yes'}
o.order!(ARGV)
end
Dir.glob("{ext,gems}/*/exts.mk") do |e|
gem = /\Agems(?=\/)/ =~ e
s = File.read(e)
s.scan(/^(extensions|EXT[A-Z]+|MFLAGS)[ \t]*=[ \t]*((?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*)$/) do |n, v|
v.gsub!(/\\\n[ \t]*/, ' ')
next if v.empty?
next if gem and n != "extensions"
v = v.split
m = macros[n] ||= []
case n
when "LIBS"
m.concat(v)
else
macros[n] = m | v
end
end
if gem
r = ""
else
r = s[/^all static: (.+)$/, 1]
deps << $&
rubies |= r.split if r
r = "(?:#{Regexp.new(r)})|"
end
s.scan(%r"^(ext/\S+)/[^/\s:]+:[ \t]*\1/static$|
^(?:#{r}
all|static|install(?:-(?:so|rb))?|
(?:dist|real)?clean
):.+$
"x) do
deps << $&
end
s.scan(%r"^note:\n((?:\t.+\n)+)") do |(n)|
note |= n.split(/^/)
end
end
deps.uniq!
if objs = macros["EXTOBJS"] and objs.any? {|e|e.start_with?("ext/extinit.")}
objs.delete_if {|e|e.start_with?("dmyext.")}
end
macros.default = [].freeze
class Array
def fold(h, w = 70)
return "" if empty?
w -= h
ret = [s = String.new]
each do |e|
if s.size + e.size + 1 > w
ret << (s = String.new)
end
s << " " << e
end
ret.join(" \\\n" + "\t" * (h / 8) + " " * (h % 8))
end
end
@erbout = _erbout
def self.column
w = 0
@erbout[/^.*\z/].scan(/\t|([^\t]+)/) {|s,| w += (s ? s.size : 8 - w % 8)}
w
end
targets = %w[all static install install-so install-rb clean distclean realclean]
objext = RbConfig::CONFIG["OBJEXT"]
if gnumake
submake = "$(MAKE) -C $(@D)"
else
submake = "cd $(@D) && "
exec = RbConfig::CONFIG["exec"] and !exec.empty? and submake << exec << " "
submake << "$(MAKE)"
mflags = " $(MFLAGS)"
end
-%>
% unless macros["MFLAGS"].empty?
MFLAGS =<%= macros["MFLAGS"].fold(column) %>
% end
extensions =<%= macros["extensions"].fold(column) %>
EXTOBJS =<%= macros["EXTOBJS"].fold(column) %>
EXTLIBS =<%= macros["EXTLIBS"].fold(column) %>
EXTSO =<%= macros["EXTSO"].fold(column) %>
EXTLDFLAGS =<%= macros["EXTLDFLAGS"].fold(column) %>
EXTINITS =<%= macros["EXTINITS"].fold(column) %>
SUBMAKEOPTS = DLDOBJS="$(EXTOBJS) $(EXTENCS)" EXTOBJS= \
EXTSOLIBS="$(EXTLIBS)" LIBRUBY_SO_UPDATE=$(LIBRUBY_EXTS) \
EXTLDFLAGS="$(EXTLDFLAGS)" EXTINITS="$(EXTINITS)" \
UPDATE_LIBRARIES="$(UPDATE_LIBRARIES)" SHOWFLAGS=
all:
static:
clean:
-$(Q)$(RM) ext/extinit.<%= objext %>
distclean:
-$(Q)$(RM) ext/extinit.c
<%= deps.join("\n") %>
% rubies.each do |ruby|
<%= ruby %>:
$(Q)$(MAKE)<%=mflags%> $(SUBMAKEOPTS) $@
% end
libencs:
$(Q)$(MAKE)<%=mflags%> -f enc.mk V=$(V) $@
ext/extinit.<%=objext%>:
$(Q)$(MAKE)<%=mflags%> V=$(V) EXTINITS="$(EXTINITS)" $@
% targets.product(macros["extensions"].map {|e|e.chomp("/.")}) do |t, e|
<%=e%>/<%=t%>:
$(Q)<%= submake %><%=mflags%> V=$(V) $(@F)
% end
extso:
@echo EXTSO=$(EXTSO)
note:
<%= note.join("") %>
|