tioga 1.11 → 1.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/Tioga_README +58 -35
  2. data/{split/scripts → bin}/tioga +1 -1
  3. data/{split → ext/Dobjects}/Dtable/dtable.c +81 -15
  4. data/{split → ext/Dobjects}/Dtable/dtable_intern.h +0 -0
  5. data/ext/Dobjects/Dtable/extconf.rb +7 -0
  6. data/{split → ext/Dobjects}/Dtable/include/dtable.h +0 -0
  7. data/{split → ext/Dobjects}/Dvector/dvector.c +361 -51
  8. data/{split → ext/Dobjects}/Dvector/dvector_intern.h +0 -0
  9. data/ext/Dobjects/Dvector/extconf.rb +22 -0
  10. data/{split/Dtable → ext/Dobjects/Dvector/include}/dvector.h +0 -0
  11. data/ext/Dobjects/Function/extconf.rb +7 -0
  12. data/{split → ext/Dobjects}/Function/function.c +636 -11
  13. data/{split → ext/Dobjects}/Function/joint_qsort.c +0 -0
  14. data/ext/Flate/extconf.rb +26 -0
  15. data/{split → ext}/Flate/flate.c +7 -3
  16. data/{split → ext}/Flate/flate_intern.h +0 -0
  17. data/{split → ext}/Flate/include/flate.h +0 -0
  18. data/ext/Flate/zlib/adler32.c +149 -0
  19. data/ext/Flate/zlib/compress.c +79 -0
  20. data/ext/Flate/zlib/crc32.c +423 -0
  21. data/ext/Flate/zlib/crc32.h +441 -0
  22. data/ext/Flate/zlib/deflate.c +1736 -0
  23. data/ext/Flate/zlib/deflate.h +331 -0
  24. data/ext/Flate/zlib/gzio.c +1026 -0
  25. data/ext/Flate/zlib/infback.c +623 -0
  26. data/ext/Flate/zlib/inffast.c +318 -0
  27. data/ext/Flate/zlib/inffast.h +11 -0
  28. data/ext/Flate/zlib/inffixed.h +94 -0
  29. data/ext/Flate/zlib/inflate.c +1368 -0
  30. data/ext/Flate/zlib/inflate.h +115 -0
  31. data/ext/Flate/zlib/inftrees.c +329 -0
  32. data/ext/Flate/zlib/inftrees.h +55 -0
  33. data/ext/Flate/zlib/trees.c +1219 -0
  34. data/ext/Flate/zlib/trees.h +128 -0
  35. data/ext/Flate/zlib/uncompr.c +61 -0
  36. data/ext/Flate/zlib/zlib.h +1357 -0
  37. data/ext/Flate/zlib/zutil.c +318 -0
  38. data/ext/Flate/zlib/zutil.h +269 -0
  39. data/ext/Tioga/FigureMaker/__shared_axes.c +1373 -0
  40. data/ext/Tioga/FigureMaker/__shared_makers.c +1303 -0
  41. data/{split/Tioga/pdf_font_dicts.c → ext/Tioga/FigureMaker/__shared_pdf_font_dicts.c} +0 -0
  42. data/{split/Tioga/pdfcolor.c → ext/Tioga/FigureMaker/__shared_pdfcolor.c} +0 -0
  43. data/{split/Tioga/pdfcoords.c → ext/Tioga/FigureMaker/__shared_pdfcoords.c} +0 -0
  44. data/{split/Tioga/pdffile.c → ext/Tioga/FigureMaker/__shared_pdffile.c} +0 -0
  45. data/{split/Tioga/pdfimage.c → ext/Tioga/FigureMaker/__shared_pdfimage.c} +0 -0
  46. data/{split/Tioga/pdfpath.c → ext/Tioga/FigureMaker/__shared_pdfpath.c} +0 -0
  47. data/{split/Tioga/pdftext.c → ext/Tioga/FigureMaker/__shared_pdftext.c} +0 -0
  48. data/{split/Tioga/texout.c → ext/Tioga/FigureMaker/__shared_texout.c} +0 -0
  49. data/ext/Tioga/FigureMaker/extconf.rb +7 -0
  50. data/{split/Tioga → ext/Tioga/FigureMaker}/figures.c +14 -2
  51. data/{split/Tioga → ext/Tioga/FigureMaker}/figures.h +0 -0
  52. data/{split/Tioga → ext/Tioga/FigureMaker}/generic.c +1 -2
  53. data/{split/Tioga → ext/Tioga/FigureMaker}/generic.h +0 -1
  54. data/{split/Tioga → ext/Tioga/FigureMaker}/init.c +0 -0
  55. data/{split/Tioga → ext/Tioga/FigureMaker}/pdfs.h +0 -0
  56. data/{split/Tioga → ext/Tioga/FigureMaker/shared}/axes.c +32 -7
  57. data/{split/Tioga → ext/Tioga/FigureMaker/shared}/makers.c +2 -2
  58. data/ext/Tioga/FigureMaker/shared/pdf_font_dicts.c +18253 -0
  59. data/ext/Tioga/FigureMaker/shared/pdfcolor.c +904 -0
  60. data/ext/Tioga/FigureMaker/shared/pdfcoords.c +518 -0
  61. data/ext/Tioga/FigureMaker/shared/pdffile.c +451 -0
  62. data/ext/Tioga/FigureMaker/shared/pdfimage.c +539 -0
  63. data/ext/Tioga/FigureMaker/shared/pdfpath.c +766 -0
  64. data/ext/Tioga/FigureMaker/shared/pdftext.c +710 -0
  65. data/ext/Tioga/FigureMaker/shared/texout.c +533 -0
  66. data/{split/Tioga → ext/Tioga/FigureMaker}/wrappers.c +5 -5
  67. data/{split/Tioga → ext/Tioga/FigureMaker}/wrappers.h +0 -0
  68. data/{split/Dtable → ext/includes}/defs.h +0 -0
  69. data/{split/Dtable → ext/includes}/namespace.h +0 -0
  70. data/{split/Dtable → ext/includes}/safe_double.h +0 -0
  71. data/{split → ext/includes}/symbols.c +0 -1
  72. data/{split/Dtable → ext/includes}/symbols.h +0 -0
  73. data/{split/Dtable/lib → lib/Dobjects}/Dtable_extras.rb +0 -0
  74. data/{split/Dvector/lib → lib/Dobjects}/Dvector_extras.rb +1 -0
  75. data/{split/Function/lib → lib/Dobjects}/Function_extras.rb +0 -0
  76. data/{split/Dvector/lib → lib/Dobjects}/Numeric_extras.rb +0 -0
  77. data/{split/Tioga/lib → lib/Tioga}/Arcs_and_Circles.rb +0 -0
  78. data/{split/Tioga/lib → lib/Tioga}/ColorConstants.rb +0 -0
  79. data/{split/Tioga/lib → lib/Tioga}/Colorbars.rb +0 -0
  80. data/{split/Tioga/lib → lib/Tioga}/Colormaps.rb +0 -0
  81. data/{split/Tioga/lib → lib/Tioga}/Coordinate_Conversions.rb +0 -0
  82. data/{split/Tioga/lib → lib/Tioga}/Creating_Paths.rb +0 -0
  83. data/{split/Tioga/lib → lib/Tioga}/Doc.rb +0 -0
  84. data/{split/Tioga/lib → lib/Tioga}/Executive.rb +0 -0
  85. data/{split/Tioga/lib → lib/Tioga}/FigMkr.rb +13 -70
  86. data/{split/Tioga/lib → lib/Tioga}/FigureConstants.rb +0 -0
  87. data/{split/Tioga/lib → lib/Tioga}/Figures_and_Plots.rb +0 -0
  88. data/{split/Tioga/lib → lib/Tioga}/Images.rb +0 -0
  89. data/{split/Tioga/lib → lib/Tioga}/Legends.rb +0 -0
  90. data/{split/Tioga/lib → lib/Tioga}/MarkerConstants.rb +0 -0
  91. data/{split/Tioga/lib → lib/Tioga}/Markers.rb +0 -0
  92. data/{split/Tioga/lib → lib/Tioga}/Page_Frame_Bounds.rb +0 -0
  93. data/{split/Tioga/lib → lib/Tioga}/Rectangles.rb +0 -0
  94. data/{split/Tioga/lib → lib/Tioga}/Shading.rb +0 -0
  95. data/{split/Tioga/lib → lib/Tioga}/Special_Paths.rb +0 -0
  96. data/{split/Tioga/lib → lib/Tioga}/Strokes.rb +0 -0
  97. data/{split/Tioga/lib → lib/Tioga}/TeX_Text.rb +0 -0
  98. data/{split/Tioga/lib → lib/Tioga}/TexPreamble.rb +0 -0
  99. data/{split/Tioga/lib → lib/Tioga}/Titles_and_Labels.rb +0 -0
  100. data/{split/Tioga/lib → lib/Tioga}/Transparency.rb +0 -0
  101. data/{split/Tioga/lib → lib/Tioga}/Using_Paths.rb +0 -0
  102. data/{split/Tioga/lib → lib/Tioga}/Utils.rb +74 -0
  103. data/{split/Tioga/lib → lib/Tioga}/X_and_Y_Axes.rb +0 -0
  104. data/{split/Tioga/lib → lib/Tioga}/irb_tioga.rb +0 -0
  105. data/{split/Tioga/lib → lib/Tioga}/maker.rb +0 -0
  106. data/{split/Tioga/lib → lib/Tioga}/tioga.rb +0 -0
  107. data/{split/Tioga/lib → lib/Tioga}/tioga_ui.rb +0 -0
  108. data/{split/Tioga/lib → lib/Tioga}/tioga_ui_cmds.rb +0 -0
  109. data/tests/Icon_Test.pdf +0 -0
  110. data/tests/benchmark_dvector_reads.rb +20 -42
  111. data/tests/tc_Dvector.rb +45 -4
  112. data/tests/tc_Flate.rb +4 -5
  113. data/tests/tc_Function.rb +79 -0
  114. data/tests/vg.log +1453 -0
  115. metadata +141 -122
  116. data/split/Dtable/extconf.rb +0 -4
  117. data/split/Dvector/defs.h +0 -39
  118. data/split/Dvector/extconf.rb +0 -4
  119. data/split/Dvector/include/dvector.h +0 -77
  120. data/split/Dvector/namespace.h +0 -59
  121. data/split/Dvector/safe_double.h +0 -104
  122. data/split/Dvector/symbols.h +0 -52
  123. data/split/Flate/defs.h +0 -39
  124. data/split/Flate/extconf.rb +0 -19
  125. data/split/Flate/namespace.h +0 -59
  126. data/split/Flate/safe_double.h +0 -104
  127. data/split/Flate/symbols.h +0 -52
  128. data/split/Function/defs.h +0 -39
  129. data/split/Function/dvector.h +0 -77
  130. data/split/Function/extconf.rb +0 -4
  131. data/split/Function/namespace.h +0 -59
  132. data/split/Function/safe_double.h +0 -104
  133. data/split/Function/symbols.h +0 -52
  134. data/split/Tioga/defs.h +0 -39
  135. data/split/Tioga/dtable.h +0 -35
  136. data/split/Tioga/dvector.h +0 -77
  137. data/split/Tioga/extconf.rb +0 -4
  138. data/split/Tioga/flate.h +0 -98
  139. data/split/Tioga/mk_tioga_sty.rb +0 -53
  140. data/split/Tioga/namespace.h +0 -59
  141. data/split/Tioga/safe_double.h +0 -104
  142. data/split/Tioga/symbols.h +0 -52
  143. data/split/defs.h +0 -39
  144. data/split/extconf.rb +0 -125
  145. data/split/mkmf2.rb +0 -1623
  146. data/split/namespace.h +0 -59
  147. data/split/safe_double.h +0 -104
  148. data/split/symbols.h +0 -52
