mkrf 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (186) hide show
  1. data/CHANGELOG +2 -0
  2. data/MIT-LICENSE +7 -0
  3. data/README +54 -0
  4. data/Rakefile +107 -0
  5. data/lib/mkrf.rb +4 -0
  6. data/lib/mkrf/availability.rb +219 -0
  7. data/lib/mkrf/generator.rb +146 -0
  8. data/test/abstract_unit.rb +4 -0
  9. data/test/fixtures/down_a_directory/header_down_a_directory.h +1 -0
  10. data/test/fixtures/stdmkrf.h +1 -0
  11. data/test/sample_files/libtrivial/Rakefile +31 -0
  12. data/test/sample_files/libtrivial/extconf.rb +3 -0
  13. data/test/sample_files/libtrivial/lib/libtrivial.c +5 -0
  14. data/test/sample_files/libtrivial/lib/libtrivial.o +0 -0
  15. data/test/sample_files/libtrivial/libtrivial_so.bundle +0 -0
  16. data/test/sample_files/libtrivial/mkrf.log +1 -0
  17. data/test/sample_files/libxml-ruby-0.3.8/CHANGELOG +74 -0
  18. data/test/sample_files/libxml-ruby-0.3.8/LICENSE +22 -0
  19. data/test/sample_files/libxml-ruby-0.3.8/README +144 -0
  20. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/cbg.c +76 -0
  21. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/extconf.rb +49 -0
  22. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.c +86 -0
  23. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.h +82 -0
  24. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/libxml.rb +107 -0
  25. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/mkrf.log +1 -0
  26. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/old_extconf.rb +95 -0
  27. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.c +372 -0
  28. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attr.h +21 -0
  29. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.c +224 -0
  30. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_attribute.h +21 -0
  31. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.c +1159 -0
  32. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_document.h +27 -0
  33. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.c +168 -0
  34. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_dtd.h +17 -0
  35. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.c +167 -0
  36. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_input_cbg.h +21 -0
  37. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.c +2139 -0
  38. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node.h +28 -0
  39. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.c +248 -0
  40. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_node_set.h +26 -0
  41. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.c +153 -0
  42. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_ns.h +21 -0
  43. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.c +1417 -0
  44. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser.h +31 -0
  45. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.c +715 -0
  46. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_parser_context.h +22 -0
  47. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.c +426 -0
  48. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_sax_parser.h +52 -0
  49. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.c +142 -0
  50. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_schema.h +16 -0
  51. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.c +43 -0
  52. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_tree.h +12 -0
  53. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.c +20 -0
  54. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xinclude.h +13 -0
  55. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.c +363 -0
  56. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath.h +24 -0
  57. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.c +125 -0
  58. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpath_context.h +24 -0
  59. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.c +100 -0
  60. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer.h +27 -0
  61. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.c +21 -0
  62. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/ruby_xml_xpointer_context.h +18 -0
  63. data/test/sample_files/libxml-ruby-0.3.8/ext/xml/sax_parser_callbacks.inc +202 -0
  64. data/test/sample_files/syck-0.55/CHANGELOG +186 -0
  65. data/test/sample_files/syck-0.55/COPYING +54 -0
  66. data/test/sample_files/syck-0.55/Makefile +582 -0
  67. data/test/sample_files/syck-0.55/Makefile.am +5 -0
  68. data/test/sample_files/syck-0.55/Makefile.in +582 -0
  69. data/test/sample_files/syck-0.55/README +105 -0
  70. data/test/sample_files/syck-0.55/README.BYTECODE +484 -0
  71. data/test/sample_files/syck-0.55/README.EXT +444 -0
  72. data/test/sample_files/syck-0.55/RELEASE +123 -0
  73. data/test/sample_files/syck-0.55/TODO +25 -0
  74. data/test/sample_files/syck-0.55/aclocal.m4 +883 -0
  75. data/test/sample_files/syck-0.55/bootstrap +7 -0
  76. data/test/sample_files/syck-0.55/config.h +79 -0
  77. data/test/sample_files/syck-0.55/config.h.in +78 -0
  78. data/test/sample_files/syck-0.55/config.status +1197 -0
  79. data/test/sample_files/syck-0.55/config/README +14 -0
  80. data/test/sample_files/syck-0.55/config/depcomp +529 -0
  81. data/test/sample_files/syck-0.55/config/install-sh +323 -0
  82. data/test/sample_files/syck-0.55/config/missing +357 -0
  83. data/test/sample_files/syck-0.55/configure +6728 -0
  84. data/test/sample_files/syck-0.55/configure.in +36 -0
  85. data/test/sample_files/syck-0.55/ext/ruby/CHANGELOG +303 -0
  86. data/test/sample_files/syck-0.55/ext/ruby/README +400 -0
  87. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/MANIFEST +1 -0
  88. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/bytecode.c +1170 -0
  89. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/emitter.c +1224 -0
  90. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/extconf.rb +10 -0
  91. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.c +1894 -0
  92. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/gram.h +79 -0
  93. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/handler.c +174 -0
  94. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/implicit.c +2989 -0
  95. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/mkrf.log +1 -0
  96. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/node.c +407 -0
  97. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/rubyext.c +2385 -0
  98. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.c +504 -0
  99. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/syck.h +458 -0
  100. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/token.c +2707 -0
  101. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yaml2byte.c +250 -0
  102. data/test/sample_files/syck-0.55/ext/ruby/ext/syck/yamlbyte.h +170 -0
  103. data/test/sample_files/syck-0.55/ext/ruby/install.rb +1022 -0
  104. data/test/sample_files/syck-0.55/ext/ruby/lib/okay.rb +161 -0
  105. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/news.rb +69 -0
  106. data/test/sample_files/syck-0.55/ext/ruby/lib/okay/rpc.rb +434 -0
  107. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml.rb +436 -0
  108. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/baseemitter.rb +247 -0
  109. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/basenode.rb +216 -0
  110. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/compat.rb +26 -0
  111. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/constants.rb +45 -0
  112. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/dbm.rb +111 -0
  113. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/emitter.rb +107 -0
  114. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/encoding.rb +33 -0
  115. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/error.rb +34 -0
  116. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/rubytypes.rb +438 -0
  117. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/store.rb +29 -0
  118. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stream.rb +40 -0
  119. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/stringio.rb +83 -0
  120. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/syck.rb +19 -0
  121. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/tag.rb +86 -0
  122. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/types.rb +188 -0
  123. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/yamlnode.rb +54 -0
  124. data/test/sample_files/syck-0.55/ext/ruby/lib/yaml/ypath.rb +52 -0
  125. data/test/sample_files/syck-0.55/ext/ruby/lib/yod.rb +1168 -0
  126. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-modules.rb +27 -0
  127. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-sample.rb +336 -0
  128. data/test/sample_files/syck-0.55/ext/ruby/samples/okayNews-validate.rb +341 -0
  129. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-client.rb +51 -0
  130. data/test/sample_files/syck-0.55/ext/ruby/samples/okayRpc-server.rb +85 -0
  131. data/test/sample_files/syck-0.55/ext/ruby/samples/yaml-sortHashKeys.rb +128 -0
  132. data/test/sample_files/syck-0.55/ext/ruby/tests/basic.rb +1653 -0
  133. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsAnchorAlias.yml +51 -0
  134. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBasicTests.yml +282 -0
  135. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockMapping.yml +78 -0
  136. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsBlockSequence.yml +0 -0
  137. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsDocumentSeparator.yml +102 -0
  138. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsErrorTests.yml +23 -0
  139. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFlowCollections.yml +73 -0
  140. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsFoldedScalars.yml +215 -0
  141. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsMapInSeq.yml +0 -0
  142. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsNullsAndEmpties.yml +66 -0
  143. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsRubyTests.yml +182 -0
  144. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsSpecificationExamples.yml +2699 -0
  145. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsTypeTransfers.yml +265 -0
  146. data/test/sample_files/syck-0.55/ext/ruby/yts/YtsYpath.yml +221 -0
  147. data/test/sample_files/syck-0.55/ext/ruby/yts/cookbook.rb +159 -0
  148. data/test/sample_files/syck-0.55/ext/ruby/yts/index.yml +10 -0
  149. data/test/sample_files/syck-0.55/ext/ruby/yts/yts.rb +193 -0
  150. data/test/sample_files/syck-0.55/lib/Makefile +497 -0
  151. data/test/sample_files/syck-0.55/lib/Makefile.am +27 -0
  152. data/test/sample_files/syck-0.55/lib/Makefile.in +497 -0
  153. data/test/sample_files/syck-0.55/lib/bytecode.c +1170 -0
  154. data/test/sample_files/syck-0.55/lib/bytecode.re +525 -0
  155. data/test/sample_files/syck-0.55/lib/emitter.c +1224 -0
  156. data/test/sample_files/syck-0.55/lib/gram.c +1894 -0
  157. data/test/sample_files/syck-0.55/lib/gram.h +79 -0
  158. data/test/sample_files/syck-0.55/lib/gram.output +2005 -0
  159. data/test/sample_files/syck-0.55/lib/gram.y +481 -0
  160. data/test/sample_files/syck-0.55/lib/handler.c +174 -0
  161. data/test/sample_files/syck-0.55/lib/implicit.c +2989 -0
  162. data/test/sample_files/syck-0.55/lib/implicit.re +206 -0
  163. data/test/sample_files/syck-0.55/lib/node.c +407 -0
  164. data/test/sample_files/syck-0.55/lib/syck.c +504 -0
  165. data/test/sample_files/syck-0.55/lib/syck.h +458 -0
  166. data/test/sample_files/syck-0.55/lib/syck_st.c +577 -0
  167. data/test/sample_files/syck-0.55/lib/syck_st.h +46 -0
  168. data/test/sample_files/syck-0.55/lib/token.c +2707 -0
  169. data/test/sample_files/syck-0.55/lib/token.re +1139 -0
  170. data/test/sample_files/syck-0.55/lib/yaml2byte.c +250 -0
  171. data/test/sample_files/syck-0.55/lib/yamlbyte.h +170 -0
  172. data/test/sample_files/syck-0.55/stamp-h1 +1 -0
  173. data/test/sample_files/syck-0.55/tests/Basic.c +141 -0
  174. data/test/sample_files/syck-0.55/tests/CuTest.c +294 -0
  175. data/test/sample_files/syck-0.55/tests/CuTest.h +84 -0
  176. data/test/sample_files/syck-0.55/tests/Emit.c +87 -0
  177. data/test/sample_files/syck-0.55/tests/Makefile +480 -0
  178. data/test/sample_files/syck-0.55/tests/Makefile.am +13 -0
  179. data/test/sample_files/syck-0.55/tests/Makefile.in +480 -0
  180. data/test/sample_files/syck-0.55/tests/Parse.c +208 -0
  181. data/test/sample_files/syck-0.55/tests/YTS.c +2310 -0
  182. data/test/sample_files/syck-0.55/tests/YTS.c.erb +326 -0
  183. data/test/sample_files/syck-0.55/tests/YTS.c.rb +44 -0
  184. data/test/test_availability.rb +68 -0
  185. data/test/test_generator.rb +74 -0
  186. metadata +252 -0
