日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用bakefile编译C工程代码

發(fā)布時間:2023/12/31 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用bakefile编译C工程代码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

一、前言

最近有個想法,想把 ineedle 整體架構(gòu)從頭自己編寫代碼來實現(xiàn)一下,來加深對iNeedle系統(tǒng)的理解,同時加強(qiáng)Linux + C相關(guān)知識。由于iNeedle系統(tǒng)的龐大,只能是先把框架搭起來,根據(jù)某些功能再往里邊添加?xùn)|西。首先遇到的問題就是每寫一部分代碼都要進(jìn)行調(diào)試,既不想使用gcc獨立的命令來進(jìn)行調(diào)試,這樣代碼多了或路徑復(fù)雜就難以控制;又不想使用iNeedle原版的編譯文件,于是自己按照舊版本抽取出需要編譯iNeedle系統(tǒng)的腳本代碼來。這個腳本用來編譯iNeedle項目,主要是利用了bakefile工具。bakefile是一個跨平臺的自動生成makefile的開源工具,需要在項目中的每個子目錄中指定***.bkl配置文件(該配置文件指定需要編譯哪些文件,指定頭文件等),bakefile利用每個子目錄中bkl文件來生成相應(yīng)的makefile文件;然后在主目錄(編譯文件所在目錄)中生成主makefile文件,由主makefile直接進(jìn)行系統(tǒng)編譯,生成可執(zhí)行程序。

1、如果CentOS系統(tǒng)安裝:

yum install bakefile -y

2、如果debian或ubuntu系統(tǒng):
需要源碼安裝,可以到官網(wǎng)下載bakefile-0.2.9.tar.gz版本的即可:

tar -zxvf bakefile-0.2.9.tar.gz; cd bakefile-0.2.9; ./configure; make; make install

二、bakefile使用

bakefile -f gnu "$folder.bkl" -o "$folder.mk" >/dev/null 2>&1

單獨使用使用make命令進(jìn)行編譯:

make -f ineedle.mk install

三、bkl文件參考

1 <?xml version="1.0"?>2 <makefile>3 <template id="posT">4 <include>../include/pcap</include>5 <include>../include/</include>6 <include>./</include>7 <sources>pos/pos_lib.c</sources>8 <sources>pos/pos_var.c</sources>9 <sources>pos/db_var.c</sources> 10 <sources>pos/pos_db.c</sources> 11 <sources>pos/hk.c</sources> 12 <sources>pos/hashfunctions.c</sources> 13 <sources>pos/md5.c</sources> 14 <sources>pos/ios_time.c</sources> 15 <sources>pos/pos_ut.c</sources> 16 <sources>pos/ios_sparse.c</sources> 17 <sources>pos/pos_lock.c</sources> 18 <sources>pos/iweb_api.c</sources> 19 <sources>pos/db_clean.c</sources> 20 <sources>pos/pos_mem.c</sources> 21 </template> 22 <exe id="pos_obj" template="posT"></exe> 23 </makefile>

四、iNeedle系統(tǒng)編譯腳本

