diff options
-rw-r--r-- | bytecomp/bytelink.ml | 29 | ||||
-rw-r--r-- | stdlib/Makefile | 19 | ||||
-rw-r--r-- | stdlib/Makefile.nt | 9 | ||||
-rw-r--r-- | stdlib/header.c | 19 | ||||
-rw-r--r-- | stdlib/headernt.c | 26 |
5 files changed, 57 insertions, 45 deletions
diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml index ac395516c..5537a2ca9 100644 --- a/bytecomp/bytelink.ml +++ b/bytecomp/bytelink.ml @@ -228,18 +228,20 @@ let link_bytecode objfiles exec_name copy_header = (* Copy the header *) if copy_header then begin try - let inchan = open_in_bin (find_in_path !load_path "camlheader") in + let header = + if String.length !Clflags.use_runtime > 0 + then "camlheader_ur" else "camlheader" in + let inchan = open_in_bin (find_in_path !load_path header) in copy_file inchan outchan; close_in inchan with Not_found | Sys_error _ -> () end; - (* The path to the bytecode interpreter *) + (* The path to the bytecode interpreter (in use_vn mode) *) let pos0 = pos_out outchan in - output_string outchan - (if String.length !Clflags.use_runtime > 0 - then make_absolute !Clflags.use_runtime - else Config.standard_runtime); - output_char outchan '\n'; + if String.length !Clflags.use_runtime > 0 then begin + output_string outchan (make_absolute !Clflags.use_runtime); + output_char outchan '\n' + end; (* The bytecode *) let pos1 = pos_out outchan in Symtable.init(); @@ -302,16 +304,14 @@ let output_code_string outchan code = let output_data_string outchan data = let counter = ref 0 in - output_string outchan "\""; for i = 0 to String.length data - 1 do - Printf.fprintf outchan "\\%03o" (Char.code(data.[i])); + Printf.fprintf outchan "%d, " (Char.code(data.[i])); incr counter; - if !counter >= 16 then begin - output_string outchan "\\\n"; + if !counter >= 12 then begin + output_string outchan "\n"; counter := 0 end - done; - output_string outchan "\";\n\n" + done (* Output a bytecode executable as a C file *) @@ -329,9 +329,10 @@ let link_bytecode_as_c objfiles outfile = (* The final STOP instruction *) Printf.fprintf outchan "\n0x%x};\n\n" Opcodes.opSTOP; (* The table of global data *) - output_string outchan "static char * caml_data =\n"; + output_string outchan "static char caml_data[] = {\n"; output_data_string outchan (Marshal.to_string (Symtable.initial_global_table()) []); + Printf.fprintf outchan "\n};\n\n"; (* The table of primitives *) Symtable.output_primitive_table outchan; (* The entry point *) 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; |