summaryrefslogtreecommitdiff
path: root/ext/cygwin32_ld.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:39 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-01-20 04:59:39 +0000
commit62e648e148b3cb9f96dcce808c55c02b7ccb4486 (patch)
tree9708892ece92e860d81559ab55e6b1f9400d7ffc /ext/cygwin32_ld.rb
parentaeb049c573be4dc24dd20650f40e4777e0f698cf (diff)
ruby 1.3 cycle
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/RUBY@372 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/cygwin32_ld.rb')
-rw-r--r--ext/cygwin32_ld.rb90
1 files changed, 90 insertions, 0 deletions
diff --git a/ext/cygwin32_ld.rb b/ext/cygwin32_ld.rb
new file mode 100644
index 0000000000..a9c8e21cb0
--- /dev/null
+++ b/ext/cygwin32_ld.rb
@@ -0,0 +1,90 @@
+#!/usr/local/bin/ruby
+require '../../rbconfig'
+include Config
+
+args = ARGV.join(" ")
+
+objs = []
+flags = []
+libname = ''
+Init = "../init"
+
+path = ''
+
+def writeInit
+ out = open("#{Init}.c", "w")
+
+ out.print %q@
+#include <windows.h>
+#include <stdio.h>
+
+extern struct _reent *__imp_reent_data;
+WINAPI dll_entry(int a, int b, int c)
+{
+ _impure_ptr =__imp_reent_data;
+ return 1;
+}
+main(){}
+//void impure_setup(struct _reent *_impure_ptrMain)
+//{
+// _impure_ptr =__imp_reent_data;
+//}
+@
+ out.close
+end
+
+def xsystem cmd
+ print cmd, "\n"
+ system cmd
+end
+
+if args =~ /-o (\w+)\.dll/i
+ libname = $1
+ # Check for path:
+ if libname =~ /(\w+\/)(\w+)$/
+ path = $1
+ libname = $2
+ end
+ for arg in ARGV
+ case arg
+ when /\.[oa]$/i
+ objs.push(arg)
+ when /-o/, /\w+\.dll/i
+ ;
+ else
+ flags << arg
+ end
+ end
+
+ writeInit unless FileTest.exist?("#{Init}.c")
+ unless FileTest.exist?("#{Init}.o") and
+ File.mtime("#{Init}.c") < File.mtime("#{Init}.o")
+ xsystem "gcc -c #{Init}.c -o #{Init}.o"
+ end
+
+ command = "echo EXPORTS > #{libname}.def"
+ xsystem command
+# xsystem "echo impure_setup >> #{libname}.def"
+ xsystem "nm --extern-only " + objs.join(" ") +
+ " | sed -n '/^........ [CDT] _/s///p' >> #{libname}.def"
+
+ command = "gcc -nostdlib -o junk.o -Wl,--base-file,#{libname}.base,--dll " +
+ objs.join(" ") + " #{Init}.o "
+ command.concat(flags.join(" ") +
+ " -Wl,-e,_dll_entry@12 -lcygwin -lkernel32 #{CONFIG['srcdir']}/libruby.a")
+ xsystem command
+
+ command = "dlltool --as=as --dllname #{libname}.dll --def #{libname}.def --base-file #{libname}.base --output-exp #{libname}.exp"
+ xsystem command
+
+ command = "gcc -s -nostdlib -o #{libname}.dll -Wl,--dll #{libname}.exp " +
+ objs.join(" ") + " #{Init}.o "
+ command.concat(flags.join(" ") +
+ " -Wl,-e,_dll_entry@12 -lcygwin -lkernel32 #{CONFIG['srcdir']}/libruby.a")
+ xsystem command
+ File.unlink "junk.o" if FileTest.exist? "junk.o"
+
+else
+ # no special processing, just call ld
+ xsystem "ld #{args}"
+end