|
18 | 18 | #include "llvm/Support/FileSystem.h"
|
19 | 19 | #include "llvm/Support/SourceMgr.h"
|
20 | 20 |
|
| 21 | +namespace cl = llvm::cl; |
| 22 | + |
21 | 23 | //////////////////////////////////////////////////////////////////////////////
|
22 | 24 |
|
23 | 25 | #if LDC_WITH_LLD
|
24 |
| -static llvm::cl::opt<bool> |
25 |
| - useInternalLinker("link-internally", llvm::cl::ZeroOrMore, |
26 |
| - llvm::cl::desc("Use internal LLD for linking"), |
27 |
| - llvm::cl::cat(opts::linkingCategory)); |
| 26 | +static cl::opt<bool> useInternalLinker("link-internally", cl::ZeroOrMore, |
| 27 | + cl::desc("Use internal LLD for linking"), |
| 28 | + cl::cat(opts::linkingCategory)); |
28 | 29 | #else
|
29 | 30 | constexpr bool useInternalLinker = false;
|
30 | 31 | #endif
|
31 | 32 |
|
| 33 | +static cl::opt<cl::boolOrDefault> |
| 34 | + staticFlag("static", cl::ZeroOrMore, |
| 35 | + cl::desc("Create a statically linked binary, including " |
| 36 | + "all system dependencies"), |
| 37 | + cl::cat(opts::linkingCategory)); |
| 38 | + |
| 39 | +static cl::opt<cl::boolOrDefault> linkDefaultLibShared( |
| 40 | + "link-defaultlib-shared", cl::ZeroOrMore, |
| 41 | + cl::desc("Link with shared versions of default libraries"), |
| 42 | + cl::cat(opts::linkingCategory)); |
| 43 | + |
32 | 44 | //////////////////////////////////////////////////////////////////////////////
|
33 | 45 |
|
34 | 46 | // linker-gcc.cpp
|
35 | 47 | int linkObjToBinaryGcc(llvm::StringRef outputPath, bool useInternalLinker,
|
36 |
| - llvm::cl::boolOrDefault fullyStaticFlag); |
| 48 | + cl::boolOrDefault fullyStaticFlag); |
37 | 49 |
|
38 | 50 | // linker-msvc.cpp
|
39 | 51 | int linkObjToBinaryMSVC(llvm::StringRef outputPath, bool useInternalLinker,
|
40 |
| - llvm::cl::boolOrDefault fullyStaticFlag); |
| 52 | + cl::boolOrDefault fullyStaticFlag); |
41 | 53 |
|
42 | 54 | //////////////////////////////////////////////////////////////////////////////
|
43 | 55 |
|
@@ -87,6 +99,16 @@ static std::string getOutputName() {
|
87 | 99 |
|
88 | 100 | //////////////////////////////////////////////////////////////////////////////
|
89 | 101 |
|
| 102 | +bool willLinkAgainstSharedDefaultLibs() { |
| 103 | + // -static enforces static default libs. |
| 104 | + // Default to shared default libs for DLLs. |
| 105 | + return staticFlag != cl::BOU_TRUE && |
| 106 | + (linkDefaultLibShared == cl::BOU_TRUE || |
| 107 | + (linkDefaultLibShared == cl::BOU_UNSET && global.params.dll)); |
| 108 | +} |
| 109 | + |
| 110 | +////////////////////////////////////////////////////////////////////////////// |
| 111 | + |
90 | 112 | /// Insert an LLVM bitcode file into the module
|
91 | 113 | static void insertBitcodeIntoModule(const char *bcFile, llvm::Module &M,
|
92 | 114 | llvm::LLVMContext &Context) {
|
@@ -130,10 +152,10 @@ int linkObjToBinary() {
|
130 | 152 | createDirectoryForFileOrFail(gExePath);
|
131 | 153 |
|
132 | 154 | if (global.params.targetTriple->isWindowsMSVCEnvironment()) {
|
133 |
| - return linkObjToBinaryMSVC(gExePath, useInternalLinker, opts::staticFlag); |
| 155 | + return linkObjToBinaryMSVC(gExePath, useInternalLinker, staticFlag); |
134 | 156 | }
|
135 | 157 |
|
136 |
| - return linkObjToBinaryGcc(gExePath, useInternalLinker, opts::staticFlag); |
| 158 | + return linkObjToBinaryGcc(gExePath, useInternalLinker, staticFlag); |
137 | 159 | }
|
138 | 160 |
|
139 | 161 | //////////////////////////////////////////////////////////////////////////////
|
|
0 commit comments