1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/template/exts.mk.tmpl

100 lines
2.4 KiB
Cheetah
Raw Normal View History

# -*- makefile -*-
V = 0
Q1 = $(V:1=)
Q = $(Q1:0=@)
ECHO1 = $(V:1=@:)
ECHO = $(ECHO1:0=@echo)
<%
require './rbconfig'
macros = {}
deps = []
note = []
Dir.glob("ext/*/exts.mk") do |e|
s = File.read(e)
s.scan(/^(extensions|EXT[A-Z]+)[ \t]*=[ \t]*((?>(?>[^\\\n]|\\.)*\\\n)*(?>[^\\\n]|\\.)*)$/) do |n, v|
v.gsub!(/\\\n[ \t]*/, ' ')
next if v.empty?
v = v.split
m = macros[n] ||= []
case n
when "LIBS"
m.concat(v)
else
macros[n] = m | v
end
end
s.scan(%r"^(ext/\S+)/[^/\s:]+:[ \t]*\1/static$|^(?:ruby|install(?:-(?:so|rb))?|static|(?:dist|real)?clean):.+$") 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"]
%>
extensions =<%= macros["extensions"].fold(column) %>
gems =
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: ruby
static: ruby
clean:
-$(Q)$(RM) ext/extinit.<%= objext %>
distclean:
-$(Q)$(RM) ext/extinit.c
<%= deps.join("\n") %>
ruby:
$(Q)$(MAKE) $(MFLAGS) $(SUBMAKEOPTS) $@
libencs:
$(Q)$(MAKE) -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)$(MAKE) -C $(@D) $(MFLAGS) V=$(V) $(@F)
% end
extso:
@echo EXTSO=$(EXTSO)
note:
<%= note.join("") %>