#!/bin/bash THISCMD=$(basename $0) usages() { cat << EOF $THISCMD: Get Dependency Tree Syntax: $THISCMD [-option] [args] -s Show the dependency tree [default] -d get a list of dependended packages (sorted) Report bugs to . EOF } pacchecked(){ for (( i=0; i<$index_line; i++ )) do if [ ${depline[i]} = $1 ]; then return 0 fi done return 1 } getdeps(){ cat $1 \ | sed "s/icedust_depends_on\>[\(]*(/mySEPERATOR icedust_depends_on /g" \ | sed "s/)/ mySEPERATOR/g" \ | sed ':label;N;s/\n/ /;t label' \ | gawk 'BEGIN{RS="mySEPERATOR"}{if ($1 == "icedust_depends_on") print $0;}' \ | sed 's/[ \t]*icedust_depends_on[ \t]*//g' } getdeptree(){ list=`getdeps CMakeLists.txt` # echo "got list: $list" deptree[((index_tree++))]=$list prepwd=`pwd` for pac in $list do # echo "check $pac" cd ../../../$pac/cmake pacs[((index_pac++))]=$pac getdeptree ((index_pac--)) if ! pacchecked ${pacs[index_pac]}; then # echo "add ${pacs[index_pac]}" depline[((index_line++))]=${pacs[index_pac]} fi done cd $prepwd } workmode='show' while getopts 'hsd' optname do case "$optname" in 'h') usages exit 0 ;; 's') workmode='show' ;; 'd') workmode='get' ;; '?') echo "Unknown option $OPTARG" echo "Try \"$THISCMD -h\" for more infomation" exit -1 ;; ':') echo "Need argument value for option $OPTARG" echo "Try \"$THISCMD -h\" for more infomation" exit -1 ;; *) # Should not occur echo 'Unknown error while processing options' exit -1 ;; esac done # CMakeLists.txt? if [ ! -e CMakeLists.txt ]; then echo "Cannot find CMakeLists.txt!" break 1 fi # get dependency tree declare -a deptree declare -a depline declare -a pacs index_tree=0 index_line=0 index_pac=0 getdeptree if [ $workmode = 'show' ]; then echo "Show mode Under developping ... Please use \"$THISCMD -d\"" elif [ $workmode = 'get' ]; then # echo "line size = $index_line" for (( i=0; i<$index_line; i++ )) do echo -n "${depline[i]} " done echo "" fi