link.lua 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. -- Usage
  2. --[[
  3. add_requires("vc-ltl5", "yy-thunks")
  4. target("test")
  5. set_kind("binary")
  6. add_files("src/*.cpp")
  7. add_rules("@yy-thunks/xp")
  8. -- add_rules("@yy-thunks/vista")
  9. -- add_rules("@yy-thunks/2k")
  10. add_packages("vc-ltl5", "yy-thunks")
  11. --]]
  12. -- TODO:
  13. -- YY_Thunks_for_Win8.obj
  14. -- YY_Thunks_for_Win10.0.10240.obj
  15. -- YY_Thunks_for_Win10.0.19041.obj
  16. rule("xp")
  17. on_config(function (target)
  18. local objectfile = "YY_Thunks_for_WinXP.obj"
  19. local thunks = target:pkg("yy-thunks")
  20. if thunks then
  21. local installdir = thunks:installdir()
  22. table.insert(target:objectfiles(), 1, path.join(installdir, "lib", objectfile))
  23. if thunks:version():ge("1.1") then
  24. if target:is_shared() then
  25. target:add("shflags", "/entry:DllMainCRTStartupForYY_Thunks", {tools = "link", force = true})
  26. end
  27. end
  28. end
  29. end)
  30. rule("vista")
  31. on_config(function (target)
  32. local objectfile = "YY_Thunks_for_Vista.obj"
  33. local thunks = target:pkg("yy-thunks")
  34. if thunks then
  35. local installdir = thunks:installdir()
  36. table.insert(target:objectfiles(), 1, path.join(installdir, "lib", objectfile))
  37. end
  38. end)
  39. rule("2k")
  40. on_config(function (target)
  41. if not target:is_arch("x86") then
  42. wprint("Win2K only supports x86 architecture")
  43. end
  44. local objectfile = "YY_Thunks_for_Win2K.obj"
  45. local thunks = target:pkg("yy-thunks")
  46. if thunks then
  47. local installdir = thunks:installdir()
  48. table.insert(target:objectfiles(), 1, path.join(installdir, "lib", objectfile))
  49. end
  50. end)
  51. after_link(function (target, opt)
  52. import("core.project.depend")
  53. import("lib.detect.find_tool")
  54. import("utils.progress")
  55. depend.on_changed(function()
  56. local msvc = target:toolchain("msvc")
  57. local editbin = assert(find_tool("editbin", {envs = msvc:runenvs()}), "editbin not found!")
  58. -- osversion -> Major/Minor OperatingSystemVersion
  59. -- subsystem -> Major/Minor SubsystemVersion
  60. os.iorunv(editbin.program, {"/osversion:5.0", "/subsystem:console,5.0", target:targetfile()})
  61. progress.show(opt.progress, "${color.build.target}editing.$(mode) %s", target:filename())
  62. end, {files = {target:targetfile()}})
  63. end)