Skip to content

Commit 3d4e682

Browse files
committed
Move the rules for win32_vk
Enable the rules only when `gperf` command is available. And replace `gperf.sed` with `extract-vk.rb` script.
1 parent 5209ac6 commit 3d4e682

5 files changed

Lines changed: 40 additions & 22 deletions

File tree

ext/io/console/depend

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,3 @@
1-
# mkdepend: depends win32_vk.inc => $(VK_HEADER)
2-
31
# AUTOGENERATED DEPENDENCIES START
42
console.o: console.c
53
# AUTOGENERATED DEPENDENCIES END
6-
7-
win32_vk.inc: win32_vk.list $(srcdir)/extract-vk.rb
8-
9-
.list.inc:
10-
( \
11-
$(RUBY) $(srcdir)/extract-vk.rb $< && \
12-
gperf --ignore-case -L ANSI-C -E -C -P -p -j1 -i 1 -g -o -t -K ofs -N console_win32_vk -k* $< \
13-
| sed -f $(top_srcdir)/tool/gperf.sed \
14-
) > $(@F)
15-
16-
.SUFFIXES: .chksum .list .inc
17-
18-
.list.chksum:
19-
@$(RUBY) -I$(top_srcdir)/tool -rchecksum \
20-
-e "Checksum.update(ARGV) {|k|k.copy(k.target) rescue k.make(k.target)}" \
21-
-- --make=$(MAKE) -I$(srcdir) $(<F) $(@F:.chksum=.inc)

ext/io/console/extconf.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,22 @@
5252
have_const("RB_WARN_CATEGORY_DEPRECATED")
5353
win32 or have_func("ttyname_r") or have_func("ttyname")
5454
have_func("rb_prepend_module") # not exported by TruffleRuby
55+
vk_tool = find_executable("gperf")
5556
create_makefile("io/console") {|conf|
56-
conf << "\n""VK_HEADER = #{vk_header}\n"
57+
if vk_header
58+
conf << <<~MK
59+
VK_HEADER = #{vk_header}
60+
all:
61+
console.#$OBJEXT: $(VK_HEADER)
62+
MK
63+
end
64+
if vk_tool
65+
unless conf.any? {|c| /^ *top_srcdir *=/.match?(c)}
66+
conf << "top_srcdir = $(srcdir)/../../..\n"
67+
end
68+
conf.concat(depend_rules(File.read("#$srcdir/win32_vk.mk")))
69+
end
70+
conf
5771
}
5872
when nil
5973
File.write("Makefile", dummy_makefile($srcdir).join(""))

ext/io/console/extract-vk.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
code = [+""]
2-
ARGF.read.scan(/^\w+,\s*\KVK_\w+/) do |n|
2+
source = File.read(ARGV.shift)
3+
source.scan(/^\w+,\s*\KVK_\w+/) do |n|
34
puts("#ifndef #{n}\n# define #{n} UNDEFINED_VK\n#endif")
45
code << +"" if n.size + code.last.size > 60
56
code.last << " x(#{n})z"
67
end
78
puts ["#define EACH_VK(x,z)", code].join(" \\\n "), ""
9+
IO.popen(["gperf", *ARGV], "r+") do |f|
10+
w = Thread.start {
11+
f.puts source
12+
f.close_write
13+
}
14+
puts f.read.sub(/^\w*hash .*\{(?m:.*?)\n\}/) {
15+
$&.sub!(" hval = ", " hval = (unsigned int)")
16+
}
17+
w.join
18+
end

ext/io/console/win32_vk.mk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
win32_vk.inc: win32_vk.list $(srcdir)/extract-vk.rb
2+
3+
.list.inc:
4+
$(Q)$(RUBY) $(srcdir)/extract-vk.rb $< \
5+
--ignore-case -L ANSI-C -E -C -P -p -j1 -i 1 -g -o -t -K ofs -N console_win32_vk -k* \
6+
> $(@F)
7+
8+
.SUFFIXES: .chksum .list .inc
9+
10+
.list.chksum:
11+
@$(RUBY) -I$(top_srcdir)/tool -rchecksum \
12+
-e "Checksum.update(ARGV) {|k|k.copy(k.target) rescue k.make(k.target)}" \
13+
-- --make=$(MAKE) -I$(srcdir) $(<F) $(@F:.chksum=.inc)

tool/test/test_mkdepend.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ def test_virtual_dependencies_are_declared
336336
%w[eventids1.h {$(VPATH)}eventids1.c],
337337
ripper.dependencies['eventids1.c'],
338338
)
339-
console = mkdepend.dependency_declarations('ext/io/console/depend')
340-
assert_equal(%w[$(VK_HEADER)], console.dependencies['win32_vk.inc'])
341339
assert_include(
342340
mkdepend.dependency_targets('ext/socket/depend'),
343341
'constdefs.h',

0 commit comments

Comments
 (0)