Recent Changes - Search:



Deprecated

Cdtools

Edit this page to change styles

--- Boxes and outlines ---

--- Headers beyond ordinary "!" level headers

--- Stegi specific stylings ---

--- Text warnings, notices, hilights ---

--- Directory paths ---

--- Calendar specific --- The easiest way to work within the source repositories is to setup a bash script that loads other scripts, each of which is used to setup your bash environment for working with a specific source repository. Each repository is known as a project and each project may have subprojects. For example, the Ironman repository is a project and the sensors, launcher and web interface are subprojects within Ironman.

cdtools - The function loader

cdtools is a shell script that loads your project scripts automatically. Having this one script makes it easier to update your shell functions without having to reload the individual project scripts. Also, by having one script sourced by your .bashrc you will always have these scripts available whenever you open a new terminal window.

Run the following command from a shell prompt to create the directories you need for these scripts:

   mkdir -p ~/bin/env

Save the following shell script to a file called cdtools in ~/bin (the code can be retrieved using the link below it):

cdtools bash script
#!/bin/bash -p
# Load environment setup scripts.
#############################################################################
ENV=~/bin/env
SPACES="                                                  "

# Support multiple bin/env* directories
for dir in ${ENV}*
do
    for file in `ls -1 $dir`
    do
        . $dir/$file
    done
done

# Print a project function and its description nicely formatted.
function cdprint
{
    file=$1
    desc=$2
    numspaces=`echo $file | wc -c`
    let numspaces=20-$numspaces
    spaces=`echo "$SPACES" | cut -c1-$numspaces`
    echo "$file$spaces $desc"
}

# List the functions and their descriptions, if any.
# The first argument to this function can be a string to search for.
# If no argument is supplied, list all project descriptions.
function cdlist
{
    for dir in ${ENV}*
    do
        for file in `ls -1 $dir`
        do
            desc=`grep DESC: $dir/$file`
            if [ "$desc" != "" ]
            then
                desc=`echo $desc | sed s/^.*DESC:.//`
                fnc=`grep "^function" $dir/$file`
                if [ "$fnc" != "" ]
                then
                    fnc=`grep "^function" $dir/$file | head -1 | cut -f2 -d" "`
                else
                    fnc="unknown"
                fi

                if [ "$1" != "" ]
                then
                    echo "$desc" | grep -i $1 > /dev/null
                    drc=$?
                    echo "$file" | grep -i $1 > /dev/null
                    frc=$?
                    if [ "$drc" = "0" ] || [ "$frc" = "0" ]
                    then
                        cdprint "$fnc" "$desc [$file]"
                    fi
                else
                    cdprint "$fnc" "$desc [$file]"
                fi
                unset lines
                unset fncs
            fi
        done
    done
}

Edit ~/.bashrc and append the following line:

   . ~/bin/cdtools

Now cdtools will run every time you open a new terminal window. It will load all the files it finds in ~/bin/env. The files you put there are the project scripts. Let's take a look at an example script.

Project bashsetup.sh files

