Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Next version
- GPR#133, GPR#147: Allow default libraries to be marked as optional (David Allsopp, report by Romain Beauxis)
- GPR#157: Improve flexlink support on Unix (for cross-compiling contexts).
(Antonin Décimo, review by David Allsopp)
- GPR#158: Reuse the compilers used during the build for later operations, such
as querying the compilers for their library search paths. Support parsing
clang output.
(Antonin Décimo, review by David Allsopp)

Version 0.43
- GPR#108: Add -lgcc_s to Cygwin's link libraries, upstreaming a patch from the
Expand Down
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@ CYGWIN64_PREFIX = x86_64-pc-cygwin-
CYG64CC = $(CYGWIN64_PREFIX)gcc

version.ml: Makefile flexdll.opam
echo "let version = \"$(VERSION)\"" > version.ml
echo "let mingw_prefix = \"$(MINGW_PREFIX)\"" >> version.ml
echo "let mingw64_prefix = \"$(MINGW64_PREFIX)\"" >> version.ml
echo 'let version = "$(VERSION)"' > $@
echo 'let mingw_prefix = "$(MINGW_PREFIX)"' >> $@
echo 'let mingw64_prefix = "$(MINGW64_PREFIX)"' >> $@
echo 'let msvc = "$(notdir $(MSVCC))"' >> $@
echo 'let msvc64 = "$(notdir $(MSVCC64))"' >> $@
echo 'let cygwin64 = "$(notdir $(CYG64CC))"' >> $@
echo 'let mingw = "$(notdir $(MINCC))"' >> $@
echo 'let mingw64 = "$(notdir $(MIN64CC))"' >> $@
echo 'let gnat = "gcc"' >> $@

# Supported tool-chains

Expand Down
51 changes: 28 additions & 23 deletions reloc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ let debug ?(dry_mode = {contents=false}) min_level fmt =
let search_path = ref []
let default_libs = ref []

let gcc = ref "gcc"
let cc = function
| `MSVC -> Version.msvc
| `MSVC64 -> Version.msvc64
| `CYGWIN64 -> Version.cygwin64
| `MINGW -> Version.mingw
| `MINGW64 -> Version.mingw64
| `GNAT | `GNAT64 -> Version.gnat
| `LIGHTLD -> failwith "No C compiler configured for this toolchain."

let objdump = ref "objdump"

let is_crt_lib = function
Expand Down Expand Up @@ -1173,7 +1181,7 @@ let build_dll link_exe output_file files exts extra_args =
in
Printf.sprintf
"%s %s%s%s -L. %s %s -o %s %s %s %s %s"
!gcc
(cc !toolchain)
(Option.fold ~none:"" ~some:(fun ld -> "-fuse-ld=" ^ ld ^ " ") !Cmdline.use_linker)
(if link_exe = `EXE then "" else "-shared ")
(if main_pgm then "" else if !noentry then "-Wl,-e0 " else if !machine = `x86 then "-Wl,-e_FlexDLLiniter@12 " else "-Wl,-eFlexDLLiniter ")
Expand All @@ -1195,7 +1203,7 @@ let build_dll link_exe output_file files exts extra_args =
in
Printf.sprintf
"%s -m%s %s%s%s -L. %s %s -o %s %s %s %s %s %s"
!gcc
(cc !toolchain)
!subsystem
(Option.fold ~none:"" ~some:(fun ld -> "-fuse-ld=" ^ ld ^ " ") !Cmdline.use_linker)
(if link_exe = `EXE then "" else "-shared ")
Expand Down Expand Up @@ -1338,13 +1346,17 @@ let remove_duplicate_paths paths =

let setup_toolchain () =
let mingw_libs pre =
gcc := pre ^ "gcc";
objdump := pre ^ "objdump";
let rec get_lib_search_dirs install libraries input =
match input with
| entry :: input ->
if String.length entry > 9 && String.sub entry 0 9 = "install: " then
get_lib_search_dirs (String.sub entry 9 (String.length entry - 9)) libraries input
let install = String.sub entry 9 (String.length entry - 9) in
(* Ensure install does not end with a separator (or
[Sys.is_directory] will fail) *)
let install = Filename.concat install Filename.current_dir_name
|> Filename.dirname in
get_lib_search_dirs (Some install) libraries input
else begin try
match split entry '=' with
| "libraries: ", paths -> get_lib_search_dirs install paths input
Expand All @@ -1353,18 +1365,9 @@ let setup_toolchain () =
get_lib_search_dirs install libraries input
end
| [] ->
let install =
if install <> "" then
(* Ensure install does not end with a separator (or
Sys.is_directory will fail) *)
Filename.concat install Filename.current_dir_name
|> Filename.dirname
else
""
in
let separator, run_through_cygpath =
if Sys.win32 then
if dir_exists_no_cygpath install then
if Option.fold ~none:true ~some:dir_exists_no_cygpath install then
';', false
else
':', (!use_cygpath <> `No)
Expand All @@ -1378,13 +1381,14 @@ let setup_toolchain () =
libraries
in
let lib_search_dirs =
get_lib_search_dirs "" "" (get_output "%s -print-search-dirs" !gcc)
get_lib_search_dirs None "" (get_output "%s -print-search-dirs" (cc !toolchain))
|> List.filter (( <> ) "")
|> List.map normalize_path
|> remove_duplicate_paths
in
search_path := !dirs @ lib_search_dirs;
if !verbose >= 1 then begin
print_endline "lib search dirs:";
Printf.printf "lib search dirs (%s):\n" (cc !toolchain);
List.iter (Printf.printf " %s\n") lib_search_dirs;
flush stdout
end;
Expand All @@ -1410,14 +1414,13 @@ let setup_toolchain () =
add_flexdll_obj := false;
noentry := true
| `CYGWIN64 ->
gcc := "gcc";
objdump := "objdump";
search_path :=
!dirs @
[
"/lib";
"/lib/w32api";
Filename.dirname (get_output1 ~use_bash:true "gcc -print-libgcc-file-name");
Filename.dirname (get_output1 ~use_bash:true "%s -print-libgcc-file-name" (cc !toolchain));
];
default_libs := ["-lkernel32"; "-luser32"; "-ladvapi32";
"-lshell32"; "-lcygwin"; "-lgcc_s"; "-lgcc"]
Expand All @@ -1436,7 +1439,7 @@ let setup_toolchain () =
search_path :=
!dirs @
[
Filename.dirname (get_output1 "%s -print-libgcc-file-name" !gcc);
Filename.dirname (get_output1 "%s -print-libgcc-file-name" (cc !toolchain));
read_gnatls ();
];
default_libs :=
Expand Down Expand Up @@ -1475,21 +1478,23 @@ let compile_if_needed file =
let cmd = match !toolchain with
| `MSVC | `MSVC64 ->
Printf.sprintf
"cl /c /MD /nologo /Fo%s %s %s%s"
"%s /c /MD /nologo /Fo%s %s %s%s"
(cc !toolchain)
(Filename.quote tmp_obj)
(mk_dirs_opt "/I")
file
pipe
| `CYGWIN64 ->
Printf.sprintf
"gcc -c -o %s %s %s"
"%s -c -o %s %s %s"
(cc !toolchain)
(Filename.quote tmp_obj)
(mk_dirs_opt "-I")
file
| `MINGW | `MINGW64 | `GNAT | `GNAT64 ->
Printf.sprintf
"%s -c -o %s %s %s"
!gcc
(cc !toolchain)
(Filename.quote tmp_obj)
(mk_dirs_opt "-I")
(Filename.quote file)
Expand Down