您的位置:首页 > 运维架构 > Linux

freescale-sdk linux移植一搭建编译环境脚本host-prepare.sh分析

2014-11-17 20:15 471 查看
接下来使用自己的课外休息时间,对基于PowerPC架构freescale-sdk,进行linux移植和分析。主要参考官方文档freescale linux sdk START_HERE.html,首先对搭建编译环境脚本host-prepare.sh分析。在移植系统之前,需要搭建编译环境,安装必要的包,为后期编译系统做准备。很多人看到脚本就头疼,下面是我的分析过程,分析不好的地方可以在下面留言,一起讨论。

一.搭建编译环境脚本分析./scripts/host-prepare.sh

freescale@freescale-sdk:~/SDK/QorIQ-SDK-V1.4-20130625-yocto$ ./scripts/host-prepare.sh -h

Usage: ./scripts/host-prepare.sh [-h] [-f]

-h: display help

-f: force install all needed host pkgs, running non-interactively

分析./scripts/host-prepare.sh脚本,输入命令./scripts/host-prepare.sh -h,显示帮助信息。

SCRIPT_DIR=`readlink -f $(dirname $0)`#获取当前脚本所在目录

usage_message() { #帮助子函数,输入-h或-?时调用该函数运行

echo "Usage: $0 [-h] [-f]

-h: display help

-f: force install all needed host pkgs, running non-interactively

"

} #getopts options variable

while getopts "fh" host_prepare_flag #每次执行循环,getopts 就检查下一个命令行参数,并判断它是否合法。即检查参数是否以 - 开头,后面跟一个包含在option中的字母

do #如果是,就把匹配的选项字母存在指定的变量 variable 中,并返回退出状态0;

case $host_prepare_flag in #如果 - 后面的字母没有包含在 options 中,就在 variable 中存入一个 ?,并返回退出状态0;

f) force_update='true'; #如果命令行中已经没有参数,或者下一个参数不以 - 开头,就返回不为0的退出状态。

;;

?) usage_message;exit 1;

;;

esac

done

# check host distribution #检查客服机系统类型,存在/etc/lsb-release文件,打开显示DISTRIB_ID=Ubuntu DISTRIB_RELEASE=10.04

if [ -r /etc/lsb-release ] && grep Ubuntu /etc/lsb-release >/dev/null 2>&1
#1表示stdout标准输出,系统默认值是1,>/dev/null相当于1>/dev/null

then #2表示stderr标准错误

# Ubuntu-based system

. /etc/lsb-release

distro="Ubuntu"

release=${DISTRIB_RELEASE}

hostpkg="apt-get"

elif [ -r /etc/debian_version ]

then

# Debian-based

distro="Debian"

release=`cat /etc/debian_version`

hostpkg="apt-get"

......

echo "Verifying sudo permission to execute $hostpkg command."
#输出Verifying sudo permission to execute apt-get command.

user=`whoami` || true #这里包括下面几句都是关于root权限判断的,以后分析???

......

case "$distro" in #根据上面系统判断得出$distro="Ubuntu",故执行脚本script="$SCRIPT_DIR/host-prepare-ubuntu-mint-debian.sh";

'Ubuntu' | 'Mint' | 'Debian' )

script="$SCRIPT_DIR/host-prepare-ubuntu-mint-debian.sh";

;;

'Redhat' | 'CentOS' | 'Fedora')

script="$SCRIPT_DIR/host-prepare-rhel-centos-fedora.sh";

;;

'SUSE' | 'openSUSE')

script="$SCRIPT_DIR/host-prepare-suse.sh";

;;

esac

#紧接着上面分析$SCRIPT_DIR/host-prepare-ubuntu-mint-debian.sh,其中$SCRIPT_DIR=~/SDK/QorIQ-SDK-V1.4-20130625-yocto/scripts

if test $force_update; then UPDATE_FLAG='-y --force-yes';fi
#force_update='true'赋值 UPDATE_FLAG='-y --force-yes'

PKGS="sed wget subversion git-core coreutils \

unzip texi2html texinfo libsdl1.2-dev docbook-utils fop gawk \

python-pysqlite2 diffstat make gcc build-essential xsltproc \

g++ desktop-file-utils chrpath libgl1-mesa-dev libglu1-mesa-dev \

autoconf automake groff libtool xterm libxml-parser-perl \

"

# pkgs required for fsl use

PKGS="$PKGS vim-common xz-utils cvs tofrodos libstring-crc32-perl"

PKGS="$PKGS patch libbonobo2-common libncurses5-dev"

if [ "`uname -m`" = "x86_64" ]; then

PKGS="$PKGS ia32-libs lib32ncurses5-dev"

fi #对PKGS赋值需要安装的包

echo "Now we're going to install all the other development packages needed to build Yocto, please wait"

sudo apt-get $UPDATE_FLAG install $PKGS #搭建编译环境,安装必要的包

至此,已安装好必要的包,为后期系统正常编译搭建好环境。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: