2017-01-22 21:50:23 -05:00
|
|
|
# -*- makefile -*-
|
|
|
|
V = 0
|
2020-12-29 02:42:24 -05:00
|
|
|
V0 = $(V:0=)
|
2017-01-22 21:50:23 -05:00
|
|
|
Q1 = $(V:1=)
|
|
|
|
Q = $(Q1:0=@)
|
|
|
|
ECHO1 = $(V:1=@:)
|
|
|
|
ECHO = $(ECHO1:0=@echo)
|
|
|
|
<%
|
|
|
|
require './rbconfig'
|
|
|
|
macros = {}
|
|
|
|
deps = []
|
2017-04-20 22:43:25 -04:00
|
|
|
notes = {}
|
2017-01-27 02:23:21 -05:00
|
|
|
rubies = []
|
|
|
|
exeext = RbConfig::CONFIG['EXEEXT']
|
2017-01-27 02:16:36 -05:00
|
|
|
gnumake = false
|
2020-06-19 02:35:14 -04:00
|
|
|
confexts = nil
|
2017-01-27 02:16:36 -05:00
|
|
|
opt = OptionParser.new do |o|
|
|
|
|
o.on('--gnumake=BOOL') {|v| gnumake = v == 'yes'}
|
2020-06-19 02:35:14 -04:00
|
|
|
o.on('--configure-exts=FILE') {|v| confexts = v}
|
2017-01-27 02:16:36 -05:00
|
|
|
o.order!(ARGV)
|
|
|
|
end
|
2020-06-19 02:35:14 -04:00
|
|
|
confexts &&= File.read(confexts).scan(/^exts: (.*\.mk)/).flatten rescue nil
|
|
|
|
confexts ||= []
|
|
|
|
macros["old_extensions"] = []
|
|
|
|
|
2017-04-20 22:43:25 -04:00
|
|
|
contpat = /(?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*/
|
2020-06-19 01:02:46 -04:00
|
|
|
Dir.glob("{ext,.bundle/gems}/*/exts.mk") do |e|
|
2017-01-28 00:02:41 -05:00
|
|
|
gem = /\Agems(?=\/)/ =~ e
|
2017-01-22 21:50:23 -05:00
|
|
|
s = File.read(e)
|
2017-07-08 08:31:55 -04:00
|
|
|
s.scan(/^(extensions|SUBMAKEOPTS|EXT[A-Z]+|MFLAGS|NOTE_[A-Z]+)[ \t]*=[ \t]*(#{contpat})$/o) 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"
|
2020-06-19 02:35:14 -04:00
|
|
|
n = "old_extensions" if n == "extensions" and !confexts.include?(e)
|
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
|
2020-06-22 11:14:39 -04:00
|
|
|
break if n == "old_extensions"
|
2017-01-22 21:50:23 -05:00
|
|
|
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
|
2017-04-20 22:43:25 -04: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 03:34:47 -04:00
|
|
|
n = n.split(/^/)
|
2017-04-20 22:43:25 -04:00
|
|
|
if m
|
|
|
|
note[1].concat(n)
|
|
|
|
else
|
|
|
|
note[1] |= n
|
|
|
|
end
|
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
|
|
|
-%>
|
2017-04-20 22:43:25 -04:00
|
|
|
% macros.each_pair do |k, v|
|
|
|
|
<%=k%> =<%= v.fold(column) %>
|
2017-02-10 01:12:22 -05:00
|
|
|
% 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
|
|
|
|
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-05-13 23:33:01 -04:00
|
|
|
% if rubies.size > 1
|
|
|
|
<%= rubies[1..-1].join(' ')%>: <%= rubies[0] %>
|
|
|
|
% end
|
2017-01-27 02:23:21 -05:00
|
|
|
|
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
|
|
|
|
2020-06-19 02:35:14 -04:00
|
|
|
% exts = (macros["extensions"] + macros["old_extensions"])
|
|
|
|
% exts.map! {|e|e.chomp("/.")}.sort
|
2018-12-01 04:29:14 -05:00
|
|
|
% targets.each do |tgt|
|
|
|
|
% exts.each do |d|
|
|
|
|
% t = "#{d}/#{tgt}"
|
|
|
|
% if /^(dist|real)?clean$/ =~ tgt
|
|
|
|
% deps = exts.select {|e|e.start_with?("#{d}/")}.map {|e|"#{e}/#{tgt}"}
|
|
|
|
% pd = ' ' + deps.join(' ') unless deps.empty?
|
|
|
|
% else
|
|
|
|
% pext = File.dirname(d)
|
|
|
|
% pd = " #{pext}/#{tgt}" if exts.include?(pext)
|
|
|
|
% end
|
|
|
|
<%=t%>:<%=pd%>
|
|
|
|
% if /^(dist|real)clean$/ =~ tgt
|
2017-02-27 03:23:18 -05:00
|
|
|
$(ECHO) $(@F)ing $(@D)
|
2018-12-01 04:29:14 -05:00
|
|
|
% end
|
2017-02-10 01:12:22 -05:00
|
|
|
$(Q)<%= submake %><%=mflags%> V=$(V) $(@F)
|
2018-12-01 04:29:14 -05:00
|
|
|
% if /^(dist|real)clean$/ =~ tgt
|
2020-06-18 23:07:05 -04:00
|
|
|
$(Q)$(RM) $(@D)/exts.mk
|
2017-02-27 03:23:18 -05:00
|
|
|
$(Q)$(RMDIRS) $(@D)
|
2018-12-01 04:29:14 -05:00
|
|
|
% end
|
2017-02-27 03:23:18 -05:00
|
|
|
% end
|
2017-01-22 21:50:23 -05:00
|
|
|
% end
|
|
|
|
|
|
|
|
extso:
|
|
|
|
@echo EXTSO=$(EXTSO)
|
|
|
|
|
2017-04-20 22:43:25 -04:00
|
|
|
% notes.each_pair do |k, (d, n)|
|
|
|
|
<%= k %>:<%= d.join(' ') %>
|
|
|
|
<%= n.join("") %>
|
|
|
|
% end
|
2020-06-19 02:35:14 -04:00
|
|
|
|
|
|
|
remove-old-extensions: $(old_extensions:/.=/distclean)
|