summaryrefslogtreecommitdiffstats
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile19
-rw-r--r--stdlib/Makefile.nt9
-rw-r--r--stdlib/header.c19
-rw-r--r--stdlib/headernt.c26
4 files changed, 42 insertions, 31 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index 0deb58b8f..7da6c6c5e 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -17,12 +17,12 @@ OBJS=pervasives.cmo list.cmo char.cmo string.cmo array.cmo sys.cmo \
digest.cmo random.cmo oo.cmo genlex.cmo callback.cmo weak.cmo \
lazy.cmo
-all: stdlib.cma std_exit.cmo camlheader
+all: stdlib.cma std_exit.cmo camlheader camlheader_ur
allopt: stdlib.cmxa std_exit.cmx
install:
- cp stdlib.cma std_exit.cmo *.cmi *.mli *.ml camlheader $(LIBDIR)
+ cp stdlib.cma std_exit.cmo *.cmi *.mli *.ml camlheader camlheader_ur $(LIBDIR)
installopt:
cp stdlib.cmxa stdlib.a std_exit.o *.cmx $(LIBDIR)
@@ -34,15 +34,18 @@ stdlib.cma: $(OBJS)
stdlib.cmxa: $(OBJS:.cmo=.cmx)
$(CAMLOPT) -a -o stdlib.cmxa $(OBJS:.cmo=.cmx)
-camlheader: sharpbang header.c ../config/Makefile
- if $(SHARPBANGSCRIPTS); \
- then cp sharpbang camlheader; \
- else $(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) header.c -o camlheader; \
- strip camlheader; \
+camlheader camlheader_ur: header.c ../config/Makefile
+ if $(SHARPBANGSCRIPTS); then \
+ echo '#! $(BINDIR)/ocamlrun' > camlheader && \
+ echo -n '#! ' > camlheader_ur; \
+ else \
+ $(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) -DRUNTIME_NAME='"$(BINDIR)/ocamlrun"' header.c -o camlheader && \
+ strip camlheader && \
+ cp camlheader camlheader_ur; \
fi
clean::
- rm -f camlheader
+ rm -f camlheader camlheader_ur
pervasives.cmi: pervasives.mli
$(CAMLC) $(COMPFLAGS) -nopervasives -c pervasives.mli
diff --git a/stdlib/Makefile.nt b/stdlib/Makefile.nt
index 1d402e32f..b086eb326 100644
--- a/stdlib/Makefile.nt
+++ b/stdlib/Makefile.nt
@@ -15,12 +15,12 @@ OBJS=pervasives.cmo list.cmo char.cmo string.cmo array.cmo sys.cmo \
digest.cmo random.cmo oo.cmo genlex.cmo callback.cmo weak.cmo \
lazy.cmo
-all: stdlib.cma std_exit.cmo camlheader
+all: stdlib.cma std_exit.cmo camlheader camlheader_ur
allopt: stdlib.cmxa std_exit.cmx
install:
- cp stdlib.cma std_exit.cmo *.cmi *.mli camlheader $(LIBDIR)
+ cp stdlib.cma std_exit.cmo *.cmi *.mli camlheader camlheader_ur $(LIBDIR)
installopt:
cp stdlib.cmxa stdlib.lib std_exit.obj *.cmx $(LIBDIR)
@@ -31,11 +31,12 @@ stdlib.cma: $(OBJS)
stdlib.cmxa: $(OBJS:.cmo=.cmx)
$(CAMLOPT) -a -o stdlib.cmxa $(OBJS:.cmo=.cmx)
-camlheader: headernt.c ..\config\Makefile.nt
+camlheader camlheader_ur: headernt.c ..\config\Makefile.nt
$(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) -o camlheader. headernt.c
+ cp camlheader camlheader_ur
clean::
- rm -f camlheader
+ rm -f camlheader camlheader_ur
pervasives.cmi: pervasives.mli
$(CAMLC) $(COMPFLAGS) -nopervasives -c pervasives.mli
diff --git a/stdlib/header.c b/stdlib/header.c
index 6166aa965..8daa22fdc 100644
--- a/stdlib/header.c
+++ b/stdlib/header.c
@@ -24,6 +24,8 @@
#include <sys/stat.h>
#include "../byterun/exec.h"
+char * default_runtime_path = RUNTIME_NAME;
+
#define MAXPATHLEN 1024
#ifndef S_ISREG
@@ -69,27 +71,29 @@ static unsigned long read_size(char * ptr)
((unsigned long) p[2] << 8) + p[3];
}
-static int read_runtime_path(int fd, char *runtime_path)
+static char * read_runtime_path(int fd)
{
char buffer[TRAILER_SIZE];
+ static char runtime_path[MAXPATHLEN];
unsigned path_size, code_size, prim_size, data_size;
unsigned symbol_size, debug_size, size;
lseek(fd, (long) -TRAILER_SIZE, SEEK_END);
- if (read(fd, buffer, TRAILER_SIZE) < TRAILER_SIZE) return -1;
+ if (read(fd, buffer, TRAILER_SIZE) < TRAILER_SIZE) return NULL;
path_size = read_size(buffer);
code_size = read_size(buffer + 4);
prim_size = read_size(buffer + 8);
data_size = read_size(buffer + 12);
symbol_size = read_size(buffer + 16);
debug_size = read_size(buffer + 20);
- if (path_size > MAXPATHLEN) return -1;
+ if (path_size > MAXPATHLEN) return NULL;
+ if (path_size == 0) return default_runtime_path;
size = path_size + code_size + prim_size +
data_size + symbol_size + debug_size + TRAILER_SIZE;
lseek(fd, -size, SEEK_END);
- if (read(fd, runtime_path, path_size) != path_size) return -1;
+ if (read(fd, runtime_path, path_size) != path_size) return NULL;
runtime_path[path_size - 1] = 0;
- return 0;
+ return runtime_path;
}
static void errwrite(char * msg)
@@ -99,13 +103,12 @@ static void errwrite(char * msg)
int main(int argc, char ** argv)
{
- char * truename;
+ char * truename, * runtime_path;
int fd;
- char runtime_path[MAXPATHLEN];
truename = searchpath(argv[0]);
fd = open(truename, O_RDONLY);
- if (fd == -1 || read_runtime_path(fd, runtime_path) == -1) {
+ if (fd == -1 || (runtime_path = read_runtime_path(fd)) == NULL) {
errwrite(truename);
errwrite(" not found or is not a bytecode executable file\n");
return 2;
diff --git a/stdlib/headernt.c b/stdlib/headernt.c
index ab31db94f..f80af66df 100644
--- a/stdlib/headernt.c
+++ b/stdlib/headernt.c
@@ -17,6 +17,8 @@
#include <process.h>
#include "../byterun/exec.h"
+char * default_runtime_name = "ocamlrun";
+
static unsigned long read_size(char * ptr)
{
unsigned char * p = (unsigned char *) ptr;
@@ -24,30 +26,32 @@ static unsigned long read_size(char * ptr)
((unsigned long) p[2] << 8) + p[3];
}
-static int read_runtime_path(HANDLE h, char *runtime_path, int path_len)
+static char * read_runtime_path(HANDLE h)
{
char buffer[TRAILER_SIZE];
+ char runtime_path[MAX_PATH];
DWORD nread;
struct exec_trailer tr;
long size;
- if (SetFilePointer(h, -TRAILER_SIZE, NULL, FILE_END) == -1) return -1;
- if (! ReadFile(h, buffer, TRAILER_SIZE, &nread, NULL)) return -1;
- if (nread != TRAILER_SIZE) return -1;
+ if (SetFilePointer(h, -TRAILER_SIZE, NULL, FILE_END) == -1) return NULL;
+ if (! ReadFile(h, buffer, TRAILER_SIZE, &nread, NULL)) return NULL;
+ if (nread != TRAILER_SIZE) return NULL;
tr.path_size = read_size(buffer);
tr.code_size = read_size(buffer + 4);
tr.prim_size = read_size(buffer + 8);
tr.data_size = read_size(buffer + 12);
tr.symbol_size = read_size(buffer + 16);
tr.debug_size = read_size(buffer + 20);
- if (tr.path_size >= path_len) return -1;
+ if (tr.path_size >= MAX_PATH) return NULL;
+ if (tr.path_size == 0) return default_runtime_path;
size = tr.path_size + tr.code_size + tr.prim_size +
tr.data_size + tr.symbol_size + tr.debug_size + TRAILER_SIZE;
- if (SetFilePointer(h, -size, NULL, FILE_END) == -1) return -1;
- if (! ReadFile(h, runtime_path, tr.path_size, &nread, NULL)) return -1;
- if (nread != tr.path_size) return -1;
+ if (SetFilePointer(h, -size, NULL, FILE_END) == -1) return NULL;
+ if (! ReadFile(h, runtime_path, tr.path_size, &nread, NULL)) return NULL;
+ if (nread != tr.path_size) return NULL;
runtime_path[tr.path_size - 1] = 0;
- return 0;
+ return runtime_path;
}
static void errwrite(char * msg)
@@ -61,14 +65,14 @@ int main(int argc, char ** argv)
{
char truename[MAX_PATH];
char * cmdline = GetCommandLine();
- char runtime_path[MAX_PATH];
+ char * runtime_path;
HANDLE h;
int retcode;
GetModuleFileName(NULL, truename, sizeof(truename));
h = CreateFile(truename, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
if (h == INVALID_HANDLE_VALUE ||
- read_runtime_path(h, runtime_path, sizeof(runtime_path)) == -1) {
+ (runtime_path = read_runtime_path(h)) == NULL) {
errwrite(truename);
errwrite(" not found or is not a bytecode executable file\r\n");
return 2;