Improve -output-obj: can now build directly a dynamic library (with all the ccobjs/ccopts); can also produces simply the uncompiled .c file (e.g. to debug). The output name (-o) is now mandatory when -output-obj is used, and only an extension amongst .c, EXT_OBJ, EXT_DLL is allowed.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@8522 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02master
parent
1b059475c8
commit
223f7bbfea
1
Makefile
1
Makefile
|
@ -359,6 +359,7 @@ utils/config.ml: utils/config.mlp config/Makefile
|
||||||
-e 's|%%ASM%%|$(ASM)|' \
|
-e 's|%%ASM%%|$(ASM)|' \
|
||||||
-e 's|%%MKDLL%%|$(MKDLL)|' \
|
-e 's|%%MKDLL%%|$(MKDLL)|' \
|
||||||
-e 's|%%MKEXE%%|$(MKEXE)|' \
|
-e 's|%%MKEXE%%|$(MKEXE)|' \
|
||||||
|
-e 's|%%MKMAINDLL%%|$(MKMAINDLL)|' \
|
||||||
utils/config.mlp > utils/config.ml
|
utils/config.mlp > utils/config.ml
|
||||||
@chmod -w utils/config.ml
|
@chmod -w utils/config.ml
|
||||||
|
|
||||||
|
|
|
@ -330,6 +330,7 @@ utils/config.ml: utils/config.mlp config/Makefile
|
||||||
-e 's|%%ASM%%|$(ASM)|' \
|
-e 's|%%ASM%%|$(ASM)|' \
|
||||||
-e 's|%%MKDLL%%|$(MKDLL)|' \
|
-e 's|%%MKDLL%%|$(MKDLL)|' \
|
||||||
-e 's|%%MKEXE%%|$(MKEXE)|' \
|
-e 's|%%MKEXE%%|$(MKEXE)|' \
|
||||||
|
-e 's|%%MKMAINDLL%%|$(MKMAINDLL)|' \
|
||||||
-e 's|%%CC_PROFILE%%||' \
|
-e 's|%%CC_PROFILE%%||' \
|
||||||
utils/config.mlp > utils/config.ml
|
utils/config.mlp > utils/config.ml
|
||||||
@chmod -w utils/config.ml
|
@chmod -w utils/config.ml
|
||||||
|
|
|
@ -485,17 +485,28 @@ let link objfiles output_name =
|
||||||
remove_file prim_name;
|
remove_file prim_name;
|
||||||
raise x
|
raise x
|
||||||
end else begin
|
end else begin
|
||||||
let c_file =
|
let basename = Filename.chop_extension output_name in
|
||||||
Filename.chop_suffix output_name Config.ext_obj ^ ".c" in
|
let c_file = basename ^ ".c"
|
||||||
|
and obj_file = basename ^ Config.ext_obj in
|
||||||
if Sys.file_exists c_file then raise(Error(File_exists c_file));
|
if Sys.file_exists c_file then raise(Error(File_exists c_file));
|
||||||
|
let temps = ref [] in
|
||||||
try
|
try
|
||||||
link_bytecode_as_c tolink c_file;
|
link_bytecode_as_c tolink c_file;
|
||||||
if Ccomp.compile_file c_file <> 0
|
if not (Filename.check_suffix output_name ".c") then begin
|
||||||
then raise(Error Custom_runtime);
|
temps := c_file :: !temps;
|
||||||
remove_file c_file
|
if Ccomp.compile_file c_file <> 0 then raise(Error Custom_runtime);
|
||||||
|
if not (Filename.check_suffix output_name Config.ext_obj) then begin
|
||||||
|
temps := obj_file :: !temps;
|
||||||
|
if not (
|
||||||
|
Ccomp.call_linker Ccomp.MainDll output_name
|
||||||
|
([obj_file] @ List.rev !Clflags.ccobjs @ ["-lcamlrun"])
|
||||||
|
Config.bytecomp_c_libraries
|
||||||
|
) then raise (Error Custom_runtime);
|
||||||
|
end
|
||||||
|
end;
|
||||||
|
List.iter remove_file !temps
|
||||||
with x ->
|
with x ->
|
||||||
remove_file c_file;
|
List.iter remove_file !temps;
|
||||||
remove_file output_name;
|
|
||||||
raise x
|
raise x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -99,6 +99,7 @@ FLEXDIR=$(shell $(FLEXLINK) -where)
|
||||||
IFLEXDIR=-I"$(FLEXDIR)"
|
IFLEXDIR=-I"$(FLEXDIR)"
|
||||||
MKDLL=$(FLEXLINK)
|
MKDLL=$(FLEXLINK)
|
||||||
MKEXE=$(FLEXLINK) -exe
|
MKEXE=$(FLEXLINK) -exe
|
||||||
|
MKMAINDLL=$(FLEXLINK) -maindll
|
||||||
|
|
||||||
### How to build a static library
|
### How to build a static library
|
||||||
MKLIB=rm -f $(1); ar rcs $(1) $(2)
|
MKLIB=rm -f $(1); ar rcs $(1) $(2)
|
||||||
|
|
|
@ -98,6 +98,7 @@ FLEXDIR=$(shell $(FLEXLINK) -where)
|
||||||
IFLEXDIR=-I"$(FLEXDIR)"
|
IFLEXDIR=-I"$(FLEXDIR)"
|
||||||
MKDLL=$(FLEXLINK)
|
MKDLL=$(FLEXLINK)
|
||||||
MKEXE=$(FLEXLINK) -exe
|
MKEXE=$(FLEXLINK) -exe
|
||||||
|
MKMAINDLL=$(FLEXLINK) -maindll
|
||||||
|
|
||||||
### How to build a static library
|
### How to build a static library
|
||||||
MKLIB=link /lib /nologo /out:$(1) $(2)
|
MKLIB=link /lib /nologo /out:$(1) $(2)
|
||||||
|
|
|
@ -102,6 +102,7 @@ FLEXDIR=$(shell $(FLEXLINK) -where)
|
||||||
IFLEXDIR=-I"$(FLEXDIR)"
|
IFLEXDIR=-I"$(FLEXDIR)"
|
||||||
MKDLL=$(FLEXLINK)
|
MKDLL=$(FLEXLINK)
|
||||||
MKEXE=$(FLEXLINK) -exe
|
MKEXE=$(FLEXLINK) -exe
|
||||||
|
MKMAINDLL=$(FLEXLINK) -maindll
|
||||||
|
|
||||||
### How to build a static library
|
### How to build a static library
|
||||||
MKLIB=link /lib /nologo /machine:AMD64 /out:$(1) $(2)
|
MKLIB=link /lib /nologo /machine:AMD64 /out:$(1) $(2)
|
||||||
|
|
|
@ -507,6 +507,7 @@ if test $withsharedlibs = "yes"; then
|
||||||
*-*-cygwin*)
|
*-*-cygwin*)
|
||||||
cmxs="cmxs"
|
cmxs="cmxs"
|
||||||
mksharedlib="$flexlink"
|
mksharedlib="$flexlink"
|
||||||
|
mkmaindll="$flexlink -maindll"
|
||||||
shared_libraries_supported=true;;
|
shared_libraries_supported=true;;
|
||||||
*-*-linux-gnu|*-*-linux|*-*-freebsd[3-9]*|*-*-openbsd*|*-*-netbsd*|*-*-gnu*)
|
*-*-linux-gnu|*-*-linux|*-*-freebsd[3-9]*|*-*-openbsd*|*-*-netbsd*|*-*-gnu*)
|
||||||
cmxs="cmxs"
|
cmxs="cmxs"
|
||||||
|
@ -593,6 +594,10 @@ if test $withsharedlibs = "yes"; then
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test -z "$mkmaindll"; then
|
||||||
|
mkmaindll=$mksharedlib
|
||||||
|
fi
|
||||||
|
|
||||||
# Further machine-specific hacks
|
# Further machine-specific hacks
|
||||||
|
|
||||||
case "$host" in
|
case "$host" in
|
||||||
|
@ -1530,6 +1535,7 @@ echo "TOOLCHAIN=cc" >> Makefile
|
||||||
echo "CMXS=$cmxs" >> Makefile
|
echo "CMXS=$cmxs" >> Makefile
|
||||||
echo "MKEXE=$mkexe" >> Makefile
|
echo "MKEXE=$mkexe" >> Makefile
|
||||||
echo "MKDLL=$mksharedlib" >> Makefile
|
echo "MKDLL=$mksharedlib" >> Makefile
|
||||||
|
echo "MKMAINDLL=$mkmaindll" >> Makefile
|
||||||
|
|
||||||
rm -f tst hasgot.c
|
rm -f tst hasgot.c
|
||||||
rm -f ../m.h ../s.h ../Makefile
|
rm -f ../m.h ../s.h ../Makefile
|
||||||
|
|
|
@ -137,12 +137,13 @@ module Options = Main_args.Make_options (struct
|
||||||
let anonymous = anonymous
|
let anonymous = anonymous
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
let fatal err =
|
||||||
|
prerr_endline err;
|
||||||
|
exit 2
|
||||||
|
|
||||||
let extract_output = function
|
let extract_output = function
|
||||||
| Some s -> s
|
| Some s -> s
|
||||||
| None ->
|
| None -> fatal "Please specify the name of the output file, using option -o"
|
||||||
prerr_endline
|
|
||||||
"Please specify the name of the output file, using option -o";
|
|
||||||
exit 2
|
|
||||||
|
|
||||||
let default_output = function
|
let default_output = function
|
||||||
| Some s -> s
|
| Some s -> s
|
||||||
|
@ -151,6 +152,12 @@ let default_output = function
|
||||||
let main () =
|
let main () =
|
||||||
try
|
try
|
||||||
Arg.parse Options.list anonymous usage;
|
Arg.parse Options.list anonymous usage;
|
||||||
|
if
|
||||||
|
List.length (List.filter (fun x -> !x)
|
||||||
|
[make_archive;make_package;compile_only;output_c_object]) > 1
|
||||||
|
then
|
||||||
|
fatal "Please specify at most one of -pack, -a, -c, -output-obj";
|
||||||
|
|
||||||
if !make_archive then begin
|
if !make_archive then begin
|
||||||
Compile.init_path();
|
Compile.init_path();
|
||||||
Bytelibrarian.create_archive (List.rev !objfiles)
|
Bytelibrarian.create_archive (List.rev !objfiles)
|
||||||
|
@ -162,8 +169,24 @@ let main () =
|
||||||
(extract_output !output_name)
|
(extract_output !output_name)
|
||||||
end
|
end
|
||||||
else if not !compile_only && !objfiles <> [] then begin
|
else if not !compile_only && !objfiles <> [] then begin
|
||||||
|
let target =
|
||||||
|
if !output_c_object then
|
||||||
|
let s = extract_output !output_name in
|
||||||
|
if (Filename.check_suffix s Config.ext_obj
|
||||||
|
|| Filename.check_suffix s Config.ext_dll
|
||||||
|
|| Filename.check_suffix s ".c")
|
||||||
|
then s
|
||||||
|
else
|
||||||
|
fatal
|
||||||
|
(Printf.sprintf
|
||||||
|
"The extension of the output file must be .c, %s or %s"
|
||||||
|
Config.ext_obj Config.ext_dll
|
||||||
|
)
|
||||||
|
else
|
||||||
|
default_output !output_name
|
||||||
|
in
|
||||||
Compile.init_path();
|
Compile.init_path();
|
||||||
Bytelink.link (List.rev !objfiles) (default_output !output_name)
|
Bytelink.link (List.rev !objfiles) target
|
||||||
end;
|
end;
|
||||||
exit 0
|
exit 0
|
||||||
with x ->
|
with x ->
|
||||||
|
|
|
@ -215,9 +215,9 @@ let main () =
|
||||||
]) (process_file ppf) usage;
|
]) (process_file ppf) usage;
|
||||||
if
|
if
|
||||||
List.length (List.filter (fun x -> !x)
|
List.length (List.filter (fun x -> !x)
|
||||||
[make_archive;make_package;shared;compile_only]) > 1
|
[make_archive;make_package;shared;compile_only;output_c_object]) > 1
|
||||||
then begin
|
then begin
|
||||||
prerr_endline "Please specify at most one of -pack, -a, -shared, -c";
|
prerr_endline "Please specify at most one of -pack, -a, -shared, -c, -output-obj";
|
||||||
exit 2
|
exit 2
|
||||||
end;
|
end;
|
||||||
if !make_archive then begin
|
if !make_archive then begin
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
include ../../config/Makefile
|
||||||
|
|
||||||
OCAMLC = ../../ocamlc
|
OCAMLC = ../../ocamlc
|
||||||
OCAMLOPT = ../../ocamlopt
|
OCAMLOPT = ../../ocamlopt
|
||||||
|
|
||||||
|
@ -5,8 +7,15 @@ test:
|
||||||
$(OCAMLC) -c main.ml
|
$(OCAMLC) -c main.ml
|
||||||
$(OCAMLC) -c entry.c
|
$(OCAMLC) -c entry.c
|
||||||
$(OCAMLC) -c plugin.ml
|
$(OCAMLC) -c plugin.ml
|
||||||
$(OCAMLC) -output-obj -o main_obj.obj dynlink.cma main.cmo
|
$(OCAMLC) -output-obj -o main_obj.$(O) dynlink.cma main.cmo
|
||||||
flexlink -merge-manifest -maindll -o main.dll main_obj.obj entry.obj ../../byterun/libcamlrun.lib -v
|
$(MKDLL) -maindll -o main.dll main_obj.$(O) entry.$(O) ../../byterun/libcamlrun.$(A) $(BYTECCLIBS) -v
|
||||||
|
csc /out:main.exe main.cs
|
||||||
|
./main.exe
|
||||||
|
|
||||||
|
test2:
|
||||||
|
$(OCAMLC) -c main.ml
|
||||||
|
$(OCAMLC) -c plugin.ml
|
||||||
|
$(OCAMLC) -output-obj -o main.dll dynlink.cma main.cmo entry.c
|
||||||
csc /out:main.exe main.cs
|
csc /out:main.exe main.cs
|
||||||
./main.exe
|
./main.exe
|
||||||
|
|
||||||
|
@ -14,8 +23,8 @@ testopt:
|
||||||
$(OCAMLOPT) -c main.ml
|
$(OCAMLOPT) -c main.ml
|
||||||
$(OCAMLC) -c entry.c
|
$(OCAMLC) -c entry.c
|
||||||
$(OCAMLOPT) -o plugin.cmxs -shared plugin.ml
|
$(OCAMLOPT) -o plugin.cmxs -shared plugin.ml
|
||||||
$(OCAMLOPT) -output-obj -o main_obj.obj dynlink.cmxa main.cmx
|
$(OCAMLOPT) -output-obj -o main_obj.$(O) dynlink.cmxa main.cmx
|
||||||
flexlink -merge-manifest -maindll -o main.dll main_obj.obj entry.obj ../../asmrun/libasmrun.lib -v
|
flexlink -merge-manifest -maindll -o main.dll main_obj.$(O) entry.$(O) ../../asmrun/libasmrun.lib -v
|
||||||
csc /out:main.exe main.cs
|
csc /out:main.exe main.cs
|
||||||
./main.exe
|
./main.exe
|
||||||
|
|
||||||
|
|
|
@ -86,6 +86,7 @@ let expand_libname name =
|
||||||
type link_mode =
|
type link_mode =
|
||||||
| Exe
|
| Exe
|
||||||
| Dll
|
| Dll
|
||||||
|
| MainDll
|
||||||
|
|
||||||
let call_linker mode output_name files extra =
|
let call_linker mode output_name files extra =
|
||||||
let files = quote_files files in
|
let files = quote_files files in
|
||||||
|
@ -94,6 +95,7 @@ let call_linker mode output_name files extra =
|
||||||
(match mode with
|
(match mode with
|
||||||
| Exe -> Config.mkexe
|
| Exe -> Config.mkexe
|
||||||
| Dll -> Config.mkdll
|
| Dll -> Config.mkdll
|
||||||
|
| MainDll -> Config.mkmaindll
|
||||||
)
|
)
|
||||||
(Filename.quote output_name)
|
(Filename.quote output_name)
|
||||||
(if !Clflags.gprofile then Config.cc_profile else "")
|
(if !Clflags.gprofile then Config.cc_profile else "")
|
||||||
|
|
|
@ -25,5 +25,6 @@ val quote_files: string list -> string
|
||||||
type link_mode =
|
type link_mode =
|
||||||
| Exe
|
| Exe
|
||||||
| Dll
|
| Dll
|
||||||
|
| MainDll
|
||||||
|
|
||||||
val call_linker: link_mode -> string -> string list -> string -> bool
|
val call_linker: link_mode -> string -> string list -> string -> bool
|
||||||
|
|
|
@ -49,7 +49,9 @@ val native_pack_linker: string
|
||||||
val mkdll: string
|
val mkdll: string
|
||||||
(* The linker command line to build dynamic libraries. *)
|
(* The linker command line to build dynamic libraries. *)
|
||||||
val mkexe: string
|
val mkexe: string
|
||||||
(* The linker command line to executables. *)
|
(* The linker command line to build executables. *)
|
||||||
|
val mkmaindll: string
|
||||||
|
(* The linker command line to build main programs as dlls. *)
|
||||||
val ranlib: string
|
val ranlib: string
|
||||||
(* Command to randomize a library, or "" if not needed *)
|
(* Command to randomize a library, or "" if not needed *)
|
||||||
val cc_profile : string
|
val cc_profile : string
|
||||||
|
|
|
@ -40,6 +40,7 @@ let ranlib = "%%RANLIBCMD%%"
|
||||||
let cc_profile = "%%CC_PROFILE%%"
|
let cc_profile = "%%CC_PROFILE%%"
|
||||||
let mkdll = "%%MKDLL%%"
|
let mkdll = "%%MKDLL%%"
|
||||||
let mkexe = "%%MKEXE%%"
|
let mkexe = "%%MKEXE%%"
|
||||||
|
let mkmaindll = "%%MKMAINDLL%%"
|
||||||
|
|
||||||
let exec_magic_number = "Caml1999X008"
|
let exec_magic_number = "Caml1999X008"
|
||||||
and cmi_magic_number = "Caml1999I011"
|
and cmi_magic_number = "Caml1999I011"
|
||||||
|
|
Loading…
Reference in New Issue