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