2011年4月11日星期一

通过kernel Makefile 生成 cscope ctags

在kernel 中使用cscope 经常会出现很多的数据是没有用,比如一个函数被不同版本的驱动定义了很多次,而这些版本是我们不需要的,查找定义是会出现很多的选项,看得眼睛都花了 T.T
于是写了一个脚本,通过kernel makefile 来生成这些数据库,这样查找就能很精确,一步到位 ^_^

source_file=/tmp/source.list
include_file=/tmp/include.list
output_file=cscope.files
source_file_temp=/tmp/source_file_temp
output_file_temp=/tmp/output.temp
make clean
make ARCH=arm CROSS_COMPILE=arm-eabi- CFLAGS_KERNEL=-H -j4 1>$source_file 2>$include_file

#for test
#source_file=source.list
#include_file=include.list
#output_file=cscope.files
#source_file_temp=/tmp/source_file_temp

# generate the include file
grep "^\.\+\ " $include_file | awk '{print $NF}' | sort -u >$output_file

# generate the source file
grep "\(\<CC\>\|\<AS\>\|LOGO\)" $source_file | awk '{print $NF}' >$source_file_temp
for i in $(cat $source_file_temp)
        do
                cc_source=${i%.o}.c
                as_source=${i%.o}.S
                if [ -f $cc_source ]; then
                        echo $cc_source >>$output_file
                        else
                        if [ -f $as_source ]; then
                                echo $as_source >>$output_file
                        fi
                fi
        done

mv $output_file $output_file_temp
for i in $(cat $output_file_temp)
        do
                if [ -f $i ]; then
                        echo $i >>$output_file
                fi
        done

rm $output_file_temp $source_file_temp $source_file $include_file
rm cscope.*out*
cscope -bkq -i $output_file
ctags -L $output_file

使用方法:先配置好.config, 使内核能正常编译。然后,在kernel 的目录下运行该脚本,就会自动生成。
通过这个脚本,还可以生成一个文件列表 output.temp, 可以加快以后更新cscope 数据库的速度。

2011年4月1日星期五

wine 中文路径问题

在Ubuntu下,把语言切换到英文模式下,用wine 程序保存的文件,如果路径中有中文,就会提示invalid name,文件保存不了,而在中文环境下可以保存。这个应该是由于跟语言有关的环境变量造成的。为了不影响以前的设置,可以采用以下办法:


先对wine进行一下备份,建立一个脚本:
sudo cp /usr/bin/wine /usr/bin/wine-run
sudo rm /usr/bin/wine
sudo touch /usr/bin/wine
sudo chmod a+x /usr/bin/wine
然后编辑/usr/bin/wine,加入一下内容:

#!/bin/bash

export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN:zh
export LC_CTYPE="zh_CN.UTF-8"
export LC_NUMERIC="zh_CN.UTF-8"
export LC_TIME="zh_CN.UTF-8"
export LC_COLLATE="zh_CN.UTF-8"
export LC_MONETARY="zh_CN.UTF-8"
export LC_MESSAGES="zh_CN.UTF-8"
export LC_PAPER="zh_CN.UTF-8"
export LC_NAME="zh_CN.UTF-8"
export LC_ADDRESS="zh_CN.UTF-8"
export LC_TELEPHONE="zh_CN.UTF-8"
export LC_MEASUREMENT="zh_CN.UTF-8"
export LC_IDENTIFICATION="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"

/usr/bin/wine-run "$@"
注意:wine-run 后的$@必须要有引号,否则不能处理带有空格的文件。

考虑到更新时候,wine会被覆盖掉,因此,下面一个脚本可以自动检测,并生成脚本:

#!/bin/bash
function create_wine_script()
{
        echo '#!/bin/bash

        export LANG=zh_CN.UTF-8
        export LANGUAGE=zh_CN:zh
        export LC_CTYPE="zh_CN.UTF-8"
        export LC_NUMERIC="zh_CN.UTF-8"
        export LC_TIME="zh_CN.UTF-8"
        export LC_COLLATE="zh_CN.UTF-8"
        export LC_MONETARY="zh_CN.UTF-8"
        export LC_MESSAGES="zh_CN.UTF-8"
        export LC_PAPER="zh_CN.UTF-8"
        export LC_NAME="zh_CN.UTF-8"
        export LC_ADDRESS="zh_CN.UTF-8"
        export LC_TELEPHONE="zh_CN.UTF-8"
        export LC_MEASUREMENT="zh_CN.UTF-8"
        export LC_IDENTIFICATION="zh_CN.UTF-8"
        export LC_ALL="zh_CN.UTF-8"

        /usr/bin/wine-run "$@" ' > $1
}

file /usr/bin/wine | grep ELF 1>/dev/null
if [ $? -eq 0 ]
        then
                cp /usr/bin/wine /usr/bin/wine-run
                rm /usr/bin/wine
                touch /usr/bin/wine
                chmod a+x /usr/bin/wine
                create_wine_script  /usr/bin/wine
fi