一、前言

最近有个想法,想把 ineedle 整体架构从头自己编写代码来实现一下,来加深对iNeedle系统的理解,同时加强Linux + C相关知识。由于iNeedle系统的庞大,只能是先把框架搭起来,根据某些功能再往里边添加东西。首先遇到的问题就是每写一部分代码都要进行调试,既不想使用gcc独立的命令来进行调试,这样代码多了或路径复杂就难以控制;又不想使用iNeedle原版的编译文件,于是自己按照旧版本抽取出需要编译iNeedle系统的脚本代码来。这个脚本用来编译iNeedle项目,主要是利用了bakefile工具。bakefile是一个跨平台的自动生成makefile的开源工具,需要在项目中的每个子目录中指定***.bkl配置文件(该配置文件指定需要编译哪些文件,指定头文件等),bakefile利用每个子目录中bkl文件来生成相应的makefile文件;然后在主目录(编译文件所在目录)中生成主makefile文件,由主makefile直接进行系统编译,生成可执行程序。

1、如果CentOS系统安装:

yum install bakefile -y

2、如果debian或ubuntu系统:
需要源码安装,可以到官网下载bakefile-0.2.9.tar.gz版本的即可:

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

二、bakefile使用

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

单独使用使用make命令进行编译:

make -f ineedle.mk install

三、bkl文件参考

 <?xml version="1.0"?>
<makefile>
<template id="posT">
<include>../include/pcap</include>
<include>../include/</include>
<include>./</include>
<sources>pos/pos_lib.c</sources>
<sources>pos/pos_var.c</sources>
<sources>pos/db_var.c</sources>
<sources>pos/pos_db.c</sources>
<sources>pos/hk.c</sources>
<sources>pos/hashfunctions.c</sources>
<sources>pos/md5.c</sources>
<sources>pos/ios_time.c</sources>
<sources>pos/pos_ut.c</sources>
<sources>pos/ios_sparse.c</sources>
<sources>pos/pos_lock.c</sources>
<sources>pos/iweb_api.c</sources>
<sources>pos/db_clean.c</sources>
<sources>pos/pos_mem.c</sources>
</template>
<exe id="pos_obj" template="posT"></exe>
</makefile>

四、iNeedle系统编译脚本

#!/bin/bash
#
# 这个编译文件是从老版本compile.dat中提取出来单独编译ineedle的,目的是用来调试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 ` function show_copyright()
{
tput clear
tput smso
echo $splitter
echo " iNeedle Compiler &copyright dztec.cn "
echo $splitter
echo
tput rmso
} function loopmodules()
{
modules=$project_modl
echo $spiltter
echo "generating module files......"
echo $spiltter for folder in $modules;do
#echo $folder
folder=`expr $folder | tr -d ' '`
filepath="$folder/$folder.bkl"
#echo $filepath
if [ ! -r "$filepath" ];then
echo -n -e "file: '$filepath' doesnot exit!"
tput blink
echo -e "\tPlz check the file"
tput sgr0
SECFLAG=`expr `
continue
fi cd "$folder"
folderlen=`expr length $folder`
if [ $folderlen -lt ];then
echo -n -e "generating $folder.mk ...... \t\t\t\t"
else
echo -n -e "generating $folder.mk ...... \t\t\t"
fi if ! bakefile -f gnu "$folder.bkl" -o "$folder.mk" >/dev/null >& ;then
tput smso
tput smul
echo "[FAILED]"
cd "../"
tput rmso
tput sgr0
SECFLAG=`expr `
continue
fi
tput blink
tput smul
echo "[OK]"
tput sgr0
cd "../"
done
} function genemake()
{
target=ineedle
compileMacro=$project_macr
targetMakeFile="ineedle.mk"
modules=$project_modl
compile_arg=$project_cmpa
if [ $compileFlag == "debug" ];then
CFLAGS="CFLAGS=-g"
release="-g"
for flg in $compileMacro
do
CFLAGS="$CFLAGS -D$flg"
done
fi
rm $targetMakeFile >/dev/null >&
echo "TARGET = $target" >> $targetMakeFile
echo "$CFLAGS" >> $targetMakeFile
HEAD="" for folder in $modules
do
FOLD=`expr $folder | tr a-z A-Z`
HEAD="$HEAD \$("$FOLD"_OBJ_OBJECTS)"
echo "include $folder/$folder.mk" >> $targetMakeFile
done echo >> $targetMakeFile
echo "install:$target">>$targetMakeFile
echo >> $targetMakeFile
echo "$target:$HEAD">>$targetMakeFile
echo -e -n "\t\$(CC)$HEAD $release -o $target $compile_arg" >>$targetMakeFile } function parseerror()
{
echo $splitter
warnings=`cat .temp | grep -E "warning" | wc -l`
tput smso
echo -n "WARNINGS: "
tput rmso
echo $warnings
tput smso
echo -n "ERRORS: "
echo "--"
tput rmso
echo
cat .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 >&
mv *.d ../obj >/dev/null >&
mv ./$target ../release/ >/dev/null >&
chmod u+s ../release/$target
chmod g+s ../release/$target
} function compile()
{
target=ineedle
targetMakeFile=ineedle.mk
if make -f $targetMakeFile install >.temp >& ;then
echo $splitter
tput smso
echo "Compiled successfully!"
tput rmso
echo $splitter
echo
else
parseerror
tput smso
echo "Compiling failed!"
tput rmso
echo $spiltter
fi
cat .temp | grep -V ".mk\|gcc -c -o" >.warning
} function run()
{
pnn="ineedle" tput smso
echo $splitter
tput rmso
tput smso
echo "compiling $pnn......"
tput rmso
tput smso
echo $splitter
tput rmso loopmodules if [ $SECFLAG == ]; then
echo $splitter
tput smso
echo "error happened"
tput rmso
echo $splitter
exit
fi genemake
compile
move_compile_files
} function load_header_file()
{
if [ -r "./ineedle-linux.h" ];then
cp ineedle-linux.h ineedle.h
fi
} load_header_file
show_copyright
run

