Skip to content

Commit

Permalink
rdmd: Fix building library files (Issue 6535)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed Mar 10, 2013
1 parent a68729d commit 0ce81aa
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions rdmd.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ version (Posix)
{
enum objExt = ".o";
enum binExt = "";
enum libExt = ".a";
enum altDirSeparator = "";
}
else version (Windows)
Expand All @@ -17,6 +18,7 @@ else version (Windows)
extern(Windows) HINSTANCE ShellExecuteA(HWND, LPCSTR, LPCSTR, LPCSTR, LPCSTR, INT);
enum objExt = ".obj";
enum binExt = ".exe";
enum libExt = ".lib";
enum altDirSeparator = "/";
}
else
Expand Down Expand Up @@ -164,13 +166,22 @@ int main(string[] args)
assert(args.length >= 1);
auto compilerFlags = args[1 .. $];

bool lib = args.canFind("-lib");
string outExt = lib ? libExt : binExt;

// --build-only implies the user would like a binary in the program's directory
if (buildOnly && !exe)
exe = exeDirname ~ dirSeparator;

if (exe && exe.endsWith(dirSeparator))
{
// user specified a directory, complete it to a file
exe = buildPath(exe, exeBasename) ~ outExt;
}

// Compute the object directory and ensure it exists
immutable workDir = getWorkPath(root, compilerFlags);
immutable objDir = buildPath(workDir, "objs");
string objDir = buildPath(workDir, "objs");
yap("stat ", workDir);
DirEntry workDirEntry;
const workDirExists =
Expand All @@ -186,6 +197,15 @@ int main(string[] args)
mkdirRecurse(workDir);
}

if (lib)
{
// When building libraries, DMD does not generate object files.
// Instead, it uses the -od parameter as the location for the library file.
// Thus, override objDir (which is normally a temporary directory)
// to be the target output directory.
objDir = exe.dirName;
}

// Fetch dependencies
const myDeps = getDependencies(root, workDir, objDir, compilerFlags);

Expand Down Expand Up @@ -219,11 +239,6 @@ int main(string[] args)
if (exe)
{
// user-specified exe name
if (exe.endsWith(dirSeparator))
{
// user specified a directory, complete it to a file
exe = buildPath(exe, exeBasename) ~ binExt;
}
buildWitness = buildPath(workDir, ".built");
if (!exe.newerThan(buildWitness))
{
Expand All @@ -235,7 +250,7 @@ int main(string[] args)
}
else
{
exe = buildPath(workDir, exeBasename) ~ binExt;
exe = buildPath(workDir, exeBasename) ~ outExt;
buildWitness = exe;
lastBuildTime = buildWitness.timeLastModified(SysTime.min);
}
Expand Down Expand Up @@ -413,7 +428,7 @@ private int rebuild(string root, string fullExe,
if (!dryRun)
{
yap("stat ", objDir);
if (objDir.exists)
if (objDir.exists && objDir.startsWith(workDir))
{
yap("rmdirRecurse ", objDir);
rmdirRecurse(objDir);
Expand Down

0 comments on commit 0ce81aa

Please sign in to comment.