一、前言

最近有个想法,想把 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. CI框架源码阅读笔记3 全局函数Common.php

    从本篇开始,将深入CI框架的内部,一步步去探索这个框架的实现.结构和设计. Common.php文件定义了一系列的全局函数(一般来说,全局函数具有最高的加载优先权,因此大多数的框架中BootStrap ...

  2. DDD为何叫好不叫座?兼论DCI与业务分析的方法论

    今天,仔细阅读了园子里面的一个朋友写的<一缕阳光:DDD(领域驱动设计)应对具体业务场景,如何聚焦 Domain Model(领域模型)?>(http://www.cnblogs.com/ ...

  3. JSON+YAML初步学习+ciscoconfparse

    Git git clone 在github.com右上角点击加号创建新的repository 在Linux或Mac命令行下,找到你想存放这个repository的目录,然后git clone 某个re ...

  4. WPF的ComboBox 数据模板自定义

    WPF的ComboBox 有些时候不能满足用户需求,需要对数据内容和样式进行自定义,下面就简要介绍一下用数据模板(DataTemplate)的方式对ComboBox 内容进行定制: 原型设计如下: 步 ...

  5. CutJS – 用于 HTML5 游戏开发的 2D 渲染引擎

    CutJS 是轻量级的,快速的,基于 Canvas 开发的 HTML5  2D 渲染引擎,可以用于游戏开发.它是开源的,跨平台的,与现代的浏览器和移动设备兼容.CutJS 提供了一个类似 DOM 树的 ...

  6. [读码]HTML5像素文字爆炸重组

    [边读码,边学习,技术也好,思路也罢] [一款基于HTML5技术的文字像素爆炸重组动画特效,我们可以在输入框中指定任意文字,点击确定按钮后,就会将原先的文字爆炸散去,新的文字以像素点的形式组合起来,看 ...

  7. tmtTable设计说明文档

    文件链接:tmt-table.js BOSS后台项目用到最多的就是列表页,所以把列表页做成通用组件,可以大大提高开发效率. 因为列表可能有不同的样式,所以在实例化组件时可以传值控制样式,用这种方式: ...

  8. 解决ReSharper自动删除换行

    使用Devexpress+ReSharper进行开发,似乎是C/S开发的最佳搭配. 但在ReSharper使用时,发现一个非常烦人的问题:即按F5进行调试时,自动删除换行,这样不仅把代码搞乱了,而且有 ...

  9. SharePoint 2013 在母版页中插入WebPart

    最近QQ群里有朋友问,如何在母版页里插入自己开发的WebPart.其实很简单,母版页中虽然不允许插入WebPartZone,但是Designer就可以插入WebPart:或者手动注册,然后插入WebP ...

  10. 渗透测试常规思路分析-FREEBUF

    最基础但练得好最后也非常厉害 1.  主要由于服务器配置等原因造成的信息泄露 常用google ,bing等搜索工具,轻量级的搜索出一些遗留后门,不想被发现的后台入口,中量级的搜索出一些用户信息泄露, ...