autogen.html 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>xmake</title>
  6. <link rel="icon" href="/assets/img/favicon.ico">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
  8. <meta name="description" content="Description">
  9. <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  10. <link href="/assets/npm/github-markdown/github-markdown.min.css" rel="stylesheet">
  11. <style>
  12. .markdown-body {
  13. box-sizing: border-box;
  14. min-width: 200px;
  15. max-width: 980px;
  16. margin: 0 auto;
  17. padding: 45px;
  18. }
  19. @media (max-width: 767px) {
  20. .markdown-body {
  21. padding: 15px;
  22. }
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <article class="markdown-body">
  28. <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>
  29. <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>
  30. </br>
  31. <script type="text/javascript" charset="UTF-8" src="https://cdn.wwads.cn/js/makemoney.js" async></script>
  32. <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CE7I52QU&placement=xmakeio" id="_carbonads_js"></script>
  33. <style>
  34. #carbonads {
  35. font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu,
  36. Cantarell, "Helvetica Neue", Helvetica, Arial, sans-serif;
  37. }
  38. #carbonads {
  39. display: flex;
  40. max-width: 330px;
  41. background-color: hsl(0, 0%, 98%);
  42. box-shadow: 0 1px 4px 1px hsla(0, 0%, 0%, .1);
  43. }
  44. #carbonads a {
  45. color: inherit;
  46. text-decoration: none;
  47. }
  48. #carbonads a:hover {
  49. color: inherit;
  50. }
  51. #carbonads span {
  52. position: relative;
  53. display: block;
  54. overflow: hidden;
  55. }
  56. #carbonads .carbon-wrap {
  57. display: flex;
  58. }
  59. .carbon-img {
  60. display: block;
  61. margin: 0;
  62. line-height: 1;
  63. }
  64. .carbon-img img {
  65. display: block;
  66. }
  67. .carbon-text {
  68. font-size: 13px;
  69. padding: 10px;
  70. line-height: 1.5;
  71. text-align: left;
  72. }
  73. .carbon-poweredby {
  74. display: block;
  75. padding: 8px 10px;
  76. 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);
  77. text-align: center;
  78. text-transform: uppercase;
  79. letter-spacing: .5px;
  80. font-weight: 600;
  81. font-size: 9px;
  82. line-height: 1;
  83. }
  84. </style>
  85. <p>对于一份工程源码,可以不用编写makefile,也不用编写各种make相关的工程描述文件(例如:xmake.lua,makefile.am, cmakelist.txt等)</p>
  86. <p>xmake就可以直接编译他们,这是如何做到的呢,简单来说下实现原理:</p>
  87. <ol>
  88. <li>首先扫描当前目录下,xmake所以支持的所有源代码文件</li>
  89. <li>分析代码,检测哪些代码拥有main入口函数</li>
  90. <li>所有没有main入口的代码编译成静态库</li>
  91. <li>带有main入口的代码,编译成可执行程序,同时链接其他静态库程序</li>
  92. </ol>
  93. <p>这种代码扫描和智能编译,非常简单,目前xmake还不支持多级目录扫描,只对单级目录的代码进行扫描编译。。</p>
  94. <h3 id="">使用场景</h3>
  95. <ol>
  96. <li>临时快速编译和运行一些零散的测试代码</li>
  97. <li>尝试对其他开源库做移植编译</li>
  98. <li>快速基于现有代码创建新xmake工程</li>
  99. </ol>
  100. <h3 id="">如何使用</h3>
  101. <p>直接在带有源码的目录(没有xmake.lua)下执行xmake,然后根据提示操作:</p>
  102. <pre><code class="lang-bash">$ xmake
  103. note: xmake.lua not found, try generating it (pass -y or --confirm=y/n/d to skip confirm)?
  104. please input: n (y/n)
  105. y
  106. </code></pre>
  107. <p>另外, 当存在其他构建系统标识性文件的时候(比如 CMakeLists.txt), 不会触发自动生成 xmake.lua 的流程, 而是首先触发 <a href="#自动探测构建系统并编译">自动探测构建系统并编译</a>, 如果要强制触发自动扫描生成 xmake.lua 的流程, 可运行: </p>
  108. <pre><code class="lang-bash">$ xmake f -y
  109. </code></pre>
  110. <h3 id="">开源代码的移植和编译</h3>
  111. <p>虽然这种方式,并不是非常智能,限制也不少,但是对于想临时写些代码进行编译运行,或者临时想交叉编译一些简单的开源库代码</p>
  112. <p>这种方式已经足够使用了,下面看下一个实际的例子:</p>
  113. <p>我下载了一份zlib-1.2.10的源码,想要编译它,只需要进入zlib的源码目录执行:</p>
  114. <pre><code class="lang-bash">$ cd zlib-1.2.10
  115. $ xmake
  116. note: xmake.lua not found, try generating it (pass -y or --confirm=y/n/d to skip confirm)?
  117. please input: n (y/n)
  118. y
  119. </code></pre>
  120. <p>就行了,输入y确认后,输出结果如下:</p>
  121. <pre><code>target(zlib-1.2): static
  122. [+]: ./adler32.c
  123. [+]: ./compress.c
  124. [+]: ./crc32.c
  125. [+]: ./deflate.c
  126. [+]: ./gzclose.c
  127. [+]: ./gzlib.c
  128. [+]: ./gzread.c
  129. [+]: ./gzwrite.c
  130. [+]: ./infback.c
  131. [+]: ./inffast.c
  132. [+]: ./inflate.c
  133. [+]: ./inftrees.c
  134. [+]: ./trees.c
  135. [+]: ./uncompr.c
  136. [+]: ./zutil.c
  137. xmake.lua generated, scan ok!👌
  138. checking for the architecture ... x86_64
  139. checking for the Xcode SDK version for macosx ... 10.12
  140. checking for the target minimal version ... 10.12
  141. checking for the c compiler (cc) ... xcrun -sdk macosx clang
  142. checking for the c++ compiler (cxx) ... xcrun -sdk macosx clang
  143. checking for the objc compiler (mm) ... xcrun -sdk macosx clang
  144. checking for the objc++ compiler (mxx) ... xcrun -sdk macosx clang++
  145. checking for the swift compiler (sc) ... xcrun -sdk macosx swiftc
  146. checking for the assember (as) ... xcrun -sdk macosx clang
  147. checking for the linker (ld) ... xcrun -sdk macosx clang++
  148. checking for the static library archiver (ar) ... xcrun -sdk macosx ar
  149. checking for the static library extractor (ex) ... xcrun -sdk macosx ar
  150. checking for the shared library linker (sh) ... xcrun -sdk macosx clang++
  151. checking for the debugger (dd) ... xcrun -sdk macosx lldb
  152. checking for the golang compiler (go) ... go
  153. configure
  154. {
  155. ex = "xcrun -sdk macosx ar"
  156. , sh = "xcrun -sdk macosx clang++"
  157. , host = "macosx"
  158. , ar = "xcrun -sdk macosx ar"
  159. , buildir = "build"
  160. , as = "xcrun -sdk macosx clang"
  161. , plat = "macosx"
  162. , xcode_dir = "/Applications/Xcode.app"
  163. , arch = "x86_64"
  164. , mxx = "xcrun -sdk macosx clang++"
  165. , go = "go"
  166. , target_minver = "10.12"
  167. , ccache = "ccache"
  168. , mode = "release"
  169. , clean = true
  170. , cxx = "xcrun -sdk macosx clang"
  171. , cc = "xcrun -sdk macosx clang"
  172. , dd = "xcrun -sdk macosx lldb"
  173. , kind = "static"
  174. , ld = "xcrun -sdk macosx clang++"
  175. , xcode_sdkver = "10.12"
  176. , sc = "xcrun -sdk macosx swiftc"
  177. , mm = "xcrun -sdk macosx clang"
  178. }
  179. configure ok!
  180. clean ok!
  181. [00%]: cache compiling.release ./adler32.c
  182. [06%]: cache compiling.release ./compress.c
  183. [13%]: cache compiling.release ./crc32.c
  184. [20%]: cache compiling.release ./deflate.c
  185. [26%]: cache compiling.release ./gzclose.c
  186. [33%]: cache compiling.release ./gzlib.c
  187. [40%]: cache compiling.release ./gzread.c
  188. [46%]: cache compiling.release ./gzwrite.c
  189. [53%]: cache compiling.release ./infback.c
  190. [60%]: cache compiling.release ./inffast.c
  191. [66%]: cache compiling.release ./inflate.c
  192. [73%]: cache compiling.release ./inftrees.c
  193. [80%]: cache compiling.release ./trees.c
  194. [86%]: cache compiling.release ./uncompr.c
  195. [93%]: cache compiling.release ./zutil.c
  196. [100%]: archiving.release libzlib-1.2.a
  197. build ok!👌
  198. </code></pre><p>通过输出结果,可以看到,xmake会去检测扫描当前目录下的所有.c代码,发现没有main入口,应该是静态库程序,因此执行xmake后,就直接编译成静态库libzlib-1.2.a了</p>
  199. <p>连xmake.lua都没有编写,其实xmake在扫描完成后,会去自动在当前目录下生成一份xmake.lua,下次编译就不需要重新扫描检测了。</p>
  200. <p>自动生成的xmake.lua内容如下:</p>
  201. <pre><code class="lang-lua">-- define target
  202. target("zlib-1.2")
  203. -- set kind
  204. set_kind("static")
  205. -- add files
  206. add_files("./adler32.c")
  207. add_files("./compress.c")
  208. add_files("./crc32.c")
  209. add_files("./deflate.c")
  210. add_files("./gzclose.c")
  211. add_files("./gzlib.c")
  212. add_files("./gzread.c")
  213. add_files("./gzwrite.c")
  214. add_files("./infback.c")
  215. add_files("./inffast.c")
  216. add_files("./inflate.c")
  217. add_files("./inftrees.c")
  218. add_files("./trees.c")
  219. add_files("./uncompr.c")
  220. add_files("./zutil.c")
  221. </code></pre>
  222. <p>也许你会说,像这种开源库,直接<code>configure; make</code>不就好了吗,他们自己也有提供makefile来直接编译的,的确是这样,我这里只是举个例子而已。。</p>
  223. <p>当然,很多开源库在交叉编译的时候,通过自带的<code>configure</code>,处理起来还是很繁琐的,用xmake进行交叉编译会更方便些。。</p>
  224. <h3 id="">即时地代码编写和编译运行</h3>
  225. <p>xmake的这个扫描代码编译特性,主要的目的:还是为了让我们在临时想写些测试代码的时候,不用考虑太多东西,直接上手敲代码,然后快速执行<code>xmake run</code> 来调试验证结果。。</p>
  226. <p>例如:</p>
  227. <p>我想写了个简单的main.c的测试程序,打印<code>hello world!</code>,如果要写makefile或者直接通过gcc命令来,就很繁琐了,你需要:</p>
  228. <pre><code class="lang-bash">gcc ./main.c -o demo
  229. ./demo
  230. </code></pre>
  231. <p>最快速的方式,也需要执行两行命令,而如果用xmake,只需要执行:</p>
  232. <pre><code class="lang-bash">xmake run
  233. </code></pre>
  234. <p>就行了,它会自动检测到代码后,自动生成对应的xmake.lua,自动编译,自动运行,然后输出:</p>
  235. <pre><code>hello world!
  236. </code></pre><p>如果你有十几个代码文件,用手敲gcc的方式,或者写makefile的方式,这个差距就更明显了,用xmake还是只需要一行命令:</p>
  237. <pre><code class="lang-bash">xmake run
  238. </code></pre>
  239. <h3 id="">多语言支持</h3>
  240. <p>这种代码检测和即时编译,是支持多语言的,不仅支持c/c++,还支持objc/swift,后期还会支持golang(正在开发中)</p>
  241. <p>例如我下载了一份fmdb的ios开源框架代码:</p>
  242. <pre><code>.
  243. ├── FMDB.h
  244. ├── FMDatabase.h
  245. ├── FMDatabase.m
  246. ├── FMDatabaseAdditions.h
  247. ├── FMDatabaseAdditions.m
  248. ├── FMDatabasePool.h
  249. ├── FMDatabasePool.m
  250. ├── FMDatabaseQueue.h
  251. ├── FMDatabaseQueue.m
  252. ├── FMResultSet.h
  253. └── FMResultSet.m
  254. </code></pre><p>想要把它编译成ios的静态库,但是又不想写xmake.lua,或者makefile,那么只需要使用xmake的这个新特性,直接执行:</p>
  255. <pre><code class="lang-bash">$ xmake f -p iphoneos; xmake
  256. </code></pre>
  257. <p>就行了,输出结果如下:</p>
  258. <pre><code>xmake.lua not found, scanning files ..
  259. target(FMDB): static
  260. [+]: ./FMDatabase.m
  261. [+]: ./FMDatabaseAdditions.m
  262. [+]: ./FMDatabasePool.m
  263. [+]: ./FMDatabaseQueue.m
  264. [+]: ./FMResultSet.m
  265. xmake.lua generated, scan ok!👌
  266. checking for the architecture ... armv7
  267. checking for the Xcode SDK version for iphoneos ... 10.1
  268. checking for the target minimal version ... 10.1
  269. checking for the c compiler (cc) ... xcrun -sdk iphoneos clang
  270. checking for the c++ compiler (cxx) ... xcrun -sdk iphoneos clang
  271. checking for the objc compiler (mm) ... xcrun -sdk iphoneos clang
  272. checking for the objc++ compiler (mxx) ... xcrun -sdk iphoneos clang++
  273. checking for the assember (as) ... gas-preprocessor.pl xcrun -sdk iphoneos clang
  274. checking for the linker (ld) ... xcrun -sdk iphoneos clang++
  275. checking for the static library archiver (ar) ... xcrun -sdk iphoneos ar
  276. checking for the static library extractor (ex) ... xcrun -sdk iphoneos ar
  277. checking for the shared library linker (sh) ... xcrun -sdk iphoneos clang++
  278. checking for the swift compiler (sc) ... xcrun -sdk iphoneos swiftc
  279. configure
  280. {
  281. ex = "xcrun -sdk iphoneos ar"
  282. , ccache = "ccache"
  283. , host = "macosx"
  284. , ar = "xcrun -sdk iphoneos ar"
  285. , buildir = "build"
  286. , as = "/usr/local/share/xmake/tools/utils/gas-preprocessor.pl xcrun -sdk iphoneos clang"
  287. , arch = "armv7"
  288. , mxx = "xcrun -sdk iphoneos clang++"
  289. , cxx = "xcrun -sdk iphoneos clang"
  290. , target_minver = "10.1"
  291. , xcode_dir = "/Applications/Xcode.app"
  292. , clean = true
  293. , sh = "xcrun -sdk iphoneos clang++"
  294. , cc = "xcrun -sdk iphoneos clang"
  295. , ld = "xcrun -sdk iphoneos clang++"
  296. , mode = "release"
  297. , kind = "static"
  298. , plat = "iphoneos"
  299. , xcode_sdkver = "10.1"
  300. , sc = "xcrun -sdk iphoneos swiftc"
  301. , mm = "xcrun -sdk iphoneos clang"
  302. }
  303. configure ok!
  304. clean ok!
  305. [00%]: cache compiling.release ./FMDatabase.m
  306. [20%]: cache compiling.release ./FMDatabaseAdditions.m
  307. [40%]: cache compiling.release ./FMDatabasePool.m
  308. [60%]: cache compiling.release ./FMDatabaseQueue.m
  309. [80%]: cache compiling.release ./FMResultSet.m
  310. [100%]: archiving.release libFMDB.a
  311. build ok!👌
  312. </code></pre><h3 id="">同时编译多个可执行文件</h3>
  313. <p>输出结果的开头部分,就是对代码的分析结果,虽然目前只支持单级目录结构的代码扫描,但是还是可以同时支持检测和编译多个可执行文件的</p>
  314. <p>我们以libjpeg的开源库为例:</p>
  315. <p>我们进入jpeg-6b目录后,执行:</p>
  316. <pre><code class="lang-bash">$ xmake
  317. </code></pre>
  318. <p>输出如下:</p>
  319. <pre><code>xmake.lua not found, scanning files ..
  320. target(jpeg-6b): static
  321. [+]: ./cdjpeg.c
  322. [+]: ./example.c
  323. [+]: ./jcapimin.c
  324. [+]: ./jcapistd.c
  325. [+]: ./jccoefct.c
  326. [+]: ./jccolor.c
  327. [+]: ./jcdctmgr.c
  328. [+]: ./jchuff.c
  329. [+]: ./jcinit.c
  330. [+]: ./jcmainct.c
  331. [+]: ./jcmarker.c
  332. [+]: ./jcmaster.c
  333. [+]: ./jcomapi.c
  334. [+]: ./jcparam.c
  335. [+]: ./jcphuff.c
  336. [+]: ./jcprepct.c
  337. [+]: ./jcsample.c
  338. [+]: ./jctrans.c
  339. [+]: ./jdapimin.c
  340. [+]: ./jdapistd.c
  341. [+]: ./jdatadst.c
  342. [+]: ./jdatasrc.c
  343. [+]: ./jdcoefct.c
  344. [+]: ./jdcolor.c
  345. [+]: ./jddctmgr.c
  346. [+]: ./jdhuff.c
  347. [+]: ./jdinput.c
  348. [+]: ./jdmainct.c
  349. [+]: ./jdmarker.c
  350. [+]: ./jdmaster.c
  351. [+]: ./jdmerge.c
  352. [+]: ./jdphuff.c
  353. [+]: ./jdpostct.c
  354. [+]: ./jdsample.c
  355. [+]: ./jdtrans.c
  356. [+]: ./jerror.c
  357. [+]: ./jfdctflt.c
  358. [+]: ./jfdctfst.c
  359. [+]: ./jfdctint.c
  360. [+]: ./jidctflt.c
  361. [+]: ./jidctfst.c
  362. [+]: ./jidctint.c
  363. [+]: ./jidctred.c
  364. [+]: ./jmemansi.c
  365. [+]: ./jmemmgr.c
  366. [+]: ./jmemname.c
  367. [+]: ./jmemnobs.c
  368. [+]: ./jquant1.c
  369. [+]: ./jquant2.c
  370. [+]: ./jutils.c
  371. [+]: ./rdbmp.c
  372. [+]: ./rdcolmap.c
  373. [+]: ./rdgif.c
  374. [+]: ./rdppm.c
  375. [+]: ./rdrle.c
  376. [+]: ./rdswitch.c
  377. [+]: ./rdtarga.c
  378. [+]: ./transupp.c
  379. [+]: ./wrbmp.c
  380. [+]: ./wrgif.c
  381. [+]: ./wrppm.c
  382. [+]: ./wrrle.c
  383. [+]: ./wrtarga.c
  384. target(ansi2knr): binary
  385. [+]: ./ansi2knr.c
  386. target(cjpeg): binary
  387. [+]: ./cjpeg.c
  388. target(ckconfig): binary
  389. [+]: ./ckconfig.c
  390. target(djpeg): binary
  391. [+]: ./djpeg.c
  392. target(jpegtran): binary
  393. [+]: ./jpegtran.c
  394. target(rdjpgcom): binary
  395. [+]: ./rdjpgcom.c
  396. target(wrjpgcom): binary
  397. [+]: ./wrjpgcom.c
  398. xmake.lua generated, scan ok!👌
  399. checking for the architecture ... x86_64
  400. checking for the Xcode SDK version for macosx ... 10.12
  401. checking for the target minimal version ... 10.12
  402. checking for the c compiler (cc) ... xcrun -sdk macosx clang
  403. checking for the c++ compiler (cxx) ... xcrun -sdk macosx clang
  404. checking for the objc compiler (mm) ... xcrun -sdk macosx clang
  405. checking for the objc++ compiler (mxx) ... xcrun -sdk macosx clang++
  406. checking for the swift compiler (sc) ... xcrun -sdk macosx swiftc
  407. checking for the assember (as) ... xcrun -sdk macosx clang
  408. checking for the linker (ld) ... xcrun -sdk macosx clang++
  409. checking for the static library archiver (ar) ... xcrun -sdk macosx ar
  410. checking for the static library extractor (ex) ... xcrun -sdk macosx ar
  411. checking for the shared library linker (sh) ... xcrun -sdk macosx clang++
  412. checking for the debugger (dd) ... xcrun -sdk macosx lldb
  413. checking for the golang compiler (go) ... go
  414. configure
  415. {
  416. ex = "xcrun -sdk macosx ar"
  417. , sh = "xcrun -sdk macosx clang++"
  418. , host = "macosx"
  419. , ar = "xcrun -sdk macosx ar"
  420. , buildir = "build"
  421. , as = "xcrun -sdk macosx clang"
  422. , plat = "macosx"
  423. , xcode_dir = "/Applications/Xcode.app"
  424. , arch = "x86_64"
  425. , mxx = "xcrun -sdk macosx clang++"
  426. , go = "go"
  427. , target_minver = "10.12"
  428. , ccache = "ccache"
  429. , mode = "release"
  430. , clean = true
  431. , cxx = "xcrun -sdk macosx clang"
  432. , cc = "xcrun -sdk macosx clang"
  433. , dd = "xcrun -sdk macosx lldb"
  434. , kind = "static"
  435. , ld = "xcrun -sdk macosx clang++"
  436. , xcode_sdkver = "10.12"
  437. , sc = "xcrun -sdk macosx swiftc"
  438. , mm = "xcrun -sdk macosx clang"
  439. }
  440. configure ok!
  441. clean ok!
  442. [00%]: cache compiling.release ./cdjpeg.c
  443. [00%]: cache compiling.release ./example.c
  444. [00%]: cache compiling.release ./jcapimin.c
  445. [00%]: cache compiling.release ./jcapistd.c
  446. [00%]: cache compiling.release ./jccoefct.c
  447. [00%]: cache compiling.release ./jccolor.c
  448. [01%]: cache compiling.release ./jcdctmgr.c
  449. [01%]: cache compiling.release ./jchuff.c
  450. [01%]: cache compiling.release ./jcinit.c
  451. [01%]: cache compiling.release ./jcmainct.c
  452. [01%]: cache compiling.release ./jcmarker.c
  453. [02%]: cache compiling.release ./jcmaster.c
  454. [02%]: cache compiling.release ./jcomapi.c
  455. [02%]: cache compiling.release ./jcparam.c
  456. [02%]: cache compiling.release ./jcphuff.c
  457. [02%]: cache compiling.release ./jcprepct.c
  458. [03%]: cache compiling.release ./jcsample.c
  459. [03%]: cache compiling.release ./jctrans.c
  460. [03%]: cache compiling.release ./jdapimin.c
  461. [03%]: cache compiling.release ./jdapistd.c
  462. [03%]: cache compiling.release ./jdatadst.c
  463. [04%]: cache compiling.release ./jdatasrc.c
  464. [04%]: cache compiling.release ./jdcoefct.c
  465. [04%]: cache compiling.release ./jdcolor.c
  466. [04%]: cache compiling.release ./jddctmgr.c
  467. [04%]: cache compiling.release ./jdhuff.c
  468. [05%]: cache compiling.release ./jdinput.c
  469. [05%]: cache compiling.release ./jdmainct.c
  470. [05%]: cache compiling.release ./jdmarker.c
  471. [05%]: cache compiling.release ./jdmaster.c
  472. [05%]: cache compiling.release ./jdmerge.c
  473. [06%]: cache compiling.release ./jdphuff.c
  474. [06%]: cache compiling.release ./jdpostct.c
  475. [06%]: cache compiling.release ./jdsample.c
  476. [06%]: cache compiling.release ./jdtrans.c
  477. [06%]: cache compiling.release ./jerror.c
  478. [07%]: cache compiling.release ./jfdctflt.c
  479. [07%]: cache compiling.release ./jfdctfst.c
  480. [07%]: cache compiling.release ./jfdctint.c
  481. [07%]: cache compiling.release ./jidctflt.c
  482. [07%]: cache compiling.release ./jidctfst.c
  483. [08%]: cache compiling.release ./jidctint.c
  484. [08%]: cache compiling.release ./jidctred.c
  485. [08%]: cache compiling.release ./jmemansi.c
  486. [08%]: cache compiling.release ./jmemmgr.c
  487. [08%]: cache compiling.release ./jmemname.c
  488. [09%]: cache compiling.release ./jmemnobs.c
  489. [09%]: cache compiling.release ./jquant1.c
  490. [09%]: cache compiling.release ./jquant2.c
  491. [09%]: cache compiling.release ./jutils.c
  492. [09%]: cache compiling.release ./rdbmp.c
  493. [10%]: cache compiling.release ./rdcolmap.c
  494. [10%]: cache compiling.release ./rdgif.c
  495. [10%]: cache compiling.release ./rdppm.c
  496. [10%]: cache compiling.release ./rdrle.c
  497. [10%]: cache compiling.release ./rdswitch.c
  498. [11%]: cache compiling.release ./rdtarga.c
  499. [11%]: cache compiling.release ./transupp.c
  500. [11%]: cache compiling.release ./wrbmp.c
  501. [11%]: cache compiling.release ./wrgif.c
  502. [11%]: cache compiling.release ./wrppm.c
  503. [12%]: cache compiling.release ./wrrle.c
  504. [12%]: cache compiling.release ./wrtarga.c
  505. [12%]: archiving.release libjpeg-6b.a
  506. [12%]: cache compiling.release ./wrjpgcom.c
  507. [25%]: linking.release wrjpgcom
  508. [25%]: cache compiling.release ./ansi2knr.c
  509. [37%]: linking.release ansi2knr
  510. [37%]: cache compiling.release ./jpegtran.c
  511. [50%]: linking.release jpegtran
  512. [50%]: cache compiling.release ./djpeg.c
  513. [62%]: linking.release djpeg
  514. [62%]: cache compiling.release ./ckconfig.c
  515. [75%]: linking.release ckconfig
  516. [75%]: cache compiling.release ./rdjpgcom.c
  517. [87%]: linking.release rdjpgcom
  518. [87%]: cache compiling.release ./cjpeg.c
  519. [100%]: linking.release cjpeg
  520. build ok!👌
  521. </code></pre><p>可以看到,处理静态库,xmake还分析出了很多可执行的测试程序,剩下的代码统一编译成一个 libjpeg.a 的静态库,供哪些测试程序链接使用。。</p>
  522. <pre><code>target(ansi2knr): binary
  523. [+]: ./ansi2knr.c
  524. target(cjpeg): binary
  525. [+]: ./cjpeg.c
  526. target(ckconfig): binary
  527. [+]: ./ckconfig.c
  528. target(djpeg): binary
  529. [+]: ./djpeg.c
  530. target(jpegtran): binary
  531. [+]: ./jpegtran.c
  532. target(rdjpgcom): binary
  533. [+]: ./rdjpgcom.c
  534. target(wrjpgcom): binary
  535. [+]: ./wrjpgcom.c
  536. </code></pre><h3 id="">遇到的一些问题和限制</h3>
  537. <p>当前xmake的这种自动分析检测还不是非常智能,对于:</p>
  538. <ol>
  539. <li>需要特殊的编译选项</li>
  540. <li>需要依赖其他目录的头文件搜索</li>
  541. <li>需要分条件编译不同源文件</li>
  542. <li>同目录需要生成多个静态库</li>
  543. <li>需要多级目录支持的源码库</li>
  544. </ol>
  545. <p>以上这些情况,xmake暂时还没发自动化的智能处理,其中限制1,2还是可以解决的,通过半手动的方式,例如:</p>
  546. <pre><code class="lang-bash">$ xmake f --cxflags="" --ldflags="" --includedirs="" --linkdirs=""; xmake
  547. </code></pre>
  548. <p>在自动检测编译的时候,手动配置这个源码工程需要的特殊编译选项,就可以直接通过编译了</p>
  549. <p>而限制3,暂时只能通过删源代码来解决了,就像刚才编译jpeg的代码,其实它的目录下面同时存在了:</p>
  550. <pre><code>jmemdos.c
  551. jmemmac.c
  552. jmemansi.c
  553. </code></pre><p>其中两个是没法编译过的,需要删掉后才行。。</p>
  554. </article>
  555. </body>
  556. </html>