#!/bin/bash # # 這個編譯文件是從老版本compile.dat中提取出來單獨編譯ineedle的,目的是用來調(diào)試ineedle使用的。 # project_name="ineedle" project_modl="root shell pos cfg ilog session sha timer traf filter istat lex monitor cron http report diskdb dll alarm snmp persist system" project_shuc="nd" project_targ="ineedle" project_cmpa="-L../lib/linux -lpcap -lmysqlclient -lhasp_linux_96828 -rdynamic -ldl -lnetsnmp" project_macr="DBG DBG2 INEEDLE_ROOT NCURSES _INEEDLE_AMON _INEEDLE_USTAT _INEEDLE_URL _INEEDLE_CIP _INEEDLE_WEBDELAY _INEEDLE_AMON_ABN _INEEDLE_ALARM _INEEDLE_ELOG _INEEDLE_POST _FILE_OFFSET_BITS=64 _LARGEFILE_SOURCE _LARGEFILE64_SOURCE "compileFlag="debug" splitter="------------------------------------------------------" SECFLAG=`expr 0`function show_copyright() {tput cleartput smsoecho $splitterecho " iNeedle Compiler &copyright dztec.cn "echo $splitterechotput rmso }function loopmodules() {modules=$project_modlecho $spiltterecho "generating module files......"echo $spiltterfor folder in $modules;do#echo $folderfolder=`expr $folder | tr -d ' '`filepath="$folder/$folder.bkl"#echo $filepathif [ ! -r "$filepath" ];thenecho -n -e "file: '$filepath' doesnot exit!"tput blinkecho -e "\tPlz check the file"tput sgr0SECFLAG=`expr 1`continueficd "$folder"folderlen=`expr length $folder`if [ $folderlen -lt 3 ];thenecho -n -e "generating $folder.mk ...... \t\t\t\t"elseecho -n -e "generating $folder.mk ...... \t\t\t"fiif ! bakefile -f gnu "$folder.bkl" -o "$folder.mk" >/dev/null 2>&1 ;thentput smsotput smulecho "[FAILED]"cd "../"tput rmsotput sgr0SECFLAG=`expr 1`continuefitput blinktput smulecho "[OK]"tput sgr0cd "../"done }function genemake() {target=ineedlecompileMacro=$project_macrtargetMakeFile="ineedle.mk"modules=$project_modlcompile_arg=$project_cmpaif [ $compileFlag == "debug" ];thenCFLAGS="CFLAGS=-g"release="-g"for flg in $compileMacrodoCFLAGS="$CFLAGS -D$flg"donefirm $targetMakeFile >/dev/null 2>&1echo "TARGET = $target" >> $targetMakeFileecho "$CFLAGS" >> $targetMakeFileHEAD=""for folder in $modulesdoFOLD=`expr $folder | tr a-z A-Z`HEAD="$HEAD \$("$FOLD"_OBJ_OBJECTS)"echo "include $folder/$folder.mk" >> $targetMakeFiledoneecho >> $targetMakeFileecho "install:$target">>$targetMakeFileecho >> $targetMakeFileecho "$target:$HEAD">>$targetMakeFileecho -e -n "\t\$(CC)$HEAD $release -o $target $compile_arg" >>$targetMakeFile}function parseerror() {echo $splitterwarnings=`cat .temp | grep -E "warning" | wc -l`tput smsoecho -n "WARNINGS: "tput rmsoecho $warningstput smsoecho -n "ERRORS: "echo "--"tput rmsoechocat .temp | grep -E -i "cannot|multiple|undefined|Error|Stop" | sed 's/.*\/\(.*\/.*\)/\1/'echo $splitter }function move_compile_files() {target="ineedle"mv *.o ../obj >/dev/null 2>&1mv *.d ../obj >/dev/null 2>&1mv ./$target ../release/ >/dev/null 2>&1chmod u+s ../release/$targetchmod g+s ../release/$target }function compile() {target=ineedletargetMakeFile=ineedle.mkif make -f $targetMakeFile install >.temp 2>&1 ;thenecho $splittertput smsoecho "Compiled successfully!"tput rmsoecho $splitterechoelseparseerrortput smsoecho "Compiling failed!"tput rmsoecho $spiltterficat .temp | grep -V ".mk\|gcc -c -o" >.warning }function run() {pnn="ineedle"tput smsoecho $splittertput rmsotput smsoecho "compiling $pnn......"tput rmsotput smsoecho $splittertput rmsoloopmodulesif [ $SECFLAG == 1 ]; thenecho $splittertput smsoecho "error happened"tput rmsoecho $splitterexitfigenemakecompilemove_compile_files }function load_header_file() {if [ -r "./ineedle-linux.h" ];thencp ineedle-linux.h ineedle.hfi }load_header_file show_copyright run

總結(jié)

以上是生活随笔為你收集整理的使用bakefile编译C工程代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。