From ac5e6c6b2d840d1cbfa0b16d38bfa9c7edc85720 Mon Sep 17 00:00:00 2001 From: ruki Date: Wed, 7 Feb 2024 22:30:34 +0800 Subject: improve soname --- xmake/rules/linker/soname/xmake.lua | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xmake/rules/linker/soname/xmake.lua b/xmake/rules/linker/soname/xmake.lua index 2af8d7489..b82b52794 100644 --- a/xmake/rules/linker/soname/xmake.lua +++ b/xmake/rules/linker/soname/xmake.lua @@ -34,6 +34,7 @@ rule("linker.soname") end) after_link(function (target) + import("core.project.depend") local soname = target:soname() if target:is_shared() and soname and target:data("soname.enabled") then local version = target:version() @@ -45,13 +46,18 @@ rule("linker.soname") end local targetfile_with_soname = path.join(target:targetdir(), soname) local targetfile = target:targetfile() - if soname ~= filename and soname ~= path.filename(targetfile_with_version) and not os.islink(target:targetfile()) then - os.cp(target:targetfile(), targetfile_with_version) - os.rm(target:targetfile()) - local oldir = os.cd(target:targetdir()) - os.ln(path.filename(targetfile_with_version), soname, {force = true}) - os.ln(soname, path.filename(targetfile), {force = true}) - os.cd(oldir) + if soname ~= filename and soname ~= path.filename(targetfile_with_version) then + depend.on_changed(function () + os.cp(target:targetfile(), targetfile_with_version) + os.rm(target:targetfile()) + local oldir = os.cd(target:targetdir()) + os.ln(path.filename(targetfile_with_version), soname, {force = true}) + os.ln(soname, path.filename(targetfile), {force = true}) + os.cd(oldir) + end, {dependfile = target:dependfile(targetfile_with_version), + files = {target:targetfile()}, + values = {soname, version}, + changed = target:is_rebuilt()}) end end end) -- cgit v1.3.1