Every repository here has a directory called docs. This directory contains a file called bashsetup.sh or maybe <project>.sh`. This is the repositories project script, which is used to work with that repository as shown in the following example.

Project script example

A project script is just a set of environment variables with some shell aliases to make working with a given set of directories specific to a given source project easier. Each project script actually creates new shell functions. By typing in the shell function name at the shell prompt you instantly configure your environment to work with the associated project. Consider the following script:

RaspberryPi project script - a shell function
  1. # -------------------------------------------------------------------
  2. # DESC: Raspberrypi: Embedded environment for ARM-based system using buildroot (rpi)
  3. # -------------------------------------------------------------------
  4. function rpi {
  5.  
  6.     # If supplied, the first argument is a suffix, to allow multiple versions of the same tree.
  7.     SFX=$1
  8.  
  9.     # -------------------------------------------------------------------
  10.     # Edit these items
  11.     # -------------------------------------------------------------------
  12.  
  13.     # Top of the source tree
  14.     # The source, build, archive and package directories will live
  15.     # under this tree.
  16.     # SRCTOP=<SET A PATH HERE>
  17.  
  18.     # -------------------------------------------------------------------
  19.     # Don't edit below here
  20.     # -------------------------------------------------------------------
  21.     # Project ID
  22.     PRJ=raspberrypi
  23.  
  24.     # PiBox GIT Repo
  25.     export GITREPO=git@gitlab.com/pibox/pibox.git
  26.  
  27.     # Where I do my dev work
  28.     GM_WORK=$SRCTOP/work
  29.     # Where the CVS is located
  30.     GM_HOME=$SRCTOP/$PRJ$SFX
  31.     # Where the source and build directories live
  32.     GM_SRC=$GM_HOME/src
  33.     GM_BUILD=$GM_HOME/bld
  34.     GM_ARCHIVE=$GM_HOME/archive
  35.     GM_PKG=$GM_HOME/pkg
  36.     GM_EXTRAS=$GM_HOME/extras
  37.  
  38.     # Put the host applications in our path
  39.     # export PATH=$GM_TOOLS:$PATH
  40.  
  41.     # Make the configured environment available to the build system.
  42.     export GM_WORK
  43.     export GM_ARCHIVE
  44.     export GM_PKG
  45.     export GM_HOME
  46.     export GM_SRC
  47.     export GM_BUILD
  48.     export GM_EXTRAS
  49.  
  50.     # Some aliases to bounce around directories easily
  51.     alias cdt='cd $SRCTOP'
  52.     alias cdh='cd $GM_HOME'
  53.     alias cdw='cd $GM_WORK'
  54.     alias cdx='cd $GM_SRC'
  55.     alias cdb='cd $GM_BUILD'
  56.     alias cda='cd $GM_ARCHIVE'
  57.     alias cdp='cd $GM_PKG'
  58.     alias cde='cd $GM_EXTRAS'
  59.  
  60.     # Show the aliases for this configuration
  61.     alias cd?='cdpi?'
  62. }
  63. function cdpi? {
  64. echo "
  65. $PRJ Alias settings:
  66. -----------------------------------------------------------------------------
  67. cdt    cd SRCTOP ($SRCTOP)
  68. cdh    cd GM_HOME ($GM_HOME)
  69. cdw    cd GM_WORK ($GM_WORK)
  70. cdx    cd GM_SRC ($GM_SRC)
  71. cdb    cd GM_BUILD ($GM_BUILD)
  72. cda    cd GM_ARCHIVE ($GM_ARCHIVE)
  73. cdp    cd GM_PKG ($GM_PKG)
  74. cde    cd GM_EXTRAS ($GM_EXTRAS)
  75.  
  76. To checkout tree:
  77. cdt
  78. mkdir $PRJ$SFX
  79. cdh
  80. git clone ssh://$GITREPO src
  81. "
  82. }

The only change required to this file before using it is to edit line 16 to set the top of your source tree. The SRCTOP is where you will create various project directories, such as RaspberryPi and BeagleBox.

Once this code is saved to ~/bin/env/raspberrypi you can load it by manually running the cdtools script:

  source ~/bin/cdtools

You can replace the word source with a period. Both cause the file that follows them to be loaded into your BASH environment. This process is known as sourcing a file.

The command loads the scripts into your environment and makes them available to use. Now load the rpi function by typing its name at the shell prompt

   rpi

Nothing is displayed but what happens is all those environment variables are set in such a way to make it easy to work with the code. To see how the configuration is set, type

   cd?

The output will look similar to this:

RaspberryPi project script - a shell function
  1. raspberrypi Alias settings:
  2. -----------------------------------------------------------------------------
  3. cdt    cd SRCTOP (/home/mjhammel/src/ximba)
  4. cdh    cd GM_HOME (/home/mjhammel/src/ximba/raspberrypi)
  5. cdw    cd GM_WORK (/home/mjhammel/src/ximba/work)
  6. cdx    cd GM_SRC (/home/mjhammel/src/ximba/raspberrypi/src)
  7. cdb    cd GM_BUILD (/home/mjhammel/src/ximba/raspberrypi/bld)
  8. cda    cd GM_ARCHIVE (/home/mjhammel/src/ximba/raspberrypi/archive)
  9. cdp    cd GM_PKG (/home/mjhammel/src/ximba/raspberrypi/pkg)
  10. cde    cd GM_EXTRAS (/home/mjhammel/src/ximba/raspberrypi/extras)
  11.  
  12. To checkout tree:
  13. cdt
  14. mkdir raspberrypi
  15. cdh
  16. git clone ssh://git@gitlab.com/pibox/pibox.git src
  17.  

Each of the "cd" commands listed are aliases for bouncing around to different directories used by the build system for this project. As stated, you can now check out the PiBox tree:

 cdt
 mkdir raspberrypi
 cdh
 git clone ssh://git@gitlab.com/pibox/pibox.git src

To get into the code directory:

 cdx

And now you can play with the build system. Start by checking what build targets are available:

  make help
Edit - History - Print - Recent Changes - Search
Page last modified on July 20, 2020, at 07:58 PM