1 問題來源
本問題來源于RT-Thread的技術(shù)論壇的一個常見問題,當(dāng)時我回答了這個問題,很榮幸拿了一個最佳答案,為了能夠再次消化并進(jìn)行知識點沉淀,我把這個問題再次拋到這里。 原問題,請戳這里:scons 命令buildlib使用方法
2 實踐分析
2.1 不懂就要問
既然不知道怎么用scons,那么我們先看到它的幫助信息,以下命令在scons的主目錄執(zhí)行,即可以找到Sconscript的目錄下執(zhí)行:
-
rt-thread/bsp/qemu-vexpress-a9$ scons -h
-
scons: Reading SConscript files ...
-
drivers/SConscript
-
applications/SConscript
-
[, , ]
-
scons: done reading SConscript files.
-
usage: scons [OPTION] [TARGET] ...
-
SCons Options:
-
-b, -d, -e, -m, -S, -t, -w, --environment-overrides, --no-keep-going,
-
--no-print-directory, --print-directory, --stop, --touch
-
Ignored for compatibility.
-
-c, --clean, --remove Remove specified targets and dependencies.
-
-C DIR, --directory=DIR Change to DIR before doing anything.
-
--cache-debug=FILE Print CacheDir debug info to FILE.
-
--cache-disable, --no-cache
-
Do not retrieve built targets from CacheDir.
-
--cache-force, --cache-populate
-
Copy already-built targets into the CacheDir.
-
--cache-readonly Do not update CacheDir with built targets.
-
--cache-show Print build actions for files from CacheDir.
-
--config=MODE Controls Configure subsystem: auto, force,
-
cache.
-
-D Search up directory tree for SConstruct,
-
build all Default() targets.
-
--debug=TYPE Print various types of debugging information:
-
count, duplicate, explain, findlibs, includes,
-
memoizer, memory, objects, pdb, prepare,
-
presub, stacktrace, time, action-timestamps.
-
--diskcheck=TYPE Enable specific on-disk checks.
-
--duplicate=DUPLICATE Set the preferred duplication methods. Must be
-
one of hard-soft-copy, soft-hard-copy,
-
hard-copy, soft-copy, copy
-
--enable-virtualenv Import certain virtualenv variables to SCons
-
-f FILE, --file=FILE, --makefile=FILE, --sconstruct=FILE
-
Read FILE as the top-level SConstruct file.
-
-h, --help Print defined help message, or this one.
-
-H, --help-options Print this message and exit.
-
-i, --ignore-errors Ignore errors from build actions.
-
-I DIR, --include-dir=DIR Search DIR for imported Python modules.
-
--ignore-virtualenv Do not import virtualenv variables to SCons
-
--implicit-cache Cache implicit dependencies
-
--implicit-deps-changed Ignore cached implicit dependencies.
-
--implicit-deps-unchanged Ignore changes in implicit dependencies.
-
--interact, --interactive Run in interactive mode.
-
-j N, --jobs=N Allow N jobs at once.
-
-k, --keep-going Keep going when a target can't be made.
-
--max-drift=N Set maximum system clock drift to N seconds.
-
--md5-chunksize=N Set chunk-size for MD5 signature computation to
-
N kilobytes.
-
-n, --no-exec, --just-print, --dry-run, --recon
-
Don't build; just print commands.
-
--no-site-dir Don't search or use the usual site_scons dir.
-
--profile=FILE Profile SCons and put results in FILE.
-
-q, --question Don't build; exit status says if up to date.
-
-Q Suppress "Reading/Building" progress messages.
-
--random Build dependencies in random order.
-
-s, --silent, --quiet Don't print commands.
-
--site-dir=DIR Use DIR instead of the usual site_scons dir.
-
--stack-size=N Set the stack size of the threads used to run
-
jobs to N kilobytes.
-
--taskmastertrace=FILE Trace Node evaluation to FILE.
-
--tree=OPTIONS Print a dependency tree in various formats: all,
-
derived, prune, status, linedraw.
-
-u, --up, --search-up Search up directory tree for SConstruct,
-
build targets at or below current directory.
-
-U Search up directory tree for SConstruct,
-
build Default() targets from local SConscript.
-
-v, --version Print the SCons version number and exit.
-
--warn=WARNING-SPEC, --warning=WARNING-SPEC
-
Enable or disable warnings.
-
-Y REPOSITORY, --repository=REPOSITORY, --srcdir=REPOSITORY
-
Search REPOSITORY for source and target files.
-
Local Options:
-
--dist make distribution
-
--dist-strip make distribution and strip useless files
-
--dist-ide make distribution for RT-Thread Studio IDE
-
--project-path=PROJECT-PATH
-
set dist-ide project output path
-
--project-name=PROJECT-NAME
-
set project name
-
--reset-project-config reset the project configurations to default
-
--cscope Build Cscope cross reference database. Requires
-
cscope installed.
-
--clang-analyzer Perform static analyze with Clang-analyzer.
-
Requires Clang installed. It is recommended to
-
use with scan-build like this: `scan-build
-
scons --clang-analyzer` If things goes well,
-
scan-build will instruct you to invoke
-
scan-view.
-
--buildlib=BUILDLIB building library of a component
-
--cleanlib clean up the library by --buildlib
-
--target=TARGET set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/
-
cdk/ses/makefile/eclipse/codelite/cmake
-
--stackanalysis thread stack static analysis
-
--genconfig Generate .config from rtconfig.h
-
--useconfig=USECONFIG make rtconfig.h from config file.
-
--verbose print verbose information during build
-
--menuconfig make menuconfig for RT-Thread BSP
-
--pyconfig Python GUI menuconfig for RT-Thread BSP
-
--pyconfig-silent Don`t show pyconfig window
精準(zhǔn)匹配下:
-
rt-thread/bsp/qemu-vexpress-a9$ scons -h | grep buildlib
-
--buildlib=BUILDLIB building library of a component
-
--cleanlib clean up the library by --buildlib
2.2 實踐出整理
從上面的幫助信息,我們已經(jīng)找到關(guān)鍵信息了,我們來實踐下:
-
rt-thread/bsp/qemu-vexpress-a9$ scons --buildlib=BUILDLIB
-
scons: Reading SConscript files ...
-
b''
-
drivers/SConscript
-
applications/SConscript
-
[, , ]
-
scons: done reading SConscript files.
-
scons: Building targets ...
-
scons: building associated VariantDir targets: build
-
scons: `.' is up to date.
-
scons: done building targets.
發(fā)現(xiàn)并沒有生成,仔細(xì)一看,這個buildlib=
后面跟的名稱不是亂填的,是需要填寫你當(dāng)前目錄下,已經(jīng)使用scons語法配置好的組件,這個東西在scons里面是叫Group。 通俗來說,就是使用buildlib
,一個Gourp就可以生成一個庫。 我們再來實踐下,以bsp/qemu-vexpress-a9的Application
這個Group為例,在其applications目錄有定義Sconsript:
那么就可以輸入scons--buildlib=Applications
就可以將Applications那個group定義的C文件編譯打包成一個靜態(tài)庫,輸出也是位于bsp的目錄中。
3 經(jīng)驗總結(jié)
- 任何命令行指令,千萬不要放過它的help信息
-
scons 使用
--buildlib=xxx
輕松生存庫文件,庫名稱為libxxx.a
4 更多分享
架構(gòu)師李肯
一個專注于嵌入式IoT領(lǐng)域的架構(gòu)師。有著近10年的嵌入式一線開發(fā)經(jīng)驗,深耕IoT領(lǐng)域多年,熟知IoT領(lǐng)域的業(yè)務(wù)發(fā)展,深度掌握IoT領(lǐng)域的相關(guān)技術(shù)棧,包括但不限于主流RTOS內(nèi)核的實現(xiàn)及其移植、硬件驅(qū)動移植開發(fā)、網(wǎng)絡(luò)通訊協(xié)議開發(fā)、編譯構(gòu)建原理及其實現(xiàn)、底層匯編及編譯原理、編譯優(yōu)化及代碼重構(gòu)、主流IoT云平臺的對接、嵌入式IoT系統(tǒng)的架構(gòu)設(shè)計等等。擁有多項IoT領(lǐng)域的發(fā)明專利,熱衷于技術(shù)分享,有多年撰寫技術(shù)博客的經(jīng)驗積累,連續(xù)多月獲得RT-Thread官方技術(shù)社區(qū)原創(chuàng)技術(shù)博文優(yōu)秀獎,榮獲CSDN博客專家、CSDN物聯(lián)網(wǎng)領(lǐng)域優(yōu)質(zhì)創(chuàng)作者、2021年度CSDN&RT-Thread技術(shù)社區(qū)之星、RT-Thread官方嵌入式開源社區(qū)認(rèn)證專家、RT-Thread 2021年度論壇之星TOP4、華為云云享專家(嵌入式物聯(lián)網(wǎng)架構(gòu)設(shè)計師)等榮譽(yù)。堅信【知識改變命運(yùn),技術(shù)改變世界】!
歡迎關(guān)注我的github倉庫01workstation,日常分享一些開發(fā)筆記和項目實戰(zhàn),歡迎指正問題。
同時也非常歡迎關(guān)注我的專欄:有問題的話,可以跟我討論,知無不答,謝謝大家。
-
靜態(tài)庫
+關(guān)注
關(guān)注
0文章
21瀏覽量
7439 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1289瀏覽量
40136 -
scons
+關(guān)注
關(guān)注
0文章
1瀏覽量
955
發(fā)布評論請先 登錄
相關(guān)推薦
評論