data/split/mkmf2.rb DELETED
@@ -1,1623 +0,0 @@
1
- require 'rbconfig'
2
- require 'fileutils'
3
-
4
- # some global variables:
5
- $LOCAL_LIBS = ""
6
-
7
- # A string extension from old mkmf.rb
8
- class String
9
- def quote
10
- /\s/ =~ self ? "\"#{self}\"" : self
11
- end
12
-
13
- # and a new function, that can come in useful in several places:
14
- def sanitize
15
- return self.tr("a-z./\055", "A-Z___")
16
- end
17
- end
18
-
19
- # An array extension from old mkmf.rb
20
- class Array
21
- def quote
22
- map {|s| s.quote}
23
- end
24
- end
25
-
26
-
27
- =begin rdoc
28
- :title: Mkmf2: a better replacement for mkmf
29
- =end
30
-
31
- =begin rdoc
32
-
33
- =Mkmf2: a drop-in replacement for mkmf
34
-
35
- Mkmf2 aims at replacing the functionnality of the old mkmf, with a better and
36
- cleaner code. It hopefully will keep all the previous mkmf files working,
37
- while providing
38
- * better control over the Makefiles produced;
39
- * installation to <tt>$HOME</tt>;
40
- * uninstallation;
41
- * more flexibility.
42
-
43
- ==Background
44
-
45
- Mkmf2 was written to supplement a missing feature on the old +mkmf.rb+: it is
46
- not possible to install include files along with the library, and not easy
47
- to make several libraries, that link each other, and install them... So here
48
- comes mkmf2.rb !
49
-
50
-
51
- ==Bugs
52
-
53
- There are probably a huge number of bugs, or missing features, or
54
- misleading features. In case you find one, please file a request
55
- in the mkmf2 project on rubyforge, at the address
56
- http://rubyforge.org/tracker/?group_id=1391
57
-
58
- But before, please, check out the latest cvs version at
59
- http://rubyforge.org/scm/?group_id=1391
60
- and make sure the bug is still there...
61
-
62
- ==Note to anyone who wishes to contribute
63
-
64
- Please, document any code you add, and keep the
65
- changelog up to date...
66
-
67
- ==Copyright
68
-
69
- This module is copyright 2006 by Vincent Fourmond. You can use and
70
- redistribute it under the terms of the General Public License version 2.
71
- As a special exception, you can distribute any verbatim copy along with
72
- a program, provided that this program depends on mkmf2 to install.
73
-
74
- =end
75
-
76
- module Mkmf2
77
-
78
- include Config
79
-
80
- # The CVS tag used for the release.
81
- CVS_TAG = '$Name: $'
82
-
83
- # The module version; it is computed from CVS_TAG
84
- VERSION = CVS_TAG.match(/\D+(.*?)\s*\$?$/)[1].tr('_-','..')
85
-
86
- # The entities: a list of Mkmf2::MfEntity representing what
87
- # we are currently building.
88
- @@entities = []
89
-
90
- # User-defined rules:
91
- @@user_rules = []
92
-
93
-
94
- # we first start the module with a whole bunch of small subclasses
95
- # that will come in really useful later.
96
-
97
- # This class provides a crude functionnality for defining a rule
98
- # in a Makefile.
99
- class MfRule
100
- attr_accessor :name, :rule, :dependencies
101
-
102
- # converts this rule to a string that can be readily printed to
103
- # the Makefile
104
- def to_s
105
- return "#{@name}: #{@dependencies.join ' '}" +
106
- if @rule.empty? # we don't need a second line
107
- "\n"
108
- else
109
- "\n\t#{@rule.join "\n\t"}\n"
110
- end
111
- end
112
-
113
- # +name+:: the name of the rule.
114
- # +rule+::
115
- # a string or an array of lines; strings are split if necessary
116
- # +deps+:: a string or an array of dependencies
117
- def initialize(name, rule = nil, deps = nil)
118
- @name = name
119
-
120
- if rule.is_a? Array
121
- @rule = rule
122
- elsif rule.nil?
123
- @rule = []
124
- else
125
- @rule = rule.split /\s*\n\t?\s*/
126
- end
127
-
128
- if deps.is_a? Array
129
- @dependencies = deps
130
- elsif deps.nil?
131
- @dependencies = []
132
- else
133
- @dependencies = deps.split /\s+/
134
- end
135
- end
136
-
137
- end
138
-
139
- # A small class to include comments into the Makefile, just to help anyone
140
- # who has to debug something. And it annoys me not to be able to clearly
141
- # read the output of the test.rb script !
142
- class MfComment < MfRule
143
-
144
- # The actual text of the comment.
145
- attr_accessor :text
146
-
147
- # +str+ is the text meant to be displayed in the makefile. If it is nil
148
- # the rule just ends up being a blank line, to allow for easy separation
149
- # of the rules.
150
- def initialize(str = nil)
151
- @text = str
152
- end
153
-
154
- def to_s
155
- if @text.nil?
156
- return "\n"
157
- else
158
- lines = @text.to_s.split '\n'
159
- lines.unshift ""
160
- return "#{lines.join "\n# "}\n"
161
- end
162
- end
163
-
164
- end
165
-
166
-
167
-
168
- # An MfEntity object reprensents something that is part of the package.
169
- # In this way, it needs to provide:
170
- #
171
- # * a way to *install* itself;
172
- # * a way to *uninstall* itself;
173
- # * a way to *clean* the source directory;
174
- # * and, possibly, a way to *build* itself.
175
- #
176
- # This class should be subclassed for objects that need building.
177
- # It should be enough though for many simple objects.
178
- #
179
- # The module will hold a list of all the MfEntities, and use them in turn
180
- # to create the Makefile.
181
- class MfEntity
182
-
183
- # +install_files+ is a hash that associates files in the building
184
- # tree to files where the installation is done. To be more precise
185
- # the install path for the files is expressed relative to
186
- # +install_path+
187
- attr_accessor :install_files
188
-
189
- # This name has to be registered by Mkmf2.register_name. Its lowercase
190
- # version will be used to name the targets (install_#{name}), etc.), and
191
- # it's uppercase version can be used as a prefix to name Makefile
192
- # variables, that we can for instance depend on.
193
- attr_accessor :name
194
-
195
- # It represents the type of the entity. It should be a valid entry
196
- # for Mkmf2.install_path.
197
- attr_accessor :kind
198
-
199
- # It is used to ask Mkmf2.install_files for the right rule for
200
- # installing files (they can be data, scripts, programs, and so on...)
201
- attr_accessor :install_rule
202
-
203
- # The +name+ parameter is turned into a unique name and ends up as
204
- # an identifier for the stuffs related to this element in the Makefile.
205
- # The +install+ parameter directly becomes install_files.
206
- # The +kind+ parameter describes the kind of thing we're going
207
- # to install. See Mkmf2.install_path.
208
-
209
- def initialize(name, install, kind = 'lib',
210
- install_rule = 'install_data')
211
-
212
- # we append kind to avoid overlaps in case of
213
- # a malchosen name (even if this is guaranteed by register_name),
214
- # it will look better.
215
- @name = Mkmf2::register_name(kind + "_" + name)
216
- @install_files = install.dup
217
- @kind = kind
218
- @install_rule = install_rule
219
- end
220
-
221
- # Returns the install path for the current object. The implementation
222
- # should call Mkmf2.install_path with an appropriate argument.
223
- def install_path
224
- return Mkmf2::install_path(@kind)
225
- end
226
-
227
-
228
- # Returns an array containing
229
- # * a string as the first element which should be appendended
230
- # as a dependency for the install target
231
- # * a set of MfRules, describing what need to be done
232
- # for that peculiar install.
233
-
234
- def install_rules
235
- rules = ["install_#{@name.downcase}"]
236
-
237
- rules.push MfComment.new("installation rules for #{name}")
238
-
239
- rules.push MfRule.new("install_#{@name.downcase}",
240
- Mkmf2.install_files_rules(@install_rule,
241
- install_path,
242
- @install_files),
243
- ["$(#{@name.upcase}_SOURCE_FILES)",
244
- "$(#{@name.upcase}_INSTALL_DIRS)"]
245
- )
246
- end
247
-
248
- # Rules for uninstalling the entity.
249
- # See install_rules for the return values.
250
- def uninstall_rules
251
- rules = ["uninstall_#{@name.downcase}"]
252
-
253
- rules.push MfComment.new("uninstallation rules for #{name}")
254
- files = [] # the rules to remove the installed files
255
- dirs = [] # the directories created during install
256
- @install_files.each_value do |v|
257
- dest = File.join(install_path,v)
258
- files.push Mkmf2.rule('remove',dest)
259
- dirs << File.dirname(dest)
260
- end
261
- dirs.uniq!
262
- for dir in dirs
263
- files << Mkmf2.rule('remove_path',dir)
264
- end
265
- rules.push MfRule.new("uninstall_#{@name.downcase}",
266
- files)
267
- end
268
-
269
- # Rules for cleaning the source directory. See #install_rules for
270
- # an explanation about return values. This implementation does
271
- # nothing, as there is nothing to be built.
272
- def clean_rules
273
- return []
274
- end
275
-
276
- # Rules for building the entity. See #install_rules for
277
- # an explanation about return values.
278
- def build_rules
279
- return []
280
- end
281
-
282
- # Returns all the variables that should be added to the Makefile.
283
- # It should return a simple hash containing the values.
284
- def variables
285
- # we need to define this variable:
286
- ret = {}
287
- install = []
288
- source = []
289
- dirs = []
290
- @install_files.each do |k,f|
291
- file = File.join(install_path,f)
292
- install << file
293
- source << k
294
- dirs << File.dirname(file) + "/"
295
- end
296
- dirs.uniq!
297
- ret["#{@name.upcase}_INSTALL_FILES"] =
298
- Mkmf2.pretty_print_list(install,"#{@name.upcase}_INSTALL_FILES=")
299
- ret["#{@name.upcase}_INSTALL_DIRS"] =
300
- Mkmf2.pretty_print_list(dirs,"#{@name.upcase}_INSTALL_DIRS=")
301
- ret["#{@name.upcase}_SOURCE_FILES"] =
302
- Mkmf2.pretty_print_list(source,"#{@name.upcase}_SOURCE_FILES=")
303
- return ret
304
- end
305
- end
306
-
307
- # The class to create libraries that need to be built (that is basically
308
- # why I wrote the whole stuff !).
309
- class MfBinaryLibEntity < MfEntity
310
-
311
- # The source files of the library.
312
- attr_accessor :sources
313
-
314
- # The object files for the library
315
- attr_accessor :objects
316
-
317
- # The name of the file produced in the source directory.
318
- attr_accessor :target_file
319
-
320
- # The libraries on which the linking does depend
321
- attr_accessor :lib_depends
322
-
323
- # Supplementary command-line arguments for the linking step.
324
- # It will be used for instance to store library info.
325
- attr_accessor :suppl_args
326
-
327
- # +name+:: of the binary library produce, for instance "Biniou/Bidule"
328
- # +sources+:: sources of the files, defaults to all the potential
329
- # +C+/+C\+\++ in the current directory.
330
- # The sources are further expanded with Dir.glob.
331
- # If you give then name of a directory, it will be
332
- # expanded
333
- # +target_file+:: how the files built in the current directory
334
- # will be called. Defaults to the same file name
335
- # as +name+.
336
- # +lib_depends+:: an array of objects, which designate ruby binary
337
- # libraries that this library does depend on;
338
-
339
- def initialize(name, sources = nil, target_file = nil,
340
- lib_depends = nil)
341
- if sources.nil?
342
- sources = ["."]
343
- end
344
-
345
- @sources = []
346
- add_sources(sources)
347
-
348
-
349
- if target_file.nil?
350
- @target_file = File.basename(name) + ".#{CONFIG["DLEXT"]}"
351
- else
352
- @target_file = target_file
353
- end
354
-
355
- install_hash = { @target_file => name + ".#{CONFIG["DLEXT"]}" }
356
- # Then, we call the function of the parent
357
- super(name, install_hash,'bin_lib','install_bin')
358
- @suppl_args = ""
359
- end
360
-
361
- # Adds source files to the library. Can come in useful inside a block
362
- def add_sources(*sources)
363
- # we flatten the array, just to make sure everything is top-level
364
- sources.flatten!
365
-
366
- # We expand directory into the files in them
367
- # (no subdirs)
368
- sources.collect! do |f|
369
- if File.directory?(f)
370
- temp = []
371
- for ext in Mkmf2.source_files_extensions
372
- temp << File.join(f,"*.#{ext}")
373
- end
374
- temp
375
- else
376
- f
377
- end
378
- end
379
-
380
- # Then, we expand the files:
381
- for f in sources
382
- files = Dir.glob(f)
383
- if files.empty?
384
- @sources << f
385
- else
386
- @sources += files
387
- end
388
- end
389
-
390
- # and we update the list of current object files
391
- @objects = @sources.collect do |f|
392
- f.gsub(/\.[^.]+$/, ".#{CONFIG["OBJEXT"]}")
393
- end
394
-
395
- end
396
- #
397
- def build_rules
398
- return [#"build_#{@name.downcase}",
399
- @target_file,
400
- # better to write this way... more clear on the
401
- # zsh command-line completion ;-) !
402
- MfRule.new(@target_file,
403
- Mkmf2.rule('build_library',
404
- "$(#{name.upcase}_OBJS)",
405
- @suppl_args),
406
- "$(#{name.upcase}_OBJS)")
407
- ]
408
- end
409
-
410
- # This removes the object files for the target...
411
- def clean_rules
412
- rules = ["clean_#{@name.downcase}"]
413
-
414
- rules.push MfComment.new("cleaning rules for #{name}")
415
- files = [] # the rules to clean the files
416
- @objects.each do |v|
417
- files.push Mkmf2.rule('remove',v)
418
- end
419
-
420
- files.push Mkmf2.rule('remove', @target_file)
421
- rules.push MfRule.new("clean_#{@name.downcase}",
422
- files)
423
- return rules
424
- end
425
-
426
- def variables
427
- vars = super
428
- # We add the object list variable
429
- vars["#{name.upcase}_OBJS"] =
430
- Mkmf2.pretty_print_list(@objects,"#{name.upcase}_OBJS=")
431
- return vars
432
- end
433
-
434
- end
435
-
436
- # Returns a list of the potential source files extensions.
437
- def Mkmf2.source_files_extensions
438
- return Mkmf2.cpp_files_extensions +
439
- Mkmf2.c_files_extensions
440
- end
441
-
442
- # Return the extensions for C++ files.
443
- def Mkmf2.cpp_files_extensions
444
- return %w{cpp cc cxx}
445
- end
446
-
447
- # Return extensions for C files.
448
- def Mkmf2.c_files_extensions
449
- return %w{c}
450
- end
451
-
452
-
453
- # This function declares a shared binary library that will be built
454
- # and installed using the appropriate functions.
455
- #
456
- # +libname+ is what is usually passed as an argument to the
457
- # +create_makefile+ function of the old
458
- #
459
- # +sources+ is the source files. They are processed using Dir.glob, so
460
- # they can contain wildcards.
461
- #
462
- # This function contends itselfs to *declare* the library, it does not
463
- # *build* it, as this will be done by +make+.
464
-
465
- def declare_binary_library(libname, *sources, &b)
466
- add_entity(MfBinaryLibEntity.new(libname, sources), &b)
467
- end
468
-
469
- def add_entity(entity)
470
- yield entity if block_given?
471
- @@entities << entity
472
- return entity
473
- end
474
-
475
- # This function declares a Ruby library, namely files that want
476
- # to be installed directly in the rubylibdir (or equivalent, depending
477
- # on the user settings).
478
- # +target_dir+:: the target directory, relative to the installation
479
- # directory;
480
- # +files+:: the files to install. Defaults to "lib/**.rb"
481
- #
482
- # For instance,
483
- # declare_library("Biniou", "toto.rb")
484
- # will install the file "Biniou/toto.rb" in the common library
485
- # directory.
486
-
487
- def declare_library(target_dir,*files, &b)
488
- if files.empty?
489
- files << "lib/**/*.rb"
490
- end
491
- declare_file_set(target_dir, files, 'lib', false, &b)
492
- end
493
-
494
- # Declares a set of files that should be executed directly be the user.
495
- def declare_exec(*files, &b)
496
- # No need for a target directory.
497
- declare_file_set("", files, 'exec', true, 'install_script',&b)
498
- end
499
-
500
- # Declares a documentation that doesn't need to be built. For the arguments,
501
- # see #declare_library.
502
- def declare_doc(target_dir, *files,&b)
503
- if files.empty?
504
- files << "doc/**/*"
505
- end
506
- declare_file_set(target_dir, files, 'doc', false,&b)
507
- end
508
-
509
- # Declares a set of include files to be installed. Defaults to
510
- # all the files in the include subdirectory.
511
- def declare_includes(target_dir,*files,&b)
512
- if files.empty?
513
- files << "include/**/*.h"
514
- end
515
- declare_file_set(target_dir, files, 'include', true,&b)
516
- end
517
-
518
-
519
-
520
- # The main place for declaring files to be installed.
521
- # +target_dir+:: the target directory relative to the install path
522
- # if it is nil or empty, then just install in the
523
- # base directory.
524
- # +files+:: the source files
525
- # +kind+:: the kind of target (see again and again install_path)
526
- # +basename+:: wether or not to strip the leading directories ?
527
- # +skip+:: a regular expression (or whatever object that has a ===
528
- # method that matches strings) saying wich files should
529
- # be excluded. Defaults to /~$/.
530
- # _base_dir_:: a source base directory to be stripped from the target
531
- # name
532
-
533
- def declare_file_set(target_dir, files, kind = 'lib',
534
- basename = true,
535
- rule = 'install_data',
536
- skip = /~$/, delete = /((^.*\/)?lib\/)?/,
537
- base_dir = false, &b)
538
- source_files = []
539
- for glob in files
540
- # If glob looks like a glob, we use Dir.glob, else we add it
541
- # without modification
542
- if glob =~ /\*|\[|\?/
543
- source_files += Dir[glob]
544
- else
545
- source_files << glob
546
- end
547
- end
548
- install_hash = {}
549
- for f in source_files
550
- next if skip === f
551
- next if File.directory? f
552
- filename = if basename
553
- File.basename(f)
554
- else
555
- f.dup
556
- end
557
- filename.gsub!(delete, '')
558
-
559
- if target_dir.nil? or target_dir.empty?
560
- install_hash[f] = filename
561
- else
562
- install_hash[f] = File.join(target_dir, filename)
563
- end
564
- end
565
- add_entity(MfEntity.new(target_dir, install_hash,
566
- kind, rule), &b)
567
- end
568
-
569
- @@model = "local"
570
-
571
- # Sets the model for directory installation. There are for now
572
- # three values:
573
- # local:: for a standard installation (like the default in mkmf.rb)
574
- # dist:: to use in a packageing system
575
- # home:: to install to a home directory (basically, prefix= <tt>$HOME</tt>)
576
- #
577
- # Please do not modify @@model directly.
578
-
579
- def Mkmf2.set_model(model = "local")
580
- @@model = model
581
- end
582
-
583
- # Sets up a whole bunch of variables necessary for installation, depending
584
- # on the current value of the @@model parameter. This is the place where we
585
- # setup the variables used by the installation process, namely:
586
- # +RUBYLIB_INSTALL_DIR+:: the directory where the text libraries
587
- # are to be installed;
588
- # +RUBYARCHLIB_INSTALL_DIR+:: the directory where architecture
589
- # dependent libraries are installed;
590
- # +INCLUDE_INSTALL_DIR+:: the directory where include files should go
591
- # if necessary;
592
- # And for now, that is all.
593
- def setup_model
594
- case @@model
595
- when "home"
596
- # I made a mistake for the home scheme.
597
- # we ensure the prefix is set to $HOME
598
- MAKEFILE_CONFIG["RUBYLIB_INSTALL_DIR"] =
599
- "$(DESTDIR)$(HOME)/lib/ruby"
600
- # For the HOME scheme, binaries and .rb files go
601
- # to the same directory.
602
- MAKEFILE_CONFIG["RUBYARCHLIB_INSTALL_DIR"] =
603
- "$(DESTDIR)$(HOME)/lib/ruby"
604
- MAKEFILE_CONFIG["INCLUDE_INSTALL_DIR"] =
605
- "$(DESTDIR)$(HOME)/include"
606
- MAKEFILE_CONFIG["EXEC_INSTALL_DIR"] =
607
- "$(DESTDIR)$(HOME)/bin"
608
-
609
- when "dist"
610
- # shares some code with the previous item, don't forget to
611
- # update *BOTH* !
612
- MAKEFILE_CONFIG["RUBYLIB_INSTALL_DIR"] =
613
- "$(DESTDIR)$(rubylibdir)"
614
- MAKEFILE_CONFIG["RUBYARCHLIB_INSTALL_DIR"] =
615
- "$(DESTDIR)$(archdir)"
616
- MAKEFILE_CONFIG["INCLUDE_INSTALL_DIR"] =
617
- "$(DESTDIR)$(includedir)"
618
- MAKEFILE_CONFIG["EXEC_INSTALL_DIR"] =
619
- File.join("$(DESTDIR)$(prefix)", "bin")
620
-
621
- when "local"
622
- MAKEFILE_CONFIG["RUBYLIB_INSTALL_DIR"] =
623
- "$(sitelibdir)"
624
- MAKEFILE_CONFIG["RUBYARCHLIB_INSTALL_DIR"] =
625
- "$(sitearchdir)"
626
-
627
- # To make the base directory for installation, I propose
628
- # to strip all the directories containing ruby from the
629
- # $(sitedir) directory and strip one more directory.
630
-
631
- basedir = MAKEFILE_CONFIG["sitedir"]
632
- while File.basename(basedir) =~ /ruby/
633
- basedir = File.dirname(basedir)
634
- end
635
- # Strip one more:
636
- basedir = File.dirname(basedir)
637
- MAKEFILE_CONFIG["basedir"] = basedir
638
- MAKEFILE_CONFIG["INCLUDE_INSTALL_DIR"] =
639
- "$(basedir)/include"
640
- MAKEFILE_CONFIG["EXEC_INSTALL_DIR"] =
641
- "$(basedir)/bin"
642
- end
643
-
644
- end
645
-
646
-
647
- # Returns the installation path for a given thing (+what+). This function
648
- # basically returns a simple MAKEFILE_CONFIG variable, which has otherwise
649
- # been setup by setup_model. What is available for now:
650
- # +lib+:: where to install .rb library
651
- # +bin_lib+:: where to install binary libs
652
- # +include+:: include files
653
-
654
- def Mkmf2.install_path(what)
655
- # we should definitely append a $(DESTDIR) to every single
656
- # directory we return, since it will make debugging
657
-
658
- case what
659
- when 'lib'
660
- return Mkmf2.config_var('RUBYLIB_INSTALL_DIR')
661
- when 'exec'
662
- return Mkmf2.config_var('EXEC_INSTALL_DIR')
663
- when 'bin_lib'
664
- return Mkmf2.config_var('RUBYARCHLIB_INSTALL_DIR')
665
- when 'include'
666
- return Mkmf2.config_var('INCLUDE_INSTALL_DIR')
667
- else
668
- raise "Unkown installation directory specification: #{what}"
669
- end
670
- end
671
-
672
- @@registered_names = {} # a hash containing already registered names
673
- # to avoid namespace clobbering.
674
-
675
- # Register a new name, making sure the name returned is unique.
676
- def Mkmf2.register_name(name)
677
- # first, transform all that is not letter into underscore
678
- name.gsub!(/[^a-zA-Z]/,'_')
679
- # pretty-print a bit
680
- name.gsub!(/^_|_$/,'')
681
- name.gsub!(/_+/, '_')
682
- name.downcase!
683
- # then, increment the number
684
- if @@registered_names[name]
685
- i = 1
686
- while @@registered_names["#{name}_#{i}"]
687
- i += 1
688
- end
689
- name = "#{name}_#{i}"
690
- end
691
- @@registered_names[name] = true
692
- return name
693
- end
694
-
695
-
696
- # Stores which configuration variables are used
697
- @@config_variables_used = []
698
- # Returns the given config key, that will be used to write a rule
699
- # in the Makefile. For better output, the function does store a list of
700
- # all the config variables which are in use, and simply outputs
701
- # +$(VARIABLE)+.
702
- def Mkmf2.config_var(str)
703
- @@config_variables_used << str
704
- return "$(#{str})"
705
- end
706
-
707
- # This hash says which of the "CONFIG" variables we should make available
708
- # as a global variable -- and use it back to output the variables. If non
709
- # nil, the second part says which name it should have as global variable.
710
- MKMF_GLOBAL_VARIABLES = {
711
- "CFLAGS" => nil,
712
- "CXXFLAGS" => nil,
713
- "LDFLAGS" => nil,
714
- "DLDFLAGS" => nil,
715
- "CPPFLAGS" => nil,
716
- "LIBS" => nil,
717
- "LIBRUBYARG" => nil,
718
- "LOCAL_LIBS" => nil,
719
- "libs" => nil,
720
- }
721
-
722
-
723
- # Takes the config variables, turn them into global variables.
724
- def config_to_global
725
- for var,name in MKMF_GLOBAL_VARIABLES
726
- name = var if name.nil?
727
- value = MAKEFILE_CONFIG[var].to_s # make sure its a string
728
- # in case it doesn't exist there...
729
- # Nice trick to get around quoting...
730
- block = eval "proc {|x| $#{name} = x}"
731
- block.call(value)
732
- end
733
- $LIBRUBYARG = "" # seems the default in mkmf.rb
734
- end
735
-
736
- # Takes the global variables taken from the config, and put them back into
737
- # the config hash.
738
- def global_to_config
739
- for var,name in MKMF_GLOBAL_VARIABLES
740
- name = var if name.nil?
741
- value = eval "$#{name}"
742
- MAKEFILE_CONFIG[var] = value
743
- end
744
- end
745
-
746
-
747
-
748
- # A constant to get a configuration variable
749
- MAKE_VARIABLE = /\$\((\w+)\)/
750
-
751
- # List config variables referenced to by the string _str_. If
752
- # hash is specified, only config variables that are keys of this hash
753
- # will be listed.
754
- def subvars(str, hash = nil)
755
- vars = []
756
- str.gsub(MAKE_VARIABLE) { |k|
757
- # we add the key to the list only if it exists, else the
758
- # environment variable gets overridden by what is written
759
- # in the Makefile (for $HOME, for instance)
760
- vars << $1 if ( hash.nil? || hash.key?($1) )
761
- }
762
- return vars
763
- end
764
-
765
- # A way to deal with compound make variables (that is,
766
- # make variables that get more than just themselves on the output)
767
-
768
- COMPOUND_MAKE_VARIABLES = {
769
- "CFLAGS" => "$(CFLAGS) $(ARCH_FLAG)",
770
- "DLDFLAGS" => "$(DLDFLAGS) $(ARCH_FLAG)",
771
- "LIBS" => "$(LIBRUBYARG) $(libs) $(LIBS)",
772
- }
773
-
774
-
775
- # Returns the contents of a "compound" variable.
776
- def compound_var_expand(var, value = nil, hash = MAKEFILE_CONFIG)
777
- if value.nil?
778
- value = MAKEFILE_CONFIG[var]
779
- end
780
- COMPOUND_MAKE_VARIABLES[var].gsub("$(#{var})",value)
781
- end
782
-
783
-
784
- # Returns a string containing all the configuration variables. We
785
- # use the MAKEFILE_CONFIG for more flexibility in the Makefile: the
786
- # variables can then be redefined on the make command-line.
787
- def output_config_variables
788
- str = ""
789
- keys = @@config_variables_used.uniq
790
- global_to_config
791
- new_keys = []
792
- begin
793
- # we merge the new keys with the old
794
- keys += new_keys
795
- keys.uniq!
796
- new_keys = []
797
- keys.each do |k|
798
- if MAKEFILE_CONFIG.key? k
799
- new_keys += subvars(MAKEFILE_CONFIG[k], MAKEFILE_CONFIG)
800
- end
801
- if COMPOUND_MAKE_VARIABLES.key? k
802
- new_keys += subvars(COMPOUND_MAKE_VARIABLES[k], MAKEFILE_CONFIG)
803
- end
804
- end
805
- end until (keys + new_keys).uniq.length == keys.length
806
-
807
- for var in keys.uniq.sort
808
- # We output the variable only if it is not empty: makes
809
- # it a lot easier to modify them from outside...
810
- if COMPOUND_MAKE_VARIABLES.key?(var)
811
- str += "#{var}=#{compound_var_expand(var)}\n"
812
- elsif MAKEFILE_CONFIG[var] =~ /\S/
813
- str += "#{var}=#{MAKEFILE_CONFIG[var]}\n"
814
- end
815
- end
816
- return str
817
- end
818
-
819
-
820
- # This hash contains replacements for basic filesystem functions
821
- # based on ruby and FileUtils. They are used only if the corresponding
822
- # element is missing in CONFIG. They also contains some other default
823
- # values for possibly missing CONFIG keys.
824
- CONFIG_DEFAULTS = {
825
- # first, a short for the rest...
826
- "RB_FILE_UTILS" => "$(RUBY_INSTALL_NAME) -r fileutils",
827
- "INSTALL_SCRIPT" =>
828
- "$(RB_FILE_UTILS) -e 'FileUtils.install(ARGV[0],ARGV[1],:mode => 0755)'",
829
- "INSTALL_DATA" =>
830
- "$(RB_FILE_UTILS) -e 'FileUtils.install(ARGV[0],ARGV[1],:mode => 0644)'",
831
- "INSTALL_PROGRAM" => "$(INSTALL_SCRIPT) ",
832
- "MAKEDIRS" =>
833
- "$(RB_FILE_UTILS) -e 'FileUtils.makedirs(ARGV)'",
834
- "RM" =>
835
- "$(RB_FILE_UTILS) -e 'FileUtils.rm(ARGV)'",
836
- "RM_PATH" => # a trick to remove a path
837
- "$(RB_FILE_UTILS) -e 'd = ARGV[0]; begin ;while FileUtils.rmdir d, :verbose=>true; d = File.dirname(d);end; rescue ; end;'",
838
- "DEFINES" => "",
839
- "LIBARG" => "-l%s",
840
- "LIBS_SUP" => "",
841
- }
842
-
843
- # This functions checks for missing features in the CONFIG hash and
844
- # supplements them using the FILE_UTILS_COMMAND hash if necessary.
845
- def check_missing_features
846
- CONFIG.delete("INSTALL_SCRIPT") # Not consistent, it's better to use
847
- # the Fileutils stuff
848
- for key, val in CONFIG_DEFAULTS
849
- if CONFIG.key?(key) and CONFIG[key] =~ /\w/
850
- # everything is fine
851
- else
852
- # we supplement the feature.
853
- MAKEFILE_CONFIG[key] = val
854
- end
855
- end
856
- end
857
-
858
- # Takes a list of CONFIG variables and returns them joined by spaces.
859
- def Mkmf2.config_join(*vars)
860
- return vars.collect { |v|
861
- Mkmf2.config_var(v)
862
- }.join(' ')
863
- end
864
-
865
-
866
- # Returns the way to represent the dependencies of a rule in the
867
- # Makefile.
868
- def Mkmf2.mf_deps
869
- return " $(@D)"
870
- end
871
-
872
- # Returns the way to represent the current target in the Makefile.
873
- def Mkmf2.mf_target
874
- return " $@"
875
- end
876
-
877
- # A small helper function to write quickly rules, based on a configuration
878
- # item.
879
- def Mkmf2.mf_rule(cfg,*args)
880
- if args.empty?
881
- return Mkmf2.config_var(cfg) +
882
- Mkmf2.mf_deps + Mkmf2.mf_target
883
- else
884
- return Mkmf2.config_var(cfg) + ' ' + args.join(' ')
885
- end
886
- end
887
-
888
- # This function returns the common build rules for C and C++ files.
889
- def Mkmf2.common_build_rules
890
- rules = []
891
- for ext in Mkmf2.c_files_extensions
892
- rules << MfRule.new(".#{ext}.#{CONFIG["OBJEXT"]}",
893
- Mkmf2.config_join("CC",
894
- "CFLAGS",
895
- "CPPFLAGS",
896
- "INCLUDEDIRS",
897
- "DEFINES") +
898
- " -c $< #{CONFIG["OUTFLAG"]} $@"
899
- )
900
- end
901
-
902
- # The same, but with C++:
903
- for ext in Mkmf2.cpp_files_extensions
904
- rules << MfRule.new(".#{ext}.#{CONFIG["OBJEXT"]}",
905
- Mkmf2.config_join("CXX",
906
- "CXXFLAGS",
907
- "CPPFLAGS",
908
- "INCLUDEDIRS",
909
- "DEFINES") +
910
- " -c $< #{CONFIG["OUTFLAG"]} $@"
911
- )
912
- end
913
- # A simple rule for making directories:
914
- rules << MfRule.new("%/",
915
- Mkmf2.config_join("MAKEDIRS") + " $@")
916
- return rules
917
- end
918
-
919
- # Now, the infrastructure for dealing with include and library
920
- # directories:
921
- if CONFIG.key?('rubyhdrdir')
922
- @@include_path = [
923
- Mkmf2.config_var("rubyhdrdir")+"/ruby",
924
- Mkmf2.config_var("rubyhdrdir"),
925
- Mkmf2.config_var("rubyhdrdir") + "/" +
926
- Mkmf2.config_var("arch")
927
- ]
928
- else
929
- @@include_path = [ Mkmf2.config_var("rubylibdir") ]
930
- end
931
-
932
- @@include_path += [
933
- Mkmf2.config_var("archdir"),
934
- '.',
935
- File.join('.','include')
936
- ]
937
-
938
-
939
- # Adds one or more +paths+ to the current include path.
940
- def add_include_path(*paths)
941
- @@include_path += paths.flatten
942
- end
943
-
944
- def output_include_path
945
- return @@include_path.collect {|v|
946
- "-I#{v}"
947
- }.join(' ')
948
- end
949
-
950
- @@library_path = []
951
-
952
- # Adds one or more +paths+ to the current library path.
953
- def add_library_path(*paths)
954
- @@library_path += paths.flatten
955
- end
956
-
957
- def output_library_path
958
- return @@library_path.collect {|v|
959
- "-L#{v}"
960
- }.join(' ')
961
- end
962
-
963
- # I know this is bad design, but that's the best I think of for now.
964
- # This function better be called before using MAKEFILE_CONFIG directly.
965
- def update_makefile_config
966
- global_to_config
967
- setup_paths_variables
968
- end
969
-
970
- # Sets up the various variables pertaining to include
971
- # and library paths.
972
- def setup_paths_variables
973
- MAKEFILE_CONFIG["INCLUDEDIRS"] = output_include_path
974
- MAKEFILE_CONFIG["LIBDIRS"] = output_library_path
975
- end
976
-
977
- # A recommandation for line size in the Makefile
978
- MAKEFILE_LINE_SIZE = 40
979
-
980
- # Returns a string where all the elements are joined together. The lines
981
- # will break if they exceed +line_size+, but the elements themselves
982
- # will not be broken. They will be indented
983
- def Mkmf2.pretty_print_list(list, indent = 0,
984
- line_size = MAKEFILE_LINE_SIZE)
985
- if indent.is_a? String
986
- indent = indent.length
987
- end
988
- lines = []
989
- for elem in list
990
- if lines.last.nil? ||
991
- (lines.last + elem).length > line_size
992
- lines << elem.dup # necessary to force ruby to create
993
- else
994
- lines.last.concat(' ' + elem)
995
- end
996
- end
997
- return lines.join("\\\n#{' ' * indent}")
998
- end
999
-
1000
-
1001
- # Returns the string corresponding to a rule, given by the string +rule+,
1002
- # which can take the following values:
1003
- # +install_data+:: returns the rule for installing a data file to a
1004
- # given place
1005
- # +install_script+:: the rule for installing code at a given place
1006
- # +remove+:: to remove files
1007
- # +directory+:: to create a directory
1008
- # +build_library+:: to build a library; in that case, the first argument
1009
- # is the name of the target, and the ones after
1010
- # the objects.
1011
- #
1012
- # the optional arguments are the arguments to the rule, if they exist. Else,
1013
- # they default to $(@D) $@ (or something like that).
1014
-
1015
- def Mkmf2.rule(rule, *args)
1016
- case rule
1017
- when 'install_data'
1018
- return Mkmf2.mf_rule("INSTALL_DATA",args)
1019
- when 'install_script'
1020
- return Mkmf2.mf_rule("INSTALL_SCRIPT",args)
1021
- when 'install_bin'
1022
- return Mkmf2.mf_rule("INSTALL_PROGRAM",args)
1023
- when 'remove'
1024
- return "-" + Mkmf2.mf_rule("RM",args)
1025
- when 'remove_path'
1026
- return "-" + Mkmf2.mf_rule("RM_PATH", args)
1027
- when 'directory' # to create a directory
1028
- return Mkmf2.mf_rule("MAKEDIRS", args)
1029
- when 'build_library'
1030
- return Mkmf2.mf_rule("LDSHARED",
1031
- Mkmf2.config_join("DLDFLAGS",
1032
- "LIBDIRS"),
1033
- CONFIG["OUTFLAG"],
1034
- "$@", # the target,
1035
- args, # and the source
1036
- # The libraries should better come in the end,
1037
- # since for instance the standard linux ld
1038
- # does only link with the symbols that have been
1039
- # reported missing in the previous files.
1040
- Mkmf2.config_join("LIBRUBYARG_SHARED",
1041
- # we shouldn't forget this one !!
1042
- "LOCAL_LIBS",
1043
- "LIBS",
1044
- # and then, the global libraries
1045
- # that have been added using
1046
- # have_library
1047
- "LIBS_SUP")
1048
- )
1049
- end
1050
- end
1051
-
1052
- @@directories = {}
1053
- # Register a directory that we might need to create. Make sure that
1054
- # the rules don't appear twice.
1055
- def Mkmf2.register_dir(dir)
1056
- if ! @@directories.key?(dir)
1057
- @@directories[dir] = true
1058
- end
1059
- end
1060
-
1061
- # Return the rules to create the necessary directories
1062
- def directory_rules
1063
- rules = []
1064
- for dir in @@directories.keys
1065
- rules << MfRule.new(dir, Mkmf2.rule('directory',dir))
1066
- end
1067
- return rules
1068
- end
1069
-
1070
-
1071
- # A small helper function to extract the install directory name
1072
- # for one file. +file+ is the file, +install_dir+ where we want to
1073
- # install it. This should take care of messy dots.
1074
- def Mkmf2.dest_dir(file, install_dir)
1075
- dir = File::dirname(file)
1076
- if dir == "."
1077
- return install_dir
1078
- else
1079
- return File.join(install_dir,dir)
1080
- end
1081
- end
1082
-
1083
- # A helper function for MfEntity instances that will have to install
1084
- # files into directories.
1085
- # +rule+:: the rule to use, see Mkmf2::rule
1086
- # +install_path+:: the installation path
1087
- # +files+:: a hash containing original -> destination pairs.
1088
-
1089
- def Mkmf2.install_files(rule, install_path,files)
1090
- rules = []
1091
- files.each do |k,v|
1092
- destdir = Mkmf2.dest_dir(v, install_path)
1093
- Mkmf2.register_dir(destdir)
1094
- rules.push(MfRule.new(File.join(install_path,v),
1095
- Mkmf2::rule(rule, k,
1096
- File.join(install_path,v)),
1097
- [k,destdir]))
1098
- # depends on both the file
1099
- # that will be installed and the directory where to install it.
1100
- end
1101
-
1102
- return rules
1103
- end
1104
-
1105
- # The companion of install_files, returning a list of strings
1106
- # rather than MfRules. Bascially behaves the same way. It is probably
1107
- # a better thing to use this function now.
1108
- def Mkmf2.install_files_rules(rule, install_path,files)
1109
- rules = []
1110
- files.each do |k,v|
1111
- dir = File::dirname(v)
1112
- Mkmf2.register_dir(Mkmf2.dest_dir(v,install_path))
1113
- rules.push Mkmf2::rule(rule, k, File.join(install_path,v))
1114
-
1115
- # depends on both the file
1116
- # that will be installed and the directory where to install it.
1117
- end
1118
-
1119
- return rules
1120
- end
1121
-
1122
- # Small helper function for write_makefile. +target+ is
1123
- # a hash containing a "deps" array and a "rules" array
1124
- # which are created in case of need.
1125
- def unwrap_rules(target, source)
1126
- # we first make sure that the keys exist, even if we don't
1127
- # have anything to append to them.
1128
- if ! target.has_key? "deps"
1129
- target["deps"] = []
1130
- end
1131
- if ! target.has_key? "rules"
1132
- target["rules"] = []
1133
- end
1134
-
1135
- return if source.empty?
1136
- target["deps"] << source.shift
1137
- target["rules"] += source
1138
- end
1139
-
1140
- # Writes the Makefile using @@entities -- and others...
1141
- def write_makefile(file_name = "Makefile")
1142
- puts "Writing #{file_name}"
1143
-
1144
- install = {}
1145
- uninstall = {}
1146
- build = {}
1147
- clean = {}
1148
- vars = []
1149
-
1150
-
1151
-
1152
- for entity in @@entities
1153
- t = entity.install_rules
1154
- unwrap_rules(install,t)
1155
-
1156
- t = entity.uninstall_rules
1157
- unwrap_rules(uninstall,t)
1158
-
1159
- t = entity.build_rules
1160
- unwrap_rules(build,t)
1161
-
1162
- t = entity.clean_rules
1163
- unwrap_rules(clean,t)
1164
-
1165
- vars << entity.variables
1166
- end
1167
-
1168
- # Common rules:
1169
- common = Mkmf2.common_build_rules()
1170
-
1171
- # Setup the path variables:
1172
- setup_paths_variables
1173
- dir_rules = directory_rules()
1174
-
1175
- # OK, now, everything is prepared, we just need to create the
1176
- # makefile and output everything into it...
1177
-
1178
- f = open(file_name, File::WRONLY|File::CREAT|File::TRUNC)
1179
-
1180
-
1181
- # First, the variables in use:
1182
- f.puts "# Configurations variables, from rbconfig.rb"
1183
- f.puts output_config_variables
1184
-
1185
- # build has to be the first target so that simply
1186
- # invoking make does the building, but not the installing.
1187
- # now, the main rules
1188
- f.puts "\n\n# main rules"
1189
- # we force the dependence on build for install so that
1190
- # ruby library files don't get installed before the c code is
1191
- # compiled...
1192
- # build is output first so that invoking make without
1193
- # arguments builds.
1194
- f.print MfRule.new("build", nil, build["deps"]).to_s
1195
- f.print MfRule.new("install", nil, ["build"] + install["deps"]).to_s
1196
- f.print MfRule.new("uninstall", nil, uninstall["deps"]).to_s
1197
- f.print MfRule.new("clean",
1198
- [Mkmf2.rule('remove',"**/*~")], # remove archive files
1199
- # by default in the clean target.
1200
- clean["deps"]).to_s
1201
-
1202
- # Add a distclean rule, to make debuild happy.
1203
- f.print <<"EOR"
1204
- distclean: clean
1205
- \t@-$(RM) Makefile extconf.h conftest.* mkmf2.log
1206
- \t@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
1207
- EOR
1208
-
1209
- # Phony targets:
1210
- f.puts ".PHONY: build install uninstall"
1211
-
1212
- f.puts "\n\n# Common rules:"
1213
- common.each {|v|
1214
- f.print v.to_s
1215
- }
1216
-
1217
-
1218
- # We write the variables:
1219
- f.puts "\n\n# entities-dependent variables"
1220
- for v in vars
1221
- v.each do |k,v|
1222
- f.print "#{k}=#{v}\n"
1223
- end
1224
- end
1225
-
1226
- f.puts "\n\n# Rules to make directories"
1227
-
1228
- # directory rules
1229
- for rule in dir_rules
1230
- f.print rule.to_s
1231
- end
1232
-
1233
- f.puts "\n\n# entities-dependent rules"
1234
- # We write the rules
1235
- for rule in (install['rules'] +
1236
- uninstall['rules'] +
1237
- build['rules'] + clean['rules'])
1238
- f.print rule.to_s
1239
- end
1240
-
1241
- if @@user_rules.length > 0
1242
- f.puts "\n\n# User-defined rules"
1243
- for rule in @@user_rules
1244
- f.puts rule.to_s
1245
- end
1246
- end
1247
-
1248
-
1249
- f.close # not necessary, but good practice ;-) ??
1250
-
1251
- end
1252
-
1253
- # Adds a custom rule to the Makefile. If only the first argument
1254
- # is specified, it is written as is to the Makefile. If at least the
1255
- # second or the third is non-nil, a MfRule is created with the arguments
1256
- # and written to the Makefile.
1257
- def custom_rule(str, rule = nil, deps = nil)
1258
- if rule || deps
1259
- @@user_rules << MfRule.new(str, rule, deps)
1260
- else
1261
- @@user_rules << str
1262
- end
1263
- end
1264
-
1265
- # *The* compatibility function with the mkmf.rb !
1266
- def create_makefile(target)
1267
- declare_library(File.dirname(target))
1268
- declare_binary_library(target, "**/*.c")
1269
-
1270
- write_makefile
1271
- end
1272
-
1273
- # A function to ease the task of producing several libraries from the
1274
- # same source tree. It sets up a library context for one directory,
1275
- # adding it to the include path, and taking care of the files in:
1276
- # +lib/+:: the ruby library files;
1277
- # +include/+:: the include files
1278
- #
1279
- # +dir+ is the directory in the source, +target_dir+ the base directory
1280
- # for target files. It is pretty rudimentary, but should do the job
1281
- # for many cases (and especially Tioga ;-) !). +name+ is the name
1282
- # of the binary library. If nil, doesn't try to build a binary library.
1283
- # +include_dir+ is the target name for includes. If +nil+, doesn't
1284
- # try to install them.
1285
- #
1286
- # You can use either the return value or a block to change somehow the
1287
- # behavior of the different objects produced (like adding a binary library
1288
- # for instance).
1289
-
1290
- def setup_dir(dir, target_dir, bin_name = nil,
1291
- include_dir = nil)
1292
- add_include_path(dir, File.join(dir, 'include'))
1293
-
1294
- lib = declare_library(target_dir, "#{dir}/lib/**/*.rb")
1295
- binlib = declare_binary_library(bin_name,
1296
- "#{dir}/**/*.c") if ! bin_name.nil?
1297
- include = declare_includes(include_dir,
1298
- "#{dir}/include/**/*.h") if ! include_dir.nil?
1299
- yield lib, binlib, include if block_given?
1300
- [lib, binlib, include]
1301
- end
1302
-
1303
- # the module variable that will hold the command-line arguments:
1304
- # even with a similar name, the contents of this variable will
1305
- # be quite different from the old $configure_args
1306
- @@configure_args = {}
1307
-
1308
- # Parses command-line arguments, wiping the ones that we understood.
1309
- def parse_cmdline
1310
- $*.delete_if do |arg|
1311
- if arg =~ /^--(.*)/ # does look like a command-line argument...
1312
- case $1
1313
- when "local" # installation to sitedir
1314
- Mkmf2.set_model("local")
1315
- true
1316
- when "dist"
1317
- Mkmf2.set_model("dist")
1318
- true
1319
- when "home"
1320
- Mkmf2.set_model("home")
1321
- true
1322
- when /^--with(.*)/ # this is my understanding of the
1323
- # with-config stuff. It is a complete rewrite, I don't like
1324
- # much the old code
1325
- rhs = $1 # right-hand side
1326
- case rhs
1327
- when /-([\w-]+)=(.*)/
1328
- @@configure_args[$1] = $2
1329
- when /out-([\w-]+)$/
1330
- @@configure_args[$1] = false
1331
- when /-([\w-]+)$/
1332
- @@configure_args[$1] = true
1333
- else
1334
- raise "Argument #{arg} not understood"
1335
- end
1336
- else
1337
- false
1338
- end
1339
- else
1340
- false
1341
- end
1342
- end
1343
- end
1344
-
1345
- # This function is a try at reproducing the functionnality of the
1346
- # old mkmf.rb's dir_config. It is not a copy, and might not work
1347
- # well in all situations. Basically, if --with-target-dir has been
1348
- # specified, use dir/include dir/lib. If --with-target-(include|lib)
1349
- # have been specified, use them !
1350
- def dir_config(target)
1351
- ldir = nil
1352
- idir = nil
1353
- if @@configure_args.key?("#{target}-lib")
1354
- ldir = @@configure_args["#{target}-lib"]
1355
- elsif @@configure_args.key?("#{target}-dir")
1356
- ldir = File::join(@@configure_args["#{target}-dir"], "lib")
1357
- end
1358
- if ldir
1359
- add_library_path(ldir.split(File::PATH_SEPARATOR))
1360
- end
1361
-
1362
- if @@configure_args.key?("#{target}-include")
1363
- idir = @@configure_args["#{target}-include"]
1364
- elsif @@configure_args.key?("#{target}-dir")
1365
- idir = File::join(@@configure_args["#{target}-dir"], "include")
1366
- end
1367
- if idir
1368
- add_include_path(idir.split(File::PATH_SEPARATOR))
1369
- end
1370
- return [idir, ldir]
1371
- end
1372
-
1373
- ###########################################################################
1374
- # This module is copied verbatim from the old mkmf.rb code. It comes dead #
1375
- # useful for logging things. I hope it will not cause licence conflicts. #
1376
- ###########################################################################
1377
-
1378
- module Logging
1379
- @log = nil
1380
- @logfile = 'mkmf2.log'
1381
- @orgerr = $stderr.dup
1382
- @orgout = $stdout.dup
1383
- @postpone = 0
1384
-
1385
- def self::open
1386
- @log ||= File::open(@logfile, 'w')
1387
- @log.sync = true
1388
- $stderr.reopen(@log)
1389
- $stdout.reopen(@log)
1390
- yield
1391
- ensure
1392
- $stderr.reopen(@orgerr)
1393
- $stdout.reopen(@orgout)
1394
- end
1395
-
1396
- def self::message(*s)
1397
- @log ||= File::open(@logfile, 'w')
1398
- @log.sync = true
1399
- @log.printf(*s)
1400
- end
1401
-
1402
- def self::logfile file
1403
- @logfile = file
1404
- if @log and not @log.closed?
1405
- @log.flush
1406
- @log.close
1407
- @log = nil
1408
- end
1409
- end
1410
-
1411
- def self::postpone
1412
- tmplog = "mkmftmp#{@postpone += 1}.log"
1413
- open do
1414
- log, *save = @log, @logfile, @orgout, @orgerr
1415
- @log, @logfile, @orgout, @orgerr = nil, tmplog, log, log
1416
- begin
1417
- log.print(open {yield})
1418
- @log.close
1419
- File::open(tmplog) {|t| FileUtils.copy_stream(t, log)}
1420
- ensure
1421
- @log, @logfile, @orgout, @orgerr = log, *save
1422
- @postpone -= 1
1423
- rm_f tmplog
1424
- end
1425
- end
1426
- end
1427
- end
1428
-
1429
- # Also from old mkmf.rb
1430
- CONFTEST_C = "conftest.c"
1431
-
1432
- def xsystem(command)
1433
- Logging::open do
1434
- puts command.quote
1435
- system(command)
1436
- end
1437
- end
1438
-
1439
- # Also from old mkmf.rb
1440
- def log_src(src)
1441
- Logging::message <<"EOM", src
1442
- checked program was:
1443
- /* begin */
1444
- %s/* end */
1445
-
1446
- EOM
1447
- end
1448
-
1449
- # Also from old mkmf.rb
1450
- def create_tmpsrc(src)
1451
- src = yield(src) if block_given?
1452
- src = src.sub(/[^\n]\z/, "\\&\n")
1453
- open(CONFTEST_C, "wb") do |cfile|
1454
- cfile.print src
1455
- end
1456
- src
1457
- end
1458
-
1459
- # Also from old mkmf.rb
1460
- def try_do(src, command, &b)
1461
- src = create_tmpsrc(src, &b)
1462
- xsystem(command)
1463
- ensure
1464
- log_src(src)
1465
- end
1466
-
1467
- # Also from old mkmf.rb
1468
- def checking_for(m, fmt = nil)
1469
- f = caller[0][/in `(.*)'$/, 1] and f << ": " #` for vim
1470
- m = "checking for #{m}... "
1471
- print m
1472
- a = r = nil
1473
- Logging::postpone do
1474
- r = yield
1475
- a = (fmt ? fmt % r : r ? "yes" : "no") << "\n"
1476
- "#{f}#{m}-------------------- #{a}\n"
1477
- end
1478
- puts a
1479
- $stdout.flush
1480
- Logging::message "--------------------\n\n"
1481
- r
1482
- end
1483
-
1484
- # also taken straight from mkmf.rb
1485
- def rm_f(*files)
1486
- FileUtils.rm_f(Dir[files.join("\0")])
1487
- end
1488
-
1489
- # A small wrapper around Config::expand which diminishes the size of the code
1490
- # and makes sure the MAKEFILE_CONFIG hash is updated.
1491
- def expand_vars(str)
1492
- update_makefile_config
1493
- string = Config::expand(str,MAKEFILE_CONFIG)
1494
- # then, we need to turn all the remaining $(THING) into $THING, so that
1495
- # the shell doesn't spawn subshells ?
1496
- return string.gsub(/\$\((\w+)\)/) { "$#$1" }
1497
- end
1498
-
1499
- # Add defines to the build
1500
- def add_define(d)
1501
- MAKEFILE_CONFIG["DEFINES"] +=
1502
- " -D_#{d}"
1503
- end
1504
-
1505
- # This is a compatibility function with the previous mkmf.rb. It does check
1506
- # for the presence of a header in the current include directories. If found,
1507
- # it returns true and sets the define HAVE_...
1508
- def have_header(header, &b)
1509
- checking_for header do
1510
- if try_do("#include <#{header}>",
1511
- expand_vars("$(CPP) $(INCLUDEDIRS) " \
1512
- "$(CPPFLAGS) $(CFLAGS) $(DEFINES) "\
1513
- "#{CONFTEST_C} $(CPPOUTFILE)"),&b)
1514
- add_define("HAVE_#{header.sanitize}")
1515
- true
1516
- else
1517
- false
1518
- end
1519
- end
1520
- ensure
1521
- rm_f("conftest*")
1522
- end
1523
-
1524
- # The same as have_header, but fails if the header is not found...
1525
- def require_header(header, message = nil ,&b)
1526
- if ! have_header(header,&b)
1527
- if message
1528
- puts message
1529
- end
1530
- raise "Header #{header} not found, stopping\n"
1531
- end
1532
- end
1533
-
1534
- def mkmf2_init
1535
- check_missing_features
1536
- parse_cmdline
1537
- setup_model
1538
- config_to_global
1539
- end
1540
-
1541
- def headers(header)
1542
- headers = ""
1543
- if header
1544
- if header.is_a?(Array)
1545
- header.each {|h|
1546
- headers += "#include <#{h.to_s}>\n"
1547
- }
1548
- else
1549
- headers += "#include <#{header.to_s}>\n"
1550
- end
1551
- end
1552
- return headers
1553
- end
1554
-
1555
- # Tries to link the given code with the extra flags given
1556
- def try_link(code, extras = "")
1557
- return try_do(code,
1558
- expand_vars("$(CC) $(OUTFLAG)conftest $(INCFLAGS) " +
1559
- "#{CONFTEST_C} " +
1560
- " -I$(hdrdir) $(CPPFLAGS) $(CFLAGS) $(src)" +
1561
- " $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) " +
1562
- " $(LOCAL_LIBS) $(LIBS) $(LIBS_SUP) #{extras}"
1563
- )
1564
- )
1565
- ensure
1566
- rm_f("conftest*")
1567
- end
1568
-
1569
- def try_func(func, extra, h)
1570
- headers = headers(h)
1571
-
1572
- try_link(<<"SRC", extra) or try_link(<<"SRC", extra)
1573
- #{headers}
1574
- /*top*/
1575
- int main() { return 0; }
1576
- int t() { #{func}(); return 0; }
1577
- SRC
1578
- #{headers}
1579
- /*top*/
1580
- int main() { return 0; }
1581
- int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; }
1582
- SRC
1583
- end
1584
-
1585
-
1586
- # Compatibility function from mkmf.rb. Checks if the compiler
1587
- # can find the given function in the given library. If the function
1588
- # is not given, we look for main but it's definitely not a good idea.
1589
- # +header+ is a header that can be included to get the prototype for
1590
- # this function. It can possibly be an array, in which case it is
1591
- # interpreted as a list of headers that should be included.
1592
-
1593
- def have_library(lib, func = nil, header=nil, &b)
1594
- if func.nil?
1595
- func = "main"
1596
- end
1597
- libarg = "#{MAKEFILE_CONFIG["LIBARG"]%lib}"
1598
- checking_for "#{func}() in #{libarg}" do
1599
- if try_func(func, libarg, header)
1600
- add_define("HAVE_#{lib.sanitize}")
1601
- MAKEFILE_CONFIG["LIBS_SUP"] += " #{libarg}"
1602
- true
1603
- else
1604
- false
1605
- end
1606
- end
1607
- end
1608
-
1609
- # Returns true if a function could be found
1610
- def have_func(func, header = nil)
1611
- checking_for "#{func}() " do
1612
- if try_func(func, "", header)
1613
- add_define("HAVE_#{func.sanitize}")
1614
- true
1615
- else
1616
- false
1617
- end
1618
- end
1619
- end
1620
- end
1621
-
1622
- include Mkmf2
1623
- mkmf2_init