rdmd: Support -shared in the same way as -lib

This commit is contained in:
Vladimir Panteleev 2023-04-30 06:25:17 +00:00
parent 02365fafdd
commit b7d2ef2f41
No known key found for this signature in database
GPG key ID: 5004F0FAD051576D
2 changed files with 14 additions and 4 deletions

3
changelog/rdmd_shared.dd Normal file
View file

@ -0,0 +1,3 @@
rdmd supports `-shared`
rdmd now understands DMD's `-shared` switch, and sets the default output file name appropriately (`.dll` or `so` depending on the platform), in the same way as `-lib`.

15
rdmd.d
View file

@ -27,6 +27,7 @@ version (Posix)
enum objExt = ".o";
enum binExt = "";
enum libExt = ".a";
enum dllExt = ".so";
enum altDirSeparator = "";
}
else version (Windows)
@ -34,6 +35,7 @@ else version (Windows)
enum objExt = ".obj";
enum binExt = ".exe";
enum libExt = ".lib";
enum dllExt = ".dll";
enum altDirSeparator = "/";
}
else
@ -242,10 +244,15 @@ int main(string[] args)
bool obj = compilerFlags.canFind("-c");
bool lib = compilerFlags.canFind("-lib");
string outExt = lib ? libExt : obj ? objExt : binExt;
bool dll = compilerFlags.canFind("-shared");
string outExt =
dll ? dllExt :
lib ? libExt :
obj ? objExt :
binExt;
// Assume --build-only for -c and -lib.
buildOnly |= obj || lib;
// Assume --build-only for -c / -lib / -shared.
buildOnly |= obj || lib || dll;
// --build-only implies the user would like a binary in the program's directory
if (buildOnly && !exe.ptr)
@ -360,7 +367,7 @@ size_t indexOfProgram(string[] args)
{
auto arg = args[i];
if (!arg.startsWith('-', '@') &&
!arg.endsWith(".obj", ".o", ".lib", ".a", ".def", ".map", ".res") &&
!arg.endsWith(".obj", ".o", ".lib", ".a", ".dll", ".so", ".def", ".map", ".res") &&
args[i - 1] != "--eval")
{
return i;