Skip to content

Commit

Permalink
support static libs
Browse files Browse the repository at this point in the history
  • Loading branch information
waruqi committed Jan 24, 2025
1 parent dbaf525 commit 1f59ab2
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 14 deletions.
27 changes: 27 additions & 0 deletions xmake/modules/core/tools/ar6x.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--!A cross-platform build utility based on Lua
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--
-- Copyright (C) 2015-present, TBOOX Open Source Group.
--
-- @author ruki
-- @file ar6x.lua
--

inherit("ar")

-- init it
function init(self)
self:set("arflags", "-r")
end

29 changes: 29 additions & 0 deletions xmake/modules/core/tools/cl6x.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,35 @@ function nf_sysincludedir(self, dir)
return nf_includedir(self, dir)
end

-- make the link flag
function nf_link(self, lib)
if not lib:endswith(".a") and not lib:endswith(".so") then
lib = "lib" .. lib .. ".a"
end
return "-l" .. lib
end

-- make the syslink flag
function nf_syslink(self, lib)
return nf_link(self, lib)
end

-- make the linkdir flag
function nf_linkdir(self, dir)
return {"-i" .. path.translate(dir)}
end

-- make the rpathdir flag
function nf_rpathdir(self, dir, opt)
opt = opt or {}
local extra = opt.extra
if extra and extra.installonly then
return
end
dir = path.translate(dir)
return {"-rpath=" .. dir}
end

-- make the link arguments list
function linkargv(self, objectfiles, targetkind, targetfile, flags, opt)
local argv = table.join("-z", "--output_file=" .. targetfile, objectfiles, flags)
Expand Down
36 changes: 23 additions & 13 deletions xmake/modules/detect/tools/find_ar6x.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,39 @@

-- imports
import("lib.detect.find_program")
import("lib.detect.find_programver")

-- find ar6x
-- check
function _check(program)

-- make a stub object file
local libraryfile = os.tmpfile() .. ".a"
local objectfile = os.tmpfile() .. ".o"
io.writefile(objectfile, "")

-- archive it
os.execv(program, {"-r", libraryfile, objectfile})

-- remove files
os.rm(objectfile)
os.rm(libraryfile)
end

-- find ar
--
-- @param opt the argument options, e.g. {version = true}
--
-- @return program, version
--
-- @code
--
-- local ar6x = find_ar6x()
-- local ar6x, version = find_ar6x({program = "ar6x", version = true})
-- local ar = find_ar6x()
-- local ar, version = find_ar6x({program = "xcrun -sdk macosx g++", version = true})
--
-- @endcode
--
function main(opt)
opt = opt or {}
opt.check = "--help"
opt.command = "--help"
local program = find_program(opt.program or "ar6x", opt)
local version = nil
if program and opt.version then
version = find_programver(program, opt)
end
return program, version
opt = opt or {}
opt.check = opt.check or _check
return find_program(opt.program or "ar6x", opt)
end

2 changes: 1 addition & 1 deletion xmake/toolchains/ti-c6000/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ toolchain("ti-c6000")
set_toolset("sh", "cl6x")
set_toolset("ar", "ar6x")
set_toolset("strip", "strip6x")
set_toolset("as", "asm6x")
set_toolset("as", "cl6x")

on_check(function (toolchain)
return import("lib.detect.find_tool")("cl6x")
Expand Down

0 comments on commit 1f59ab2

Please sign in to comment.