Deprecated
|
Cdtools /
Cdtools
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
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
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 |