Skip to content

Instantly share code, notes, and snippets.

@jballanc
Created August 27, 2010 06:37
Show Gist options
  • Save jballanc/552924 to your computer and use it in GitHub Desktop.
Save jballanc/552924 to your computer and use it in GitHub Desktop.
diff --git a/bin/rubyc b/bin/rubyc
index c14de80..cbb9448 100644
--- a/bin/rubyc
+++ b/bin/rubyc
@@ -16,6 +16,7 @@ class Compiler
@archs = []
@internal = argv.delete('--internal')
@frameworks = %w{Foundation}
+ @linkf = []
# Parse arguments.
OptionParser.new do |opts|
@@ -26,6 +27,9 @@ class Compiler
opts.on('--framework <name>', "Link standalone static executable with given framework") { |p| @frameworks << p }
opts.on('--sdk <path>', "Use SDK when compiling standalone static executable") { |x| @sdk = x }
opts.on('--dylib', "Create a dynamic library") { @dylib = true }
+ opts.on('--compatibility_version <VERSION>', "Compatibility Version for linking") { |ver| @linkf << "-compatibility_version #{ver}" }
+ opts.on('--current_version <VERSION>', "Current Version for linking") { |ver| @linkf << "-current_version #{ver}" }
+ opts.on('--install_name <NAME>', "Install Name for linking") { |name| @linkf << "-install_name #{name}" }
opts.on('-C', 'Compile, assemble and link a loadable object file') { @bundle = true }
opts.on('-a', '--arch <ARCH>', 'Compile for specified CPU architecture') { |arch| @archs << arch }
opts.on('-v', '--version', 'Display the version') { puts RUBY_DESCRIPTION; exit 1 }
@@ -139,7 +143,7 @@ class Compiler
end
def cleanup
- @tmpfiles.each { |x| File.delete(x) }
+ @tmpfiles.each { |x| File.delete(x) if File.exist?(x) }
end
private
@@ -224,9 +228,9 @@ EOS
# Build.
main = gen_tmpfile('main', 'c')
File.open(main, 'w') { |io| io.write(main_txt) }
- linkf = @internal ? "-L. -lmacruby" : "-L#{RbConfig::CONFIG['libdir']} -lmacruby"
+ @linkf << @internal ? "-L. -lmacruby" : "-L#{RbConfig::CONFIG['libdir']} -lmacruby"
objs = objs_data.map { |obj, f| "\"#{obj}\"" }.join(' ')
- execute("#{@gcxx} \"#{main}\" -dynamiclib -dynamic -undefined suppress -flat_namespace #{arch_flags} #{linkf} #{objs} -o \"#{output}\"")
+ execute("#{@gcxx} \"#{main}\" -dynamiclib -dynamic -undefined suppress -flat_namespace #{arch_flags} #{@linkf.join(' ')} #{objs} -o \"#{output}\"")
strip(output)
end
diff --git a/rubyc.1 b/rubyc.1
index 75f0877..5a945ea 100644
--- a/rubyc.1
+++ b/rubyc.1
@@ -45,15 +45,6 @@ using a default file name which consists of the source file name with the .rbo f
.Nm require
method.
.Pp
-.It Fl -dylib
-Create a dynamic library instead of an executable. This option compiles every Ruby source file passed to
-.Nm macrubyc
-and produces a Mach-O dynamic library (.dylib). This library is compiled with a global constructor that will register every Ruby machine code file into the MacRuby runtime once it's loaded by the dynamic linker, at runtime. This library is intended to be linked against an executable that uses the MacRuby runtime, for example executables generated by
-.Nm macrubyc .
-The
-.Fl o
-option must be provided when building dynamic libraries.
-.Pp
.It Fl h, Fl -help
Display a short description of the command line options.
.Pp
@@ -64,6 +55,26 @@ If this option is not given,
.Nm macrubyc
will try to determine a default output file name based on the object file type that is being generated. For executables, the default is a.out. For objects, the default is the original source file name with the object type extension. For dynamic libraries, this option is mandatory.
.Pp
+.It Fl -dylib
+Create a dynamic library instead of an executable. This option compiles every Ruby source file passed to
+.Nm macrubyc
+and produces a Mach-O dynamic library (.dylib). This library is compiled with a global constructor that will register every Ruby machine code file into the MacRuby runtime once it's loaded by the dynamic linker, at runtime. This library is intended to be linked against an executable that uses the MacRuby runtime, for example executables generated by
+.Nm macrubyc .
+The
+.Fl o
+option must be provided when building dynamic libraries.
+.Pp
+.Bl -tag -width XXXXXXXXXX
+The
+.Fl -dylib
+option can also take the following optional linker arguments (see
+.Xr libtool 1
+for more information):
+.It Fl -compatibility_version Ar VERSION
+.It Fl -current_version Ar VERSION
+.It Fl -install_name Ar NAME
+.El
+.Pp
.It Fl -static
Create a standalone, static executable. By default, executables created by
.Nm macrubyc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment