| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>xmake</title>
- <link rel="icon" href="/assets/img/favicon.ico">
- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
- <meta name="description" content="Description">
- <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
- <style>
- .markdown-body {
- box-sizing: border-box;
- min-width: 200px;
- max-width: 980px;
- margin: 0 auto;
- padding: 45px;
- }
- @media (max-width: 767px) {
- .markdown-body {
- padding: 15px;
- }
- }
- </style>
- </head>
- <body>
- <article class="markdown-body">
- <h4>This is a mirror page, please see the original page: </h4><a href="https://xmake.io/#/zh-cn/features/autogen">https://xmake.io/#/zh-cn/features/autogen</a>
- <div id="wwads-panel" class="wwads-cn wwads-vertical wwads-sticky" data-id="239" style="max-width:180px;bottom:20px;right:20px;width:200px;height:260px;background:#fff;position:fixed"></div>
- </br>
- <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
- <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
- <style>
- #carbonads {
- font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
- Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
- }
- #carbonads {
- display: flex;
- max-width: 330px;
- background-color: hsl(0, 0%, 98%);
- box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
- }
- #carbonads a {
- color: inherit;
- text-decoration: none;
- }
- #carbonads a:hover {
- color: inherit;
- }
- #carbonads span {
- position: relative;
- display: block;
- overflow: hidden;
- }
- #carbonads .carbon-wrap {
- display: flex;
- }
- .carbon-img {
- display: block;
- margin: 0;
- line-height: 1;
- }
- .carbon-img img {
- display: block;
- }
- .carbon-text {
- font-size: 13px;
- padding: 10px;
- line-height: 1.5;
- text-align: left;
- }
- .carbon-poweredby {
- display: block;
- padding: 8px 10px;
- background: repeating-linear-gradient(-45deg, transparent, transparent 5px, hsla(0, 0%, 0%, .025) 5px, hsla(0, 0%, 0%, .025) 10px) hsla(203, 11%, 95%, .4);
- text-align: center;
- text-transform: uppercase;
- letter-spacing: .5px;
- font-weight: 600;
- font-size: 9px;
- line-height: 1;
- }
- </style>
- <p>对于一份工程源码,可以不用编写makefile,也不用编写各种make相关的工程描述文件(例如:xmake.lua,makefile.am, cmakelist.txt等)</p>
- <p>xmake就可以直接编译他们,这是如何做到的呢,简单来说下实现原理:</p>
- <ol>
- <li>首先扫描当前目录下,xmake所以支持的所有源代码文件</li>
- <li>分析代码,检测哪些代码拥有main入口函数</li>
- <li>所有没有main入口的代码编译成静态库</li>
- <li>带有main入口的代码,编译成可执行程序,同时链接其他静态库程序</li>
- </ol>
- <p>这种代码扫描和智能编译,非常简单,目前xmake还不支持多级目录扫描,只对单级目录的代码进行扫描编译。。</p>
- <h3 id="">使用场景</h3>
- <ol>
- <li>临时快速编译和运行一些零散的测试代码</li>
- <li>尝试对其他开源库做移植编译</li>
- <li>快速基于现有代码创建新xmake工程</li>
- </ol>
- <h3 id="">如何使用</h3>
- <p>直接在带有源码的目录(没有xmake.lua)下执行xmake,然后根据提示操作:</p>
- <pre><code class="lang-bash">$ xmake
- note: xmake.lua not found, try generating it (pass -y or --confirm=y/n/d to skip confirm)?
- please input: n (y/n)
- y
- </code></pre>
- <p>另外, 当存在其他构建系统标识性文件的时候(比如 CMakeLists.txt), 不会触发自动生成 xmake.lua 的流程, 而是首先触发 <a href="#自动探测构建系统并编译">自动探测构建系统并编译</a>, 如果要强制触发自动扫描生成 xmake.lua 的流程, 可运行: </p>
- <pre><code class="lang-bash">$ xmake f -y
- </code></pre>
- <h3 id="">开源代码的移植和编译</h3>
- <p>虽然这种方式,并不是非常智能,限制也不少,但是对于想临时写些代码进行编译运行,或者临时想交叉编译一些简单的开源库代码</p>
- <p>这种方式已经足够使用了,下面看下一个实际的例子:</p>
- <p>我下载了一份zlib-1.2.10的源码,想要编译它,只需要进入zlib的源码目录执行:</p>
- <pre><code class="lang-bash">$ cd zlib-1.2.10
- $ xmake
- note: xmake.lua not found, try generating it (pass -y or --confirm=y/n/d to skip confirm)?
- please input: n (y/n)
- y
- </code></pre>
- <p>就行了,输入y确认后,输出结果如下:</p>
- <pre><code>target(zlib-1.2): static
- [+]: ./adler32.c
- [+]: ./compress.c
- [+]: ./crc32.c
- [+]: ./deflate.c
- [+]: ./gzclose.c
- [+]: ./gzlib.c
- [+]: ./gzread.c
- [+]: ./gzwrite.c
- [+]: ./infback.c
- [+]: ./inffast.c
- [+]: ./inflate.c
- [+]: ./inftrees.c
- [+]: ./trees.c
- [+]: ./uncompr.c
- [+]: ./zutil.c
- xmake.lua generated, scan ok!👌
- checking for the architecture ... x86_64
- checking for the Xcode SDK version for macosx ... 10.12
- checking for the target minimal version ... 10.12
- checking for the c compiler (cc) ... xcrun -sdk macosx clang
- checking for the c++ compiler (cxx) ... xcrun -sdk macosx clang
- checking for the objc compiler (mm) ... xcrun -sdk macosx clang
- checking for the objc++ compiler (mxx) ... xcrun -sdk macosx clang++
- checking for the swift compiler (sc) ... xcrun -sdk macosx swiftc
- checking for the assember (as) ... xcrun -sdk macosx clang
- checking for the linker (ld) ... xcrun -sdk macosx clang++
- checking for the static library archiver (ar) ... xcrun -sdk macosx ar
- checking for the static library extractor (ex) ... xcrun -sdk macosx ar
- checking for the shared library linker (sh) ... xcrun -sdk macosx clang++
- checking for the debugger (dd) ... xcrun -sdk macosx lldb
- checking for the golang compiler (go) ... go
- configure
- {
- ex = "xcrun -sdk macosx ar"
- , sh = "xcrun -sdk macosx clang++"
- , host = "macosx"
- , ar = "xcrun -sdk macosx ar"
- , buildir = "build"
- , as = "xcrun -sdk macosx clang"
- , plat = "macosx"
- , xcode_dir = "/Applications/Xcode.app"
- , arch = "x86_64"
- , mxx = "xcrun -sdk macosx clang++"
- , go = "go"
- , target_minver = "10.12"
- , ccache = "ccache"
- , mode = "release"
- , clean = true
- , cxx = "xcrun -sdk macosx clang"
- , cc = "xcrun -sdk macosx clang"
- , dd = "xcrun -sdk macosx lldb"
- , kind = "static"
- , ld = "xcrun -sdk macosx clang++"
- , xcode_sdkver = "10.12"
- , sc = "xcrun -sdk macosx swiftc"
- , mm = "xcrun -sdk macosx clang"
- }
- configure ok!
- clean ok!
- [00%]: cache compiling.release ./adler32.c
- [06%]: cache compiling.release ./compress.c
- [13%]: cache compiling.release ./crc32.c
- [20%]: cache compiling.release ./deflate.c
- [26%]: cache compiling.release ./gzclose.c
- [33%]: cache compiling.release ./gzlib.c
- [40%]: cache compiling.release ./gzread.c
- [46%]: cache compiling.release ./gzwrite.c
- [53%]: cache compiling.release ./infback.c
- [60%]: cache compiling.release ./inffast.c
- [66%]: cache compiling.release ./inflate.c
- [73%]: cache compiling.release ./inftrees.c
- [80%]: cache compiling.release ./trees.c
- [86%]: cache compiling.release ./uncompr.c
- [93%]: cache compiling.release ./zutil.c
- [100%]: archiving.release libzlib-1.2.a
- build ok!👌
- </code></pre><p>通过输出结果,可以看到,xmake会去检测扫描当前目录下的所有.c代码,发现没有main入口,应该是静态库程序,因此执行xmake后,就直接编译成静态库libzlib-1.2.a了</p>
- <p>连xmake.lua都没有编写,其实xmake在扫描完成后,会去自动在当前目录下生成一份xmake.lua,下次编译就不需要重新扫描检测了。</p>
- <p>自动生成的xmake.lua内容如下:</p>
- <pre><code class="lang-lua">-- define target
- target("zlib-1.2")
- -- set kind
- set_kind("static")
- -- add files
- add_files("./adler32.c")
- add_files("./compress.c")
- add_files("./crc32.c")
- add_files("./deflate.c")
- add_files("./gzclose.c")
- add_files("./gzlib.c")
- add_files("./gzread.c")
- add_files("./gzwrite.c")
- add_files("./infback.c")
- add_files("./inffast.c")
- add_files("./inflate.c")
- add_files("./inftrees.c")
- add_files("./trees.c")
- add_files("./uncompr.c")
- add_files("./zutil.c")
- </code></pre>
- <p>也许你会说,像这种开源库,直接<code>configure; make</code>不就好了吗,他们自己也有提供makefile来直接编译的,的确是这样,我这里只是举个例子而已。。</p>
- <p>当然,很多开源库在交叉编译的时候,通过自带的<code>configure</code>,处理起来还是很繁琐的,用xmake进行交叉编译会更方便些。。</p>
- <h3 id="">即时地代码编写和编译运行</h3>
- <p>xmake的这个扫描代码编译特性,主要的目的:还是为了让我们在临时想写些测试代码的时候,不用考虑太多东西,直接上手敲代码,然后快速执行<code>xmake run</code> 来调试验证结果。。</p>
- <p>例如:</p>
- <p>我想写了个简单的main.c的测试程序,打印<code>hello world!</code>,如果要写makefile或者直接通过gcc命令来,就很繁琐了,你需要:</p>
- <pre><code class="lang-bash">gcc ./main.c -o demo
- ./demo
- </code></pre>
- <p>最快速的方式,也需要执行两行命令,而如果用xmake,只需要执行:</p>
- <pre><code class="lang-bash">xmake run
- </code></pre>
- <p>就行了,它会自动检测到代码后,自动生成对应的xmake.lua,自动编译,自动运行,然后输出:</p>
- <pre><code>hello world!
- </code></pre><p>如果你有十几个代码文件,用手敲gcc的方式,或者写makefile的方式,这个差距就更明显了,用xmake还是只需要一行命令:</p>
- <pre><code class="lang-bash">xmake run
- </code></pre>
- <h3 id="">多语言支持</h3>
- <p>这种代码检测和即时编译,是支持多语言的,不仅支持c/c++,还支持objc/swift,后期还会支持golang(正在开发中)</p>
- <p>例如我下载了一份fmdb的ios开源框架代码:</p>
- <pre><code>.
- ├── FMDB.h
- ├── FMDatabase.h
- ├── FMDatabase.m
- ├── FMDatabaseAdditions.h
- ├── FMDatabaseAdditions.m
- ├── FMDatabasePool.h
- ├── FMDatabasePool.m
- ├── FMDatabaseQueue.h
- ├── FMDatabaseQueue.m
- ├── FMResultSet.h
- └── FMResultSet.m
- </code></pre><p>想要把它编译成ios的静态库,但是又不想写xmake.lua,或者makefile,那么只需要使用xmake的这个新特性,直接执行:</p>
- <pre><code class="lang-bash">$ xmake f -p iphoneos; xmake
- </code></pre>
- <p>就行了,输出结果如下:</p>
- <pre><code>xmake.lua not found, scanning files ..
- target(FMDB): static
- [+]: ./FMDatabase.m
- [+]: ./FMDatabaseAdditions.m
- [+]: ./FMDatabasePool.m
- [+]: ./FMDatabaseQueue.m
- [+]: ./FMResultSet.m
- xmake.lua generated, scan ok!👌
- checking for the architecture ... armv7
- checking for the Xcode SDK version for iphoneos ... 10.1
- checking for the target minimal version ... 10.1
- checking for the c compiler (cc) ... xcrun -sdk iphoneos clang
- checking for the c++ compiler (cxx) ... xcrun -sdk iphoneos clang
- checking for the objc compiler (mm) ... xcrun -sdk iphoneos clang
- checking for the objc++ compiler (mxx) ... xcrun -sdk iphoneos clang++
- checking for the assember (as) ... gas-preprocessor.pl xcrun -sdk iphoneos clang
- checking for the linker (ld) ... xcrun -sdk iphoneos clang++
- checking for the static library archiver (ar) ... xcrun -sdk iphoneos ar
- checking for the static library extractor (ex) ... xcrun -sdk iphoneos ar
- checking for the shared library linker (sh) ... xcrun -sdk iphoneos clang++
- checking for the swift compiler (sc) ... xcrun -sdk iphoneos swiftc
- configure
- {
- ex = "xcrun -sdk iphoneos ar"
- , ccache = "ccache"
- , host = "macosx"
- , ar = "xcrun -sdk iphoneos ar"
- , buildir = "build"
- , as = "/usr/local/share/xmake/tools/utils/gas-preprocessor.pl xcrun -sdk iphoneos clang"
- , arch = "armv7"
- , mxx = "xcrun -sdk iphoneos clang++"
- , cxx = "xcrun -sdk iphoneos clang"
- , target_minver = "10.1"
- , xcode_dir = "/Applications/Xcode.app"
- , clean = true
- , sh = "xcrun -sdk iphoneos clang++"
- , cc = "xcrun -sdk iphoneos clang"
- , ld = "xcrun -sdk iphoneos clang++"
- , mode = "release"
- , kind = "static"
- , plat = "iphoneos"
- , xcode_sdkver = "10.1"
- , sc = "xcrun -sdk iphoneos swiftc"
- , mm = "xcrun -sdk iphoneos clang"
- }
- configure ok!
- clean ok!
- [00%]: cache compiling.release ./FMDatabase.m
- [20%]: cache compiling.release ./FMDatabaseAdditions.m
- [40%]: cache compiling.release ./FMDatabasePool.m
- [60%]: cache compiling.release ./FMDatabaseQueue.m
- [80%]: cache compiling.release ./FMResultSet.m
- [100%]: archiving.release libFMDB.a
- build ok!👌
- </code></pre><h3 id="">同时编译多个可执行文件</h3>
- <p>输出结果的开头部分,就是对代码的分析结果,虽然目前只支持单级目录结构的代码扫描,但是还是可以同时支持检测和编译多个可执行文件的</p>
- <p>我们以libjpeg的开源库为例:</p>
- <p>我们进入jpeg-6b目录后,执行:</p>
- <pre><code class="lang-bash">$ xmake
- </code></pre>
- <p>输出如下:</p>
- <pre><code>xmake.lua not found, scanning files ..
- target(jpeg-6b): static
- [+]: ./cdjpeg.c
- [+]: ./example.c
- [+]: ./jcapimin.c
- [+]: ./jcapistd.c
- [+]: ./jccoefct.c
- [+]: ./jccolor.c
- [+]: ./jcdctmgr.c
- [+]: ./jchuff.c
- [+]: ./jcinit.c
- [+]: ./jcmainct.c
- [+]: ./jcmarker.c
- [+]: ./jcmaster.c
- [+]: ./jcomapi.c
- [+]: ./jcparam.c
- [+]: ./jcphuff.c
- [+]: ./jcprepct.c
- [+]: ./jcsample.c
- [+]: ./jctrans.c
- [+]: ./jdapimin.c
- [+]: ./jdapistd.c
- [+]: ./jdatadst.c
- [+]: ./jdatasrc.c
- [+]: ./jdcoefct.c
- [+]: ./jdcolor.c
- [+]: ./jddctmgr.c
- [+]: ./jdhuff.c
- [+]: ./jdinput.c
- [+]: ./jdmainct.c
- [+]: ./jdmarker.c
- [+]: ./jdmaster.c
- [+]: ./jdmerge.c
- [+]: ./jdphuff.c
- [+]: ./jdpostct.c
- [+]: ./jdsample.c
- [+]: ./jdtrans.c
- [+]: ./jerror.c
- [+]: ./jfdctflt.c
- [+]: ./jfdctfst.c
- [+]: ./jfdctint.c
- [+]: ./jidctflt.c
- [+]: ./jidctfst.c
- [+]: ./jidctint.c
- [+]: ./jidctred.c
- [+]: ./jmemansi.c
- [+]: ./jmemmgr.c
- [+]: ./jmemname.c
- [+]: ./jmemnobs.c
- [+]: ./jquant1.c
- [+]: ./jquant2.c
- [+]: ./jutils.c
- [+]: ./rdbmp.c
- [+]: ./rdcolmap.c
- [+]: ./rdgif.c
- [+]: ./rdppm.c
- [+]: ./rdrle.c
- [+]: ./rdswitch.c
- [+]: ./rdtarga.c
- [+]: ./transupp.c
- [+]: ./wrbmp.c
- [+]: ./wrgif.c
- [+]: ./wrppm.c
- [+]: ./wrrle.c
- [+]: ./wrtarga.c
- target(ansi2knr): binary
- [+]: ./ansi2knr.c
- target(cjpeg): binary
- [+]: ./cjpeg.c
- target(ckconfig): binary
- [+]: ./ckconfig.c
- target(djpeg): binary
- [+]: ./djpeg.c
- target(jpegtran): binary
- [+]: ./jpegtran.c
- target(rdjpgcom): binary
- [+]: ./rdjpgcom.c
- target(wrjpgcom): binary
- [+]: ./wrjpgcom.c
- xmake.lua generated, scan ok!👌
- checking for the architecture ... x86_64
- checking for the Xcode SDK version for macosx ... 10.12
- checking for the target minimal version ... 10.12
- checking for the c compiler (cc) ... xcrun -sdk macosx clang
- checking for the c++ compiler (cxx) ... xcrun -sdk macosx clang
- checking for the objc compiler (mm) ... xcrun -sdk macosx clang
- checking for the objc++ compiler (mxx) ... xcrun -sdk macosx clang++
- checking for the swift compiler (sc) ... xcrun -sdk macosx swiftc
- checking for the assember (as) ... xcrun -sdk macosx clang
- checking for the linker (ld) ... xcrun -sdk macosx clang++
- checking for the static library archiver (ar) ... xcrun -sdk macosx ar
- checking for the static library extractor (ex) ... xcrun -sdk macosx ar
- checking for the shared library linker (sh) ... xcrun -sdk macosx clang++
- checking for the debugger (dd) ... xcrun -sdk macosx lldb
- checking for the golang compiler (go) ... go
- configure
- {
- ex = "xcrun -sdk macosx ar"
- , sh = "xcrun -sdk macosx clang++"
- , host = "macosx"
- , ar = "xcrun -sdk macosx ar"
- , buildir = "build"
- , as = "xcrun -sdk macosx clang"
- , plat = "macosx"
- , xcode_dir = "/Applications/Xcode.app"
- , arch = "x86_64"
- , mxx = "xcrun -sdk macosx clang++"
- , go = "go"
- , target_minver = "10.12"
- , ccache = "ccache"
- , mode = "release"
- , clean = true
- , cxx = "xcrun -sdk macosx clang"
- , cc = "xcrun -sdk macosx clang"
- , dd = "xcrun -sdk macosx lldb"
- , kind = "static"
- , ld = "xcrun -sdk macosx clang++"
- , xcode_sdkver = "10.12"
- , sc = "xcrun -sdk macosx swiftc"
- , mm = "xcrun -sdk macosx clang"
- }
- configure ok!
- clean ok!
- [00%]: cache compiling.release ./cdjpeg.c
- [00%]: cache compiling.release ./example.c
- [00%]: cache compiling.release ./jcapimin.c
- [00%]: cache compiling.release ./jcapistd.c
- [00%]: cache compiling.release ./jccoefct.c
- [00%]: cache compiling.release ./jccolor.c
- [01%]: cache compiling.release ./jcdctmgr.c
- [01%]: cache compiling.release ./jchuff.c
- [01%]: cache compiling.release ./jcinit.c
- [01%]: cache compiling.release ./jcmainct.c
- [01%]: cache compiling.release ./jcmarker.c
- [02%]: cache compiling.release ./jcmaster.c
- [02%]: cache compiling.release ./jcomapi.c
- [02%]: cache compiling.release ./jcparam.c
- [02%]: cache compiling.release ./jcphuff.c
- [02%]: cache compiling.release ./jcprepct.c
- [03%]: cache compiling.release ./jcsample.c
- [03%]: cache compiling.release ./jctrans.c
- [03%]: cache compiling.release ./jdapimin.c
- [03%]: cache compiling.release ./jdapistd.c
- [03%]: cache compiling.release ./jdatadst.c
- [04%]: cache compiling.release ./jdatasrc.c
- [04%]: cache compiling.release ./jdcoefct.c
- [04%]: cache compiling.release ./jdcolor.c
- [04%]: cache compiling.release ./jddctmgr.c
- [04%]: cache compiling.release ./jdhuff.c
- [05%]: cache compiling.release ./jdinput.c
- [05%]: cache compiling.release ./jdmainct.c
- [05%]: cache compiling.release ./jdmarker.c
- [05%]: cache compiling.release ./jdmaster.c
- [05%]: cache compiling.release ./jdmerge.c
- [06%]: cache compiling.release ./jdphuff.c
- [06%]: cache compiling.release ./jdpostct.c
- [06%]: cache compiling.release ./jdsample.c
- [06%]: cache compiling.release ./jdtrans.c
- [06%]: cache compiling.release ./jerror.c
- [07%]: cache compiling.release ./jfdctflt.c
- [07%]: cache compiling.release ./jfdctfst.c
- [07%]: cache compiling.release ./jfdctint.c
- [07%]: cache compiling.release ./jidctflt.c
- [07%]: cache compiling.release ./jidctfst.c
- [08%]: cache compiling.release ./jidctint.c
- [08%]: cache compiling.release ./jidctred.c
- [08%]: cache compiling.release ./jmemansi.c
- [08%]: cache compiling.release ./jmemmgr.c
- [08%]: cache compiling.release ./jmemname.c
- [09%]: cache compiling.release ./jmemnobs.c
- [09%]: cache compiling.release ./jquant1.c
- [09%]: cache compiling.release ./jquant2.c
- [09%]: cache compiling.release ./jutils.c
- [09%]: cache compiling.release ./rdbmp.c
- [10%]: cache compiling.release ./rdcolmap.c
- [10%]: cache compiling.release ./rdgif.c
- [10%]: cache compiling.release ./rdppm.c
- [10%]: cache compiling.release ./rdrle.c
- [10%]: cache compiling.release ./rdswitch.c
- [11%]: cache compiling.release ./rdtarga.c
- [11%]: cache compiling.release ./transupp.c
- [11%]: cache compiling.release ./wrbmp.c
- [11%]: cache compiling.release ./wrgif.c
- [11%]: cache compiling.release ./wrppm.c
- [12%]: cache compiling.release ./wrrle.c
- [12%]: cache compiling.release ./wrtarga.c
- [12%]: archiving.release libjpeg-6b.a
- [12%]: cache compiling.release ./wrjpgcom.c
- [25%]: linking.release wrjpgcom
- [25%]: cache compiling.release ./ansi2knr.c
- [37%]: linking.release ansi2knr
- [37%]: cache compiling.release ./jpegtran.c
- [50%]: linking.release jpegtran
- [50%]: cache compiling.release ./djpeg.c
- [62%]: linking.release djpeg
- [62%]: cache compiling.release ./ckconfig.c
- [75%]: linking.release ckconfig
- [75%]: cache compiling.release ./rdjpgcom.c
- [87%]: linking.release rdjpgcom
- [87%]: cache compiling.release ./cjpeg.c
- [100%]: linking.release cjpeg
- build ok!👌
- </code></pre><p>可以看到,处理静态库,xmake还分析出了很多可执行的测试程序,剩下的代码统一编译成一个 libjpeg.a 的静态库,供哪些测试程序链接使用。。</p>
- <pre><code>target(ansi2knr): binary
- [+]: ./ansi2knr.c
- target(cjpeg): binary
- [+]: ./cjpeg.c
- target(ckconfig): binary
- [+]: ./ckconfig.c
- target(djpeg): binary
- [+]: ./djpeg.c
- target(jpegtran): binary
- [+]: ./jpegtran.c
- target(rdjpgcom): binary
- [+]: ./rdjpgcom.c
- target(wrjpgcom): binary
- [+]: ./wrjpgcom.c
- </code></pre><h3 id="">遇到的一些问题和限制</h3>
- <p>当前xmake的这种自动分析检测还不是非常智能,对于:</p>
- <ol>
- <li>需要特殊的编译选项</li>
- <li>需要依赖其他目录的头文件搜索</li>
- <li>需要分条件编译不同源文件</li>
- <li>同目录需要生成多个静态库</li>
- <li>需要多级目录支持的源码库</li>
- </ol>
- <p>以上这些情况,xmake暂时还没发自动化的智能处理,其中限制1,2还是可以解决的,通过半手动的方式,例如:</p>
- <pre><code class="lang-bash">$ xmake f --cxflags="" --ldflags="" --includedirs="" --linkdirs=""; xmake
- </code></pre>
- <p>在自动检测编译的时候,手动配置这个源码工程需要的特殊编译选项,就可以直接通过编译了</p>
- <p>而限制3,暂时只能通过删源代码来解决了,就像刚才编译jpeg的代码,其实它的目录下面同时存在了:</p>
- <pre><code>jmemdos.c
- jmemmac.c
- jmemansi.c
- </code></pre><p>其中两个是没法编译过的,需要删掉后才行。。</p>
- </article>
- </body>
- </html>
|