lib/mkmf.rb
DEFINITIONS
This source file includes following functions.
1 # module to create Makefile for extension modules
2 # invoke like: ruby -r mkmf extconf.rb
3
4 require 'rbconfig'
5 require 'find'
6 require 'shellwords'
7
8 CONFIG = Config::MAKEFILE_CONFIG
9 ORIG_LIBPATH = ENV['LIB']
10
11 SRC_EXT = ["c", "cc", "m", "cxx", "cpp", "C"]
12
13 unless defined? $configure_args
14 $configure_args = {}
15 args = CONFIG["configure_args"]
16 if /mswin32|bccwin32|mingw/ =~ RUBY_PLATFORM and ENV["CONFIGURE_ARGS"]
17 args << " " << ENV["CONFIGURE_ARGS"]
18 end
19 for arg in Shellwords::shellwords(args)
20 arg, val = arg.split('=', 2)
21 if arg.sub!(/^(?!--)/, '--')
22 val or next
23 arg.downcase!
24 end
25 next if /^--(?:top|topsrc|src|cur)dir$/ =~ arg
26 $configure_args[arg] = val || true
27 end
28 for arg in ARGV
29 arg, val = arg.split('=', 2)
30 if arg.sub!(/^(?!--)/, '--')
31 val or next
32 arg.downcase!
33 end
34 $configure_args[arg] = val || true
35 end
36 end
37
38 $srcdir = CONFIG["srcdir"]
39 $libdir = CONFIG["libdir"]
40 $rubylibdir = CONFIG["rubylibdir"]
41 $archdir = CONFIG["archdir"]
42 $sitedir = CONFIG["sitedir"]
43 $sitelibdir = CONFIG["sitelibdir"]
44 $sitearchdir = CONFIG["sitearchdir"]
45
46 $extmk = /extmk\.rb/ =~ $0
47
48 def dir_re(dir)
49 Regexp.new('\$(?:\('+dir+'\)|\{'+dir+'\})(?:\$\(target_prefix\)|\{target_prefix\})?')
50 end
51 commondir = dir_re('commondir')
52
53 INSTALL_DIRS = [
54 [commondir, "$(rubylibdir)"],
55 [dir_re('sitelibdir'), "$(rubylibdir)$(target_prefix)"],
56 [dir_re('sitearchdir'), "$(archdir)$(target_prefix)"]
57 ]
58
59 SITEINSTALL_DIRS = [
60 [commondir, "$(sitedir)$(target_prefix)"],
61 [dir_re('rubylibdir'), "$(sitelibdir)$(target_prefix)"],
62 [dir_re('archdir'), "$(sitearchdir)$(target_prefix)"]
63 ]
64
65 if not $extmk and File.exist? Config::CONFIG["archdir"] + "/ruby.h"
66 $hdrdir = $archdir
67 elsif File.exist? $srcdir + "/ruby.h"
68 $hdrdir = $srcdir
69 else
70 STDERR.print "can't find header files for ruby.\n"
71 exit 1
72 end
73 $topdir = $hdrdir
74 # $hdrdir.gsub!('/', '\\') if RUBY_PLATFORM =~ /mswin32|bccwin32/
75
76 CFLAGS = CONFIG["CFLAGS"]
77 if RUBY_PLATFORM == "m68k-human"
78 CFLAGS.gsub!(/-c..-stack=[0-9]+ */, '')
79 elsif RUBY_PLATFORM =~ /-nextstep|-rhapsody|-darwin/
80 CFLAGS.gsub!( /-arch\s\w*/, '' )
81 end
82
83 if /mswin32/ =~ RUBY_PLATFORM
84 OUTFLAG = '-Fe'
85 CPPOUTFILE = '-P'
86 elsif /bccwin32/ =~ RUBY_PLATFORM
87 OUTFLAG = '-o'
88 CPPOUTFILE = '-oconftest.i'
89 else
90 OUTFLAG = '-o '
91 CPPOUTFILE = '-o conftest.i'
92 end
93
94 $LINK = "#{CONFIG['CC']} #{OUTFLAG}conftest %s -I#{$hdrdir} %s #{CFLAGS} %s #{CONFIG['LDFLAGS']} %s conftest.c %s %s #{CONFIG['LIBS']}"
95 $CC = "#{CONFIG['CC']} -c #{CONFIG['CPPFLAGS']} %s -I#{$hdrdir} %s #{CFLAGS} %s %s conftest.c"
96 $CPP = "#{CONFIG['CPP']} #{CONFIG['CPPFLAGS']} %s -I#{$hdrdir} %s #{CFLAGS} %s %s %s conftest.c"
97
98 def rm_f(*files)
99 targets = []
100 for file in files
101 targets.concat Dir[file]
102 end
103 if not targets.empty?
104 File::chmod(0777, *targets)
105 File::unlink(*targets)
106 end
107 end
108
109 def older(file1, file2)
110 if !File.exist?(file1) then
111 return true
112 end
113 if !File.exist?(file2) then
114 return false
115 end
116 if File.mtime(file1) < File.mtime(file2)
117 return true
118 end
119 return false
120 end
121
122 module Logging
123 @log = nil
124 @logfile = 'mkmf.log'
125 @orgerr = $stderr.dup
126 @orgout = $stdout.dup
127
128 def self::open
129 @log ||= File::open(@logfile, 'w')
130 $stderr.reopen(@log)
131 $stdout.reopen(@log)
132 yield
133 ensure
134 $stderr.reopen(@orgerr)
135 $stdout.reopen(@orgout)
136 end
137
138 def self::logfile file
139 @logfile = file
140 if @log and not @log.closed?
141 @log.close
142 @log = nil
143 end
144 end
145 end
146
147 def xsystem command
148 Config.expand(command)
149 Logging::open do
150 puts command
151 system(command)
152 end
153 end
154
155 def xpopen command, *mode, &block
156 Config.expand(command)
157 Logging::open do
158 case mode[0]
159 when nil, /^r/
160 puts "#{command} |"
161 else
162 puts "| #{command}"
163 end
164 IO.popen(command, *mode, &block)
165 end
166 end
167
168 def try_link0(src, opt="")
169 cfile = open("conftest.c", "w")
170 cfile.print src
171 cfile.close
172 ldflags = $LDFLAGS
173 if /mswin32|bccwin32/ =~ RUBY_PLATFORM and !$LIBPATH.empty?
174 ENV['LIB'] = ($LIBPATH + [ORIG_LIBPATH]).compact.join(';')
175 else
176 $LDFLAGS = ldflags.dup
177 $LIBPATH.each {|d| $LDFLAGS << " -L" + d}
178 end
179 begin
180 xsystem(format($LINK, $INCFLAGS, $CPPFLAGS, $CFLAGS, $LDFLAGS, opt, $LOCAL_LIBS))
181 ensure
182 $LDFLAGS = ldflags
183 ENV['LIB'] = ORIG_LIBPATH if /mswin32|bccwin32/ =~ RUBY_PLATFORM
184 end
185 end
186
187 def try_link(src, opt="")
188 begin
189 try_link0(src, opt)
190 ensure
191 rm_f "conftest*"
192 if /bccwin32/ =~ RUBY_PLATFORM
193 rm_f "c0x32*"
194 end
195 end
196 end
197
198 def try_compile(src, opt="")
199 cfile = open("conftest.c", "w")
200 cfile.print src
201 cfile.close
202 begin
203 xsystem(format($CC, $INCFLAGS, $CPPFLAGS, $CFLAGS, opt))
204 ensure
205 rm_f "conftest*"
206 end
207 end
208
209 def try_cpp(src, opt="")
210 cfile = open("conftest.c", "w")
211 cfile.print src
212 cfile.close
213 begin
214 xsystem(format($CPP, $INCFLAGS, $CPPFLAGS, $CFLAGS, CPPOUTFILE, opt))
215 ensure
216 rm_f "conftest*"
217 end
218 end
219
220 def egrep_cpp(pat, src, opt="")
221 cfile = open("conftest.c", "w")
222 cfile.print src
223 cfile.close
224 begin
225 xpopen(format($CPP, $INCFLAGS, $CPPFLAGS, $CFLAGS, '', opt)) do |f|
226 if Regexp === pat
227 puts(" ruby -ne 'print if /#{pat.source}/'")
228 f.grep(pat) {|l|
229 puts "#{f.lineno}: #{l}"
230 return true
231 }
232 false
233 else
234 puts(" egrep '#{pat}'")
235 begin
236 stdin = $stdin.dup
237 $stdin.reopen(f)
238 system("egrep", pat)
239 ensure
240 $stdin.reopen(stdin)
241 end
242 end
243 end
244 ensure
245 rm_f "conftest*"
246 end
247 end
248
249 def macro_defined?(macro, src, opt="")
250 try_cpp(src + <<EOP, opt)
251 #ifndef #{macro}
252 # error
253 #endif
254 EOP
255 end
256
257 def try_run(src, opt="")
258 begin
259 if try_link0(src, opt)
260 if xsystem("./conftest")
261 true
262 else
263 false
264 end
265 else
266 nil
267 end
268 ensure
269 rm_f "conftest*"
270 end
271 end
272
273 def install_files(mfile, ifiles, map = INSTALL_DIRS, srcprefix = nil)
274 ifiles or return
275 srcprefix ||= '$(srcdir)'
276 Config::expand(srcdir = srcprefix.dup)
277 dirs = []
278 path = Hash.new {|h, i| h[i] = dirs.push([i])[-1]}
279 ifiles.each do |files, dir, prefix|
280 dir = map.inject(dir) {|dir, (orig, new)| dir.gsub(orig, new)} if map
281 prefix = %r"\A#{Regexp.quote(prefix)}/?" if prefix
282 if( files[0,2] == "./" )
283 # install files which are in current working directory.
284 Dir.glob(files) do |f|
285 d = File.dirname(f)
286 d.sub!(prefix, "") if prefix
287 d = (d.empty? || d == ".") ? dir : File.join(dir,d)
288 path[d] << f
289 end
290 else
291 # install files which are under the $(srcdir).
292 Dir.glob(File.join(srcdir,files)) do |f|
293 f[0..srcdir.size] = ""
294 d = File.dirname(f)
295 d.sub!(prefix, "") if prefix
296 d = (d.empty? || d == ".") ? dir : File.join(dir, d)
297 path[d] << (srcprefix ? File.join(srcprefix, f) : f)
298 end
299 end
300 end
301
302 dirs.each do |dir, *files|
303 mfile.printf("\t@$(MAKEDIRS) %s\n", dir)
304 files.each do |f|
305 mfile.printf("\t@$(INSTALL_DATA) %s %s\n", f, dir)
306 end
307 end
308 end
309
310 def install_rb(mfile, dest, srcdir = nil)
311 install_files(mfile, [["lib/**/*.rb", dest, "lib"]], nil, srcdir)
312 end
313
314 def append_library(libs, lib)
315 if /mswin32|bccwin32/ =~ RUBY_PLATFORM
316 lib + ".lib " + libs
317 else
318 "-l" + lib + " " + libs
319 end
320 end
321
322 def message(*s)
323 unless $extmk and not $VERBOSE
324 print(*s)
325 STDOUT.flush
326 end
327 end
328
329 def have_library(lib, func="main")
330 message "checking for #{func}() in -l#{lib}... "
331
332 if func && func != ""
333 libs = append_library($libs, lib)
334 if /mswin32|bccwin32|mingw/ =~ RUBY_PLATFORM
335 if lib == 'm'
336 message "yes\n"
337 return true
338 end
339 r = try_link(<<"SRC", libs)
340 #define WIN32_LEAN_AND_MEAN
341 #include <windows.h>
342 #include <winsock.h>
343 int main() { return 0; }
344 int t() { #{func}(); return 0; }
345 SRC
346 unless r
347 r = try_link(<<"SRC", libs)
348 #define WIN32_LEAN_AND_MEAN
349 #include <windows.h>
350 #include <winsock.h>
351 int main() { return 0; }
352 int t() { void ((*p)()); p = (void ((*)()))#{func}; return 0; }
353 SRC
354 end
355 else
356 r = try_link(<<"SRC", libs)
357 int main() { return 0; }
358 int t() { #{func}(); return 0; }
359 SRC
360 end
361 unless r
362 message "no\n"
363 return false
364 end
365 else
366 libs = append_library($libs, lib)
367 end
368
369 $libs = libs
370 message "yes\n"
371 return true
372 end
373
374 def find_library(lib, func, *paths)
375 message "checking for #{func}() in -l#{lib}... "
376
377 libpath = $LIBPATH
378 libs = append_library($libs, lib)
379 until try_link(<<"SRC", libs)
380 int main() { return 0; }
381 int t() { #{func}(); return 0; }
382 SRC
383 if paths.size == 0
384 $LIBPATH = libpath
385 message "no\n"
386 return false
387 end
388 $LIBPATH = libpath | [paths.shift]
389 end
390 $libs = libs
391 message "yes\n"
392 return true
393 end
394
395 def have_func(func, header=nil)
396 message "checking for #{func}()... "
397
398 libs = $libs
399 src =
400 if /mswin32|bccwin32|mingw/ =~ RUBY_PLATFORM
401 r = <<"SRC"
402 #define WIN32_LEAN_AND_MEAN
403 #include <windows.h>
404 #include <winsock.h>
405 SRC
406 else
407 ""
408 end
409 unless header.nil?
410 src << <<"SRC"
411 #include <#{header}>
412 SRC
413 end
414 r = try_link(src + <<"SRC", libs)
415 int main() { return 0; }
416 int t() { #{func}(); return 0; }
417 SRC
418 unless r
419 r = try_link(src + <<"SRC", libs)
420 int main() { return 0; }
421 int t() { void ((*volatile p)()); p = (void ((*)()))#{func}; return 0; }
422 SRC
423 end
424 unless r
425 message "no\n"
426 return false
427 end
428 $defs.push(format("-DHAVE_%s", func.upcase))
429 message "yes\n"
430 return true
431 end
432
433 def have_header(header)
434 message "checking for #{header}... "
435
436 unless try_cpp(<<"SRC")
437 #include <#{header}>
438 SRC
439 message "no\n"
440 return false
441 end
442 $defs.push(format("-DHAVE_%s", header.tr("a-z./\055", "A-Z___")))
443 message "yes\n"
444 return true
445 end
446
447 def have_struct_member(type, member, header=nil)
448 message "checking for #{type}.#{member}... "
449
450 src =
451 if /mswin32|bccwin32|mingw/ =~ RUBY_PLATFORM
452 r = <<"SRC"
453 #define WIN32_LEAN_AND_MEAN
454 #include <windows.h>
455 #include <winsock.h>
456 SRC
457 else
458 ""
459 end
460 unless header.nil?
461 header = [header] unless header.kind_of? Array
462 header.each {|h|
463 src << <<"SRC"
464 #include <#{h}>
465 SRC
466 }
467 end
468 src << <<"SRC"
469 int main() { return 0; }
470 int s = (char *)&((#{type}*)0)->#{member} - (char *)0;
471 SRC
472 r = try_compile(src)
473 unless r
474 message "no\n"
475 return false
476 end
477 $defs.push(format("-DHAVE_ST_%s", member.upcase))
478 message "yes\n"
479 return true
480 end
481
482 def find_executable(bin, path = nil)
483 message "checking for #{bin}... "
484
485 if path.nil?
486 path = ENV['PATH'].split(Config::CONFIG['PATH_SEPARATOR'])
487 else
488 path = path.split(Config::CONFIG['PATH_SEPARATOR'])
489 end
490
491 bin += Config::CONFIG['EXEEXT']
492 for dir in path
493 file = File.join(dir, bin)
494 if FileTest.executable?(file)
495 message "yes\n"
496 return file
497 else
498 next
499 end
500 end
501 message "no\n"
502 return nil
503 end
504
505 def arg_config(config, default=nil)
506 $configure_args.fetch(config, default)
507 end
508
509 def with_config(config, default=nil)
510 unless /^--with-/ =~ config
511 config = '--with-' + config
512 end
513 arg_config(config, default)
514 end
515
516 def enable_config(config, default=nil)
517 if arg_config("--enable-"+config)
518 true
519 elsif arg_config("--disable-"+config)
520 false
521 else
522 default
523 end
524 end
525
526 def create_header()
527 message "creating extconf.h\n"
528 if $defs.length > 0
529 open("extconf.h", "w") do |hfile|
530 for line in $defs
531 line =~ /^-D(.*)/
532 hfile.printf "#define %s 1\n", $1
533 end
534 end
535 end
536 end
537
538 def dir_config(target, idefault=nil, ldefault=nil)
539 if dir = with_config(target + "-dir", (idefault unless ldefault))
540 idefault = dir + "/include"
541 ldefault = dir + "/lib"
542 end
543
544 idir = with_config(target + "-include", idefault)
545 ldir = with_config(target + "-lib", ldefault)
546
547 if idir
548 idircflag = "-I" + idir
549 $CPPFLAGS += " " + idircflag unless $CPPFLAGS.split.include?(idircflag)
550 end
551
552 if ldir
553 $LIBPATH << ldir unless $LIBPATH.include?(ldir)
554 end
555
556 [idir, ldir]
557 end
558
559 def with_destdir(dir)
560 /^\$[\(\{]/ =~ dir ? dir : "$(DESTDIR)"+dir
561 end
562
563 def winsep(s)
564 s.tr('/', '\\')
565 end
566
567 def create_makefile(target, srcprefix = nil)
568 save_libs = $libs.dup
569 save_libpath = $LIBPATH.dup
570 message "creating Makefile\n"
571 rm_f "conftest*"
572 if target.include?('/')
573 target_prefix, target = File.split(target)
574 target_prefix[0,0] = '/'
575 else
576 target_prefix = ""
577 end
578 if CONFIG["DLEXT"] == $OBJEXT
579 libs = $libs.split
580 for lib in libs
581 lib.sub!(/-l(.*)/, '"lib\1.a"')
582 end
583 $defs.push(format("-DEXTLIB='%s'", libs.join(",")))
584 end
585 $DLDFLAGS = CONFIG["DLDFLAGS"]
586
587 $libs = CONFIG["LIBRUBYARG"] + " " + $libs + " " + CONFIG["LIBS"]
588 $configure_args['--enable-shared'] or $LIBPATH |= [$topdir]
589 $LIBPATH |= [CONFIG["libdir"]]
590
591 srcprefix ||= '$(srcdir)'
592 Config::expand(srcdir = srcprefix.dup)
593 defflag = ''
594 if RUBY_PLATFORM =~ /bccwin32/
595 deffile = target + '.def'
596 if not File.exist? deffile
597 open(deffile, 'wb') do |f|
598 f.print "EXPORTS\n", "_Init_", target, "\n"
599 end
600 end
601 elsif RUBY_PLATFORM =~ /cygwin|mingw/
602 deffile = target + '.def'
603 if not File.exist? deffile
604 if File.exist? File.join(srcdir, deffile)
605 deffile = File.join srcdir, deffile
606 else
607 open(deffile, 'wb') do |f|
608 f.print "EXPORTS\n", "Init_", target, "\n"
609 end
610 end
611 end
612 defflag = deffile
613 end
614
615 if RUBY_PLATFORM =~ /mswin32|bccwin32/
616 libpath = $LIBPATH.join(';')
617 else
618 $LIBPATH.each {|d| $DLDFLAGS << " -L" << d}
619 if /netbsdelf/ =~ RUBY_PLATFORM
620 $LIBPATH.each {|d| $DLDFLAGS << " -Wl,-R" + d}
621 end
622 end
623 drive = File::PATH_SEPARATOR == ';' ? /\A\w:/ : /\A/
624
625 unless $objs then
626 $objs = []
627 for f in Dir[File.join(srcdir, "*.{#{SRC_EXT.join(%q{,})}}")]
628 f = File.basename(f)
629 f.sub!(/(#{SRC_EXT.join(%q{|})})$/, $OBJEXT)
630 $objs.push f
631 end
632 else
633 for i in $objs
634 i.sub!(/\.o\z/, ".#{$OBJEXT}")
635 end
636 end
637 $objs = $objs.join(" ")
638
639 mfile = open("Makefile", "w")
640 mfile.binmode if /mingw/ =~ RUBY_PLATFORM
641 mfile.print <<EOMF
642 SHELL = /bin/sh
643
644 #### Start of system configuration section. ####
645
646 srcdir = #{srcdir}
647 topdir = #{$topdir}
648 hdrdir = #{$hdrdir}
649 VPATH = $(srcdir)
650
651 CC = #{CONFIG["CC"]}
652
653 CFLAGS = #{CONFIG["CCDLFLAGS"]} #{CFLAGS} #{$CFLAGS}
654 CPPFLAGS = -I. -I$(hdrdir) -I$(srcdir) #{$defs.join(" ")} #{CONFIG["CPPFLAGS"]} #{$CPPFLAGS}
655 CXXFLAGS = $(CFLAGS)
656 #{
657 if /bccwin32/ =~ RUBY_PLATFORM
658 "DLDFLAGS = #$LDFLAGS -L\"$(libdir:/=\\);$(topdir:/=\\)\"\n" +
659 "LDSHARED = #{CONFIG['LDSHARED']}\n"
660 else
661 "DLDFLAGS = #{$DLDFLAGS} #{$LDFLAGS}\n" +
662 "LDSHARED = #{CONFIG['LDSHARED']} #{defflag}\n"
663 end
664 }
665 LIBPATH = #{libpath}
666
667 RUBY_INSTALL_NAME = #{CONFIG["RUBY_INSTALL_NAME"]}
668 RUBY_SO_NAME = #{CONFIG["RUBY_SO_NAME"]}
669 arch = #{CONFIG["arch"]}
670 sitearch = #{CONFIG["sitearch"]}
671 ruby_version = #{Config::CONFIG["ruby_version"]}
672 EOMF
673 if destdir = CONFIG["prefix"].scan(drive)[0] and !destdir.empty?
674 mfile.print "\nDESTDIR = ", destdir, "\n"
675 end
676 CONFIG.each do |key, var|
677 next unless /prefix$/ =~ key
678 mfile.print key, " = ", with_destdir(var.sub(drive, '')), "\n"
679 end
680 CONFIG.each do |key, var|
681 next unless /^(?:src|top|(.*))dir$/ =~ key and $1
682 mfile.print key, " = ", with_destdir(var.sub(drive, '')), "\n"
683 end
684 mfile.print <<EOMF
685 target_prefix = #{target_prefix}
686
687 #### End of system configuration section. ####
688
689 LOCAL_LIBS = #{$LOCAL_LIBS} #{$local_flags}
690 LIBS = #{$libs}
691 OBJS = #{$objs}
692
693 TARGET = #{target}
694 DLLIB = $(TARGET).#{CONFIG["DLEXT"]}
695
696 RUBY = #{CONFIG["ruby_install_name"]}
697 RM = $(RUBY) -rftools -e "File::rm_f(*ARGV.map do|x|Dir[x]end.flatten.uniq)"
698 MAKEDIRS = $(RUBY) -r ftools -e 'File::makedirs(*ARGV)'
699 INSTALL_PROG = $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0555, true)'
700 INSTALL_DATA = $(RUBY) -r ftools -e 'File::install(ARGV[0], ARGV[1], 0644, true)'
701
702 EXEEXT = #{CONFIG["EXEEXT"]}
703
704 all: $(DLLIB)
705
706 clean:
707 @$(RM) *.#{$OBJEXT} *.so *.sl *.a $(DLLIB)
708 #{
709 if /bccwin32/ =~ RUBY_PLATFORM
710 " @$(RM) $(TARGET).lib $(TARGET).def $(TARGET).ilc $(TARGET).ild $(TARGET).ilf $(TARGET).ils $(TARGET).tds $(TARGET).map $(CLEANFILES)\n"+
711 " @if exist $(target).def.org ren $(target).def.org $(target).def"
712 else
713 " @$(RM) $(TARGET).lib $(TARGET).exp $(TARGET).ilk *.pdb $(CLEANFILES)"
714 end
715 }
716
717 distclean: clean
718 @$(RM) Makefile extconf.h conftest.* mkmf.log
719 @$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
720
721 realclean: distclean
722
723 install: $(archdir)$(target_prefix)/$(DLLIB)
724
725 site-install: $(sitearchdir)$(target_prefix)/$(DLLIB)
726
727 $(archdir)$(target_prefix)/$(DLLIB): $(DLLIB)
728 @$(MAKEDIRS) $(rubylibdir) $(archdir)$(target_prefix)
729 @$(INSTALL_PROG) $(DLLIB) $(archdir)$(target_prefix)/$(DLLIB)
730
731 $(sitearchdir)$(target_prefix)/$(DLLIB): $(DLLIB)
732 @$(MAKEDIRS) $(sitearchdir)$(target_prefix)
733 @$(INSTALL_PROG) $(DLLIB) $(sitearchdir)$(target_prefix)/$(DLLIB)
734
735 EOMF
736 mfile.print "install:\n"
737 install_rb(mfile, "$(rubylibdir)$(target_prefix)", srcprefix)
738 install_files(mfile, $INSTALLFILES, INSTALL_DIRS, srcprefix)
739 mfile.print "\n"
740 mfile.print "site-install:\n"
741 install_rb(mfile, "$(sitelibdir)$(target_prefix)", srcprefix)
742 install_files(mfile, $INSTALLFILES, SITEINSTALL_DIRS, srcprefix)
743
744 unless /mswin32/ =~ RUBY_PLATFORM
745 if /bccwin32/ =~ RUBY_PLATFORM
746 src = '$(<:\\=/)'
747 else
748 src = '$<'
749 end
750 copt = cxxopt = ''
751 else
752 if /nmake/i =~ $make
753 src = '$(<:\\=/)'
754 else
755 src = '$(subst /,\\\\,$<)'
756 end
757 copt = '-Tc'
758 cxxopt = '-Tp'
759 end
760
761 mfile.print ".SUFFIXES: .#{SRC_EXT.join(' .')} .#{$OBJEXT}\n"
762 unless /nmake/i =~ $make
763 if /bccwin32/ =~ RUBY_PLATFORM
764 mfile.print "
765 {$(srcdir)}.cc{}.@OBJEXT@:
766 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
767 {$(srcdir)}.cpp{}.@OBJEXT@:
768 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
769 {$(srcdir)}.cxx{}.@OBJEXT@:
770 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
771 {$(srcdir)}.c{}.@OBJEXT@:
772 $(CC) $(CFLAGS) $(CPPFLAGS) -c #{copt}#{src}
773 "
774 end
775 mfile.puts "
776 .cc.#{$OBJEXT}:
777 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
778 .cpp.#{$OBJEXT}:
779 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
780 .cxx.#{$OBJEXT}:
781 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
782 .C.#{$OBJEXT}:
783 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
784 .c.#{$OBJEXT}:
785 $(CC) $(CFLAGS) $(CPPFLAGS) -c #{copt}#{src}
786 "
787 else
788 mfile.print "
789 {$(srcdir)}.c{}.#{$OBJEXT}:
790 $(CC) -I. -I$(<D) $(CFLAGS) $(CPPFLAGS) -c #{copt}#{src}
791 .c.#{$OBJEXT}:
792 $(CC) $(CFLAGS) $(CPPFLAGS) -c #{copt}#{src}
793 {$(srcdir)}.cc{}.#{$OBJEXT}:
794 $(CXX) -I. -I$(<D) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
795 .cc.#{$OBJEXT}:
796 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
797 {$(srcdir)}.cpp{}.#{$OBJEXT}:
798 $(CXX) -I. -I$(<D) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
799 .cpp.#{$OBJEXT}:
800 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
801 {$(srcdir)}.cxx{}.#{$OBJEXT}:
802 $(CXX) -I. -I$(<D) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
803 .cxx.#{$OBJEXT}:
804 $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c #{cxxopt}#{src}
805 "
806 end
807
808 if CONFIG["DLEXT"] != $OBJEXT
809 mfile.print "$(DLLIB): $(OBJS)\n"
810 if /bccwin32/ =~ RUBY_PLATFORM
811 mfile.print "\t$(LDSHARED) $(DLDFLAGS) C0D32.OBJ $(OBJS), $@,, CW32.LIB IMPORT32.LIB WS2_32.LIB $(LIBS), #{deffile}\n"
812 else
813 if /mswin32|bccwin32/ =~ RUBY_PLATFORM
814 if /nmake/i =~ $make
815 mfile.print "\tset LIB=$(LIBPATH:/=\\);$(LIB)\n"
816 else
817 mfile.print "\tenv LIB='$(subst /,\\\\,$(LIBPATH));$(LIB)' \\\n"
818 end
819 end
820 mfile.print "\t$(LDSHARED) $(DLDFLAGS) #{OUTFLAG}$(DLLIB) $(OBJS) $(LIBS) $(LOCAL_LIBS)\n"
821 end
822 elsif not File.exist?(target + ".c") and not File.exist?(target + ".cc")
823 mfile.print "$(DLLIB): $(OBJS)\n"
824 case RUBY_PLATFORM
825 when "m68k-human"
826 mfile.printf "ar cru $(DLLIB) $(OBJS)\n"
827 else
828 mfile.printf "ld $(DLDFLAGS) -r -o $(DLLIB) $(OBJS)\n"
829 end
830 end
831
832 depend = File.join(srcdir, "depend")
833 if File.exist?(depend)
834 dfile = open(depend, "r")
835 mfile.printf "###\n"
836 while line = dfile.gets()
837 line.gsub!(/\.o\b/, ".#{$OBJEXT}")
838 line.gsub!(/(\s)([^\s\/]+\.[ch])/, '\1{$(srcdir)}\2') if /nmake/i =~ $make
839 mfile.printf "%s", line
840 end
841 dfile.close
842 end
843 mfile.close
844 $libs = save_libs
845 $LIBPATH = save_libpath
846 end
847
848 $OBJEXT = CONFIG["OBJEXT"]
849 $objs = nil
850 $libs = CONFIG["DLDLIBS"]
851 $local_flags = ""
852 case RUBY_PLATFORM
853 when /mswin32/
854 $local_flags = "-link /INCREMENTAL:no /EXPORT:Init_$(TARGET)"
855 end
856 $LOCAL_LIBS = ""
857 $defs = []
858
859 $make = with_config("make-prog", ENV["MAKE"] || "make")
860
861 $CFLAGS = with_config("cflags", arg_config("CFLAGS", ""))
862 $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS", ""))
863 $LDFLAGS = with_config("ldflags", arg_config("LDFLAGS", ""))
864 $LIBPATH = []
865 $INCFLAGS = ""
866
867 dir_config("opt")
868
869 Config::CONFIG["srcdir"] = CONFIG["srcdir"] =
870 $srcdir = arg_config("--srcdir", File.dirname($0))
871 $configure_args["--topsrcdir"] ||= $srcdir
872 Config::CONFIG["topdir"] = CONFIG["topdir"] =
873 $curdir = arg_config("--curdir", Dir.pwd)
874 $configure_args["--topdir"] ||= $curdir