]>
Dogcows Code - chaz/yoink/blob - build/check.lua
3 -- A collection of Lua functions for performing checks.
5 -- Copyright (c) 2011, Charles McGarvey
6 -- Distributable under the terms and conditions of the 2-clause BSD
7 -- license; see the file COPYING for a complete text of the license.
13 local util
= require
"utility"
14 local print_check
= util
.printer("checking for %s... ")
16 -- TODO: Should have check for toolset triplet, compiling arbitrary code,
17 -- headers, libraries.
27 compile
= function(compiler
, ext
, flags
, code
)
28 if type(compiler
) ~= "table" then compiler
= {compiler
} end
29 local key
= util
.concat(compiler
, "&") .. ext
.. code
30 if cache
[key
] then return cache
[key
], "cached value" end
31 local tmpdir
= util
.make_tempdir("config.XXXXXX")
34 local fd
, err
= io
.open(tmpdir
.. "/test." .. ext
, "w")
35 if not fd
then die("failed to create temporary file", fd
) end
38 --util.print_log("code to be compiled:\n" .. code)
39 compiler
= util
.find_command(compiler
, "test." .. ext
, tmpdir
)
40 os
.execute("rm -rf " .. tmpdir
)
42 die("failed to create temporary directory", tmpdir
)
45 if compiler
== nil then return nil, "test program could not be compiled" end
53 local function cc(...)
54 local arg
= util
.copy(arg
, "v", tostring)
55 local key
= util
.concat(arg
)
56 if cache
[key
] then return cache
[key
], "cached value" end
57 --print_check("C compiler")
58 local cc
, err
= compile(arg
, "c", "", "int main() { return 0; }")
59 --if cc then util.print(cc) else util.print("no") end
61 --util.print_info("cccheck:", key, cc)
62 if cc
== nil then return nil, err
end
67 local function native_cc(triplet
)
68 local ccenv
= os
.getenv("CC")
71 local result
= cc(ccenv
)
72 if result
then return result
end
74 if type(triplet
) ~= "string" then triplet
= util
.exec("config.guess") end
75 return cc(triplet
.. "-gcc", "cc", "gcc")
77 M
.native_cc
= native_cc
79 local function cross_cc(triplet
)
80 return cc(triplet
.. "-gcc")
87 local function cxx(...)
88 local arg
= util
.copy(arg
, "v", tostring)
89 local key
= util
.concat(arg
)
90 if cache
[key
] then return cache
[key
], "cached value" end
91 --print_check("C++ compiler")
92 local cxx
, err
= compile(arg
, "c++", "", "int main() { return 0; }")
93 --if cxx then util.print(cxx) else util.print("no") end
96 --util.print_info("cxxcheck:", key, cxx)
97 if cxx
== nil then return nil, err
end
102 local function native_cxx(triplet
)
103 if type(triplet
) ~= "string" then triplet
= util
.exec("config.guess") end
104 return cxx(os
.getenv("CXX"), "g++", "c++")
106 M
.native_cxx
= native_cxx
108 local function cross_cxx(triplet
)
109 return cxx(triplet
.. "-g++")
111 M
.cross_cxx
= cross_cxx
116 local function lib(...)
117 --local key = util.concat(arg, ", ")
118 --if cache[key] then return cache[key] end
121 --local result = false
122 --for _,header in ipairs(arg)
124 --code = string.format("%s#include <%s>\n", code, header)
126 --code = code .. "int main() { return 0; }\n"
127 --if compile({CC}, "c", "", code) or compile({CC}, "c++", "", code)
134 --cache[key] = result
143 local function header(...)
144 local CC
= M
.native_cc()
145 local key
= util
.concat(arg
, ", ")
146 if cache
[key
] then return cache
[key
] end
150 for _
,header
in util
.npairs(arg
)
152 code
= string.format("%s#include <%s>\n", code
, header
)
154 code
= code
.. "int main() { return 0; }\n"
155 if compile({CC
}, "c", "", code
) or compile({CC
}, "c++", "", code
)
This page took 0.044006 seconds and 5 git commands to generate.