rake-convert 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rake/convert.rb +316 -0
- metadata +64 -0
data/lib/rake/convert.rb
ADDED
@@ -0,0 +1,316 @@
|
|
1
|
+
EXPORT = [:CC, :CXX]
|
2
|
+
|
3
|
+
$convert = false
|
4
|
+
$makefile = ''
|
5
|
+
$configure = ''
|
6
|
+
|
7
|
+
clean = []
|
8
|
+
|
9
|
+
if (Rake::Task[:clean] rescue nil) || (Rake::Task[:clobber] rescue nil)
|
10
|
+
if defined?(CLOBBER)
|
11
|
+
CLOBBER.include 'configure', 'Makefile'
|
12
|
+
end
|
13
|
+
|
14
|
+
if (Rake::Task[:clobber] rescue nil)
|
15
|
+
clean << :clobber
|
16
|
+
elsif (Rake::Task[:clean] rescue nil)
|
17
|
+
clean << :clean
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# Makefile stuff
|
22
|
+
def sh (args)
|
23
|
+
if $convert
|
24
|
+
puts "Makefile: #{args}"
|
25
|
+
$makefile << "\t#{args.gsub(/\$\{(.*?)\}/, '$(\1)')}\n"
|
26
|
+
else
|
27
|
+
super(args)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
# Makefile stuff
|
31
|
+
|
32
|
+
# configure stuff
|
33
|
+
if $".grep(/mkmf\.rb$/).first
|
34
|
+
alias __have_header have_header
|
35
|
+
alias __have_library have_library
|
36
|
+
alias __have_func have_func
|
37
|
+
alias __have_macro have_macro
|
38
|
+
alias __check_sizeof check_sizeof
|
39
|
+
alias __create_header create_header
|
40
|
+
|
41
|
+
def have_header (header, preheaders = nil, &block)
|
42
|
+
source = nil
|
43
|
+
result = __have_header(header, preheaders) {|c|
|
44
|
+
source = block ? block.call(c) : c
|
45
|
+
}
|
46
|
+
|
47
|
+
source.sub!('#include "ruby.h"', '')
|
48
|
+
|
49
|
+
if $convert
|
50
|
+
$configure << %{
|
51
|
+
|
52
|
+
cat > $FILE.c <<EOF
|
53
|
+
#{source}
|
54
|
+
EOF
|
55
|
+
|
56
|
+
echo -n "Checking for #{header}... "
|
57
|
+
if [[ "`($CC $CFLAGS -c $FILE.c) 2>&1`" == "" ]]; then
|
58
|
+
DEFS="$DEFS\\n#define #{"HAVE_#{header.tr_cpp}"} 1"
|
59
|
+
|
60
|
+
echo yes
|
61
|
+
else
|
62
|
+
echo no
|
63
|
+
fi
|
64
|
+
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
result
|
69
|
+
end
|
70
|
+
|
71
|
+
def have_library (lib, func = nil, headers = nil, &block)
|
72
|
+
source = nil
|
73
|
+
result = __have_library(lib, func, headers) {|c|
|
74
|
+
source = block ? block.call(c) : c
|
75
|
+
}
|
76
|
+
|
77
|
+
source.sub!('#include "ruby.h"', '')
|
78
|
+
|
79
|
+
if $convert
|
80
|
+
$configure << %{
|
81
|
+
|
82
|
+
cat > $FILE.c <<EOF
|
83
|
+
#{source}
|
84
|
+
EOF
|
85
|
+
|
86
|
+
echo -n "Checking for #{lib}... "
|
87
|
+
if [[ "`($CC $CFLAGS -o $FILE -c $FILE.c -l#{lib}) 2>&1`" == "" ]]; then
|
88
|
+
echo yes
|
89
|
+
else
|
90
|
+
echo no
|
91
|
+
|
92
|
+
echo "Install #{lib} and try again"
|
93
|
+
|
94
|
+
exit 1
|
95
|
+
fi
|
96
|
+
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
result
|
101
|
+
end
|
102
|
+
|
103
|
+
def have_func (func, headers = nil, &block)
|
104
|
+
source = nil
|
105
|
+
result = __have_func(func, headers) {|c|
|
106
|
+
source = block ? block.call(c) : c
|
107
|
+
}
|
108
|
+
|
109
|
+
source.sub!('#include "ruby.h"', '')
|
110
|
+
|
111
|
+
if $convert
|
112
|
+
$configure << %{
|
113
|
+
|
114
|
+
cat > $FILE.c <<EOF
|
115
|
+
#{source}
|
116
|
+
EOF
|
117
|
+
|
118
|
+
echo -n "Checking for #{func}()#{" in #{[headers].flatten.join(' ')}" if headers}... "
|
119
|
+
if [[ "`($CC $CFLAGS -Wall -c $FILE.c) 2>&1`" == "" ]]; then
|
120
|
+
DEFS="$DEFS\\n#define #{"HAVE_#{func.tr_cpp}"} 1"
|
121
|
+
|
122
|
+
echo yes
|
123
|
+
else
|
124
|
+
echo no
|
125
|
+
fi
|
126
|
+
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
result
|
131
|
+
end
|
132
|
+
|
133
|
+
def have_macro (macro, headers = nil, opts = '', &block)
|
134
|
+
source = nil
|
135
|
+
result = __have_macro(macro, headers, opts) {|c|
|
136
|
+
source = block ? block.call(c) : c
|
137
|
+
}
|
138
|
+
|
139
|
+
source.sub!('#include "ruby.h"', '')
|
140
|
+
|
141
|
+
if $convert
|
142
|
+
$configure << %{
|
143
|
+
|
144
|
+
cat > $FILE.c <<EOF
|
145
|
+
#{source}
|
146
|
+
EOF
|
147
|
+
|
148
|
+
echo -n "Checking for #{macro}#{" in #{[headers].flatten.join(' ')}" if headers}... "
|
149
|
+
if [[ "`($CC $CFLAGS -c $FILE.c) 2>&1`" == "" ]]; then
|
150
|
+
DEFS="$DEFS\\n#define #{"HAVE_#{macro.tr_cpp}"} 1"
|
151
|
+
|
152
|
+
echo yes
|
153
|
+
else
|
154
|
+
echo no
|
155
|
+
fi
|
156
|
+
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
result
|
161
|
+
end
|
162
|
+
|
163
|
+
def check_sizeof (type, headers = nil, opts = '', &block)
|
164
|
+
source = nil
|
165
|
+
result = __check_sizeof(type, headers, opts) {|c|
|
166
|
+
source = block ? block.call(c) : c
|
167
|
+
}
|
168
|
+
|
169
|
+
source.sub!('#include "ruby.h"', '')
|
170
|
+
|
171
|
+
if $convert
|
172
|
+
$configure << %{
|
173
|
+
|
174
|
+
cat > $FILE.c <<EOF
|
175
|
+
#{source}
|
176
|
+
EOF
|
177
|
+
|
178
|
+
$CC $CFLAGS -o $FILE $FILE.c
|
179
|
+
|
180
|
+
echo -n "Checking size of #{type}#{" in #{[headers].flatten.join(' ')}" if headers}... "
|
181
|
+
if [[ "`($CC $CFLAGS -o $FILE $FILE.c) 2>&1`" == "" ]]; then
|
182
|
+
SIZE=$(exec $FILE)
|
183
|
+
DEFS="$DEFS\\n#define #{"SIZEOF_#{type.tr_cpp}"} $SIZE"
|
184
|
+
|
185
|
+
echo $SIZE
|
186
|
+
else
|
187
|
+
echo no
|
188
|
+
|
189
|
+
echo "Could not define size of #{type}"
|
190
|
+
|
191
|
+
exit 1
|
192
|
+
fi
|
193
|
+
|
194
|
+
}
|
195
|
+
end
|
196
|
+
|
197
|
+
result
|
198
|
+
end
|
199
|
+
|
200
|
+
def create_header (header = 'extconf.h')
|
201
|
+
if $convert
|
202
|
+
$configure << %{
|
203
|
+
|
204
|
+
cat > #{header} <<EOF
|
205
|
+
#ifndef #{header.tr_cpp}
|
206
|
+
#define #{header.tr_cpp}
|
207
|
+
EOF
|
208
|
+
|
209
|
+
echo -e $DEFS >> #{header}
|
210
|
+
|
211
|
+
cat >> #{header} <<EOF
|
212
|
+
|
213
|
+
#endif
|
214
|
+
EOF
|
215
|
+
|
216
|
+
DEFS=
|
217
|
+
|
218
|
+
}
|
219
|
+
end
|
220
|
+
|
221
|
+
__create_header(header)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
# configure stuff
|
225
|
+
|
226
|
+
desc 'Convert the Rakefile to Makefile/configure'
|
227
|
+
task :convert => clean do |task|
|
228
|
+
class << task
|
229
|
+
def escape (name)
|
230
|
+
name.gsub(/[:]/, '_')
|
231
|
+
end
|
232
|
+
|
233
|
+
def do_make (task)
|
234
|
+
return if !task || (@done ||= []).member?(task)
|
235
|
+
|
236
|
+
task.prerequisites.each {|p|
|
237
|
+
scope = task.name.split(':')
|
238
|
+
scope.pop
|
239
|
+
|
240
|
+
t = Rake::Task[Rake::Task.scope_name(scope, p)] rescue nil
|
241
|
+
|
242
|
+
if !t
|
243
|
+
t = Rake::Task[p] rescue nil
|
244
|
+
t = nil unless t.is_a?(Rake::FileTask)
|
245
|
+
end
|
246
|
+
|
247
|
+
do_make(t)
|
248
|
+
}
|
249
|
+
|
250
|
+
$makefile << "\n#{escape(task.name)}: #{task.prerequisites.map {|p|
|
251
|
+
scope = task.name.split(':')
|
252
|
+
scope.pop
|
253
|
+
|
254
|
+
t = Rake::Task[Rake::Task.scope_name(scope, p)] rescue nil
|
255
|
+
|
256
|
+
if !t
|
257
|
+
t = Rake::Task[p] rescue nil
|
258
|
+
t = nil unless t.is_a?(Rake::FileTask)
|
259
|
+
end
|
260
|
+
|
261
|
+
escape(t.name) if t
|
262
|
+
}.compact.join(' ')}\n"
|
263
|
+
|
264
|
+
task.invoke
|
265
|
+
|
266
|
+
@done << task
|
267
|
+
end
|
268
|
+
|
269
|
+
def add_env (*names)
|
270
|
+
names.flatten.compact.each {|name|
|
271
|
+
$makefile << "#{name} = #{eval("::#{name}")}\n" if eval("::#{name}") rescue nil
|
272
|
+
}
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
$convert = true
|
277
|
+
|
278
|
+
task.add_env(EXPORT)
|
279
|
+
|
280
|
+
$makefile << "all: default\n"
|
281
|
+
|
282
|
+
Rake::Task.tasks.each {|t|
|
283
|
+
next if t.name == 'clean' || t.name == 'clobber'
|
284
|
+
|
285
|
+
task.do_make(t)
|
286
|
+
}
|
287
|
+
|
288
|
+
$makefile << "\nclean:\n"
|
289
|
+
CLEAN.exclude('Makefile', 'configure').each do |f|
|
290
|
+
$makefile << "\trm -rf #{f}\n"
|
291
|
+
end
|
292
|
+
|
293
|
+
$makefile << "\nclobber:\n"
|
294
|
+
CLEAN.exclude('Makefile', 'configure').each do |f|
|
295
|
+
$makefile << "\trm -rf #{f}\n"
|
296
|
+
end
|
297
|
+
|
298
|
+
CLOBBER.exclude('Makefile', 'configure').each do |f|
|
299
|
+
$makefile << "\trm -rf #{f}\n"
|
300
|
+
end
|
301
|
+
|
302
|
+
File.open('Makefile', 'w') {|f|
|
303
|
+
f.write $makefile
|
304
|
+
}
|
305
|
+
|
306
|
+
File.open('configure', 'w', 0755) {|f|
|
307
|
+
f.write "CC=${CC:-gcc}\n"
|
308
|
+
f.write "FILE=`mktemp -u`\n"
|
309
|
+
f.write "DEFS=\n"
|
310
|
+
|
311
|
+
f.write $configure
|
312
|
+
}
|
313
|
+
|
314
|
+
$makefile = ''
|
315
|
+
$configure = ''
|
316
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rake-convert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- meh.
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-03-23 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: meh@paranoici.org
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/rake/convert.rb
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/meh/rake-convert
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.7
|
60
|
+
signing_key:
|
61
|
+
specification_version: 3
|
62
|
+
summary: Convert a Rakefile to Makefile and configure script
|
63
|
+
test_files: []
|
64
|
+
|