|
| 1 | +rule("win.subsystem.console") |
| 2 | + add_deps("win.subsystem") |
| 3 | + on_load(function(target) |
| 4 | + target:data_set("win.subsystem", "console") |
| 5 | + end) |
| 6 | + |
| 7 | +rule("win.subsystem.windows") |
| 8 | + add_deps("win.subsystem") |
| 9 | + on_load(function(target) |
| 10 | + target:data_set("win.subsystem", "windows") |
| 11 | + end) |
| 12 | + |
| 13 | +rule("win.subsystem") |
| 14 | + on_config("mingw", "windows", function(target) |
| 15 | + local subsystems = { |
| 16 | + "BOOT_APPLICATION", "CONSOLE", "EFI_APPLICATION", "EFI_BOOT_SERVICE_DRIVER", "EFI_ROM", "EFI_RUNTIME_DRIVER", "NATIVE", "POSIX", "WINDOWS" |
| 17 | + } |
| 18 | + |
| 19 | + local subsystem = target:data("win.subsystem") |
| 20 | + local valid = false |
| 21 | + for _, s in ipairs(subsystems) do |
| 22 | + if string.upper(subsystem):startswith(s) then |
| 23 | + valid = true |
| 24 | + break |
| 25 | + end |
| 26 | + end |
| 27 | + assert(valid, "Invalid subsystem " .. subsystem) |
| 28 | + |
| 29 | + local linker = target:tool("ld") |
| 30 | + linker = path.filename(linker) |
| 31 | + if linker:startswith("clang") then |
| 32 | + target:add("ldflags", "-Wl,-subsystem:" .. subsystem, { force = true }) |
| 33 | + elseif linker:startswith("link") or linker:startswith("lld-link") then |
| 34 | + target:add("ldflags", "/SUBSYSTEM:" .. string.upper(subsystem), { force = true }) |
| 35 | + elseif linker:startswith("gcc") or linker:startswith("g++") then |
| 36 | + target:add("ldflags", "-Wl,-m" .. subsystem, { force = true }) |
| 37 | + elseif linker:startswith("ld") then |
| 38 | + target:add("ldflags", "-m" .. subsystem, { force = true }) |
| 39 | + end |
| 40 | + end) |
0 commit comments