diff --git a/source/dub/compilers/compiler.d b/source/dub/compilers/compiler.d index 3456d68..9c6bcbc 100644 --- a/source/dub/compilers/compiler.d +++ b/source/dub/compilers/compiler.d @@ -245,6 +245,9 @@ /// Invokes the underlying linker directly void invokeLinker(in BuildSettings settings, in BuildPlatform platform, string[] objects, void delegate(int, string) output_callback); + /// Convert linker flags to compiler format + string[] lflagsToDFlags(in string[] lflags) const; + protected final void invokeTool(string[] args, void delegate(int, string) output_callback) { import std.string; diff --git a/source/dub/compilers/dmd.d b/source/dub/compilers/dmd.d index a5e6364..53d7626 100644 --- a/source/dub/compilers/dmd.d +++ b/source/dub/compilers/dmd.d @@ -131,7 +131,7 @@ } if (!(fields & BuildSetting.lflags)) { - settings.addDFlags(settings.lflags.map!(f => "-L"~f)().array()); + settings.addDFlags(lflagsToDFlags(settings.lflags)); settings.lflags = null; } @@ -204,7 +204,7 @@ args ~= objects; args ~= settings.sourceFiles; version(linux) args ~= "-L--no-as-needed"; // avoids linker errors due to libraries being speficied in the wrong order by DMD - args ~= settings.lflags.map!(l => "-L"~l)().array; + args ~= lflagsToDFlags(settings.lflags); args ~= settings.dflags.filter!(f => isLinkerDFlag(f)).array; auto res_file = getTempFile("dub-build", ".lnk"); @@ -214,6 +214,11 @@ invokeTool([platform.compilerBinary, "@"~res_file.toNativeString()], output_callback); } + string[] lflagsToDFlags(in string[] lflags) const + { + return lflags.map!(f => "-L"~f)().array(); + } + private auto escapeArgs(in string[] args) { return args.map!(s => s.canFind(' ') ? "\""~s~"\"" : s); diff --git a/source/dub/compilers/gdc.d b/source/dub/compilers/gdc.d index e2985f0..1eac982 100644 --- a/source/dub/compilers/gdc.d +++ b/source/dub/compilers/gdc.d @@ -136,8 +136,7 @@ } if (!(fields & BuildSetting.lflags)) { - foreach( f; settings.lflags ) - settings.addDFlags(["-Xlinker", f]); + settings.addDFlags(lflagsToDFlags(settings.lflags)); settings.lflags = null; } @@ -211,6 +210,18 @@ logDiagnostic("%s", args.join(" ")); invokeTool(args, output_callback); } + + string[] lflagsToDFlags(in string[] lflags) const + { + string[] dflags; + foreach( f; lflags ) + { + dflags ~= "-Xlinker"; + dflags ~= f; + } + + return dflags; + } } private string extractTarget(const string[] args) { auto i = args.countUntil("-o"); return i >= 0 ? args[i+1] : null; } diff --git a/source/dub/compilers/ldc.d b/source/dub/compilers/ldc.d index f09ba96..098e756 100644 --- a/source/dub/compilers/ldc.d +++ b/source/dub/compilers/ldc.d @@ -120,7 +120,7 @@ } if (!(fields & BuildSetting.lflags)) { - settings.addDFlags(settings.lflags.map!(s => "-L="~s)().array()); + settings.addDFlags(lflagsToDFlags(settings.lflags)); settings.lflags = null; } @@ -184,4 +184,9 @@ { assert(false, "Separate linking not implemented for LDC"); } + + string[] lflagsToDFlags(in string[] lflags) const + { + return lflags.map!(s => "-L="~s)().array(); + } } diff --git a/source/dub/project.d b/source/dub/project.d index a438953..5e65007 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -693,9 +693,9 @@ compiler.prepareBuildSettings(bs, BuildSetting.all & ~to!BuildSetting(attributeName)); if (bs.lflags) - values = bs.lflags; + values = compiler.lflagsToDFlags( bs.lflags ); else if (bs.sourceFiles) - values = bs.sourceFiles; + values = compiler.lflagsToDFlags( bs.sourceFiles ); else values = bs.dflags; diff --git a/test/4-describe-data-2-dmd.sh b/test/4-describe-data-2-dmd.sh index af0681c..64af07d 100755 --- a/test/4-describe-data-2-dmd.sh +++ b/test/4-describe-data-2-dmd.sh @@ -43,8 +43,8 @@ echo -n "-L--some-lflag " >> "$expected_file" echo -n "-L--another-lflag " >> "$expected_file" # --data=libs -echo -n "-lcrypto " >> "$expected_file" -echo -n "-lcurl " >> "$expected_file" +echo -n "-L-lcrypto " >> "$expected_file" +echo -n "-L-lcurl " >> "$expected_file" # --data=linker-files echo -n "'$CURR_DIR/describe-dependency-3/libdescribe-dependency-3.a' " >> "$expected_file" echo -n "'$CURR_DIR/describe-project/some.a' " >> "$expected_file"