summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Frisch <alain@frisch.fr>2007-11-15 13:21:15 +0000
committerAlain Frisch <alain@frisch.fr>2007-11-15 13:21:15 +0000
commit1b059475c88cd6e719c20c39e2411cf750eaa108 (patch)
tree6b42ad026ac715c2e2e88621add61f93e4c8fb17
parentb4f96d6574b9f197122e78e4644a2dcc026e3f4c (diff)
Cleanup and factorization of linker-related code.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@8521 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
-rw-r--r--Makefile3
-rw-r--r--Makefile.nt3
-rw-r--r--asmcomp/asmlink.ml100
-rw-r--r--asmrun/Makefile2
-rw-r--r--asmrun/Makefile.nt2
-rwxr-xr-xbuild/mkmyocamlbuild_config.sh2
-rw-r--r--bytecomp/bytelink.ml41
-rw-r--r--byterun/Makefile6
-rw-r--r--byterun/Makefile.nt6
-rw-r--r--config/Makefile.mingw17
-rw-r--r--config/Makefile.msvc17
-rw-r--r--config/Makefile.msvc6417
-rwxr-xr-xconfigure48
-rw-r--r--myocamlbuild.ml8
-rw-r--r--myocamlbuild_config.mli4
-rw-r--r--stdlib/Makefile.nt2
-rw-r--r--tools/Makefile.shared2
-rw-r--r--tools/ocamlmklib.mlp18
-rw-r--r--utils/ccomp.ml74
-rw-r--r--utils/ccomp.mli8
-rw-r--r--utils/config.mli4
-rw-r--r--utils/config.mlp3
-rw-r--r--win32caml/Makefile2
-rw-r--r--yacc/Makefile.nt2
24 files changed, 147 insertions, 244 deletions
diff --git a/Makefile b/Makefile
index 1fcbb95bc..0d0ea5acf 100644
--- a/Makefile
+++ b/Makefile
@@ -357,7 +357,8 @@ utils/config.ml: utils/config.mlp config/Makefile
-e 's|%%EXT_DLL%%|.so|' \
-e 's|%%SYSTHREAD_SUPPORT%%|$(SYSTHREAD_SUPPORT)|' \
-e 's|%%ASM%%|$(ASM)|' \
- -e 's|%%MKSHAREDLIB%%|$(MKSHAREDLIB)|' \
+ -e 's|%%MKDLL%%|$(MKDLL)|' \
+ -e 's|%%MKEXE%%|$(MKEXE)|' \
utils/config.mlp > utils/config.ml
@chmod -w utils/config.ml
diff --git a/Makefile.nt b/Makefile.nt
index ffca36d99..ed8ed76a5 100644
--- a/Makefile.nt
+++ b/Makefile.nt
@@ -328,6 +328,9 @@ utils/config.ml: utils/config.mlp config/Makefile
-e "s|%%EXT_DLL%%|.dll|" \
-e "s|%%SYSTHREAD_SUPPORT%%|true|" \
-e 's|%%ASM%%|$(ASM)|' \
+ -e 's|%%MKDLL%%|$(MKDLL)|' \
+ -e 's|%%MKEXE%%|$(MKEXE)|' \
+ -e 's|%%CC_PROFILE%%||' \
utils/config.mlp > utils/config.ml
@chmod -w utils/config.ml
diff --git a/asmcomp/asmlink.ml b/asmcomp/asmlink.ml
index 7e5fac3f3..b39fc2eac 100644
--- a/asmcomp/asmlink.ml
+++ b/asmcomp/asmlink.ml
@@ -252,37 +252,8 @@ let make_shared_startup_file ppf units filename =
let call_linker_shared file_list output_name =
- let files = Ccomp.quote_files file_list in
- let cmd = match Config.system with
- | "mingw" | "win32" | "cygwin" | "win64" ->
- Printf.sprintf
- "flexlink -merge-manifest -chain %s -o %s %s %s %s %s %s"
- (match Config.system with
- | "mingw" -> "mingw"
- | "win32" -> "msvc"
- | "win64" -> "msvc -x64"
- | "cygwin" -> "cygwin"
- | _ -> assert false)
- (Filename.quote output_name)
- (String.concat " "
- (List.map (fun s -> if s = "" then "" else
- "-I " ^ (Filename.quote s)) !load_path))
- files
- (if !Clflags.verbose then "-v" else "")
- (Ccomp.make_link_options !Clflags.ccopts)
- (if !Clflags.verbose then "" else ">NUL")
- | _ ->
- Printf.sprintf
- "%s %s %s %s %s"
- mksharedlib
- (Filename.quote output_name)
- (Ccomp.quote_files
- (List.map (fun dir -> if dir = "" then "" else "-L" ^ dir)
- !load_path))
- (String.concat " " (List.rev !Clflags.ccopts))
- files
- in
- if Ccomp.command cmd <> 0 then raise(Error Linking_error)
+ if not (Ccomp.call_linker Ccomp.Dll output_name file_list "")
+ then raise(Error Linking_error)
let link_shared ppf objfiles output_name =
let units_tolink = List.fold_right scan_file objfiles [] in
@@ -309,64 +280,31 @@ let link_shared ppf objfiles output_name =
let call_linker file_list startup_file output_name =
let c_lib =
if !Clflags.nopervasives then "" else Config.native_c_libraries in
- match Config.system, Config.ccomp_type with
- | (("win32"|"win64"|"mingw"|"cygwin"), _) when not !Clflags.output_c_object ->
- let cmd =
- Printf.sprintf
- "flexlink -chain %s -merge-manifest -exe -o %s %s %s %s %s %s %s %s %s"
- (match Config.system with
- | "win32" -> "msvc"
- | "win64" -> "msvc -x64"
- | "mingw" -> "mingw"
- | "cygwin" -> "cygwin"
- | _ -> assert false)
- (Filename.quote output_name)
- (String.concat " "
- (List.map (fun s -> if s = "" then "" else
- "-I " ^ (Filename.quote s)) !load_path))
- (Filename.quote startup_file)
- (Ccomp.quote_files (List.rev file_list))
- (Ccomp.quote_files (List.rev !Clflags.ccobjs))
- (Filename.quote (runtime_lib ()))
- c_lib
- (if !Clflags.verbose then " -v" else "")
- (Ccomp.make_link_options !Clflags.ccopts)
- in
- let res = Ccomp.command cmd in
- if res <> 0 then raise(Error Linking_error)
- | _,"cc" ->
- let cmd =
- if not !Clflags.output_c_object then
- Printf.sprintf "%s %s -o %s %s %s %s %s %s %s %s %s"
- !Clflags.c_linker
- (if !Clflags.gprofile then Config.cc_profile else "")
+ if not !Clflags.output_c_object then begin
+ let files = [startup_file] @ (List.rev file_list) @
+ (List.rev !Clflags.ccobjs) @ [runtime_lib ()] in
+ if not (Ccomp.call_linker Ccomp.Exe output_name files c_lib)
+ then raise(Error Linking_error)
+ end
+ else
+ let cmd =
+ match Config.system with
+ | "win32"|"win64"|"mingw"|"cygwin" ->
+ Printf.sprintf "%s /out:%s %s %s"
+ Config.native_partial_linker
(Filename.quote output_name)
- (Clflags.std_include_flag "-I")
- (String.concat " " (List.rev !Clflags.ccopts))
(Filename.quote startup_file)
(Ccomp.quote_files (List.rev file_list))
- (Ccomp.quote_files
- (List.map (fun dir -> if dir = "" then "" else "-L" ^ dir)
- !load_path))
- (Ccomp.quote_files (List.rev !Clflags.ccobjs))
- (Filename.quote (runtime_lib ()))
- c_lib
- else
+ | _ ->
Printf.sprintf "%s -o %s %s %s"
Config.native_partial_linker
(Filename.quote output_name)
(Filename.quote startup_file)
(Ccomp.quote_files (List.rev file_list))
- in if Ccomp.command cmd <> 0 then raise(Error Linking_error)
- | (("win32"|"win64"|"mingw"|"cygwin"), _) when !Clflags.output_c_object ->
- let cmd =
- Printf.sprintf "%s /out:%s %s %s"
- Config.native_partial_linker
- (Filename.quote output_name)
- (Filename.quote startup_file)
- (Ccomp.quote_files (List.rev file_list))
- in if Ccomp.command cmd <> 0 then raise(Error Linking_error)
- | _ -> assert false
+ in
+ let res = Ccomp.command cmd in
+ if res <> 0 then raise(Error Linking_error)
+
(* Main entry point *)
diff --git a/asmrun/Makefile b/asmrun/Makefile
index ba5f4c036..633ce5254 100644
--- a/asmrun/Makefile
+++ b/asmrun/Makefile
@@ -17,7 +17,7 @@ include ../config/Makefile
CC=$(NATIVECC)
FLAGS=-I../byterun -DCAML_NAME_SPACE -DNATIVE_CODE \
- -DTARGET_$(ARCH) -DSYS_$(SYSTEM) $(FLEXLINK)
+ -DTARGET_$(ARCH) -DSYS_$(SYSTEM) $(IFLEXDIR)
CFLAGS=$(FLAGS) -O $(NATIVECCCOMPOPTS)
DFLAGS=$(FLAGS) -g -DDEBUG $(NATIVECCCOMPOPTS)
PFLAGS=$(FLAGS) -pg -O -DPROFILING $(NATIVECCPROFOPTS)
diff --git a/asmrun/Makefile.nt b/asmrun/Makefile.nt
index b28c9d708..ca24bc71a 100644
--- a/asmrun/Makefile.nt
+++ b/asmrun/Makefile.nt
@@ -62,7 +62,7 @@ $(LINKEDFILES): %.c: ../byterun/%.c
# Need special compilation rule so as not to do -I../byterun
win32.$(O): ../byterun/win32.c
- $(CC) -c $(NATIVECCCOMPOPTS) -DNATIVE_CODE $(FLEXLINK) ../byterun/win32.c
+ $(CC) -c $(NATIVECCCOMPOPTS) -DNATIVE_CODE $(IFLEXDIR) ../byterun/win32.c
.SUFFIXES: .c .$(O)
diff --git a/build/mkmyocamlbuild_config.sh b/build/mkmyocamlbuild_config.sh
index 1a7a19441..7ae597ef8 100755
--- a/build/mkmyocamlbuild_config.sh
+++ b/build/mkmyocamlbuild_config.sh
@@ -4,7 +4,7 @@
cd `dirname $0`/..
sed \
- -e 's/^FLEX.*$//g' \
+ -e 's/^.*FLEXDIR.*$//g' \
-e 's/^#ml \(.*\)/\1/' \
-e 's/^\(#.*\)$/(* \1 *)/' \
-e 's/^\(.*\$([0-9]).*\)$/(* \1 *)/' \
diff --git a/bytecomp/bytelink.ml b/bytecomp/bytelink.ml
index c5e302433..f1531850e 100644
--- a/bytecomp/bytelink.ml
+++ b/bytecomp/bytelink.ml
@@ -431,42 +431,9 @@ void caml_startup(char ** argv)
(* Build a custom runtime *)
let build_custom_runtime prim_name exec_name =
- match Config.system, Config.ccomp_type with
- | ("win32"|"win64"|"mingw"|"cygwin"),_ ->
- Ccomp.command
- (Printf.sprintf
- "flexlink -chain %s -merge-manifest -exe -o %s %s %s %s %s %s %s %s"
- (match Config.system with
- | "win32" -> "msvc"
- | "win64" -> "msvc -x64"
- | "mingw" -> "mingw"
- | "cygwin" -> "cygwin"
- | _ -> assert false)
- (Filename.quote exec_name)
- (Clflags.std_include_flag "-I ")
- prim_name
- (Ccomp.quote_files
- (List.map (fun dir -> if dir = "" then "" else "-L" ^ dir)
- !load_path))
- (Ccomp.quote_files (List.rev !Clflags.ccobjs))
- (Filename.quote "-lcamlrun")
- Config.bytecomp_c_libraries
- (Ccomp.make_link_options !Clflags.ccopts))
- | _,"cc" ->
- Ccomp.command
- (Printf.sprintf
- "%s -o %s %s %s %s %s %s -lcamlrun %s"
- !Clflags.c_linker
- (Filename.quote exec_name)
- (Clflags.std_include_flag "-I")
- (String.concat " " (List.rev !Clflags.ccopts))
- prim_name
- (Ccomp.quote_files
- (List.map (fun dir -> if dir = "" then "" else "-L" ^ dir)
- !load_path))
- (Ccomp.quote_files (List.rev !Clflags.ccobjs))
- Config.bytecomp_c_libraries)
- | _ -> assert false
+ Ccomp.call_linker Ccomp.Exe exec_name
+ ([prim_name] @ List.rev !Clflags.ccobjs @ ["-lcamlrun"])
+ Config.bytecomp_c_libraries
let append_bytecode_and_cleanup bytecode_name exec_name prim_name =
let oc = open_out_gen [Open_wronly; Open_append; Open_binary] 0 exec_name in
@@ -508,7 +475,7 @@ let link objfiles output_name =
Symtable.output_primitive_table poc;
close_out poc;
let exec_name = fix_exec_name output_name in
- if build_custom_runtime prim_name exec_name <> 0
+ if not (build_custom_runtime prim_name exec_name)
then raise(Error Custom_runtime);
if !Clflags.make_runtime
then (remove_file bytecode_name; remove_file prim_name)
diff --git a/byterun/Makefile b/byterun/Makefile
index 85af97aa7..288edbc96 100644
--- a/byterun/Makefile
+++ b/byterun/Makefile
@@ -15,18 +15,18 @@
include Makefile.common
-CFLAGS=-DCAML_NAME_SPACE -O $(BYTECCCOMPOPTS) $(FLEXLINK)
+CFLAGS=-DCAML_NAME_SPACE -O $(BYTECCCOMPOPTS) $(IFLEXDIR)
DFLAGS=-DCAML_NAME_SPACE -g -DDEBUG $(BYTECCCOMPOPTS)
OBJS=$(COMMONOBJS) unix.o main.o
DOBJS=$(OBJS:.o=.d.o) instrtrace.d.o
ocamlrun$(EXE): libcamlrun.a prims.o
- $(BYTECC) $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) -o ocamlrun$(EXE) \
+ $(MKEXE) $(BYTECCLINKOPTS) -o ocamlrun$(EXE) \
prims.o libcamlrun.a $(BYTECCLIBS)
ocamlrund$(EXE): libcamlrund.a prims.o
- $(BYTECC) -g $(BYTECCCOMPOPTS) $(BYTECCLINKOPTS) -o ocamlrund$(EXE) \
+ $(MKEXE) -g $(BYTECCLINKOPTS) -o ocamlrund$(EXE) \
prims.o libcamlrund.a $(BYTECCLIBS)
libcamlrun.a: $(OBJS)
diff --git a/byterun/Makefile.nt b/byterun/Makefile.nt
index b3afc561f..1dbda5852 100644
--- a/byterun/Makefile.nt
+++ b/byterun/Makefile.nt
@@ -15,17 +15,17 @@
include Makefile.common
-CFLAGS=-DOCAML_STDLIB_DIR='"$(LIBDIR)"' $(FLEXLINK)
+CFLAGS=-DOCAML_STDLIB_DIR='"$(LIBDIR)"' $(IFLEXDIR)
DBGO=d.$(O)
OBJS=$(COMMONOBJS:.o=.$(O)) win32.$(O) main.$(O)
DOBJS=$(OBJS:.$(O)=.$(DBGO)) instrtrace.$(DBGO)
ocamlrun$(EXE): libcamlrun.$(A) prims.$(O)
- $(call MKEXE,ocamlrun$(EXE),prims.$(O) libcamlrun.$(A))
+ $(MKEXE) -o ocamlrun$(EXE) prims.$(O) libcamlrun.$(A)
ocamlrund$(EXE): libcamlrund.$(A) prims.$(O) main.$(O)
- $(call MKEXE,ocamlrun$(EXE),$(BYTECCDBGCOMPOPTS) prims.$(O) libcamlrund.$(A))
+ $(MKEXE) -o ocamlrun$(EXE) $(BYTECCDBGCOMPOPTS) prims.$(O) libcamlrund.$(A)
libcamlrun.$(A): $(OBJS)
$(call MKLIB,libcamlrun.$(A),$(OBJS))
diff --git a/config/Makefile.mingw b/config/Makefile.mingw
index 00acc8b62..e266275ee 100644
--- a/config/Makefile.mingw
+++ b/config/Makefile.mingw
@@ -93,17 +93,12 @@ NATIVECCLIBS=
### How to invoke the C preprocessor
CPP=$(BYTECC) -E
-### Path to the FlexDLL includes
-FLEXDIR=$(shell flexlink -where)
-FLEXLINK=-I"$(FLEXDIR)"
-
-### How to build an EXE
-MKEXE=flexlink -merge-manifest -chain mingw -exe -o $(1) $(2) -- $(3)
-#ml let mkexe out files opts = Printf.sprintf "flexlink -merge-manifest -chain mingw -exe -o %s %s -- %s" out files opts;;
-
-### How to build a DLL
-MKDLL=flexlink -merge-manifest -chain mingw -o $(1) $(3) -- $(4)
-#ml let mkdll out implib files opts = Printf.sprintf "flexlink -merge-manifest -chain mingw -o %s %s -- %s" out files opts;;
+### Flexlink
+FLEXLINK=flexlink -chain mingw -merge-manifest
+FLEXDIR=$(shell $(FLEXLINK) -where)
+IFLEXDIR=-I"$(FLEXDIR)"
+MKDLL=$(FLEXLINK)
+MKEXE=$(FLEXLINK) -exe
### How to build a static library
MKLIB=rm -f $(1); ar rcs $(1) $(2)
diff --git a/config/Makefile.msvc b/config/Makefile.msvc
index 4404732a0..acf4b0e58 100644
--- a/config/Makefile.msvc
+++ b/config/Makefile.msvc
@@ -92,17 +92,12 @@ NATIVECCLIBS=advapi32.lib
### How to invoke the C preprocessor
CPP=cl /nologo /EP
-### Path to the FlexDLL includes
-FLEXDIR=$(shell flexlink -where)
-FLEXLINK=-I"$(FLEXDIR)"
-
-### How to build an EXE
-MKEXE=flexlink -merge-manifest -exe -o $(1) $(2) -- $(3)
-#ml let mkexe out files opts = Printf.sprintf "flexlink -merge-manifest -exe -o %s %s -- %s" out files opts;;
-
-### How to build a DLL
-MKDLL=flexlink -merge-manifest -o $(1) $(3) -- $(4)
-#ml let mkdll out implib files opts = Printf.sprintf "flexlink -merge-manifest -o %s %s -- %s" out files opts;;
+### Flexlink
+FLEXLINK=flexlink -merge-manifest
+FLEXDIR=$(shell $(FLEXLINK) -where)
+IFLEXDIR=-I"$(FLEXDIR)"
+MKDLL=$(FLEXLINK)
+MKEXE=$(FLEXLINK) -exe
### How to build a static library
MKLIB=link /lib /nologo /out:$(1) $(2)
diff --git a/config/Makefile.msvc64 b/config/Makefile.msvc64
index 9202cb01e..bbdbbf922 100644
--- a/config/Makefile.msvc64
+++ b/config/Makefile.msvc64
@@ -96,17 +96,12 @@ NATIVECCLIBS=advapi32.lib $(EXTRALIBS)
### How to invoke the C preprocessor
CPP=cl /nologo /EP
-### Path to the FlexDLL includes
-FLEXDIR=$(shell flexlink -where)
-FLEXLINK=-I"$(FLEXDIR)"
-
-### How to build an EXE
-MKEXE=flexlink -x64 -merge-manifest -exe -o $(1) $(2) $(EXTRALIBS) -- $(3)
-#ml let mkexe out files opts = Printf.sprintf "flexlink -x64 -merge-manifest -exe -o %s %s -- %s" out files opts;;
-
-### How to build a DLL
-MKDLL=flexlink -x64 -merge-manifest -o $(1) $(3) $(EXTRALIBS) -- $(4)
-#ml let mkdll out implib files opts = Printf.sprintf "flexlink -x64 -merge-manifest -o %s %s %s -- %s" out files extralibs opts;;
+### Flexlink
+FLEXLINK=flexlink -x64 -merge-manifest
+FLEXDIR=$(shell $(FLEXLINK) -where)
+IFLEXDIR=-I"$(FLEXDIR)"
+MKDLL=$(FLEXLINK)
+MKEXE=$(FLEXLINK) -exe
### How to build a static library
MKLIB=link /lib /nologo /machine:AMD64 /out:$(1) $(2)
diff --git a/configure b/configure
index 4a7f94f45..ad88e1800 100755
--- a/configure
+++ b/configure
@@ -239,13 +239,13 @@ esac
# Configure the bytecode compiler
bytecc="$cc"
-mkexe="\$(BYTECC) -o \$(1) \$(2) \$(3)"
-mkexe_ml="Printf.sprintf \"%s -o %s %s %s\" bytecc out opts files"
+mkexe="\$(BYTECC)"
bytecccompopts=""
bytecclinkopts=""
dllccompopts=""
ostype="Unix"
exe=""
+iflexdir=""
case "$bytecc,$host" in
cc,*-*-nextstep*)
@@ -301,8 +301,10 @@ case "$bytecc,$host" in
gcc*,*-*-cygwin*)
bytecccompopts="-fno-defer-pop $gcc_warnings -U_WIN32"
dllccompopts="-D_WIN32 -DCAML_DLL"
- mkexe="flexlink -exe -chain cygwin -o \$(1) \$(2) -- \$(3)"
- mkexe_ml="Printf.sprintf \"flexlink -exe -chain cygwin -o %s %s -- %s\" out files opts"
+ flexlink="flexlink -chain cygwin -merge-manifest"
+ flexdir=`$flexlink -where | dos2unix`
+ iflexdir="-I\"$flexdir\""
+ mkexe="$flexlink -exe"
exe=".exe"
ostype="Cygwin";;
gcc*,x86_64-*-linux*)
@@ -498,20 +500,18 @@ mksharedlib=''
byteccrpath=''
mksharedlibrpath=''
natdynlinkopts=""
-flexlink=''
cmxs="cmxa"
if test $withsharedlibs = "yes"; then
case "$host" in
*-*-cygwin*)
cmxs="cmxs"
- flexlink="-I`flexlink -where`"
- mksharedlib="flexlink -chain cygwin -o"
+ mksharedlib="$flexlink"
shared_libraries_supported=true;;
*-*-linux-gnu|*-*-linux|*-*-freebsd[3-9]*|*-*-openbsd*|*-*-netbsd*|*-*-gnu*)
cmxs="cmxs"
sharedcccompopts="-fPIC"
- mksharedlib="$bytecc -shared -o"
+ mksharedlib="$bytecc -shared"
bytecclinkopts="$bytecclinkopts -Wl,-E"
byteccrpath="-Wl,-rpath,"
mksharedlibrpath="-Wl,-rpath,"
@@ -521,13 +521,13 @@ if test $withsharedlibs = "yes"; then
case "$bytecc" in
gcc*)
sharedcccompopts="-fPIC"
- mksharedlib="$bytecc -shared -o"
+ mksharedlib="$bytecc -shared"
byteccrpath="-Wl,-rpath,"
mksharedlibrpath="-Wl,-rpath,"
shared_libraries_supported=true;;
cc*)
sharedcccompopts=""
- mksharedlib="ld -shared -expect_unresolved '*' -o"
+ mksharedlib="ld -shared -expect_unresolved '*'"
byteccrpath="-Wl,-rpath,"
mksharedlibrpath="-rpath "
shared_libraries_supported=true;;
@@ -537,11 +537,11 @@ if test $withsharedlibs = "yes"; then
gcc*)
sharedcccompopts="-fPIC"
if sh ./solaris-ld; then
- mksharedlib="$bytecc -shared -o"
+ mksharedlib="$bytecc -shared"
byteccrpath="-R"
mksharedlibrpath="-R"
else
- mksharedlib="$bytecc -shared -o"
+ mksharedlib="$bytecc -shared"
bytecclinkopts="$bytecclinkopts -Wl,-E"
byteccrpath="-Wl,-rpath,"
mksharedlibrpath="-Wl,-rpath,"
@@ -551,7 +551,7 @@ if test $withsharedlibs = "yes"; then
sharedcccompopts="-KPIC"
byteccrpath="-R"
mksharedlibrpath="-R"
- mksharedlib="/usr/ccs/bin/ld -G -o"
+ mksharedlib="/usr/ccs/bin/ld -G"
shared_libraries_supported=true;;
esac;;
mips*-*-irix[56]*)
@@ -559,7 +559,7 @@ if test $withsharedlibs = "yes"; then
cc*) sharedcccompopts="";;
gcc*) sharedcccompopts="-fPIC";;
esac
- mksharedlib="ld -shared -rdata_shared -o"
+ mksharedlib="ld -shared -rdata_shared"
byteccrpath="-Wl,-rpath,"
mksharedlibrpath="-rpath "
shared_libraries_supported=true;;
@@ -569,12 +569,12 @@ if test $withsharedlibs = "yes"; then
# The new linker in Mac OS X 10.5 does not support read_only_relocs
dyld=/usr/bin/ld_classic
fi
- mksharedlib="$dyld -bundle -flat_namespace -undefined suppress -read_only_relocs suppress -o"
+ mksharedlib="$dyld -bundle -flat_namespace -undefined suppress -read_only_relocs suppress"
bytecccompopts="$dl_defs $bytecccompopts"
dl_needs_underscore=false
shared_libraries_supported=true;;
*-apple-darwin*)
- mksharedlib="$bytecc -bundle -flat_namespace -undefined suppress -o"
+ mksharedlib="$bytecc -bundle -flat_namespace -undefined suppress"
bytecccompopts="$dl_defs $bytecccompopts"
#sharedcccompopts="-fnocommon"
dl_needs_underscore=false
@@ -585,7 +585,7 @@ if test $withsharedlibs = "yes"; then
shared_libraries_supported=false;;
*-*-openbsd*)
sharedcccompopts="-fPIC"
- mksharedlib="$bytecc -shared -o"
+ mksharedlib="$bytecc -shared"
bytecclinkopts="$bytecclinkopts -Wl,-E"
byteccrpath="-Wl,-rpath,"
mksharedlibrpath="-Wl,-rpath,"
@@ -1493,13 +1493,6 @@ cat >> Makefile <<EOF
SYSLIB=-l\$(1)
#ml let syslib x = "-l"^x;;
-MKEXE=$mkexe
-#ml let mkexe out files opts = $mkexe_ml;;
-
-### How to build a DLL
-MKDLL=$mksharedlib \$(1) \$(3)
-#ml let mkdll out _implib files opts = Printf.sprintf "%s %s %s %s" "$mksharedlib" out opts files;;
-
### How to build a static library
MKLIB=ar rc \$(1) \$(2); ranlib \$(1)
#ml let mklib out files opts = Printf.sprintf "ar rc %s %s %s; ranlib %s" out opts files out;;
@@ -1524,7 +1517,7 @@ echo "CC_PROFILE=$cc_profile" >> Makefile
echo "SYSTHREAD_SUPPORT=$systhread_support" >> Makefile
echo "PARTIALLD=$partialld" >> Makefile
echo "DLLCCCOMPOPTS=$dllccompopts" >> Makefile
-echo "FLEXLINK=$flexlink" >> Makefile
+echo "IFLEXDIR=$iflexdir" >> Makefile
echo "O=o" >> Makefile
echo "A=a" >> Makefile
echo "EXT_OBJ=.o" >> Makefile
@@ -1535,7 +1528,8 @@ echo "EXTRALIBS=" >> Makefile
echo "CCOMPTYPE=cc" >> Makefile
echo "TOOLCHAIN=cc" >> Makefile
echo "CMXS=$cmxs" >> Makefile
-echo "MKSHAREDLIB=$mksharedlib" >> Makefile
+echo "MKEXE=$mkexe" >> Makefile
+echo "MKDLL=$mksharedlib" >> Makefile
rm -f tst hasgot.c
rm -f ../m.h ../s.h ../Makefile
@@ -1558,7 +1552,7 @@ echo " options for linking....... $bytecclinkopts $cclibs $dllib $cursesl
if $shared_libraries_supported; then
echo " shared libraries are supported"
echo " options for compiling..... $sharedcccompopts $bytecccompopts"
-echo " command for building...... $mksharedlib lib.so $mksharedlibrpath/a/path objs"
+echo " command for building...... $mksharedlib -o lib.so $mksharedlibrpath/a/path objs"
else
echo " shared libraries not supported"
fi
diff --git a/myocamlbuild.ml b/myocamlbuild.ml
index c56404343..b6f44e3ef 100644
--- a/myocamlbuild.ml
+++ b/myocamlbuild.ml
@@ -14,13 +14,13 @@ let fp_cat oc f = with_input_file ~bin:true f (fun ic -> copy_chan ic oc)
(* Improve using the command module in Myocamlbuild_config
with the variant version (`S, `A...) *)
-let mkdll out implib files opts =
+let mkdll out files opts =
let s = Command.string_of_command_spec in
- Cmd(Sh(C.mkdll out (s implib) (s files) (s opts)))
+ Cmd(Sh(Printf.sprintf "%s -o %s %s %s" C.mkdll out (s files) (s opts)))
let mkexe out files opts =
let s = Command.string_of_command_spec in
- Cmd(Sh(C.mkexe out (s files) (s opts)))
+ Cmd(Sh(Printf.sprintf "%s -o %s %s %s" C.mkexe out (s files) (s opts)))
let mklib out files opts =
let s = Command.string_of_command_spec in
@@ -631,7 +631,7 @@ rule "ocaml C stubs on windows: dlib & d.o* -> dll"
| Outcome.Good d_o -> d_o
| Outcome.Bad exn -> raise exn
end resluts in
- mkdll dll (P("tmp"-.-C.a)) (S[atomize objs; P("byterun/ocamlrun"-.-C.a)])
+ mkdll dll (S[atomize objs; P("byterun/ocamlrun"-.-C.a)])
(T(tags_of_pathname dll++"dll"++"link"++"c"))
end;;
diff --git a/myocamlbuild_config.mli b/myocamlbuild_config.mli
index 37f0d8acd..ff8cb807c 100644
--- a/myocamlbuild_config.mli
+++ b/myocamlbuild_config.mli
@@ -43,8 +43,8 @@ val cc_profile : string
val systhread_support : bool
val partialld : string
val syslib : string -> string
-val mkexe : string -> string -> string -> string
-val mkdll : string -> string -> string -> string -> string
+val mkexe : string
+val mkdll : string
val mklib : string -> string -> string -> string
val ext_lib : string
val ext_obj : string
diff --git a/stdlib/Makefile.nt b/stdlib/Makefile.nt
index 1182ecc25..499c59ad4 100644
--- a/stdlib/Makefile.nt
+++ b/stdlib/Makefile.nt
@@ -56,7 +56,7 @@ stdlib.cmxa: $(OBJS:.cmo=.cmx)
camlheader camlheader_ur: headernt.c ../config/Makefile
$(BYTECC) $(BYTECCCOMPOPTS) -c -I../byterun headernt.c
- $(call MKEXE,tmpheader.exe,headernt.$(O) $(EXTRALIBS), $(BYTECCLINKOPTS))
+ $(MKEXE) -o tmpheader.exe headernt.$(O) $(EXTRALIBS)
rm -f camlheader.exe
mv tmpheader.exe camlheader
cp camlheader camlheader_ur
diff --git a/tools/Makefile.shared b/tools/Makefile.shared
index 154be6429..8025d9c8a 100644
--- a/tools/Makefile.shared
+++ b/tools/Makefile.shared
@@ -86,7 +86,7 @@ ocamlmklib: myocamlbuild_config.cmo ocamlmklib.cmo
$(CAMLC) $(LINKFLAGS) -o ocamlmklib myocamlbuild_config.cmo ocamlmklib.cmo
ocamlmklib.cmo: myocamlbuild_config.cmi
-myocamlbuild_config.ml: ../config/Makefile
+myocamlbuild_config.ml: ../config/Makefile ../build/mkmyocamlbuild_config.sh
../build/mkmyocamlbuild_config.sh
cp ../myocamlbuild_config.ml .
diff --git a/tools/ocamlmklib.mlp b/tools/ocamlmklib.mlp
index fcf2396c6..882884ccb 100644
--- a/tools/ocamlmklib.mlp
+++ b/tools/ocamlmklib.mlp
@@ -206,14 +206,16 @@ let build_libs () =
if !c_objs <> [] then begin
if !dynlink then begin
let retcode = command
- (mkdll (prepostfix "dll" !output_c ext_dll)
- "" (* no implib *)
- (sprintf "%s %s %s %s %s"
- (String.concat " " !c_objs)
- (String.concat " " !c_opts)
- (String.concat " " !ld_opts)
- (make_rpath mksharedlibrpath)
- (String.concat " " !c_libs)) "") in
+ (Printf.sprintf "%s -o %s %s %s %s %s %s"
+ mkdll
+ (prepostfix "dll" !output_c ext_dll)
+ (String.concat " " !c_objs)
+ (String.concat " " !c_opts)
+ (String.concat " " !ld_opts)
+ (make_rpath mksharedlibrpath)
+ (String.concat " " !c_libs)
+ )
+ in
if retcode <> 0 then if !failsafe then dynlink := false else exit 2
end;
safe_remove (prepostfix "lib" !output_c ext_lib);
diff --git a/utils/ccomp.ml b/utils/ccomp.ml
index d290a8c1c..255722ce2 100644
--- a/utils/ccomp.ml
+++ b/utils/ccomp.ml
@@ -28,38 +28,33 @@ let run_command cmdline = ignore(command cmdline)
command-line length *)
let build_diversion lst =
let (responsefile, oc) = Filename.open_temp_file "camlresp" "" in
- List.iter
- (fun f ->
- if f <> "" then begin
- output_string oc (Filename.quote f); output_char oc '\n'
- end)
- lst;
+ List.iter (fun f -> Printf.fprintf oc "%s\n" f) lst;
close_out oc;
at_exit (fun () -> Misc.remove_file responsefile);
"@" ^ responsefile
-let need_diversion = match Sys.os_type with
- | "Win32" (* | "Cygwin" *) -> true
- | _ -> false
-
let quote_files lst =
- let s =
- String.concat " "
- (List.map (fun f -> if f = "" then f else Filename.quote f) lst) in
- if String.length s >= 8192 && need_diversion
- then build_diversion lst
+ let lst = List.filter (fun f -> f <> "") lst in
+ let quoted = List.map Filename.quote lst in
+ let s = String.concat " " quoted in
+ if String.length s >= 4096 && Sys.os_type = "Win32"
+ then build_diversion quoted
else s
+let quote_prefixed pr lst =
+ let lst = List.filter (fun f -> f <> "") lst in
+ let lst = List.map (fun f -> pr ^ f) lst in
+ quote_files lst
+
let compile_file name =
- command
- (Printf.sprintf
- "%s -c %s %s %s %s"
- !Clflags.c_compiler
- (String.concat " " (List.rev !Clflags.ccopts))
- (quote_files
- (List.rev_map (fun dir -> "-I" ^ dir) !Clflags.include_dirs))
- (Clflags.std_include_flag "-I")
- (Filename.quote name))
+ command
+ (Printf.sprintf
+ "%s -c %s %s %s %s"
+ !Clflags.c_compiler
+ (String.concat " " (List.rev !Clflags.ccopts))
+ (quote_prefixed "-I" (List.rev !Clflags.include_dirs))
+ (Clflags.std_include_flag "-I")
+ (Filename.quote name))
let create_archive archive file_list =
Misc.remove_file archive;
@@ -88,15 +83,24 @@ let expand_libname name =
libname
end
-(* Handling of msvc's /link options *)
+type link_mode =
+ | Exe
+ | Dll
-let make_link_options optlist =
- let rec split linkopts otheropts = function
- | [] -> String.concat " " otheropts
- ^ " -- " ^ String.concat " " linkopts
- | opt :: rem ->
- if String.length opt >= 5 && String.sub opt 0 5 = "/link"
- then split (String.sub opt 5 (String.length opt - 5) :: linkopts)
- otheropts rem
- else split linkopts (opt :: otheropts) rem
- in split [] [] optlist
+let call_linker mode output_name files extra =
+ let files = quote_files files in
+ let cmd =
+ Printf.sprintf "%s -o %s %s %s %s %s %s %s"
+ (match mode with
+ | Exe -> Config.mkexe
+ | Dll -> Config.mkdll
+ )
+ (Filename.quote output_name)
+ (if !Clflags.gprofile then Config.cc_profile else "")
+ (Clflags.std_include_flag "-I")
+ (quote_prefixed "-L" !Config.load_path)
+ files
+ extra
+ (String.concat " " (List.rev !Clflags.ccopts))
+ in
+ command cmd = 0
diff --git a/utils/ccomp.mli b/utils/ccomp.mli
index d5d49c772..bf6bc443d 100644
--- a/utils/ccomp.mli
+++ b/utils/ccomp.mli
@@ -20,4 +20,10 @@ val compile_file: string -> int
val create_archive: string -> string list -> int
val expand_libname: string -> string
val quote_files: string list -> string
-val make_link_options: string list -> string
+(*val make_link_options: string list -> string*)
+
+type link_mode =
+ | Exe
+ | Dll
+
+val call_linker: link_mode -> string -> string list -> string -> bool
diff --git a/utils/config.mli b/utils/config.mli
index e5066813a..7078e352c 100644
--- a/utils/config.mli
+++ b/utils/config.mli
@@ -46,8 +46,10 @@ val native_partial_linker: string
(* The linker to use for partial links (ocamlopt -output-obj) *)
val native_pack_linker: string
(* The linker to use for packaging (ocamlopt -pack) *)
-val mksharedlib: string
+val mkdll: string
(* The linker command line to build dynamic libraries. *)
+val mkexe: string
+ (* The linker command line to executables. *)
val ranlib: string
(* Command to randomize a library, or "" if not needed *)
val cc_profile : string
diff --git a/utils/config.mlp b/utils/config.mlp
index a283044cc..2b301cce1 100644
--- a/utils/config.mlp
+++ b/utils/config.mlp
@@ -38,7 +38,8 @@ let native_partial_linker = "%%PARTIALLD%%"
let native_pack_linker = "%%PACKLD%%"
let ranlib = "%%RANLIBCMD%%"
let cc_profile = "%%CC_PROFILE%%"
-let mksharedlib = "%%MKSHAREDLIB%%"
+let mkdll = "%%MKDLL%%"
+let mkexe = "%%MKEXE%%"
let exec_magic_number = "Caml1999X008"
and cmi_magic_number = "Caml1999I011"
diff --git a/win32caml/Makefile b/win32caml/Makefile
index 31bd426e6..a73b73152 100644
--- a/win32caml/Makefile
+++ b/win32caml/Makefile
@@ -27,7 +27,7 @@ LIBS=$(call SYSLIB,kernel32) $(call SYSLIB,advapi32) $(call SYSLIB,gdi32) \
all: ocamlwin.exe
ocamlwin.exe: $(OBJS)
- $(call MKEXE,ocamlwin.exe,$(OBJS) $(LIBS) $(EXTRALIBS))
+ $(MKEXE) -o ocamlwin.exe $(OBJS) $(LIBS) $(EXTRALIBS) -subsystem windows
ocamlres.$(O): ocaml.rc ocaml.ico
ifeq ($(TOOLCHAIN),msvc)
diff --git a/yacc/Makefile.nt b/yacc/Makefile.nt
index 8f603bb1e..ec1cbfb44 100644
--- a/yacc/Makefile.nt
+++ b/yacc/Makefile.nt
@@ -23,7 +23,7 @@ OBJS= closure.$(O) error.$(O) lalr.$(O) lr0.$(O) main.$(O) \
all: ocamlyacc.exe
ocamlyacc.exe: $(OBJS)
- $(call MKEXE,ocamlyacc.exe,$(OBJS) $(EXTRALIBS),$(BYTECCLINKOPTS))
+ $(MKEXE) -o ocamlyacc.exe $(OBJS) $(EXTRALIBS)
version.h : ../VERSION
echo "#define OCAML_VERSION \"`head -1 ../VERSION`\"" >version.h