3
# tool/update-deps assists you to update dependencies in common.mk.
5
# This script uses preprocessed source files (*.i) to extract
7
# It is possible to generate *.i using gcc with -save-temps option as:
9
# ./configure CFLAGS='-save-temps'
12
# After that, tool/update-deps generate common.mk with up-to-date dependencies.
13
# Currently, the result is not perfect around version.o, compile.o, etc.
14
# So you must see each changes and incorporate right changes.
16
# ./tool/update-deps > z
17
# wdiff =(sed -e 's/\\$//' common.mk ) =(sed -e 's/\\$//' z) |less -j 5 -p '\{\+|\+\}|\[-|-\]'
20
src = File.read("common.mk")
23
src.scan(/^([A-Z_]+_H_INCLUDES)[ \t]*=(([^\\\n]|\\(.|\n))*)\n/) {
26
#STDERR.puts vals.inspect
27
vals.gsub!(/\\\n/, ' ')
28
vals.gsub!(/\{\$\(VPATH\)\}/, '')
29
vals.gsub!(/thread_\$\(THREAD_MODEL\)/, 'thread_pthread')
30
vals = vals.strip.split(/\s+/)
31
includes_macro[name] = vals
32
#STDERR.puts [name, vals].inspect
37
includes_macro.each {|name, vals|
39
if /\A\$\((.*_H_INCLUDES)\)\z/ =~ val
41
includes_macro.fetch($1)
50
src.gsub!(/^([0-9a-z._]+)\.\$\(OBJEXT\):(.*\n(?:[ ].*\n)*)/) {
51
#STDERR.puts $&.inspect
56
dd.gsub!(/\{\$\(VPATH\)\}/, '')
58
dd.gsub!(/thread_\$\(THREAD_MODEL\)/, 'thread_pthread')
60
includes_macro.each {|k, v|
61
if dd.sub!(/\$\(#{Regexp.escape k}\)/) { v.join(' ') }
65
dd = dd.strip.split(/\s+/)
66
if !File.file?("#{basename}.o")
67
warn "#{basename}.o not found."
69
unless File.file? "#{basename}.i"
70
puts "#{basename}.i not found."
74
File.foreach("#{basename}.i") {|line|
75
next unless /^# \d+ "([^"]*)"/ =~ line
77
next if %r{\A[/<]} =~ inc
78
inc.sub!(%r{\A\./}, '')
79
inc.sub!(%r{\Ainclude/ruby/}, '') or
80
inc.sub!(%r{\Ainclude/}, '') or
81
inc.sub!(%r{\A\.ext/include/[^/]+/ruby/}, '') or
82
inc.sub!(%r{\Aenc/}, '') or
83
inc.sub!(%r{\Amissing/}, '')
88
incs = incs.sort_by {|inc| [(dd.index(inc) || dd.length), incs.index(inc)] }
90
if !add.empty? || true
92
raise "first file not matched: #{incs[0].inspect} v.s. #{dd[0].inspect}"
94
depline = "#{basename}.$(OBJEXT):"
95
used_imacro.each_key {|k|
96
if includes_macro[k].all? {|v| incs.include? v }
99
if includes_macro[k].include? inc
109
needless = includes_macro[k].reject {|v| incs.include? v }
110
STDERR.puts "#{basename}.$(OBJEXT) can't use #{k}. #{needless.join(' ')} is not used."
115
inc = inc.sub(/\Athread_pthread/, 'thread_$(THREAD_MODEL)')
116
if /_INCLUDES\)\z/ =~ inc
117
# use $(RUBY_H_INCLUDES) as is.
118
elsif inc == 'revision.h'
119
inc = '$(srcdir)/revision.h'
121
inc = "{$(VPATH)}#{inc}"
126
while 72 < depline.length && depline.sub!(/\A(.{0,72}|.{72}.*?) /, '')
130
matched = lines.join("\\\n ")
134
#STDERR.puts matched.inspect