summaryrefslogtreecommitdiff
path: root/template/ruby-runner.c.in
diff options
context:
space:
mode:
Diffstat (limited to 'template/ruby-runner.c.in')
-rw-r--r--template/ruby-runner.c.in27
1 files changed, 27 insertions, 0 deletions
diff --git a/template/ruby-runner.c.in b/template/ruby-runner.c.in
new file mode 100644
index 0000000000..56386a8d6f
--- /dev/null
+++ b/template/ruby-runner.c.in
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define BUILDDIR "@abs_top_builddir@"
+#define LIBPATHENV "@LIBPATHENV@"
+
+int
+main(int argc, char **argv)
+{
+ static const char builddir[] = BUILDDIR;
+ const char *libpath = getenv(LIBPATHENV);
+ if (libpath) {
+ size_t n = strlen(libpath);
+ char *e = malloc(sizeof(builddir)+n+1);
+ memcpy(e, builddir, sizeof(builddir)-1);
+ e[sizeof(builddir)-1] = '@PATH_SEPARATOR@';
+ memcpy(e+sizeof(builddir), libpath, n+1);
+ libpath = e;
+ }
+ else {
+ libpath = builddir;
+ }
+ setenv(LIBPATHENV, libpath, 1);
+ execv(BUILDDIR"/@RUBY_BASE_NAME@", argv);
+ return -1;
+}