ruki пре 5 година
родитељ
комит
6f6ebddd2a

+ 2 - 0
guide/configuration.md

@@ -394,6 +394,8 @@ envs          Environment variables toolchain
 fasm          Flat Assembler
 ```
 
+#### Custom toolchain
+
 In addition, we can also customize the toolchain in xmake.lua, and then specify the switch through `xmake f --toolchain=myclang`, for example:
 
 ```lua

+ 30 - 32
manual/configuration_option.md

@@ -48,36 +48,34 @@ The `option` field can be repeatedly entered to implement separate settings. If
 | [add_cxxtypes](#optionadd_cxxtypes)                   | Add c++ type detection                            | >= 1.0.1           |
 | [add_csnippet](#optionadd_csnippet)                   | Add c-code snippets detection                     | >= 2.1.5           |
 | [add_cxxsnippet](#optionadd_cxxsnippet)               | Add c++ code snippet detection                    | >= 2.1.5           |
-| [set_warnings](#targetset_warnings)                   | Setting the warning level                         | >= 1.0.1           |
-| [set_optimize](#targetset_optimize)                   | Setting the optimization level                    | >= 1.0.1           |
-| [set_languages](#targetset_languages)                 | Setting the Code Language Standard                | >= 1.0.1           |
-| [add_includedirs](#targetadd_includedirs)             | Add Header Search Directory                       | >= 1.0.1           |
-| [add_defines](#targetadd_defines)                     | Add Macro Definition                              | >= 1.0.1           |
-| [add_undefines](#targetadd_undefines)                 | Cancel Macro Definition                           | >= 1.0.1           |
-| [add_defines_h](#targetadd_defines_h)                 | Add macro definitions to header files             | >= 1.0.1           |
-| [add_undefines_h](#targetadd_undefines_h)             | Cancel macro definition to header file            | >= 1.0.1           |
-| [add_cflags](#targetadd_cflags)                       | Add c Compile Options                             | >= 1.0.1           |
-| [add_cxflags](#targetadd_cxflags)                     | Add c/c++ Compile Options                         | >= 1.0.1           |
-| [add_cxxflags](#targetadd_cxxflags)                   | Add c++ Compile Options                           | >= 1.0.1           |
-| [add_mflags](#targetadd_mflags)                       | Add objc compile options                          | >= 2.0.1           |
-| [add_mxflags](#targetadd_mxflags)                     | Add objc/objc++ Compile Options                   | >= 2.0.1           |
-| [add_mxxflags](#targetadd_mxxflags)                   | Add objc++ Compile Options                        | >= 2.0.1           |
-| [add_scflags](#targetadd_scflags)                     | Add swift compile options                         | >= 2.1.1           |
-| [add_asflags](#targetadd_asflags)                     | Add assembly compile options                      | >= 2.1.1           |
-| [add_gcflags](#targetadd_gcflags)                     | Add go compile options                            | >= 2.1.1           |
-| [add_dcflags](#targetadd_dcflags)                     | Add dlang compile options                         | >= 2.1.1           |
-| [add_rcflags](#targetadd_rcflags)                     | Add rust compile option                           | >= 2.1.1           |
-| [add_cuflags](#targetadd_cuflags)                     | Add cuda compile options                          | >= 2.2.1           |
-| [add_culdflags](#targetadd_culdflags)                 | Add cuda device-link options                      | >= 2.2.7           |
-| [add_ldflags](#targetadd_ldflags)                     | Add Link Options                                  | >= 2.1.1           |
-| [add_arflags](#targetadd_arflags)                     | Add Static Library Archive Options                | >= 2.1.1           |
-| [add_shflags](#targetadd_shflags)                     | Add Dynamic Library Link Options                  | >= 2.0.1           |
-| [add_cfuncs](#targetadd_cfuncs)                       | Add c library function detection                  | >= 1.0.1           |
-| [add_cxxfuncs](#targetadd_cxxfuncs)                   | Add C++ Library Function Interface                | >= 1.0.1           |
-| [add_languages](#targetadd_languages)                 | Add Language Standards                            | >= 2.0.1           |
-| [add_vectorexts](#targetadd_vectorexts)               | Add Vector Extension Instructions                 | >= 2.0.1           |
-| [add_frameworks](#targetadd_frameworks)               | Add Linked Framework                              | >= 2.1.1           |
-| [add_frameworkdirs](#targetadd_frameworkdirs)         | Add Linked Framework                              | >= 2.1.5           |
+| [set_warnings](/manual/project_target?id=targetset_warnings)                   | Setting the warning level                         | >= 1.0.1           |
+| [set_optimize](/manual/project_target?id=targetset_optimize)                   | Setting the optimization level                    | >= 1.0.1           |
+| [set_languages](/manual/project_target?id=targetset_languages)                 | Setting the Code Language Standard                | >= 1.0.1           |
+| [add_includedirs](/manual/project_target?id=targetadd_includedirs)             | Add Header Search Directory                       | >= 1.0.1           |
+| [add_defines](/manual/project_target?id=targetadd_defines)                     | Add Macro Definition                              | >= 1.0.1           |
+| [add_undefines](/manual/project_target?id=targetadd_undefines)                 | Cancel Macro Definition                           | >= 1.0.1           |
+| [add_defines_h](/manual/project_target?id=targetadd_defines_h)                 | Add macro definitions to header files             | >= 1.0.1           |
+| [add_undefines_h](/manual/project_target?id=targetadd_undefines_h)             | Cancel macro definition to header file            | >= 1.0.1           |
+| [add_cflags](/manual/project_target?id=targetadd_cflags)                       | Add c Compile Options                             | >= 1.0.1           |
+| [add_cxflags](/manual/project_target?id=targetadd_cxflags)                     | Add c/c++ Compile Options                         | >= 1.0.1           |
+| [add_cxxflags](/manual/project_target?id=targetadd_cxxflags)                   | Add c++ Compile Options                           | >= 1.0.1           |
+| [add_mflags](/manual/project_target?id=targetadd_mflags)                       | Add objc compile options                          | >= 2.0.1           |
+| [add_mxflags](/manual/project_target?id=targetadd_mxflags)                     | Add objc/objc++ Compile Options                   | >= 2.0.1           |
+| [add_mxxflags](/manual/project_target?id=targetadd_mxxflags)                   | Add objc++ Compile Options                        | >= 2.0.1           |
+| [add_scflags](/manual/project_target?id=targetadd_scflags)                     | Add swift compile options                         | >= 2.1.1           |
+| [add_asflags](/manual/project_target?id=targetadd_asflags)                     | Add assembly compile options                      | >= 2.1.1           |
+| [add_gcflags](/manual/project_target?id=targetadd_gcflags)                     | Add go compile options                            | >= 2.1.1           |
+| [add_dcflags](/manual/project_target?id=targetadd_dcflags)                     | Add dlang compile options                         | >= 2.1.1           |
+| [add_rcflags](/manual/project_target?id=targetadd_rcflags)                     | Add rust compile option                           | >= 2.1.1           |
+| [add_cuflags](/manual/project_target?id=targetadd_cuflags)                     | Add cuda compile options                          | >= 2.2.1           |
+| [add_culdflags](/manual/project_target?id=targetadd_culdflags)                 | Add cuda device-link options                      | >= 2.2.7           |
+| [add_ldflags](/manual/project_target?id=targetadd_ldflags)                     | Add Link Options                                  | >= 2.1.1           |
+| [add_arflags](/manual/project_target?id=targetadd_arflags)                     | Add Static Library Archive Options                | >= 2.1.1           |
+| [add_shflags](/manual/project_target?id=targetadd_shflags)                     | Add Dynamic Library Link Options                  | >= 2.0.1           |
+| [add_languages](/manual/project_target?id=targetadd_languages)                 | Add Language Standards                            | >= 2.0.1           |
+| [add_vectorexts](/manual/project_target?id=targetadd_vectorexts)               | Add Vector Extension Instructions                 | >= 2.0.1           |
+| [add_frameworks](/manual/project_target?id=targetadd_frameworks)               | Add Linked Framework                              | >= 2.1.1           |
+| [add_frameworkdirs](/manual/project_target?id=targetadd_frameworkdirs)         | Add Linked Framework                              | >= 2.1.5           |
 
 ### option
 
@@ -113,7 +111,7 @@ $ xmake
 
 #### End definition option
 
-This is an optional api that shows the departure option scope, similar to [target_end](#target_end).
+This is an optional api that shows the departure option scope, similar to [target_end](/manual/project_target?id=target_end).
 
 ### option:add_deps
 
@@ -499,7 +497,7 @@ This is optional. Generally, the system library does not need to add this, and i
 
 #### Adding a load search directory for a dynamic library at runtime
 
-After the option passes the detection, it will be automatically added to the corresponding target. For details, see: [target.add_rpathdirs](#targetadd_rpathdirs).
+After the option passes the detection, it will be automatically added to the corresponding target. For details, see: [target.add_rpathdirs](/manual/project_target?id=targetadd_rpathdirs).
 
 ### option:add_cincludes
 

+ 252 - 1
manual/custom_toolchain.md

@@ -1,2 +1,253 @@
 
-test
+After version 2.3.4, xmake has supported custom toolchain in user's project xmake.lua, for example:
+
+```lua
+-- define toolchain
+toolchain("myclang")
+
+    -- mark as standalone toolchain
+    set_kind("standalone")
+        
+    -- set toolsets
+    set_toolsets("cc", "clang")
+    set_toolsets("cxx", "clang", "clang++")
+    set_toolsets("ld", "clang++", "clang")
+    set_toolsets("sh", "clang++", "clang")
+    set_toolsets("ar", "ar")
+    set_toolsets("ex", "ar")
+    set_toolsets("strip", "strip")
+    set_toolsets("mm", "clang")
+    set_toolsets("mxx", "clang", "clang++")
+    set_toolsets("as", "clang")
+
+    add_defines("MYCLANG")
+
+    -- check toolchain
+    on_check(function (toolchain)
+        return import("lib.detect.find_tool")("clang")
+    end)
+
+    -- on load
+    on_load(function (toolchain)
+
+        -- get march
+        local march = is_arch("x86_64", "x64") and "-m64" or "-m32"
+
+        -- init flags for c/c++
+        toolchain:add("cxflags", march)
+        toolchain:add("ldflags", march)
+        toolchain:add("shflags", march)
+        if not is_plat("windows") and os.isdir("/usr") then
+            for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do
+                if os.isdir(includedir) then
+                    toolchain:add("includedirs", includedir)
+                end
+            end
+            for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do
+                if os.isdir(linkdir) then
+                    toolchain:add("linkdirs", linkdir)
+                end
+            end
+        end
+
+        -- init flags for objc/c++  (with ldflags and shflags)
+        toolchain:add("mxflags", march)
+
+        -- init flags for asm
+        toolchain:add("asflags", march)
+    end)
+```
+
+Then use the following command to cut to the toolchain you defined:
+
+```bash
+$ xmake f --toolchain=myclang
+```
+
+Of course, we can also switch to the specified target directly to the custom toolchain through the `set_toolchains` interface.
+
+Before customizing the tool, we can run the following command to view the complete list of built-in toolchains to ensure that xmake does not provide it. If so, just use it directly. There is no need to define it yourself:
+
+```bash
+$ xmake show -l toolchains
+```
+
+The following is a list of interfaces currently supported by the custom toolchain:
+
+| Interface                                                              | Description                                   | Supported Version |
+| -----------------------------------------------                        | - ------------------------------------------- | ------ -          |
+| [toolchain](#toolchain)                                                | Define Toolchain                              | >= 2.3.4          |
+| [set_kind](#toolchainset_kind)                                         | Set toolchain type                            | >= 2.3.4          |
+| [set_toolsets](#toolchainset_toolsets)                                 | Set toolset                                   | >= 2.3.4          |
+| [set_sdkdir](#toolchainset_sdkdir)                                     | Set toolchain sdk directory path              | >= 2.3.4          |
+| [set_bindir](#toolchainset_bindir)                                     | Set toolchain bin directory path              | >= 2.3.4          |
+| [on_check](#toolchainon_check)                                         | Check toolchain                               | >= 2.3.4          |
+| [on_load](#toolchainonon_load)                                         | Load Toolchain                                | >= 2.3.4          |
+| [toolchain_end](#toolchain_end)                                        | End defining toolchain                        | >= 2.3.4          |
+| [add_includedirs](/manual/project_target?id=targetadd_includedirs)     | Add header file search directory              | >= 2.3.4          |
+| [add_defines](/manual/project_target?id=targetadd_defines)             | Add Macro Definition                          | >= 2.3.4          |
+| [add_undefines](/manual/project_target?id=targetadd_undefines)         | Cancel macro definition                       | >= 2.3.4          |
+| [add_cflags](/manual/project_target?id=targetadd_cflags)               | Add c compilation option                      | >= 2.3.4          |
+| [add_cxflags](/manual/project_target?id=targetadd_cxflags)             | Add c/c++ compilation options                 | >= 2.3.4          |
+| [add_cxxflags](/manual/project_target?id=targetadd_cxxflags)           | Add c++ compilation options                   | >= 2.3.4          |
+| [add_mflags](/manual/project_target?id=targetadd_mflags)               | Add objc compilation option                   | >= 2.3.4          |
+| [add_mxflags](/manual/project_target?id=targetadd_mxflags)             | Add objc/objc++ compilation options           | >= 2.3.4          |
+| [add_mxxflags](/manual/project_target?id=targetadd_mxxflags)           | Add objc++ compilation options                | >= 2.3.4          |
+| [add_scflags](/manual/project_target?id=targetadd_scflags)             | Add swift compilation options                 | >= 2.3.4          |
+| [add_asflags](/manual/project_target?id=targetadd_asflags)             | Add assembly compilation options              | >= 2.3.4          |
+| [add_gcflags](/manual/project_target?id=targetadd_gcflags)             | Add go compilation options                    | >= 2.3.4          |
+| [add_dcflags](/manual/project_target?id=targetadd_dcflags)             | Add dlang compilation options                 | >= 2.3.4          |
+| [add_rcflags](/manual/project_target?id=targetadd_rcflags)             | Add rust compilation option                   | >= 2.3.4          |
+| [add_cuflags](/manual/project_target?id=targetadd_cuflags)             | Add cuda compilation options                  | >= 2.3.4          |
+| [add_culdflags](/manual/project_target?id=targetadd_culdflags)         | Add cuda device link option                   | >= 2.3.4          |
+| [add_ldflags](/manual/project_target?id=targetadd_ldflags)             | Add link options                              | >= 2.3.4          |
+| [add_arflags](/manual/project_target?id=targetadd_arflags)             | Add static library archive option             | >= 2.3.4          |
+| [add_shflags](/manual/project_target?id=targetadd_shflags)             | Add dynamic library link option               | >= 2.3.4          |
+| [add_languages](/manual/project_target?id=targetadd_languages)         | Add language standards                        | >= 2.3.4          |
+| [add_frameworks](/manual/project_target?id=targetadd_frameworks)       | Add Link Frame                                | >= 2.3.4          |
+| [add_frameworkdirs](/manual/project_target?id=targetadd_frameworkdirs) | Add Link Framework                            | >= 2.3.4          |
+
+### toolchain
+
+#### Define toolchain
+
+It can be defined in the user project xmake.lua, or it can be independently defined by a separate xmake.lua to specifically define various toolchains
+
+```lua
+toolchain("myclang")
+    set_toolsets("cc", "clang")
+    set_toolsets("cxx", "clang", "clang++")
+toolchain_end()
+```
+
+### toolchain:set_kind
+
+#### Set toolchain type
+
+Currently only supports the setting of `standalone` type, which means that the current toolchain is an independent and complete toolchain, including a complete set of tool set configurations such as cc/cxx/ld/sh/ar and other compilers, archivers, and linkers.
+
+Usually used when a target is set with multiple toolchains at the same time, but only one independent toolchain can be effective at the same time. This configuration can ensure that the toolchains in effect are mutually exclusive. For example, the gcc/clang toolchain will not be simultaneously. Take effect.
+
+However, local toolchains such as yasm/nasm belong to the extension of additional local toolchains, and there is no need to set up standalone because two toolchains of clang/yasm may exist at the same time.
+
+!> Just remember that the toolchain with a complete compilation environment is set to standalone
+
+### toolchain:set_toolsets
+
+#### Set Tool Set
+
+Used to set the name and path of each individual tool, for example:
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    set_toolsets("cc", "clang")
+    set_toolsets("cxx", "clang", "clang++")
+    set_toolsets("ld", "clang++", "clang")
+    set_toolsets("sh", "clang++", "clang")
+    set_toolsets("ar", "ar")
+    set_toolsets("ex", "ar")
+    set_toolsets("strip", "strip")
+    set_toolsets("mm", "clang")
+    set_toolsets("mxx", "clang", "clang++")
+    set_toolsets("as", "clang")
+```
+
+For details about this interface, you can see: [target.set_toolsets](/manual/project_target?id=targetset_toolsets)
+
+### toolchain:set_sdkdir
+
+#### Set toolchain sdk directory path
+
+Usually we can configure the sdk directory through `xmake f --toolchain=myclang --sdk=xxx`, but each time the configuration is more cumbersome, we can also pre-configure to xmake.lua through this interface to facilitate quick switching.
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    set_sdkdir("/tmp/sdkdir")
+    set_toolsets("cc", "clang")
+```
+
+### toolchain:set_bindir
+
+#### Set toolchain bin directory path
+
+Normally, we can configure the SDK directory through `xmake f --toolchain=myclang --bin=xxx`, but each time the configuration is more cumbersome, we can also pre-configure to xmake.lua through this interface, which is convenient for quick switching.
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    set_bindir("/tmp/sdkdir/bin")
+    set_toolsets("cc", "clang")
+```
+
+### toolchain:on_check
+
+#### Detection toolchain
+
+It is used to detect whether the sdk or program where the specified toolchain exists exists on the current system. It is usually used in the case of multiple standalone toolchains to automatically detect and select an effective toolchain.
+
+For scenes specified manually by `xmake f --toolchain=myclang`, this detection configuration is not necessary and can be omitted.
+
+```lua
+toolchain("myclang")
+    on_check(function (toolchain)
+        return import("lib.detect.find_tool")("clang")
+    end)
+```
+
+### toolchain:on_load
+
+#### Loading toolchain
+
+For some complex scenarios, we can dynamically and flexibly set various toolchain configurations in on_load, which is more flexible and powerful than setting in the description field:
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    on_load(function (toolchain)
+        
+        - set toolsets
+        toolchain:set("toolsets", "cc", "clang")
+        toolchain:set("toolsets", "ld", "clang++")
+        - ..
+
+        - get march
+        local march = is_arch("x86_64", "x64") and "-m64" or "-m32"
+
+        - init flags for c/c++
+        toolchain:add("cxflags", march)
+        toolchain:add("ldflags", march)
+        toolchain:add("shflags", march)
+        if not is_plat("windows") and os.isdir("/usr") then
+            for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do
+                if os.isdir(includedir) then
+                    toolchain:add("includedirs", includedir)
+                end
+            end
+            for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do
+                if os.isdir(linkdir) then
+                    toolchain:add("linkdirs", linkdir)
+                end
+            end
+        end
+
+        - init flags for objc/c++ (with ldflags and shflags)
+        toolchain:add("mxflags", march)
+
+        - init flags for asm
+        toolchain:add("asflags", march)
+    end)
+```
+
+### toolchain_end
+
+#### End definition toolchain
+
+This is optional, if you want to manually end the definition of toolchain, you can call it:
+
+```lua
+toolchain("myclang")
+    - ..
+toolchain_end()
+```

+ 2 - 0
zh-cn/guide/configuration.md

@@ -390,6 +390,8 @@ envs          Environment variables toolchain
 fasm          Flat Assembler
 ```
 
+#### 自定义工具链
+
 另外,我们也可以在xmake.lua中自定义toolchain,然后通过`xmake f --toolchain=myclang`指定切换,例如:
 
 ```lua

+ 50 - 54
zh-cn/manual/configuration_option.md

@@ -26,58 +26,54 @@ option("test2")
 </p>
 
 
-| 接口                                                  | 描述                                         | 支持版本 |
-| ----------------------------------------------------- | -------------------------------------------- | -------- |
-| [option](#option)                                     | 定义选项                                     | >= 2.0.1 |
-| [option_end](#option_end)                             | 结束定义选项                                 | >= 2.1.1 |
-| [add_deps](#optionadd_deps)                           | 添加选项依赖                                 | >= 2.1.5 |
-| [before_check](#optionbefore_check)                   | 选项检测之前执行此脚本                       | >= 2.1.5 |
-| [on_check](#optionon_check)                           | 自定义选项检测脚本                           | >= 2.1.5 |
-| [after_check](#optionafter_check)                     | 选项检测之后执行此脚本                       | >= 2.1.5 |
-| [set_values](#optionset_values)                       | 设置选项值列表                               | >= 2.1.9 |
-| [set_default](#optionset_default)                     | 设置默认值                                   | >= 2.0.1 |
-| [set_showmenu](#optionset_showmenu)                   | 设置是否启用菜单显示                         | >= 1.0.1 |
-| [set_category](#optionset_category)                   | 设置选项分类,仅用于菜单显示                 | >= 1.0.1 |
-| [set_description](#optionset_description)             | 设置菜单显示描述                             | >= 1.0.1 |
-| [add_links](#optionadd_links)                         | 添加链接库检测                               | >= 1.0.1 |
-| [add_linkdirs](#optionadd_linkdirs)                   | 添加链接库检测需要的搜索目录                 | >= 1.0.1 |
-| [add_rpathdirs](#optionadd_rpathdirs)                 | 添加运行时候动态链接库搜索目录               | >= 2.1.3 |
-| [add_cincludes](#optionadd_cincludes)                 | 添加c头文件检测                              | >= 1.0.1 |
-| [add_cxxincludes](#optionadd_cxxincludes)             | 添加c++头文件检测                            | >= 1.0.1 |
-| [add_ctypes](#optionadd_ctypes)                       | 添加c类型检测                                | >= 1.0.1 |
-| [add_cxxtypes](#optionadd_cxxtypes)                   | 添加c++类型检测                              | >= 1.0.1 |
-| [add_csnippet](#optionadd_csnippet)                   | 添加c代码片段检测                            | >= 2.1.5 |
-| [add_cxxsnippet](#optionadd_cxxsnippet)               | 添加c++代码片段检测                          | >= 2.1.5 |
-| [set_warnings](#targetset_warnings)                   | 设置警告级别                                 | >= 1.0.1 |
-| [set_optimize](#targetset_optimize)                   | 设置优化级别                                 | >= 1.0.1 |
-| [set_languages](#targetset_languages)                 | 设置代码语言标准                             | >= 1.0.1 |
-| [add_includedirs](#targetadd_includedirs)             | 添加头文件搜索目录                           | >= 1.0.1 |
-| [add_defines](#targetadd_defines)                     | 添加宏定义                                   | >= 1.0.1 |
-| [add_undefines](#targetadd_undefines)                 | 取消宏定义                                   | >= 1.0.1 |
-| [add_defines_h](#targetadd_defines_h)                 | 添加宏定义到头文件                           | >= 1.0.1 |
-| [add_undefines_h](#targetadd_undefines_h)             | 取消宏定义到头文件                           | >= 1.0.1 |
-| [add_cflags](#targetadd_cflags)                       | 添加c编译选项                                | >= 1.0.1 |
-| [add_cxflags](#targetadd_cxflags)                     | 添加c/c++编译选项                            | >= 1.0.1 |
-| [add_cxxflags](#targetadd_cxxflags)                   | 添加c++编译选项                              | >= 1.0.1 |
-| [add_mflags](#targetadd_mflags)                       | 添加objc编译选项                             | >= 2.0.1 |
-| [add_mxflags](#targetadd_mxflags)                     | 添加objc/objc++编译选项                      | >= 2.0.1 |
-| [add_mxxflags](#targetadd_mxxflags)                   | 添加objc++编译选项                           | >= 2.0.1 |
-| [add_scflags](#targetadd_scflags)                     | 添加swift编译选项                            | >= 2.1.1 |
-| [add_asflags](#targetadd_asflags)                     | 添加汇编编译选项                             | >= 2.1.1 |
-| [add_gcflags](#targetadd_gcflags)                     | 添加go编译选项                               | >= 2.1.1 |
-| [add_dcflags](#targetadd_dcflags)                     | 添加dlang编译选项                            | >= 2.1.1 |
-| [add_rcflags](#targetadd_rcflags)                     | 添加rust编译选项                             | >= 2.1.1 |
-| [add_cuflags](#targetadd_cuflags)                     | 添加cuda编译选项                             | >= 2.2.1 |
-| [add_culdflags](#targetadd_culdflags)                 | 添加cuda设备链接选项                         | >= 2.2.7 |
-| [add_ldflags](#targetadd_ldflags)                     | 添加链接选项                                 | >= 2.1.1 |
-| [add_arflags](#targetadd_arflags)                     | 添加静态库归档选项                           | >= 2.1.1 |
-| [add_shflags](#targetadd_shflags)                     | 添加动态库链接选项                           | >= 2.0.1 |
-| [add_cfuncs](#targetadd_cfuncs)                       | 添加c库函数检测                              | >= 1.0.1 |
-| [add_cxxfuncs](#targetadd_cxxfuncs)                   | 添加c++库函数接口                            | >= 1.0.1 |
-| [add_languages](#targetadd_languages)                 | 添加语言标准                                 | >= 2.0.1 |
-| [add_vectorexts](#targetadd_vectorexts)               | 添加向量扩展指令                             | >= 2.0.1 |
-| [add_frameworks](#targetadd_frameworks)               | 添加链接框架                                 | >= 2.1.1 |
-| [add_frameworkdirs](#targetadd_frameworkdirs)         | 添加链接框架                                 | >= 2.1.5 |
+| 接口                                                                         | 描述                                         | 支持版本 |
+| -----------------------------------------------------                        | -------------------------------------------- | -------- |
+| [option](#option)                                                            | 定义选项                                     | >= 2.0.1 |
+| [option_end](#option_end)                                                    | 结束定义选项                                 | >= 2.1.1 |
+| [add_deps](#optionadd_deps)                                                  | 添加选项依赖                                 | >= 2.1.5 |
+| [before_check](#optionbefore_check)                                          | 选项检测之前执行此脚本                       | >= 2.1.5 |
+| [on_check](#optionon_check)                                                  | 自定义选项检测脚本                           | >= 2.1.5 |
+| [after_check](#optionafter_check)                                            | 选项检测之后执行此脚本                       | >= 2.1.5 |
+| [set_values](#optionset_values)                                              | 设置选项值列表                               | >= 2.1.9 |
+| [set_default](#optionset_default)                                            | 设置默认值                                   | >= 2.0.1 |
+| [set_showmenu](#optionset_showmenu)                                          | 设置是否启用菜单显示                         | >= 1.0.1 |
+| [set_category](#optionset_category)                                          | 设置选项分类,仅用于菜单显示                 | >= 1.0.1 |
+| [set_description](#optionset_description)                                    | 设置菜单显示描述                             | >= 1.0.1 |
+| [add_links](#optionadd_links)                                                | 添加链接库检测                               | >= 1.0.1 |
+| [add_linkdirs](#optionadd_linkdirs)                                          | 添加链接库检测需要的搜索目录                 | >= 1.0.1 |
+| [add_rpathdirs](#optionadd_rpathdirs)                                        | 添加运行时候动态链接库搜索目录               | >= 2.1.3 |
+| [add_cincludes](#optionadd_cincludes)                                        | 添加c头文件检测                              | >= 1.0.1 |
+| [add_cxxincludes](#optionadd_cxxincludes)                                    | 添加c++头文件检测                            | >= 1.0.1 |
+| [add_ctypes](#optionadd_ctypes)                                              | 添加c类型检测                                | >= 1.0.1 |
+| [add_cxxtypes](#optionadd_cxxtypes)                                          | 添加c++类型检测                              | >= 1.0.1 |
+| [add_csnippet](#optionadd_csnippet)                                          | 添加c代码片段检测                            | >= 2.1.5 |
+| [add_cxxsnippet](#optionadd_cxxsnippet)                                      | 添加c++代码片段检测                          | >= 2.1.5 |
+| [set_warnings](/zh-cn/manual/project_target?id=targetset_warnings)           | 设置警告级别                                 | >= 1.0.1 |
+| [set_optimize](/zh-cn/manual/project_target?id=targetset_optimize)           | 设置优化级别                                 | >= 1.0.1 |
+| [set_languages](/zh-cn/manual/project_target?id=targetset_languages)         | 设置代码语言标准                             | >= 1.0.1 |
+| [add_includedirs](/zh-cn/manual/project_target?id=targetadd_includedirs)     | 添加头文件搜索目录                           | >= 1.0.1 |
+| [add_defines](/zh-cn/manual/project_target?id=targetadd_defines)             | 添加宏定义                                   | >= 1.0.1 |
+| [add_undefines](/zh-cn/manual/project_target?id=targetadd_undefines)         | 取消宏定义                                   | >= 1.0.1 |
+| [add_cflags](/zh-cn/manual/project_target?id=targetadd_cflags)               | 添加c编译选项                                | >= 1.0.1 |
+| [add_cxflags](/zh-cn/manual/project_target?id=targetadd_cxflags)             | 添加c/c++编译选项                            | >= 1.0.1 |
+| [add_cxxflags](/zh-cn/manual/project_target?id=targetadd_cxxflags)           | 添加c++编译选项                              | >= 1.0.1 |
+| [add_mflags](/zh-cn/manual/project_target?id=targetadd_mflags)               | 添加objc编译选项                             | >= 2.0.1 |
+| [add_mxflags](/zh-cn/manual/project_target?id=targetadd_mxflags)             | 添加objc/objc++编译选项                      | >= 2.0.1 |
+| [add_mxxflags](/zh-cn/manual/project_target?id=targetadd_mxxflags)           | 添加objc++编译选项                           | >= 2.0.1 |
+| [add_scflags](/zh-cn/manual/project_target?id=targetadd_scflags)             | 添加swift编译选项                            | >= 2.1.1 |
+| [add_asflags](/zh-cn/manual/project_target?id=targetadd_asflags)             | 添加汇编编译选项                             | >= 2.1.1 |
+| [add_gcflags](/zh-cn/manual/project_target?id=targetadd_gcflags)             | 添加go编译选项                               | >= 2.1.1 |
+| [add_dcflags](/zh-cn/manual/project_target?id=targetadd_dcflags)             | 添加dlang编译选项                            | >= 2.1.1 |
+| [add_rcflags](/zh-cn/manual/project_target?id=targetadd_rcflags)             | 添加rust编译选项                             | >= 2.1.1 |
+| [add_cuflags](/zh-cn/manual/project_target?id=targetadd_cuflags)             | 添加cuda编译选项                             | >= 2.2.1 |
+| [add_culdflags](/zh-cn/manual/project_target?id=targetadd_culdflags)         | 添加cuda设备链接选项                         | >= 2.2.7 |
+| [add_ldflags](/zh-cn/manual/project_target?id=targetadd_ldflags)             | 添加链接选项                                 | >= 2.1.1 |
+| [add_arflags](/zh-cn/manual/project_target?id=targetadd_arflags)             | 添加静态库归档选项                           | >= 2.1.1 |
+| [add_shflags](/zh-cn/manual/project_target?id=targetadd_shflags)             | 添加动态库链接选项                           | >= 2.0.1 |
+| [add_languages](/zh-cn/manual/project_target?id=targetadd_languages)         | 添加语言标准                                 | >= 2.0.1 |
+| [add_vectorexts](/zh-cn/manual/project_target?id=targetadd_vectorexts)       | 添加向量扩展指令                             | >= 2.0.1 |
+| [add_frameworks](/zh-cn/manual/project_target?id=targetadd_frameworks)       | 添加链接框架                                 | >= 2.1.1 |
+| [add_frameworkdirs](/zh-cn/manual/project_target?id=targetadd_frameworkdirs) | 添加链接框架                                 | >= 2.1.5 |
 
 ### option
 
@@ -113,7 +109,7 @@ $ xmake
 
 #### 结束定义选项
 
-这是一个可选api,显示离开选项作用域,用法和[target_end](#target_end)类似。
+这是一个可选api,显示离开选项作用域,用法和[target_end](/zh-cn/manual/project_target?id=target_end)类似。
 
 ### option:add_deps
 
@@ -447,7 +443,7 @@ target("test")
 
 #### 添加程序运行时动态库的加载搜索目录
 
-在选项通过检测后,会自动添加到对应的target上去,具体使用见:[target.add_rpathdirs](#targetadd_rpathdirs)。
+在选项通过检测后,会自动添加到对应的target上去,具体使用见:[target.add_rpathdirs](/zh-cn/manual/project_target?id=targetadd_rpathdirs)。
 
 ### option:add_cincludes
 

+ 252 - 1
zh-cn/manual/custom_toolchain.md

@@ -1,2 +1,253 @@
 
-test
+在2.3.4版本之后,xmake已经支持在用户的项目xmake.lua中自定义工具链,例如:
+
+```lua
+-- define toolchain
+toolchain("myclang")
+
+    -- mark as standalone toolchain
+    set_kind("standalone")
+        
+    -- set toolsets
+    set_toolsets("cc", "clang")
+    set_toolsets("cxx", "clang", "clang++")
+    set_toolsets("ld", "clang++", "clang")
+    set_toolsets("sh", "clang++", "clang")
+    set_toolsets("ar", "ar")
+    set_toolsets("ex", "ar")
+    set_toolsets("strip", "strip")
+    set_toolsets("mm", "clang")
+    set_toolsets("mxx", "clang", "clang++")
+    set_toolsets("as", "clang")
+
+    add_defines("MYCLANG")
+
+    -- check toolchain
+    on_check(function (toolchain)
+        return import("lib.detect.find_tool")("clang")
+    end)
+
+    -- on load
+    on_load(function (toolchain)
+
+        -- get march
+        local march = is_arch("x86_64", "x64") and "-m64" or "-m32"
+
+        -- init flags for c/c++
+        toolchain:add("cxflags", march)
+        toolchain:add("ldflags", march)
+        toolchain:add("shflags", march)
+        if not is_plat("windows") and os.isdir("/usr") then
+            for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do
+                if os.isdir(includedir) then
+                    toolchain:add("includedirs", includedir)
+                end
+            end
+            for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do
+                if os.isdir(linkdir) then
+                    toolchain:add("linkdirs", linkdir)
+                end
+            end
+        end
+
+        -- init flags for objc/c++  (with ldflags and shflags)
+        toolchain:add("mxflags", march)
+
+        -- init flags for asm
+        toolchain:add("asflags", march)
+    end)
+```
+
+然后通过下面的命令切到自己定义的工具链就行了:
+
+```bash
+$ xmake f --toolchain=myclang
+```
+
+当然,我们也可以通过`set_toolchains`接口直接对指定target切换设置到自定义工具链。
+
+在自定义工具前,我们可以通过先运行以下命令,查看完整的内置工具链列表,确保xmake没有提供,如果有的话,直接使用就行了,没必要自己定义:
+
+```bash
+$ xmake show -l toolchains
+```
+
+下面是自定义toolchain目前支持的接口列表:
+
+| 接口                                                                         | 描述                                         | 支持版本 |
+| -----------------------------------------------                              | -------------------------------------------- | -------- |
+| [toolchain](#toolchain)                                                      | 定义工具链                                   | >= 2.3.4 |
+| [set_kind](#toolchainset_kind)                                               | 设置工具链类型                               | >= 2.3.4 |
+| [set_toolsets](#toolchainset_toolsets)                                       | 设置工具集                                   | >= 2.3.4 |
+| [set_sdkdir](#toolchainset_sdkdir)                                           | 设置工具链sdk目录路径                        | >= 2.3.4 |
+| [set_bindir](#toolchainset_bindir)                                           | 设置工具链bin目录路径                        | >= 2.3.4 |
+| [on_check](#toolchainon_check)                                               | 检测工具链                                   | >= 2.3.4 |
+| [on_load](#toolchainonon_load)                                               | 加载工具链                                   | >= 2.3.4 |
+| [toolchain_end](#toolchain_end)                                              | 结束定义工具链                               | >= 2.3.4 |
+| [add_includedirs](/zh-cn/manual/project_target?id=targetadd_includedirs)     | 添加头文件搜索目录                           | >= 2.3.4 |
+| [add_defines](/zh-cn/manual/project_target?id=targetadd_defines)             | 添加宏定义                                   | >= 2.3.4 |
+| [add_undefines](/zh-cn/manual/project_target?id=targetadd_undefines)         | 取消宏定义                                   | >= 2.3.4 |
+| [add_cflags](/zh-cn/manual/project_target?id=targetadd_cflags)               | 添加c编译选项                                | >= 2.3.4 |
+| [add_cxflags](/zh-cn/manual/project_target?id=targetadd_cxflags)             | 添加c/c++编译选项                            | >= 2.3.4 |
+| [add_cxxflags](/zh-cn/manual/project_target?id=targetadd_cxxflags)           | 添加c++编译选项                              | >= 2.3.4 |
+| [add_mflags](/zh-cn/manual/project_target?id=targetadd_mflags)               | 添加objc编译选项                             | >= 2.3.4 |
+| [add_mxflags](/zh-cn/manual/project_target?id=targetadd_mxflags)             | 添加objc/objc++编译选项                      | >= 2.3.4 |
+| [add_mxxflags](/zh-cn/manual/project_target?id=targetadd_mxxflags)           | 添加objc++编译选项                           | >= 2.3.4 |
+| [add_scflags](/zh-cn/manual/project_target?id=targetadd_scflags)             | 添加swift编译选项                            | >= 2.3.4 |
+| [add_asflags](/zh-cn/manual/project_target?id=targetadd_asflags)             | 添加汇编编译选项                             | >= 2.3.4 |
+| [add_gcflags](/zh-cn/manual/project_target?id=targetadd_gcflags)             | 添加go编译选项                               | >= 2.3.4 |
+| [add_dcflags](/zh-cn/manual/project_target?id=targetadd_dcflags)             | 添加dlang编译选项                            | >= 2.3.4 |
+| [add_rcflags](/zh-cn/manual/project_target?id=targetadd_rcflags)             | 添加rust编译选项                             | >= 2.3.4 |
+| [add_cuflags](/zh-cn/manual/project_target?id=targetadd_cuflags)             | 添加cuda编译选项                             | >= 2.3.4 |
+| [add_culdflags](/zh-cn/manual/project_target?id=targetadd_culdflags)         | 添加cuda设备链接选项                         | >= 2.3.4 |
+| [add_ldflags](/zh-cn/manual/project_target?id=targetadd_ldflags)             | 添加链接选项                                 | >= 2.3.4 |
+| [add_arflags](/zh-cn/manual/project_target?id=targetadd_arflags)             | 添加静态库归档选项                           | >= 2.3.4 |
+| [add_shflags](/zh-cn/manual/project_target?id=targetadd_shflags)             | 添加动态库链接选项                           | >= 2.3.4 |
+| [add_languages](/zh-cn/manual/project_target?id=targetadd_languages)         | 添加语言标准                                 | >= 2.3.4 |
+| [add_frameworks](/zh-cn/manual/project_target?id=targetadd_frameworks)       | 添加链接框架                                 | >= 2.3.4 |
+| [add_frameworkdirs](/zh-cn/manual/project_target?id=targetadd_frameworkdirs) | 添加链接框架                                 | >= 2.3.4 |
+
+### toolchain
+
+#### 定义工具链
+
+可以在用户项目xmake.lua中定义,也可以通过includes独立到单独的xmake.lua去专门定义各种工具链
+
+```lua
+toolchain("myclang")
+    set_toolsets("cc", "clang")
+    set_toolsets("cxx", "clang", "clang++")
+toolchain_end()
+```
+
+### toolchain:set_kind
+
+#### 设置工具链类型
+
+目前仅支持设置为`standalone`类型,表示当前工具链是独立完整的工具链,包括cc/cxx/ld/sh/ar等编译器、归档器、链接器等一整套工具集的配置。
+
+通常用于某个target被同时设置了多个工具链的情况,但同时只能生效一个独立工具链,通过此配置可以保证生效的工具链存在互斥关系,比如gcc/clang工具链不会同时生效。
+
+而像yasm/nasm这种局部工具链,属于附加的局部工具链扩展,不用设置standalone,因为clang/yasm两个工具链有可能同时存在。
+
+!> 只要记住,存在完整编译环境的工具链,都设置为standalone就行了
+
+### toolchain:set_toolsets
+
+#### 设置工具集
+
+用于设置每个单独工具名和路径,例如:
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    set_toolsets("cc", "clang")
+    set_toolsets("cxx", "clang", "clang++")
+    set_toolsets("ld", "clang++", "clang")
+    set_toolsets("sh", "clang++", "clang")
+    set_toolsets("ar", "ar")
+    set_toolsets("ex", "ar")
+    set_toolsets("strip", "strip")
+    set_toolsets("mm", "clang")
+    set_toolsets("mxx", "clang", "clang++")
+    set_toolsets("as", "clang")
+```
+
+关于这个接口的详情,可以看下:[target.set_toolsets](/zh-cn/manual/project_target?id=targetset_toolsets)
+
+### toolchain:set_sdkdir
+
+#### 设置工具链sdk目录路径
+
+通常我们可以通过`xmake f --toolchain=myclang --sdk=xxx`来配置sdk目录,但是每次配置比较繁琐,我们也可以通过此接口预先配置到xmake.lua中去,方便快速切换使用。
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    set_sdkdir("/tmp/sdkdir")
+    set_toolsets("cc", "clang")
+```
+
+### toolchain:set_bindir
+
+#### 设置工具链bin目录路径
+
+通常我们可以通过`xmake f --toolchain=myclang --bin=xxx`来配置sdk目录,但是每次配置比较繁琐,我们也可以通过此接口预先配置到xmake.lua中去,方便快速切换使用。
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    set_bindir("/tmp/sdkdir/bin")
+    set_toolsets("cc", "clang")
+```
+
+### toolchain:on_check
+
+#### 检测工具链
+
+用于检测指定工具链所在sdk或者程序在当前系统上是否存在,通常用于多个standalone工具链的情况,进行自动探测和选择有效工具链。
+
+而对于`xmake f --toolchain=myclang`手动指定的场景,此检测配置不是必须的,可以省略。
+
+```lua
+toolchain("myclang")
+    on_check(function (toolchain)
+        return import("lib.detect.find_tool")("clang")
+    end)
+```
+
+### toolchain:on_load
+
+#### 加载工具链
+
+对于一些复杂的场景,我们可以在on_load中动态灵活的设置各种工具链配置,比在描述域设置更加灵活,更加强大:
+
+```lua
+toolchain("myclang")
+    set_kind("standalone")
+    on_load(function (toolchain)
+        
+        -- set toolsets
+        toolchain:set("toolsets", "cc", "clang")
+        toolchain:set("toolsets", "ld", "clang++")
+        -- ..
+
+        -- get march
+        local march = is_arch("x86_64", "x64") and "-m64" or "-m32"
+
+        -- init flags for c/c++
+        toolchain:add("cxflags", march)
+        toolchain:add("ldflags", march)
+        toolchain:add("shflags", march)
+        if not is_plat("windows") and os.isdir("/usr") then
+            for _, includedir in ipairs({"/usr/local/include", "/usr/include"}) do
+                if os.isdir(includedir) then
+                    toolchain:add("includedirs", includedir)
+                end
+            end
+            for _, linkdir in ipairs({"/usr/local/lib", "/usr/lib"}) do
+                if os.isdir(linkdir) then
+                    toolchain:add("linkdirs", linkdir)
+                end
+            end
+        end
+
+        -- init flags for objc/c++  (with ldflags and shflags)
+        toolchain:add("mxflags", march)
+
+        -- init flags for asm
+        toolchain:add("asflags", march)
+    end)
+```
+
+### toolchain_end
+
+#### 结束定义规则
+
+这个是可选的,如果想要手动结束toolchain的定义,可以调用它:
+
+```lua
+toolchain("myclang")
+    -- ..
+toolchain_end()
+```