2017-01-23 05:50:23 +03:00
|
|
|
# -*- makefile -*-
|
|
|
|
V = 0
|
2020-12-29 10:42:24 +03:00
|
|
|
V0 = $(V:0=)
|
2017-01-23 05:50:23 +03:00
|
|
|
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
|
2020-06-19 09:35:14 +03:00
|
|
|
confexts = nil
|
2017-01-27 10:16:36 +03:00
|
|
|
opt = OptionParser.new do |o|
|
|
|
|
o.on('--gnumake=BOOL') {|v| gnumake = v == 'yes'}
|
2020-06-19 09:35:14 +03:00
|
|
|
o.on('--configure-exts=FILE') {|v| confexts = v}
|
2017-01-27 10:16:36 +03:00
|
|
|
o.order!(ARGV)
|
|
|
|
end
|
2022-04-06 14:25:53 +03:00
|
|
|
confexts &&= File.read(confexts).scan(/^(?:ext|gem)s: (.*\.mk)/).flatten rescue nil
|
2020-06-19 09:35:14 +03:00
|
|
|
confexts ||= []
|
|
|
|
macros["old_extensions"] = []
|
|
|
|
|
2017-04-21 05:43:25 +03:00
|
|
|
contpat = /(?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*/
|
2020-06-19 08:02:46 +03:00
|
|
|
Dir.glob("{ext,.bundle/gems}/*/exts.mk") do |e|
|
2022-04-05 17:24:00 +03:00
|
|
|
gem = e.start_with?(".bundle/gems/")
|
2017-01-23 05:50:23 +03:00
|
|
|
s = File.read(e)
|
2023-03-02 13:18:13 +03:00
|
|
|
s.scan(/^(extensions|SUBMAKEOPTS|EXT[A-Z]+|MFLAGS|MESSAGE_(?:BEGIN|END)|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?
|
2020-06-19 09:35:14 +03:00
|
|
|
n = "old_extensions" if n == "extensions" and !confexts.include?(e)
|
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
|
2020-06-22 18:14:39 +03:00
|
|
|
break if n == "old_extensions"
|
2017-01-23 05:50:23 +03:00
|
|
|
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!
|
2024-02-21 13:17:13 +03:00
|
|
|
|
|
|
|
# NOTE: Only if extensions are configured as static and dynamic heterogeneously
|
|
|
|
# (e.g. --with-static-linked-ext=foo or ext/Setup can mix static and dynamic
|
|
|
|
# extensions), EXTOBJS may contain both extinit.o and dmyext.o. In such case,
|
|
|
|
# prefer extinit.o, which does actual Init_${ext} function calls for statically
|
|
|
|
# linked extensions, and drop dmyext.o, which does nothing but just to make the
|
|
|
|
# linker happy.
|
2017-01-23 05:50:23 +03:00
|
|
|
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
|
|
|
|
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:
|
2022-03-07 08:44:57 +03:00
|
|
|
$(Q)$(MAKE)<%=mflags%> -f enc.mk V=$(V) MINIRUBY="$(MINIRUBY)" $@
|
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
|
|
|
|
2020-06-19 09:35:14 +03:00
|
|
|
% exts = (macros["extensions"] + macros["old_extensions"])
|
|
|
|
% exts.map! {|e|e.chomp("/.")}.sort
|
2018-12-01 12:29:14 +03: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 11:23:18 +03:00
|
|
|
$(ECHO) $(@F)ing $(@D)
|
2018-12-01 12:29:14 +03:00
|
|
|
% end
|
2017-02-10 09:12:22 +03:00
|
|
|
$(Q)<%= submake %><%=mflags%> V=$(V) $(@F)
|
2018-12-01 12:29:14 +03:00
|
|
|
% if /^(dist|real)clean$/ =~ tgt
|
2022-08-11 09:21:03 +03:00
|
|
|
$(Q)$(RM) <%=t[%r[\A(?:\.[^/]+/)?(?:[^/]+/){2}]]%>exts.mk
|
2024-03-08 16:21:11 +03:00
|
|
|
-$(Q)$(RMDIRS) $(@D)
|
2018-12-01 12:29:14 +03:00
|
|
|
% end
|
2017-02-27 11:23:18 +03:00
|
|
|
% 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
|
2020-06-19 09:35:14 +03:00
|
|
|
|
|
|
|
remove-old-extensions: $(old_extensions:/.=/distclean)
|