Latest Posts

Topic: Alternative compile script for linuxers

kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 1523
Ranking
One Elder of Players
Location: Germany
Posted at: 2018-10-18, 10:44

Just want to share my alternative compile script which has some advantages over the shipped compile script (compile.sh):

  1. It uses per default more processor cores: Available cores -1, so one core is preserved for doing other things during compiling. Compiling with ninja uses all cores, which make my system unusable for some time.
  2. The compile output get doubled: As usual the output during compiling is shown in the console, but additionally stored in a file. This can be helpful because the consoles cache is limited and one couldn't scroll to first output messages

The script assumes that you have the proposed directory structure:

~/widelands-repo
~/widelands-repo/trunk
~/widelands-repo/OTHER_BRANCHES

The script should be stored in the folder 'widelands-repo' and can be used in two ways:

  1. Call it from folder widelands-repo in form of ./compile.sh FOLDEROFBRANCH, e.g.: ./complie.sh trunk
  2. Call it from a branchs folder, say from '~/widelands-repo/trunk', in form of: ../compile.sh (Note the double points in front)

The file containing the compile output is stored always in the directory where this script lives and is called 'compile.txt'

One disadvantage: Changing compile options needs editing the script file. But i assume most people do always use the same options, so editing one time will suffice.

And here is the script. If you want to use it, don't forget to mark it as executable (chmod +x compile.sh):

#!/bin/bash

CALL_DIR="$(basename $PWD)"
SCRIPT_PATH="$(dirname $(readlink -e "$0"))"
SCRIPT_DIR="$(basename $SCRIPT_PATH)"

# Check the folder from where we are running this script
if [ "$1" == "" ]; then
   if [ "$CALL_DIR" == "$SCRIPT_DIR" ]; then
      # We're in the script folder but an argument is missing
      echo "Use command: ./compile.sh DIRECTORY"
      exit 0
   else
      # We're in the folder of the branch we want to compile
      BRANCH_DIR="$(basename "$PWD")"
   fi
fi

if [ -z $BRANCH_DIR ]; then
   # We're not in the folder of the branch, so cd into it
   cd $1
fi

# Set amount of available processor cores -1
CORES="$(nproc --ignore=1)"

# For systems with only one core
if [ $CORES == "0" ]; then
   CORES=1
fi

echo "-------------------------------------------"
echo "Compiling branch $1 $BRANCH_DIR" | tee $SCRIPT_PATH/compile.txt
echo "-------------------------------------------"

# Check if directories / links already exists and create / update them if needed.
test -d build/locale || mkdir -p build/locale
test -e data/locale || ln -s ../build/locale data/locale

cd build

# Change the approriate compile option here!
cmake -DCMAKE_BUILD_TYPE=Debug \
      -DOPTION_BUILD_WEBSITE_TOOLS=OFF \
      -DOPTION_BUILD_TRANSLATIONS=ON \
      -DOPTION_ASAN=OFF \
      .. | tee -a $SCRIPT_PATH/compile.txt

make -j$CORES | tee -a $SCRIPT_PATH/compile.txt

rm  -f ../VERSION || true
rm  -f ../widelands || true

rm  -f ../wl_map_object_info || true
rm  -f ../wl_map_info || true

mv VERSION ../VERSION
mv src/widelands ../widelands

if [ -e ../build/src/website/wl_map_object_info ]; then
   mv ../build/src/website/wl_map_object_info ../wl_map_object_info
   mv ../build/src/website/wl_map_info ../wl_map_info
fi

Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 2626
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2018-10-19, 08:58

Would you like to contribute the cores restriction to the ninja route of our general compile script? I'd find it useful for when compiling on Windows. I don't use Ninja on my Linux machine, because it only has 2 cores.


Busy indexing nil values

Top Quote
kaputtnik
Avatar
Joined: 2013-02-18, 20:48
Posts: 1523
Ranking
One Elder of Players
Location: Germany
Posted at: 2018-10-19, 14:56

Can do, but i am AFK for the next two weeks face-smile.png


Top Quote
GunChleoc
Avatar
Joined: 2013-10-07, 15:56
Posts: 2626
Ranking
One Elder of Players
Location: RenderedRect
Posted at: 2018-10-20, 09:58

Enjoy your AFK - there is no hurry face-smile.png


Busy indexing nil values

Top Quote