Skip to content

Commit 69596fd

Browse files
committed
add specific options for the modules to modify the compiler and linker options
1 parent 99789d8 commit 69596fd

9 files changed

Lines changed: 22 additions & 7 deletions

File tree

ebuild.api/ArgumentBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ public ArgumentBuilder Add(string command)
1010

1111
public ArgumentBuilder AddRange(IEnumerable<string> commands)
1212
{
13-
_args.AddRange(commands);
13+
_args.UnionWith(commands);
1414
return this;
1515
}
1616

17-
private readonly List<string> _args = new();
17+
private readonly HashSet<string> _args = new();
1818

1919
public override string ToString()
2020
{

ebuild.api/ModuleBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public abstract class ModuleBase
7171

7272
public ModuleContext Context;
7373

74+
public List<string> CompilerOptions = [];
75+
public List<string> LinkerOptions = [];
76+
7477
protected ModuleBase(ModuleContext context)
7578
{
7679
Context = context;

ebuild/Compilers/GccCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private string GenerateCompileCommand(bool includeSourceFiles)
242242

243243
// Add additional compiler options
244244
args += AdditionalCompilerOptions;
245-
245+
args += CurrentModule.CompilerOptions;
246246
// Add source files if requested
247247
if (includeSourceFiles)
248248
{

ebuild/Compilers/GppCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ private string GenerateCompileCommand(bool includeSourceFiles)
309309

310310
// Add additional compiler options
311311
args += AdditionalCompilerOptions;
312-
312+
args += CurrentModule.CompilerOptions;
313313
// Add source files if requested
314314
if (includeSourceFiles)
315315
{

ebuild/Compilers/MSVCCompiler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ private void AddModuleCompileArguments(ModuleBase inputModule, bool compilingInp
154154
if (compilingInputModule)
155155
{
156156
args += $"/D\"{(inputModule.Name ?? inputModule.Context.ModuleDirectory!.Name).ToUpperInvariant()}_BUILDING\"";
157+
args += inputModule.CompilerOptions;
157158
// TODO: Disabled for now to test.
158159
// args += module.SourceFiles.Select(s => GetModuleFilePath(s, module));
159160
}

ebuild/Linkers/GccLinker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ private string BuildLinkCommand()
326326

327327
// Add additional linker options
328328
args += AdditionalLinkerOptions;
329+
args += CurrentModule.LinkerOptions;
329330

330331
return args.ToString();
331332
}

ebuild/Linkers/MsvcLibLinker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ private async Task<bool> CallLibExe()
101101
argumentBuilder +=
102102
$"/OUT:\"{Path.Join(GetBinaryOutputFolder(), (CurrentModule.Name ?? CurrentModule.GetType().Name) + ".lib")}\"";
103103
argumentBuilder += AdditionalLinkerOptions;
104+
argumentBuilder += CurrentModule.LinkerOptions;
104105
argumentBuilder += CurrentModule.LibrarySearchPaths.Joined().Select(s => $"/LIBPATH:\"{s}\"");
105106
argumentBuilder += files.Select(f => GetModuleFilePath(f, CurrentModule));
106107
argumentBuilder += CurrentModule.Libraries.Joined()

ebuild/Linkers/MsvcLinkLinker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ private async Task<bool> CallLinkExe()
9999
}
100100

101101
argumentBuilder += AdditionalLinkerOptions;
102-
102+
argumentBuilder += CurrentModule.LinkerOptions;
103103
var outType = ".exe";
104104
switch (CurrentModule.Type)
105105
{

examples/zlib/zlib.ebuild.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public ZlibEbuild(ModuleContext context) : base(context)
3333
Name = "zlib";
3434

3535
// Use C99 standard for zlib (it's a C library)
36-
CStandard = CStandards.C99;
36+
CStandard = CStandards.C17;
3737

3838
// Setup should be called in constructor as per README
3939
// Call setup synchronously instead of using async/await
@@ -259,7 +259,16 @@ public void SetupSourceFiles(string extractPath)
259259

260260
// Add include directories
261261
Includes.Add(extractPath);
262-
262+
if (Context.Platform == "Unix")
263+
{
264+
CompilerOptions.Add("-Wno-error=implicit-function-declaration");
265+
}
266+
if (Context.Platform == "Win32")
267+
{
268+
Definitions.Private.Add(new Definition("_CRT_SECURE_NO_DEPRECATE"));
269+
Definitions.Private.Add(new Definition("_CRT_NONSTDC_NO_DEPRECATE"));
270+
}
271+
263272
// Apply module options to definitions
264273
if (EnableDebug)
265274
{

0 commit comments

Comments
 (0)