2017-01-23 05:50:23 +03:00
|
|
|
# -*- makefile -*-
|
|
|
|
V = 0
|
|
|
|
Q1 = $(V:1=)
|
|
|
|
Q = $(Q1:0=@)
|
|
|
|
ECHO1 = $(V:1=@:)
|
|
|
|
ECHO = $(ECHO1:0=@echo)
|
|
|
|
<%
|
|
|
|
require './rbconfig'
|
|
|
|
macros = {}
|
|
|
|
deps = []
|
2017-04-21 05:43:25 +03:00
|
|
|
notes = {}
|
2017-01-27 10:23:21 +03:00
|
|
|
rubies = []
|
|
|
|
exeext = RbConfig::CONFIG['EXEEXT']
|
2017-01-27 10:16:36 +03:00
|
|
|
gnumake = false
|
|
|
|
opt = OptionParser.new do |o|
|
|
|
|
o.on('--gnumake=BOOL') {|v| gnumake = v == 'yes'}
|
|
|
|
o.order!(ARGV)
|
|
|
|
end
|
2017-04-21 05:43:25 +03:00
|
|
|
contpat = /(?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*/
|
2017-01-28 08:02:41 +03:00
|
|
|
Dir.glob("{ext,gems}/*/exts.mk") do |e|
|
|
|
|
gem = /\Agems(?=\/)/ =~ e
|
2017-01-23 05:50:23 +03:00
|
|
|
s = File.read(e)
|
2017-04-21 05:43:25 +03:00
|
|
|
s.scan(/^(extensions|EXT[A-Z]+|MFLAGS|NOTE_[A-Z]+)[ \t]*=[ \t]*(#{contpat})$/o) do |n, v|
|
2017-01-23 05:50:23 +03:00
|
|
|
v.gsub!(/\\\n[ \t]*/, ' ')
|
|
|
|
next if v.empty?
|
2017-01-28 08:02:41 +03:00
|
|
|
next if gem and n != "extensions"
|
2017-01-23 05:50:23 +03:00
|
|
|
v = v.split
|
|
|
|
m = macros[n] ||= []
|
|
|
|
case n
|
|
|
|
when "LIBS"
|
|
|
|
m.concat(v)
|
|
|
|
else
|
|
|
|
macros[n] = m | v
|
|
|
|
end
|
|
|
|
end
|
2017-01-28 08:02:41 +03:00
|
|
|
if gem
|
|
|
|
r = ""
|
|
|
|
else
|
|
|
|
r = s[/^all static: (.+)$/, 1]
|
|
|
|
deps << $&
|
|
|
|
rubies |= r.split if r
|
|
|
|
r = "(?:#{Regexp.new(r)})|"
|
|
|
|
end
|
2017-01-28 04:43:29 +03:00
|
|
|
s.scan(%r"^(ext/\S+)/[^/\s:]+:[ \t]*\1/static$|
|
2017-01-28 08:02:41 +03:00
|
|
|
^(?:#{r}
|
2017-01-27 10:23:21 +03:00
|
|
|
all|static|install(?:-(?:so|rb))?|
|
|
|
|
(?:dist|real)?clean
|
|
|
|
):.+$
|
2017-01-28 04:43:29 +03:00
|
|
|
"x) do
|
2017-04-20 11:31:20 +03:00
|
|
|
deps << $&.sub(/ +note$/, '')
|
2017-01-23 05:50:23 +03:00
|
|
|
end
|
2017-04-21 05:43:25 +03:00
|
|
|
s.scan(%r"^(note(?:-\w+)?):(:)?[ \t]*(#{contpat})\n((?:\t.+\n)*)"o) do |(t, m, d, n)|
|
|
|
|
note = (notes[t] ||= [[m||""], []])
|
|
|
|
note[0] |= d.split(/(?:\\\n|[ \t])[ \t]*/)
|
2017-03-31 10:34:47 +03:00
|
|
|
n = n.split(/^/)
|
2017-04-21 05:43:25 +03:00
|
|
|
if m
|
|
|
|
note[1].concat(n)
|
|
|
|
else
|
|
|
|
note[1] |= n
|
|
|
|
end
|
2017-01-23 05:50:23 +03:00
|
|
|
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"]
|
2017-01-27 10:16:36 +03:00
|
|
|
if gnumake
|
|
|
|
submake = "$(MAKE) -C $(@D)"
|
|
|
|
else
|
|
|
|
submake = "cd $(@D) && "
|
2017-01-27 18:32:50 +03:00
|
|
|
exec = RbConfig::CONFIG["exec"] and !exec.empty? and submake << exec << " "
|
2017-01-27 10:16:36 +03:00
|
|
|
submake << "$(MAKE)"
|
2017-02-10 09:12:22 +03:00
|
|
|
mflags = " $(MFLAGS)"
|
2017-01-27 10:16:36 +03:00
|
|
|
end
|
2017-02-10 09:12:22 +03:00
|
|
|
-%>
|
2017-04-21 05:43:25 +03:00
|
|
|
% macros.each_pair do |k, v|
|
|
|
|
<%=k%> =<%= v.fold(column) %>
|
2017-02-10 09:12:22 +03:00
|
|
|
% end
|
2017-02-27 11:23:18 +03:00
|
|
|
% RbConfig::MAKEFILE_CONFIG.keys.grep(/RM/) do |k|
|
|
|
|
<%=k%> = <%=RbConfig::MAKEFILE_CONFIG[k]%>
|
|
|
|
% end
|
2017-01-23 05:50:23 +03:00
|
|
|
|
|
|
|
SUBMAKEOPTS = DLDOBJS="$(EXTOBJS) $(EXTENCS)" EXTOBJS= \
|
|
|
|
EXTSOLIBS="$(EXTLIBS)" LIBRUBY_SO_UPDATE=$(LIBRUBY_EXTS) \
|
|
|
|
EXTLDFLAGS="$(EXTLDFLAGS)" EXTINITS="$(EXTINITS)" \
|
|
|
|
UPDATE_LIBRARIES="$(UPDATE_LIBRARIES)" SHOWFLAGS=
|
|
|
|
|
2017-01-28 04:43:29 +03:00
|
|
|
all:
|
|
|
|
static:
|
2017-01-23 05:50:23 +03:00
|
|
|
|
|
|
|
clean:
|
|
|
|
-$(Q)$(RM) ext/extinit.<%= objext %>
|
|
|
|
distclean:
|
|
|
|
-$(Q)$(RM) ext/extinit.c
|
|
|
|
|
2017-04-20 11:13:16 +03:00
|
|
|
% deps.each do |d|
|
|
|
|
<%= d %>
|
|
|
|
% end
|
2017-01-27 10:23:21 +03:00
|
|
|
|
|
|
|
% rubies.each do |ruby|
|
|
|
|
<%= ruby %>:
|
2017-02-10 09:12:22 +03:00
|
|
|
$(Q)$(MAKE)<%=mflags%> $(SUBMAKEOPTS) $@
|
2017-01-27 10:23:21 +03:00
|
|
|
% end
|
2017-05-14 06:33:01 +03:00
|
|
|
% if rubies.size > 1
|
|
|
|
<%= rubies[1..-1].join(' ')%>: <%= rubies[0] %>
|
|
|
|
% end
|
2017-01-27 10:23:21 +03:00
|
|
|
|
2017-01-23 05:50:23 +03:00
|
|
|
libencs:
|
2017-02-10 09:12:22 +03:00
|
|
|
$(Q)$(MAKE)<%=mflags%> -f enc.mk V=$(V) $@
|
2017-01-23 05:50:23 +03:00
|
|
|
ext/extinit.<%=objext%>:
|
2017-02-10 09:12:22 +03:00
|
|
|
$(Q)$(MAKE)<%=mflags%> V=$(V) EXTINITS="$(EXTINITS)" $@
|
2017-01-23 05:50:23 +03:00
|
|
|
|
|
|
|
% targets.product(macros["extensions"].map {|e|e.chomp("/.")}) do |t, e|
|
|
|
|
<%=e%>/<%=t%>:
|
2017-02-27 11:23:18 +03:00
|
|
|
% if /^(dist|real)clean$/ =~ t
|
|
|
|
$(ECHO) $(@F)ing $(@D)
|
|
|
|
% end
|
2017-02-10 09:12:22 +03:00
|
|
|
$(Q)<%= submake %><%=mflags%> V=$(V) $(@F)
|
2017-02-27 11:23:18 +03:00
|
|
|
% if /^(dist|real)clean$/ =~ t
|
|
|
|
$(Q)$(RMDIRS) $(@D)
|
|
|
|
% end
|
2017-01-23 05:50:23 +03:00
|
|
|
% end
|
|
|
|
|
|
|
|
extso:
|
|
|
|
@echo EXTSO=$(EXTSO)
|
|
|
|
|
2017-04-21 05:43:25 +03:00
|
|
|
% notes.each_pair do |k, (d, n)|
|
|
|
|
<%= k %>:<%= d.join(' ') %>
|
|
|
|
<%= n.join("") %>
|
|
|
|
% end
|