zoukankan      html  css  js  c++  java
  • learning armbian steps(7) ----- armbian 源码分析(二)

    从compile.sh开始入手:

     16 SRC="$(dirname "$(realpath "${BASH_SOURCE}")")"
     17 # fallback for Trusty
     18 [[ -z "${SRC}" ]] && SRC="$(pwd)"
     19 
     20 # check for whitespace in $SRC and exit for safety reasons
     21 grep -q "[[:space:]]" <<<"${SRC}" && { echo ""${SRC}" contains whitespace. Not supported. Aborting." >&2 ; exit 1 ; }
     22 
     23 cd $SRC

    如上主要是获取源代码的路径,并判断路径是否存在空格合法

    在compile.sh

     25 if [[ -f $SRC/lib/general.sh && -L $SRC/main.sh ]]; then
     26         source $SRC/lib/general.sh
     27 else
     28         echo "Error: missing build directory structure"
     29         echo "Please clone the full repository https://github.com/armbian/build/"
     30         exit -1
     31 fi

    很明显在这一步里,我们可以进入general.sh看一下实际做了什么?

    在lib/general.sh

     定义了很多的shell 函数

    Cleaning()

             根据不同的参数做清除工作

    Exit_with_error()

             出错时用于显示错误调节的功能,文件,行号,是否高亮,及相关的出错描述

    Get_package_list_hash()

             打印新构建的文件系统安装包列表,以及文件系统的版本

    Create_source_list()

             更新apt source.list到新构建的文件系统当中

    fetch_from_repo()

             用于拉取git 仓库的代码

     # fetch_from_repo <url> <directory> <ref> <ref_subdir>

    # <url>: remote repository URL

    # <directory>: local directory; subdir for branch/tag will be created

    # <ref>:

    #       branch:name

    #       tag:name

    #       head(*)

    #       commit:hash@depth(**)

    #

    # *: Implies ref_subdir=no

    # **: Not implemented yet

    # <ref_subdir>: "yes" to create subdirectory for tag or branch name

    #

    display_alert()

             根据不同的级别显示

    fingerprint_image()

             将编译信息生成至etc/armbian.txt,其中包含      

    Title:                  Armbian $REVISION ${BOARD^} $DISTRIBUTION $RELEASE $BRANCH

            Kernel:                 Linux $VER

            Build date:             $(date +'%d.%m.%Y')

            Authors:                https://www.armbian.com/authors

            Sources:                https://github.com/armbian/

            Support:                https://forum.armbian.com/

            Changelog:              https://www.armbian.com/logbook/

            Documantation:          https://docs.armbian.com/

    addtorepo()

             用于创建本地的apt仓库,下载交叉编译工具链,下载etcher_cli工具。可定制自已的镜像打包脚本。

             [[ ! -f $SRC/userpatches/customize-image.sh ]] && cp $SRC/config/templates/customize-image.sh.template $SRC/userpatches/customize-image.sh

    download_toolchain()

             用于下载工具链。

    download_etcher_cli()

             用于下载etcher_cli,该命令工具的功能相当于dd命令与校验功能的合体。

    接来再次回到compile.sh脚本当中

     33 # copy default config from the template
     34 [[ ! -f $SRC/config-default.conf ]] && cp $SRC/config/templates/config-example.conf $SRC/config-default.conf
     35 
     36 # source build configuration file
     37 if [[ -n $1 && -f $SRC/config-$1.conf ]]; then
     38         display_alert "Using config file" "config-$1.conf" "info"
     39         source $SRC/config-$1.conf
     40 else
     41         display_alert "Using config file" "config-default.conf" "info"
     42         source $SRC/config-default.conf
     43 fi

    在默认的config-default.conf内容如下所示:

    KERNEL_ONLY=""                          # leave empty to select each time, set to "yes" or "no" to skip dialog prompt
    KERNEL_CONFIGURE=""                     # leave empty to select each time, set to "yes" or "no" to skip dialog prompt
    CLEAN_LEVEL="make,debs,oldcache"        # comma-separated list of clean targets: "make" = make clean for selected kernel and u-boot,
                                            # "debs" = delete packages in "./output/debs" for current branch and family,
                                            # "alldebs" = delete all packages in "./output/debs", "images" = delete "./output/images",
                                            # "cache" = delete "./output/cache", "sources" = delete "./sources"
                                            # "oldcache" = remove old cached rootfs except for the newest 6 files
    
    DEST_LANG="en_US.UTF-8"                 # sl_SI.UTF-8, en_US.UTF-8
    
    # advanced
    KERNEL_KEEP_CONFIG="no"                 # do not overwrite kernel config before compilation
    EXTERNAL="yes"                          # build and install extra applications and drivers
    EXTERNAL_NEW="prebuilt"                 # compile and install or install prebuilt additional packages
    CREATE_PATCHES="no"                     # wait that you make changes to uboot and kernel source and creates patches
    BUILD_ALL="no"                          # cycle through available boards and make images or kernel/u-boot packages.
                                            # set KERNEL_ONLY to "yes" or "no" to build all packages/all images
    
    BSPFREEZE=""                            # freeze armbian packages (u-boot, kernel, dtb)
    INSTALL_HEADERS=""                      # install kernel headers package
    LIB_TAG="master"                        # change to "branchname" to use any branch currently available.
    CARD_DEVICE=""                          # device name /dev/sdx of your SD card to burn directly to the card when done
    
    PROGRESS_LOG_TO_FILE="yes"
    BUILD_KSRC="no"

    在compile.sh当中允许传递 key=value, 比如./compile.sh  test_cmd=test_value

     51 # Script parameters handling
     52 for i in "$@"; do
     53         if [[ $i == *=* ]]; then
     54                 parameter=${i%%=*}
     55                 value=${i##*=}
     56                 display_alert "Command line: setting $parameter to" "${value:-(empty)}" "info"
     57                 eval $parameter=$value
     58         fi
     59 done

     接下来我们继续看compile.sh

     74 if [[ $BUILD_ALL == yes || $BUILD_ALL == demo ]]; then
     75         source $SRC/lib/build-all.sh
     76 else
     77         source $SRC/lib/main.sh
     78 fi

    由于默认的BUILD_ALL = “no” , 所以接下来会去执行$SRC/lib/main.sh.脚本。

    总结一下compile.sh的功能:

    1)    获取shell脚本相关的钩子函数,在lib/generate.sh当中

    2)    获取并解析默认的参数。

    3)    最后的主要功能还是在/lib/main.sh脚本当中,接下来我们会来解析main.sh脚本的功能。

             

     

  • 相关阅读:
    由老赵反对青鸟想到的——关于自学编程的讨论
    蛙蛙推荐:《代码大全》第45章读书笔记
    大家来找错自己写个正则引擎(二)构建抽象模式树
    大家来找错自己写个正则引擎(五)检查表及总结
    大家来找错自己写个正则引擎(一)概要介绍
    大家来找错自己写个正则引擎(三)构建正则解析树及分词
    蛙蛙推荐:《代码大全》1至3章读书笔记
    sql for xml path用法(转) dodo
    sql语句总结一 dodo
    System.Management.ManagementException: 访问遭到拒绝的解决方案 dodo
  • 原文地址:https://www.cnblogs.com/lianghong881018/p/10395491.html
Copyright © 2011-2022 走看看