Skip to content

Commit

Permalink
Script: Developer build update (indilib#1537)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedramardakani authored Sep 23, 2021
1 parent 619e936 commit fd25142
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 32 deletions.
40 changes: 31 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,49 @@ sudo make install

## Build indi-core (script)

You can use the `developer-build.bash` script for faster building.
**Alternatively**, you can use the `developer-build.bash` script for faster build and less stress on your SSD or HDD.

```bash
cd ~/Projects/indi
./developer-build.bash
```

By default, this script builds the `indi-core` inside machine's `RAM`, i.e. `/dev/shm`.
To change the default build directory, just pass in the desired directory after calling the script, for instance:
However, you can change the target build directory using the `-o` option, for instance:

```bash
cd ~/Projects/indi
./developer-build.bash /path/to/new/build/dir
./developer-build.bash -o /path/to/new/build/dir
```

Also, this script checks if the target build directory has at least `512MB` of memory available and aborts if this is not the case.
You can force skip this test with the `-f` option:

```bash
./developer-build.bash -f
```

Furthermore, this script executes `make` in *parallel* by default.
If you are having problems or need to use fewer CPU cores, please adjust using the `-j` option.
For example, to disable parallel execution:

```bash
./developer-build.bash -j1
```

This script creates a soft symbolic link file named `build` to the target build directory.
This helps easier access by simply following the symbolic link:

```bash
cd ~/Projects/indi/build
```

Also, this script checks if the target build directory is a subdirectory of `/dev/shm`.
If so, the build process aborts if there is less than `1Gb` free space in `RAM`.
One can reset this limitation with changing the `NEED_MEMORY` variable to his/her liking.
Lastly, you could give all the options and arguments at once.
For instance, if you want to build in `~/indi-build` directory, skip the memory check, and run make using `8` cores, call the script with the following options:

In addition, this script creates a soft symbolic link file named `build` from the build directory to the source directory.
This helps with accessing the build directory by simply following the link inside the source folder like any other directory, i.e. `cd ~/Projects/indi/build`.
```bash
cd ~/Projects/indi
./developer-build.bash -o ~/indi-build -f -j8
```

## Build indi-core (Qt Creator)

Expand Down
104 changes: 81 additions & 23 deletions developer-build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -28,48 +28,106 @@
# needs gracefully.

TOP_DIR=$PWD
NEED_MEMORY=524288
BUILD_LINK=$TOP_DIR/build
BUILD_DIR=/dev/shm/indi-build





if [ ! x"$1" = x"" ]; then
# Take the option given as the new build directory
BUILD_DIR="$1"
# A useful short tutorial on getopt:
# https://wiki.bash-hackers.org/howto/getopts_tutorial
while getopts ":o:j:f" opt; do
case $opt in
o)
BUILD_DIR="$OPTARG"
;;
j)
NUMBER_OF_JOBS=$OPTARG
;;
f)
NEED_MEMORY=""
;;
\?)
echo "Invalid option -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac

# Check if another option is mistakenly passed as an argument
case $OPTARG in
-*)
echo "Option '-$opt' requires an argument."
exit 1
;;
esac
done





# Use maximum cores available in GNU/Linux and macOS by default
if [ -z $NUMBER_OF_JOBS ]; then
OS_TYPE=$(uname -s)
case $OS_TYPE in
Linux*)
NUMBER_OF_JOBS=$(nproc)
;;
Darwin*)
NUMBER_OF_JOBS=$(sysctl -n hw.ncpu)
;;
*)
NUMBER_OF_JOBS=1
;;
esac
fi
echo ">>> Build using $NUMBER_OF_JOBS core(s), " \
"i.e. \$ make -j$NUMBER_OF_JOBS"


echo ">>> Target build directory: $BUILD_DIR"

case $BUILD_DIR/ in
/dev/shm/*)
# Build directory is in RAM
# ONLY continue if there is at least 1GB of RAM available
NEED_MEMORY=1000000
FREE_MEMORY=$(free | awk '$1 == "Mem:" {print $NF}')

if [ $FREE_MEMORY -lt $NEED_MEMORY ]; then
echo "*** Not enough memory available in RAM (current "\
"$FREE_MEMORY, need $NEED_MEMORY)"

# Create the build directory if it is not available already
if [ ! -d $BUILD_DIR ]; then
mkdir -p $BUILD_DIR >&2

# Exit in case of receiving errors from mkdir
if [ ! $? -eq 0 ]; then
echo "*** Please fix the issue with build directory '$BUILD_DIR' and try again."
echo "*** OR create the directory yourself and re-run the script."
exit 1
fi
;;
fi

*)
# Build directory is not in RAM
;;
esac
echo ">>> Target build directory: $BUILD_DIR"





# Create the build directory and a symbolic link for quick access
if [ ! -d $BUILD_DIR ]; then
mkdir -p $BUILD_DIR
# Check for available free space in the build directory
FREE_MEMORY=$(df $BUILD_DIR | awk 'END{print $4}')

if [ -z $NEED_MEMORY ]; then
echo ">>> Skipping free memory check. Available: $FREE_MEMORY"
elif [ $FREE_MEMORY -lt $NEED_MEMORY ]; then
echo "*** Not enough memory available in '$BUILD_DIR'"
echo "*** (current $FREE_MEMORY, need $NEED_MEMORY)"
exit 1
fi





# Create the symbolic link
if [ ! -h $BUILD_LINK ]; then
echo ">>> Creating a symbolic link for quick access:"
ln -s $BUILD_DIR $BUILD_LINK
Expand All @@ -82,7 +140,7 @@ fi



# Begin the build process, with all cores available
# Begin the build process
cd $BUILD_DIR
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug $TOP_DIR
make -j
make -j$NUMBER_OF_JOBS

0 comments on commit fd25142

Please sign in to comment.