1 % deffile = (true if /\$\(DEFFILE\)/ =~ CONFIG["LINK_SO"])
2 % encs = Dir.open($srcdir) {|d| d.grep(/.+\.c\z/)} - BUILTIN_ENCS
3 % encs.each {|e| e.chomp!(".c")}
4 % encs.reject! {|e| !ENC_PATTERNS.any? {|p| File.fnmatch?(p, e)}} if !ENC_PATTERNS.empty?
5 % encs.reject! {|e| NOENC_PATTERNS.any? {|p| File.fnmatch?(p, e)}}
6 % alphanumeric_order = proc {|e| e.scan(/(\d+)|(\D+)/).map {|n,a| a||[n.size,n.to_i]}.flatten}
7 % encs = encs.sort_by(&alphanumeric_order)
8 % encs.unshift(encs.delete("encdb"))
10 % trans = Dir.open($srcdir+"/trans") {|d|
12 % if e.chomp!('.trans')
15 % elsif e.chomp!('.c')
21 % atrans = atrans.sort_by(&alphanumeric_order)
22 % trans = trans.sort_by(&alphanumeric_order)
23 % trans.unshift(trans.delete("transdb"))
25 % trans.map! {|e| "trans/#{e}"}
26 % dependencies = encs + trans
27 % cleanlibs = Shellwords.shellwords(CONFIG["cleanlibs"] || "")
28 % cleanobjs = Shellwords.shellwords(CONFIG["cleanobjs"] || "")
29 % rule_subst = CONFIG["RULE_SUBST"] || "%s"
30 % transvpath = rule_subst.dup.sub!(/\{[^{}]+\}/, '$(TRANSVPATH)/') || "enc/trans/%s"
31 % transvpath_prefix = (rule_subst.dup.sub!(/\{[^{}]+\}/, '{$(TRANSVPATH)}') || "") % ""
32 % if File::ALT_SEPARATOR
33 % pathrep = proc {|path| path.gsub('/', File::ALT_SEPARATOR).gsub(/\$\(([@<?*]\w?|\w+)\)/, "$(\\1:/=\\#{File::ALT_SEPARATOR})")}
35 % pathrep = proc {|path| path}
38 VPATH = <%=%w[$(arch_hdrdir)/ruby $(hdrdir)/ruby $(srcdir) $(encsrcdir)].join(CONFIG["PATH_SEPARATOR"])%>
39 LIBPATH = <%=libpathflag($DEFLIBPATH)%>
41 ENCOBJS = <%=encs.map {|e|"enc/#{e}.$(OBJEXT)"}.join(" \\\n\t ")%><%="\n" if encs.size>1%>
42 ENCSOS = <%=encs.map {|e|"$(ENCSODIR)/#{e}.$(DLEXT)"}.join(" \\\n\t ")%><%="\n" if encs.size>1%>
43 ENCCLEANLIBS = <%=cleanlibs.map {|clean|
44 clean.gsub(/\$\*(\.\w+)?/) {"$(ENCOBJS#{$1 ? ":.#{CONFIG["OBJEXT"]}=#{$1}" : ""})"}
46 ENCCLEANOBJS = <%=cleanobjs.map {|clean|
47 clean.gsub(/\$\*(\.\w+)?/) {"$(ENCOBJS#{$1 ? ":.#{CONFIG["OBJEXT"]}=#{$1}" : ""})"}
50 TRANSVPATH = $(srcdir)/enc/trans
52 TRANSCSRCS = <%=atrans.map {|e| transvpath % "#{e}.c"}.join(" \\\n\t ")%><%="\n" if trans.size>1%>
53 TRANSOBJS = <%=trans.map {|e|"enc/#{e}.$(OBJEXT)"}.join(" \\\n\t ")%><%="\n" if trans.size>1%>
54 TRANSSOS = <%=trans.map {|e|"$(ENCSODIR)/#{e}.$(DLEXT)"}.join(" \\\n\t ")%><%="\n" if trans.size>1%>
55 TRANSCLEANLIBS = <%=cleanlibs.map {|clean|
56 clean.gsub(/\$\*(\.\w+)?/) {"$(TRANSOBJS#{$1 ? ":.#{CONFIG["OBJEXT"]}=#{$1}" : ""})"}
58 TRANSCLEANOBJS = <%=cleanobjs.map {|clean|
59 clean.gsub(/\$\*(\.\w+)?/) {"$(TRANSOBJS#{$1 ? ":.#{CONFIG["OBJEXT"]}=#{$1}" : ""})"}
62 all: $(ENCSOS) $(TRANSSOS)
66 % if rule = (compile_rules = COMPILE_RULES).find(&/\$\(srcdir\)/.method(:=~))
67 % compile_rules = [rule.sub(/\$\(srcdir\)/, '\&/enc'), rule.sub(/\$\(srcdir\)/, '\&/enc/trans')] + compile_rules
69 % compile_rules.each do |rule|
70 <%= rule % %w[c $(OBJEXT)] %>
76 <%=transvpath_prefix%>.trans<%=transvpath_prefix%>.c:
77 $(MINIRUBY) "$(srcdir)/tool/transcode-tblgen.rb" -vo "$@" "$<"
79 % unless encs.empty? or trans.empty?
82 $(ENCOBJS): regenc.h oniguruma.h config.h defines.h
85 $(TRANSOBJS): ruby.h intern.h config.h defines.h missing.h encoding.h oniguruma.h st.h transcode_data.h
90 <%=transvpath % "#{e}.c"%>: <%= transvpath % "#{e}.trans"%>
91 % src = [*IO.read(File.join($srcdir, "trans", src)).scan(/^\s*require\s+[\'\"]([^\'\"]*)/).flatten.map{|c|c+".rb"}]
92 <%=transvpath % "#{e}.c"%>: <%= src.map {|e| transvpath % "#{e}"}.join(" ")%> $(srcdir)/tool/transcode-tblgen.rb
96 % link_so = LINK_SO.gsub(/\n/, "\n\t")
97 % link_so.gsub!(/(-(?:implib|pdb):\S+)-\$\(arch\)\./, '\1.')
98 % dependencies.each do |e|
99 % obj = "enc/#{e}.$(OBJEXT)"
100 % df = ("enc/#{e}.def" if deffile)
101 $(ENCSODIR)/<%=e%>.$(DLEXT): <%=obj%>
103 echo> <%=df%> EXPORTS
104 echo>> <%=df%> <%=EXPORT_PREFIX%>Init_<%=File.basename(e)%>
107 <%=link_so.sub(/\$\(OBJS\)/) {obj}.sub(/\$\(DEFFILE\)/) {df}.gsub(/-(?:implib|pdb):/) {|s|"#{s}enc/#{e.sub(/[^\/]+\z/, '')}"}%>
110 % dependencies.each do |e|
111 <%=rule_subst % "enc/#{e}.$(OBJEXT)"%>: <%=rule_subst % "enc/#{e}.c"%>
114 enc/encdb.$(OBJEXT): encdb.h
115 enc/trans/transdb.$(OBJEXT): transdb.h
118 % %w[$(ENCSOS) $(ENCOBJS) $(ENCCLEANOBJS) $(ENCCLEANLIBS) $(TRANSSOS) $(TRANSOBJS) $(TRANSCLEANOBJS) $(TRANSCLEANLIBS) $(TRANSCSRCS)].each do |clean|
119 @$(RM) <%=pathrep[clean]%>
121 % %w[$(ENCSODIR)/trans $(ENCSODIR) enc/trans enc].each do|dir|
122 @-rmdir <%=pathrep[dir]%>