@@ -0,0 +1,2 @@
1
+ = 0.1.0 6/28/06
2
+ * First release.
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2006 Kevin Clark
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,54 @@
1
+ = mkrf -- making C extensions for Ruby a bit easier
2
+
3
+ <tt>mkrf</tt> is intended to replace <tt>mkmf</tt>, a library for buildling
4
+ Makefiles to build C extensions to Ruby. Its major goals are easy code reuse of
5
+ its <tt>Availability</tt> class and simple, well documented, use of the
6
+ <tt>Generator</tt> class for Rakefile generation for extensions.
7
+
8
+ == Basic Usage
9
+
10
+ <tt>mkrf</tt> works similarly to <tt>mkmf</tt> in that a user writes an
11
+ extension configuration (usually <tt>extconf.rb</tt>) and then runs it, which
12
+ generates a <tt>Rakefile</tt>.
13
+
14
+ In general, <tt>extconf.rb</tt> should be placed in the root directory of the
15
+ extension and it expects by default that files to be compiled have a <tt>.c</tt>
16
+ extension and are in the <tt>lib/</tt> directory.
17
+
18
+ The most basic usage looks like this, with the name of the library to be linked
19
+ as the first argument to <tt>Mkrf::Generator.new</tt>:
20
+
21
+ require 'mkrf'
22
+ Mkrf::Generator.new('libtrivial_so.bundle')
23
+
24
+ Extra arguments may be passed to the generator in a block:
25
+
26
+ Mkrf::Generator.new('libxml_so.bundle', '*.c') do |g|
27
+ g.include_library('socket','socket')
28
+ g.include_header('libxml/xmlversion.h',
29
+ '/opt/include/libxml2',
30
+ '/usr/local/include/libxml2',
31
+ '/usr/include/libxml2')
32
+ end
33
+
34
+ If the extension does not follow the source in <tt>lib/</tt> / <tt>.c</tt>
35
+ extension convention, it may be overridden in the constructor:
36
+
37
+ Mkrf::Generator.new('syck.bundle', '*.c') do |g|
38
+ g.include_header("st.h")
39
+ end
40
+
41
+
42
+ == Credits
43
+ * Jim Weirich for writing Rake
44
+
45
+ == Licence
46
+ mkrf is available under an MIT-style license.
47
+
48
+ Copyright (c) 2006 Kevin Clark
49
+
50
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
51
+
52
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,107 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/packagetask'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'rubygems'
7
+
8
+ $:.unshift(File.dirname(__FILE__) + "/lib")
9
+ require 'mkrf'
10
+
11
+ PKG_NAME = 'mkrf'
12
+ PKG_VERSION = Mkrf::VERSION
13
+ PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
14
+
15
+ RELEASE_NAME = "REL #{PKG_VERSION}"
16
+
17
+ RUBY_FORGE_PROJECT = "mkrf"
18
+ RUBY_FORGE_USER = "kevinclark"
19
+
20
+
21
+ task :default => ["test:units"]
22
+
23
+ namespace :test do
24
+
25
+ desc "Run basic tests"
26
+ Rake::TestTask.new("units") { |t|
27
+ t.pattern = 'test/test_*.rb'
28
+ t.verbose = true
29
+ t.warning = true
30
+ }
31
+
32
+ namespace :samples do
33
+
34
+ BASE_DIR = File.dirname(__FILE__) + '/test/sample_files'
35
+
36
+ SAMPLE_DIRS = {
37
+ :libtrivial => BASE_DIR + '/libtrivial/',
38
+ :syck => BASE_DIR + '/syck-0.55/ext/ruby/ext/syck/',
39
+ :libxml => BASE_DIR + '/libxml-ruby-0.3.8/ext/xml/'
40
+ }
41
+
42
+ task :default => [:all]
43
+
44
+ desc "Try to compile all of the sample extensions"
45
+ task :all => [:clean, :trivial, :libxml, :syck]
46
+
47
+ desc "Try to compile a trivial extension"
48
+ task :trivial do
49
+ sh "cd #{SAMPLE_DIRS[:libtrivial]}; ruby extconf.rb; rake"
50
+ end
51
+
52
+ desc "Try to compile libxml"
53
+ task :libxml do
54
+ sh "cd #{SAMPLE_DIRS[:libxml]}; ruby extconf.rb; rake"
55
+ end
56
+
57
+ desc "Try to compile syck"
58
+ task :syck do
59
+ sh "cd #{SAMPLE_DIRS[:syck]}; ruby extconf.rb; rake"
60
+ end
61
+
62
+ desc "Clean up after sample tests"
63
+ task :clean do
64
+ SAMPLE_DIRS.each_value do |test_dir|
65
+ puts "test_dir is #{test_dir}"
66
+ next unless File.exist?(test_dir + "/Rakefile")
67
+ sh "cd #{test_dir}; rake clean; rake clobber; rm Rakefile"
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ Rake::RDocTask.new do |rd|
76
+ rd.main = "README"
77
+ rd.rdoc_files.include("README", "lib/**/*.rb")
78
+ end
79
+
80
+ # Create compressed packages
81
+ spec = Gem::Specification.new do |s|
82
+ s.platform = Gem::Platform::RUBY
83
+ s.name = PKG_NAME
84
+ s.summary = "Generate Rakefiles to Build C Extensions to Ruby"
85
+ s.description = %q{This proposed replacement to mkmf generates Rakefiles to build C Extensions.}
86
+ s.version = PKG_VERSION
87
+
88
+ s.author = "Kevin Clark"
89
+ s.email = "kevin.clark@gmail.com"
90
+ s.rubyforge_project = RUBY_FORGE_PROJECT
91
+ s.homepage = "http://glu.ttono.us"
92
+
93
+ s.has_rdoc = true
94
+ s.requirements << 'rake'
95
+ s.require_path = 'lib'
96
+ s.autorequire = 'mkrf'
97
+
98
+ s.files = [ "Rakefile", "README", "CHANGELOG", "MIT-LICENSE" ]
99
+ s.files = s.files + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
100
+ s.files = s.files + Dir.glob( "test/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
101
+ end
102
+
103
+ Rake::GemPackageTask.new(spec) do |p|
104
+ p.gem_spec = spec
105
+ p.need_tar = true
106
+ p.need_zip = true
107
+ end
@@ -0,0 +1,4 @@
1
+ require File.dirname(__FILE__) + '/mkrf/availability'
2
+ require File.dirname(__FILE__) + '/mkrf/generator'
3
+
4
+ Mkrf::VERSION = "0.1.0"
@@ -0,0 +1,219 @@
1
+ require 'rbconfig'
2
+ require 'logger'
3
+
4
+ module Mkrf
5
+
6
+ # The +Availability+ class is concerned with libraries, headers, and
7
+ # functions. It can be easily wrapped (see <tt>Mkrf::Generator</tt> for an
8
+ # example) and should be able to be used as a basis for a variety of programs
9
+ # which need to determine functionality based on what libraries are available
10
+ # on the current system.
11
+ class Availability
12
+ DEFAULT_LIBS = ["ruby", "dl"]
13
+
14
+ # These really shouldn't be static like this..
15
+ TEMP_SOURCE_FILE = "temp_source.c"
16
+ TEMP_EXECUTABLE = "temp_executable"
17
+
18
+ attr_reader :headers, :loaded_libs, :includes
19
+
20
+ # Create a new Availability instance.
21
+ #
22
+ # Valid keys for the options hash include:
23
+ # * <tt>:loaded_libs</tt> -- libraries to load by default
24
+ # * <tt>:headers</tt> -- headers to load by default
25
+ # * <tt>:compiler</tt> -- which compiler to use when determining availability
26
+ # * <tt>:includes</tt> -- directories that should be searched for include files
27
+ def initialize(options = {})
28
+ @loaded_libs = options[:loaded_libs] || DEFAULT_LIBS
29
+ @headers = options[:headers] || []
30
+ @compiler = options[:compiler] || "gcc"
31
+ @includes = (options[:includes].to_a) || []
32
+ @logger = Logger.new('mkrf.log')
33
+ end
34
+
35
+ # Include a library in the list of available libs. Returns +false+ if the
36
+ # library is not available. Returns non-false otherwise.
37
+ #
38
+ # Params:
39
+ # * <tt>library</tt> -- the library to be included as a string.
40
+ # * <tt>function</tt> -- a method to base the inclusion of the library on. +main+ by default.
41
+ def include_library(library, function = "main")
42
+ @loaded_libs << library if has_library?(library, function)
43
+ end
44
+
45
+ # Include a header in the list of availiable headers. Returns +false+ if the
46
+ # header is not available. Returns non-false otherwise.
47
+ #
48
+ # Params:
49
+ # * <tt>header</tt> -- the name of the header to be included as a string.
50
+ # * <tt>paths</tt> -- an optional list of search paths if the header is not found in the default paths.
51
+ def include_header(header, *paths)
52
+ @headers << header if has_header?(header, *paths)
53
+ end
54
+
55
+ # Returns a boolean whether indicating whether the library can be found
56
+ # by attempting to reference the function passed (+main+ by default).
57
+ #
58
+ # Params:
59
+ # * <tt>library</tt> -- the library to be included as a string
60
+ # * <tt>function</tt> -- a method to base the inclusion of the library on. +main+ by default.
61
+ def has_library?(library, function = "main")
62
+ return true if @loaded_libs.include? library
63
+ with_loaded_libs(library) {
64
+ has_function? function
65
+ }
66
+ end
67
+
68
+ # Returns +true+ if the header is found in the default search path or in
69
+ # optional paths passed as an argument, +false+ otherwise.
70
+ #
71
+ # Params:
72
+ # * <tt>header</tt> -- the header to be searched for
73
+ # * <tt>paths</tt> -- an optional list of search paths if the header is not found in the default paths
74
+ def has_header?(header, *paths)
75
+ return true if @headers.include? header
76
+
77
+ has_header = with_headers(header) {
78
+ can_link?(simple_include(header))
79
+ }
80
+
81
+ return true if has_header
82
+
83
+ paths.each do |include_path|
84
+ has_header = with_includes(include_path) {
85
+ with_headers(header) {
86
+ can_link?(simple_include(header))
87
+ }
88
+ }
89
+ @includes << include_path and return true if has_header
90
+ end
91
+
92
+ return false
93
+ end
94
+
95
+ # Returns +true+ if the function is able to be called based on libraries and
96
+ # headers currently loaded. Returns +false+ otherwise.
97
+ #
98
+ # Params:
99
+ # * <tt>function</tt> -- the function to check for
100
+ def has_function?(function)
101
+ can_link?(simple_call(function)) or can_link?(simple_reference(function))
102
+ end
103
+
104
+ # Returns the result of an attempt to compile and link the function body
105
+ # passed in
106
+ def can_link?(function_body)
107
+ silence_command_line do
108
+ create_source(function_body)
109
+ system(link_command)
110
+ end
111
+ ensure
112
+ FileUtils.rm_f TEMP_SOURCE_FILE
113
+ FileUtils.rm_f TEMP_EXECUTABLE
114
+ end
115
+
116
+ def method_missing(method, *args, &b)
117
+ if match = /^with_([_a-zA-Z]\w*)$/.match(method.to_s)
118
+ super unless STACKABLE_ATTRIBUTES.include? match[1]
119
+ with_stackable_attribute(match[1], *args, &b)
120
+ else
121
+ super
122
+ end
123
+ end
124
+
125
+ # Returns a string of libraries formatted for compilation
126
+ def library_compile_string
127
+ @loaded_libs.collect {|l| "-l#{l}"}.join(' ')
128
+ end
129
+
130
+ # Returns a string of include directories formatted for compilation
131
+ def includes_compile_string
132
+ @includes.collect {|i| "-I#{i}"}.join(' ')
133
+ end
134
+
135
+ private
136
+
137
+ STACKABLE_ATTRIBUTES = ['loaded_libs', 'headers', 'includes']
138
+
139
+ def with_stackable_attribute(attribute, *args)
140
+ args = args.to_a
141
+ instance_variable_set(:"@#{attribute}",
142
+ instance_variable_get(:"@#{attribute}") + args)
143
+ value = yield
144
+ instance_variable_set(:"@#{attribute}",
145
+ instance_variable_get(:"@#{attribute}") - args)
146
+ return value
147
+ end
148
+
149
+ def header_include_string
150
+ @headers.collect {|header| "#include <#{header}>"}.join('\n')
151
+ end
152
+
153
+ def link_command
154
+ "#{@compiler} -o #{TEMP_EXECUTABLE} #{library_compile_string} " +
155
+ "#{includes_compile_string} #{TEMP_SOURCE_FILE}"
156
+ end
157
+
158
+ # Creates a temporary source file with the string passed
159
+ def create_source(src)
160
+ File.open(TEMP_SOURCE_FILE, "w+") do |f|
161
+ f.write(src)
162
+ end
163
+ end
164
+
165
+ # Basic skeleton for calling a function
166
+ def simple_call(func)
167
+ src = <<-SRC
168
+ #{header_include_string}
169
+ int main() { return 0; }
170
+ int t() { #{func}(); return 0; }
171
+ SRC
172
+ end
173
+
174
+ # Basic skeleton for referencing a function
175
+ def simple_reference(func)
176
+ src = <<-SRC
177
+ #{header_include_string}
178
+ int main() { return 0; }
179
+ int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; }
180
+ SRC
181
+ end
182
+
183
+ # skeleton for testing includes
184
+ def simple_include(header)
185
+ src = <<-SRC
186
+ #{header_include_string}
187
+ #include <#{header}>
188
+ int main() { return 0; }
189
+ SRC
190
+ end
191
+
192
+ def silence_command_line
193
+ silence_stream(STDERR) do
194
+ silence_stream(STDOUT) do
195
+ yield
196
+ end
197
+ end
198
+ end
199
+
200
+ # silence_stream taken from Rails ActiveSupport reporting.rb
201
+
202
+ # Silences any stream for the duration of the block.
203
+ #
204
+ # silence_stream(STDOUT) do
205
+ # puts 'This will never be seen'
206
+ # end
207
+ #
208
+ # puts 'But this will'
209
+ def silence_stream(stream)
210
+ old_stream = stream.dup
211
+ stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
212
+ stream.sync = true
213
+ yield
214
+ ensure
215
+ stream.reopen(old_stream)
216
+ end
217
+
218
+ end
219
+ end
@@ -0,0 +1,146 @@
1
+ require 'rubygems'
2
+ require 'rbconfig'
3
+ require 'rake/tasklib'
4
+
5
+ module Mkrf
6
+
7
+ # +Generator+ is concerned with taking configuration for an extension
8
+ # and writing a +Rakefile+ to the local filesystem to build the extension.
9
+ #
10
+ # = Usage
11
+ # In the most basic usage, +Generator+ simply takes the name of the library
12
+ # to compile:
13
+ #
14
+ # require 'mkrf'
15
+ # Mkrf::Generator.new('libtrivial_so.bundle')
16
+ #
17
+ # Configuration of the build can be passed to the +Generator+ constructor
18
+ # as a block:
19
+ #
20
+ # Mkrf::Generator.new('libxml_so.bundle', '*.c') do |g|
21
+ # g.include_library('socket','socket')
22
+ # g.include_header('libxml/xmlversion.h',
23
+ # '/opt/include/libxml2',
24
+ # '/usr/local/include/libxml2',
25
+ # '/usr/include/libxml2')
26
+ # end
27
+ #
28
+ class Generator
29
+ include Rake
30
+
31
+ CONFIG = Config::CONFIG
32
+
33
+ # Create a new generator which will write a new +Rakefile+ to the local
34
+ # filesystem.
35
+ #
36
+ # Params:
37
+ # * +library_location+ -- the location of the library to be compiled on the local filesystem
38
+ # * +source_patterns+ -- a pattern describing source files to be compiled, "lib/*.c" by default
39
+ def initialize(library_location, *source_patterns)
40
+ @sources = source_patterns || ["lib/*.c"]
41
+ @library_location = library_location
42
+ @available = Mkrf::Availability.new(:includes => [CONFIG['includedir'], CONFIG["archdir"],
43
+ CONFIG['sitelibdir'], "."] )
44
+ @defines = []
45
+
46
+ yield self if block_given?
47
+ write_rakefile
48
+ end
49
+
50
+ # Add a new pattern to the list of source patterns
51
+ def add_source(pattern)
52
+ @sources << pattern
53
+ end
54
+
55
+ # An array of the source patterns as single quoted strings
56
+ def sources
57
+ @sources.collect {|s| "'#{s}'"}
58
+ end
59
+
60
+ # Add a define to the compile string. Example:
61
+ #
62
+ # Mkrf::Generator.new('my_library.bundle') do |g|
63
+ # g.add_define(HAVE_PTHREADS)
64
+ # end
65
+ #
66
+ # Params:
67
+ # * +defn+ -- string to add to compile time defines
68
+ def add_define(defn)
69
+ @defines.push(defn)
70
+ end
71
+
72
+ # Include a library in the compile. Returns +false+ if the
73
+ # library is not available. Returns non-false otherwise.
74
+ # Parameters are the same as Mkrf::Availability#include_library
75
+ def include_library(*args)
76
+ @available.include_library(*args)
77
+ end
78
+
79
+ # Include a header in the compile. Returns +false+ if the header is not
80
+ # available, returns non-false otherwise. As a side effect, a compile
81
+ # time define occurs as +HAVE_+ appended with the name of the header in
82
+ # upper and scored case.
83
+ # Parameters are the same as Mkrf::Availability#include_header
84
+ def include_header(*args)
85
+ @available.include_header(*args)
86
+ end
87
+
88
+ # Returns +true+ if the function is able to be called based on libraries and
89
+ # headers currently loaded. Returns +false+ otherwise.
90
+ #
91
+ # Params:
92
+ # * <tt>function</tt> -- the function to check for
93
+ def has_function?(function)
94
+ @available.has_function? function
95
+ end
96
+
97
+ def write_rakefile(filename = "Rakefile") # :nodoc:
98
+ File.open(filename, "w+") do |f|
99
+ f.puts rakefile_contents
100
+ end
101
+ end
102
+
103
+ def defines_compile_string # :nodoc:
104
+ (@defines.collect {|define| "-D#{define}" } +
105
+ @available.headers.collect { |header|
106
+ format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___"))
107
+ }).join(' ')
108
+ end
109
+
110
+ def rakefile_contents # :nodoc:
111
+ <<-END_RAKEFILE
112
+ require 'rake/clean'
113
+
114
+ CLEAN.include('*.o')
115
+ CLOBBER.include('#{@library_location}')
116
+
117
+ SRC = FileList[#{sources.join(',')}]
118
+ OBJ = SRC.ext('o')
119
+ CC = "gcc"
120
+
121
+ LDSHARED = "#{CONFIG['LDSHARED']}"
122
+ LIBPATH = '-L"/usr/local/lib"'
123
+
124
+ INCLUDES = "#{@available.includes_compile_string}"
125
+
126
+ LIBS = "#{@available.library_compile_string}"
127
+
128
+ CFLAGS = "#{CONFIG['CCDLFLAGS']} #{CONFIG['CFLAGS']} #{CONFIG['ARCH_FLAG']} #{defines_compile_string}"
129
+
130
+ task :default => ['#{@library_location}']
131
+
132
+ rule '.o' => '.c' do |t|
133
+ sh "\#{CC} \#{CFLAGS} \#{INCLUDES} -c -o \#{t.name} \#{t.source}"
134
+ end
135
+
136
+ rule '.so' => '.o' do |t|
137
+ sh "\#{LDSHARED} \#{LIBPATH} -o \#{OBJ} \#{LOCAL_LIBS} \#{LIBS}"
138
+ end
139
+
140
+ file '#{@library_location}' => OBJ do
141
+ sh "\#{LDSHARED} \#{LIBPATH} -o #{@library_location} \#{OBJ} \#{LIBS}"
142
+ end
143
+ END_RAKEFILE
144
+ end
145
+ end
146
+ end