Notes:

All bash script files to be saved with Linux line ending LF. Windows line endings CRLF in bash script files spoil the script as Bash will think CR is a command.

Create environment for compiling (example):

#!/bin/bash

#c++ header directories
export CPATH="\
/mnt/d/abi/projects/valgo-cpp/src:\
/mnt/d/abi/projects/valgo-cpp/libs/eidheim/sws:\
/usr/local/include:\
/usr/local/include/bsoncxx/v_noabi:\
/usr/local/include/mongocxx/v_noabi\
"

#c++ dynamic library files .so (shared object)
export LD_LIBRARY_PATH="\
/usr/lib:\
/usr/local/lib\
"

Only compile changed files, stop bash script when G++ raise an error (example):

#!/bin/bash

md5sum searcher.cpp >temp.md5
if cmp -s temp.md5 searcher.md5
then
  echo "searcher.cpp (unchanged)"
else
  echo "searcher.cpp is being compiled..."
  if g++-6 -std=c++14 -Wall -Wfatal-errors -c -o searcher.o searcher.cpp
  then
    md5sum searcher.cpp >searcher.md5
    echo "(compiled)"
  else
    echo "(failed)"
    exit
  fi
fi
Advertisements