diff options
| author | ruki <[email protected]> | 2015-06-11 16:19:30 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2015-06-11 16:19:30 +0800 |
| commit | 76fd1ccaf43262df8fae3d9d3bfba1c2f0e04ca5 (patch) | |
| tree | dff91d1b1692ab1153f46c7626134de0fa3fceb9 | |
| parent | ef4fe60273da742248fe9111e9141df51185c204 (diff) | |
merge clang to gcc
| -rw-r--r-- | tests/console/xmake.lua | 10 | ||||
| -rw-r--r-- | xmake/scripts/base/main.lua | 5 | ||||
| -rw-r--r-- | xmake/scripts/tools/clang.lua | 146 | ||||
| -rw-r--r-- | xmake/scripts/tools/gcc.lua | 27 |
4 files changed, 36 insertions, 152 deletions
diff --git a/tests/console/xmake.lua b/tests/console/xmake.lua index d352e5785..3c0cb0886 100644 --- a/tests/console/xmake.lua +++ b/tests/console/xmake.lua @@ -49,12 +49,12 @@ add_option("option3") add_option("option4") set_option_default(false) add_option_defines_if_ok("OPTION4_ENABLE") - add_option_cincludes("stdio.h", "hello1.h") - add_option_includedirs("src/hello1") - add_option_links("hello1") - add_option_linkdirs("$(buildir)") - add_option_cfuncs("hello1") set_option_description("The option for finding interfaces.") + if not plats("windows") then + add_option_links("z", "sqlite3") + add_option_cfuncs("sqlite3_open") + add_option_cincludes("stdio.h", "sqlite3.h") + end add_target("hello1") set_kind("static") diff --git a/xmake/scripts/base/main.lua b/xmake/scripts/base/main.lua index 888c4d41a..c8ce0fe37 100644 --- a/xmake/scripts/base/main.lua +++ b/xmake/scripts/base/main.lua @@ -117,6 +117,11 @@ function main._init_project() local options = xmake._OPTIONS assert(options) + -- check the project file + if not os.isfile(xmake._PROJECT_FILE) then + return string.format("not found the project file: %s", xmake._PROJECT_FILE) + end + -- init the build directory if options.buildir and path.is_absolute(options.buildir) then options.buildir = path.relative(options.buildir, xmake._PROJECT_DIR) diff --git a/xmake/scripts/tools/clang.lua b/xmake/scripts/tools/clang.lua index 144fc2cfe..d1e1fad0b 100644 --- a/xmake/scripts/tools/clang.lua +++ b/xmake/scripts/tools/clang.lua @@ -20,148 +20,4 @@ -- @file clang.lua -- --- load modules -local utils = require("base/utils") -local table = require("base/table") -local string = require("base/string") -local config = require("base/config") - --- define module: clang -local clang = clang or {} - --- check the given flag -function clang._check(flag) - - -- this flag has been checked? - clang._CHECK = clang._CHECK or {} - if clang._CHECK[flag] then - return clang._CHECK[flag] - end - - -- check it - if 0 ~= os.execute(string.format("%s %s -S -o %s -xc %s > %s 2>&1", clang.name, flag, xmake._NULDEV, xmake._NULDEV, xmake._NULDEV)) then - flag = "" - end - - -- save it - clang._CHECK[flag] = flag - - -- ok? - return flag -end - --- the init function -function clang.init(name) - - -- save name - clang.name = name or "clang" - - -- the architecture - local arch = config.get("arch") - assert(arch) - - -- init flags for architecture - local flags_arch = "" - if arch == "x86" then flags_arch = "-m32" - elseif arch == "x64" then flags_arch = "-m64" - else flags_arch = "-arch " .. arch - end - - -- init cxflags - clang.cxflags = { flags_arch } - - -- init mxflags - clang.mxflags = { flags_arch - , "-fmessage-length=0" - , "-pipe" - , "-fpascal-strings" - , "\"-DIBOutlet=__attribute__((iboutlet))\"" - , "\"-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))\"" - , "\"-DIBAction=void)__attribute__((ibaction)\""} - - -- init asflags - clang.asflags = { flags_arch } - - -- init ldflags - clang.ldflags = { flags_arch } - - -- init shflags - clang.shflags = { flags_arch, "-dynamiclib" } - - -- suppress warning for the ccache bug - if config.get("ccache") then - table.join2(clang.cxflags, "-Qunused-arguments") - table.join2(clang.mxflags, "-Qunused-arguments") - end - - -- init flags map - clang.mapflags = - { - -- others - ["-ftrapv"] = clang._check - , ["-fsanitize=address"] = clang._check - } - -end - --- make the compile command -function clang.command_compile(srcfile, objfile, flags) - - -- make it - return string.format("%s -c %s -o%s %s", clang.name, flags, objfile, srcfile) -end - --- make the link command -function clang.command_link(objfiles, targetfile, flags) - - -- make it - return string.format("%s %s -o%s %s", clang.name, flags, targetfile, objfiles) -end - --- make the define flag -function clang.flag_define(define) - - -- make it - return "-D" .. define -end - --- make the undefine flag -function clang.flag_undefine(undefine) - - -- make it - return "-U" .. undefine -end - --- make the includedir flag -function clang.flag_includedir(includedir) - - -- make it - return "-I" .. includedir -end - --- make the link flag -function clang.flag_link(link) - - -- make it - return "-l" .. link -end - --- make the linkdir flag -function clang.flag_linkdir(linkdir) - - -- make it - return "-L" .. linkdir -end - --- the main function -function clang.main(cmd) - - -- execute it - local ok = os.execute(cmd) - - -- ok? - return utils.ifelse(ok == 0, true, false) -end - --- return module: clang -return clang +return require("tools/gcc") diff --git a/xmake/scripts/tools/gcc.lua b/xmake/scripts/tools/gcc.lua index f814944e1..2cf61a0a2 100644 --- a/xmake/scripts/tools/gcc.lua +++ b/xmake/scripts/tools/gcc.lua @@ -25,6 +25,7 @@ local utils = require("base/utils") local table = require("base/table") local string = require("base/string") local config = require("base/config") +local platform = require("platform/platform") -- define module: gcc local gcc = gcc or {} @@ -54,7 +55,7 @@ end function gcc.init(name) -- save name - gcc.name = name or "gcc" + gcc.name = name -- the architecture local arch = config.get("arch") @@ -86,7 +87,29 @@ function gcc.init(name) gcc.ldflags = { flags_arch } -- init shflags - gcc.shflags = { flags_arch, "-shared -Wl,-soname" } + if name:find("clang") then + gcc.shflags = { flags_arch, "-dynamiclib" } + else + gcc.shflags = { flags_arch, "-shared -Wl,-soname" } + end + + -- append the xcode sdk directory if exists + local plat = config.get("plat") + if plat and (plat == "macosx" or plat == "iphoneos" or plat == "iphonesimulator") then + local xcode_sdkdir = platform.get("xcode_sdkdir") + if xcode_sdkdir then + table.join2(gcc.cxflags, "-isysroot " .. xcode_sdkdir) + table.join2(gcc.mxflags, "-isysroot " .. xcode_sdkdir) + table.join2(gcc.ldflags, "-isysroot " .. xcode_sdkdir) + table.join2(gcc.shflags, "-isysroot " .. xcode_sdkdir) + end + end + + -- suppress warning for the ccache bug + if name:find("clang") and config.get("ccache") then + table.join2(gcc.cxflags, "-Qunused-arguments") + table.join2(gcc.mxflags, "-Qunused-arguments") + end -- init flags map gcc.mapflags = |