使用bakefile编译C工程代码的更多相关文章

  1. VS2010每次编译都重新编译整个工程的解决方案

      在使用VS2010编译C++程序的时候,每次修改工程中的某一个文件,点击“生成-仅用于项目-仅生成**”时,往往都是整个工程都需要重新编译一遍.由于这个工程代码量太大,每次编译完成都需要将近10分 ...

  2. 在VS13上编译通过的代码放在12上编译-错误:l __dtoui3 referenced in function _event_debug_map_HT_GROW

    在VS13上编译通过的代码放在12上编译 遇到错误:l __dtoui3 referenced in function _event_debug_map_HT_GROW 1>------ 已启动 ...

  3. KEIL MDK编译后的代码量和RAM使用详解

    一般 MCU 包含的存储空间有:片内 Flash 与片内 RAM,RAM 相当于内存,Flash 相当于硬盘.编译器会将一个程序分为好几个部分,分别存储在 MCU 不同的存储区.Keil 工程在编译完 ...

  4. 使用Jenkins + git submodule 实现自动化编译,解决代码安全性问题

    道哥的第 030 篇原创 目录 一.一个真实的代码泄漏故事 二.Jenkins 的基本使用 1. Jenkins 是什么? 2. 安装 JDK8 3. 安装 Jenkins 4. 在浏览器中配置 Je ...

  5. 反编译.NET工程

    工具:       1.  .Net Reflector       2.   远程桌面 步骤: 1. 远程桌面连接到服务器 IP,port,user,pwd 2. 打开 IIS 这里面就是所部属的网 ...

  6. apt 根据注解,编译时生成代码

    apt: @Retention后面的值,设置的为CLASS,说明就是编译时动态处理的.一般这类注解会在编译的时候,根据注解标识,动态生成一些类或者生成一些xml都可以,在运行时期,这类注解是没有的~~ ...

  7. 转:Android开发实践:用脚本编译Android工程

    转自: http://ticktick.blog.51cto.com/823160/1365947 一般情况下,我们都是使用Eclipse+ADT插件或者Android studio软件来编译Andr ...

  8. 如何在编译Xcode-Plugin工程的时候增加Cocoapods依赖

    关于如何在编译Xcode-Plugin工程的时候增加Cocoapods依赖 以及在Mac App上使用Cocoapods的时候遇到Library not found for -lPods时的解决办法 ...

  9. C#动态编译、执行代码

    在开始之前,先熟悉几个类及部分属性.方法:CSharpCodeProvider.ICodeCompiler.CompilerParameters.CompilerResults.Assembly. 一 ...

随机推荐

  1. win server 2008 r2 sharepoint 域环境安装经历

    环境: 物理机:win7(x64,计算机名字:wyman-pc,ip:192.168.10.102)  / sql server 2008 r2(x64) /VM10 虚拟机:win svr 2008 ...

  2. 手机端Swiper 触屏滑动

    在线实例 默认 响应式 垂直 空间间隔 滚动 自动滚动 中心化 中心化自动 免费模式 多个滚动 水平滚动 grab-cursor 使用方法 <div class="swiper-con ...

  3. Stickup – 轻松实现元素固定效果的 jQuery 插件

    粘贴是一个简单的 jQuery 插件,在页面滚动的时候固定一个元素到浏览器窗口的顶部,让其总是保持在视图中可见.这个插件作用于多页的网站,但是对于单页的布局有额外的功能.借助 CSS,还可以实现当前视 ...

  4. CSS3 使用自定义字体

    CSS3 @font-face 规则 在 CSS3 之前,web 设计师必须使用已在用户计算机上安装好的字体.通过 CSS3,web 设计师可以使用他们喜欢的任意字体.当您您找到或购买到希望使用的字体 ...

  5. Javascript的历史

    阅读了JavaScript dom简史,从网上看了下,学问很深啊. 首先简单说下网景公司(Netscape)的发展史:1993年,美国国家超级计算机应用中心(NCSA),发表了一个浏览器,命名为“Mo ...

  6. HTML <b>、 <strong> 、<big>、<small>、<em>、<i>、<sub>和<sup> 标签

    HTML <b> 标签 所有浏览器都支持 <b> 标签. 定义和用法 <b> 标签规定粗体文本. 注释:根据 HTML5 规范,在没有其他合适标签更合适时,才应该把 ...

  7. 封装Nvelocity的渲染方法

    public class CommonHelper { /// <summary> /// 用data数据填充templatename模板,渲染返回html返回 /// </summ ...

  8. JavaScript学习02 基础语法

    JavaScript学习02 基础语法 JavaScript中很多基础内容和Java中大体上基本一样,所以不需要再单独重复讲了,包括: 各种算术运算符.比较运算符.逻辑运算符: if else语句.s ...

  9. Servlet基础(三) Servlet的多线程同步问题

    Servlet基础(三) Servlet的多线程同步问题 Servlet/JSP技术和ASP.PHP等相比,由于其多线程运行而具有很高的执行效率. 由于Servlet/JSP默认是以多线程模式执行的, ...

  10. android加固系列—4.加固前先学会破解,无源码调试apk

    [版权所有,转载请注明出处.出处:http://www.cnblogs.com/joey-hua/p/5138585.html] 项目关键java代码为,将tv设置为从jni读取的字符串,这里的破解内 ...