|
| 1 | +--!A cross-platform build utility based on Lua |
| 2 | +-- |
| 3 | +-- Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +-- you may not use this file except in compliance with the License. |
| 5 | +-- You may obtain a copy of the License at |
| 6 | +-- |
| 7 | +-- http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +-- |
| 9 | +-- Unless required by applicable law or agreed to in writing, software |
| 10 | +-- distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +-- See the License for the specific language governing permissions and |
| 13 | +-- limitations under the License. |
| 14 | +-- |
| 15 | +-- Copyright (C) 2015-present, TBOOX Open Source Group. |
| 16 | +-- |
| 17 | +-- @author ruki, Arthapz |
| 18 | +-- @file xmake.lua |
| 19 | +-- |
| 20 | + |
| 21 | +-- define rule: subsystem |
| 22 | +-- set any of "boot_application" "console" "efi_application" "efi_boot_service_driver" "efi_rom" "efi_runtime_driver" "native" "posix" "windows" |
| 23 | +-- with target:set_values("windows.subsystem", <your value>) and the rule will pass the proper flag to the linker |
| 24 | +rule("platform.windows.subsystem") |
| 25 | + on_config("mingw", "windows", function(target) |
| 26 | + local subsystems = { |
| 27 | + "BOOT_APPLICATION", "CONSOLE", "EFI_APPLICATION", "EFI_BOOT_SERVICE_DRIVER", "EFI_ROM", "EFI_RUNTIME_DRIVER", "NATIVE", "POSIX", "WINDOWS" |
| 28 | + } |
| 29 | + |
| 30 | + local subsystem = target:values("windows.subsystem") |
| 31 | + if subsystem then |
| 32 | + local valid = false |
| 33 | + for _, s in ipairs(subsystems) do |
| 34 | + if subsystem:upper():startwiths(s) then |
| 35 | + valid = true |
| 36 | + break |
| 37 | + end |
| 38 | + end |
| 39 | + assert(valid, "Invalid subsystem " .. subsystem) |
| 40 | + |
| 41 | + if target:has_tool("ld", "clang") then |
| 42 | + target:add("ldflags", "-Wl,-subsystem:" .. subsystem, { force = true }) |
| 43 | + elseif target:has_tool("ld", "link", "lld-link") then |
| 44 | + target:add("ldflags", "/SUBSYSTEM:" .. upper(subsystem), { force = true }) |
| 45 | + elseif target:has_tool("ld", "gcc", "g++") then |
| 46 | + target:add("ldflags", "-Wl,-m" .. subsystem, { force = true }) |
| 47 | + elseif target:has_tool("ld", "ld") then |
| 48 | + target:add("ldflags", "-m" .. subsystem, { force = true }) |
| 49 | + end |
| 50 | + end |
| 51 | + end) |
0 commit comments