pastebin - collaborative debugging tool
rovema.kpaste.net RSS


RDE: buildrdecygwin.bash
Posted by Anonymous on Tue 5th Sep 2023 16:55
raw | new post
modification of post by Anonymous (view diff)

  1. #!/bin/bash
  2.  
  3. #
  4. # buildrdecygwin.bash - build ROVEMA RDE using Cygwin
  5. #
  6.  
  7. #
  8. # Written by Roland Mainz <roland.mainz@rovema.de>
  9. #
  10.  
  11. #
  12. # Usage:
  13. #
  14. # 1. Build RDE
  15. # mkdir try10_rde_new_rds/
  16. # cd try10_rde_new_rds
  17. # git clone https://RovemaDevelopment@dev.azure.com/RovemaDevelopment/RDE-Development/_git/Dependencies
  18. # git clone --recurse-submodules https://RovemaDevelopment@dev.azure.com/RovemaDevelopment/RDE-Development/_git/RDE-Development
  19. # cd RDE-Development/
  20. # mkdir build_windows4
  21. # cd build_windows4/
  22. # time nice bash ../scripts/buildrdecygwin.bash buildall 2>&1 | tee -a buildlog.log
  23. #
  24. # 2a. Start RDE (manually):
  25. # $ bash -c 'PATH+=":${qtpath}/5.15.2/mingw81_64/bin" ; ./rde'
  26. #
  27. # 2b. Start RDE (via script):
  28. # $ bash buildrdecygwin.bash run
  29. #
  30.  
  31.  
  32. function calc_max_parallel_jobs
  33. {
  34.         set -o nounset
  35.  
  36.         typeset -li mem_total=-1
  37.         typeset -li swap_total=-1
  38.         typeset -r -li memory_per_job=$2
  39.         typeset -r -li jobs_per_cpu=$3
  40.         typeset -r -li num_cpus=$(getconf '_NPROCESSORS_ONLN')
  41.         typeset -li numjobs_in_memory
  42.         typeset -n numjobs=$1
  43.  
  44.         read mem_total <<<"$(awk \
  45.                 $'/MemTotal/ { print $2 }' \
  46.                 <'/proc/meminfo')"
  47.         read swap_total <<<"$(awk \
  48.                 $'/SwapTotal/ { print $2 }' \
  49.                 <'/proc/meminfo')"
  50.  
  51.         printf $"# mem_total=%d, swap_total=%d\n" \
  52.                 "$mem_total" \
  53.                 "$swap_total"
  54.  
  55.         # data in /proc/meminto are in KB, but we need bytes
  56.         (( mem_total*=1024, swap_total*=1024 ))
  57.  
  58.         # handle read errors
  59.         if (( (mem_total < 0) || (swap_total < 0) )) ; then
  60.                 printf $"%s: error, could not read memory data\n" "$0" 1>&2
  61.                 return 1
  62.         fi
  63.  
  64.         # we need at least 1GB of swap space
  65.         if (( swap_total < (1024*1024*1924) )) ; then
  66.                 printf $"#\n# %s: ERROR: Swap memory too low %d\n#\n" "$0" "$swap_total" 1>&2
  67.                 return 1
  68.         fi
  69.  
  70.         # Reserve 512MB for the Windows OS
  71.         (( mem_total -= 512*1024*1024 ))
  72.  
  73.         # calculate how much jobs would fit into the memory
  74.         (( numjobs_in_memory = (mem_total+memory_per_job+1) / memory_per_job ))
  75.  
  76.         # run "jobs_per_cpu" per CPU, only limited to the available memory
  77.         (( numjobs = (numjobs_in_memory > (num_cpus*jobs_per_cpu))?(num_cpus*jobs_per_cpu):numjobs_in_memory ))
  78.  
  79.         # we want at least one job
  80.         (( numjobs = (numjobs > 1)?numjobs:1 ))
  81.  
  82.         # statistics
  83.         printf $"# number of online CPUs=%d\n"      "$num_cpus"
  84.         printf $"# memory_per_job=%d\n"             "$memory_per_job"
  85.         printf $"# numjobs_in_memory=%d\n"          "$numjobs_in_memory"
  86.         printf $"# numjobs=%d\n"                    "$numjobs"
  87.  
  88.         return 0
  89. }
  90.  
  91.  
  92. #
  93. # Configuration paths
  94. #
  95. function configure_paths
  96. {
  97.         boost_Version='1_71_0'
  98.         qt_Version='5_15_2'
  99.  
  100.         #
  101.         # Prebuild RDE build tools (compiler etc)
  102.         # (from $ git clone https://RovemaDevelopment@dev.azure.com/RovemaDevelopment/RDE-Development/_git/Dependencies #)
  103.         #
  104.         #git_rde_dependicies_dir='/cygdrive/h/tmp/winnfstest/hummingbirdnfstest1/rde_windows_developmement/Dependencies/win/'
  105.         #git_rde_dependicies_dir='/home/roland_mainz/work/rde/build_dep/Dependencies/win/'
  106.         git_rde_dependicies_dir="$(realpath "$PWD/../../Dependencies")/win/"
  107.         if [[ ! -d "$git_rde_dependicies_dir" ]] ; then
  108.                 printf $"%s: ERROR: %s dir not found\n" "$0" "$git_rde_dependicies_dir" 1>&2
  109.                 return 1
  110.         fi
  111.  
  112.         boostpath="${git_rde_dependicies_dir}/boost/boost_${boost_Version}/"
  113.         qtpath="${git_rde_dependicies_dir}/qt/qt_${qt_Version}/"
  114.  
  115.         printf $"# building with boost version %s and qt version %s\n" "$boost_Version" "qt_Version"
  116.  
  117.         # Setting-up PATH
  118.         export PATH="$qtpath/Tools/mingw810_64/bin/:$qtpath/5.15.2/mingw81_64/bin/:$qtpath/Tools/CMake_64/bin/:$boostpath/bin/:$boostpath/lib/:$PATH"
  119.         printf $"# PATH=%s\n# Windows PATH=%s\n" "$PATH" "$(cygpath -p -w "$PATH")"
  120.         return 0
  121. }
  122.  
  123. function probe_paths
  124. {
  125.         printf $"# Probing PATH for tools ...\n"
  126.         which -a gcc
  127.         which -a g++
  128.         which -a cmake
  129.         which -a make
  130.  
  131.         return 0
  132. }
  133.  
  134. #
  135. # Build
  136. #
  137.  
  138. function build_clean
  139. {
  140.         printf $"# Cleanup old build stuff ...\n"
  141.         rm -Rf CMake* CPack* CTestTestfile.cmake app_translations.qrc cmake_install.cmake nowide tests RDS Makefile *.qm rde.rc rde_autogen tmp versioninfo.cpp
  142.         return 0
  143. }
  144.  
  145. function build_cmake_config
  146. {
  147.         printf $"# Running build configuration via cmake ...\n"
  148.         # note: Windows/minGW uses '-G "MinGW Makefiles"', while compiling with Cygwin requires '-G "Unix Makefiles"'
  149.         cmake -G "Unix Makefiles" -DBOOST_ROOT="$boostpath" -DBoost_LIB_PREFIX="lib" -DBoost_USE_STATIC_LIBS=TRUE -DBoost_ARCHITECTURE="-x64" -DBUILD_TESTS=ON ".."
  150.         return 0
  151. }
  152.  
  153. function build_cmake_clean
  154. {
  155.         printf $"# Target clean ...\n"
  156.         cmake --build . -j 1 --target clean
  157.         return 0
  158. }
  159.  
  160. function build_cmake_targets
  161. {
  162.         typeset -li num_parallel_jobs=$1
  163.  
  164.         printf $"# Building ...\n"
  165.         cmake --build . -j $num_parallel_jobs
  166.         printf $"# Build done.\n"
  167.         return 0
  168. }
  169.  
  170.  
  171. #
  172. # main
  173. #
  174. set -o errexit
  175. set -o nounset
  176. #set -o xtrace # debug
  177.  
  178. printf $"# %s: Start ...\n\n" "$0"
  179.  
  180. printf $"# uname=%q\n" "$(uname -a)"
  181.  
  182. # Check whether we are really on Cygwin...
  183. if [[ "$(uname -s)" != *CYGWIN* ]] ; then
  184.         printf $"%s: ERROR: Not a Cygwin environment.\n" "$0" 1>&2
  185.         exit 1
  186. fi
  187.  
  188. typeset boost_Version qt_Version git_rde_dependicies_dir boostpath qtpath
  189. typeset -li num_parallel_jobs
  190.  
  191. configure_paths
  192.  
  193. case "${1-}" in
  194.         'rebuildall')
  195.                 calc_max_parallel_jobs num_parallel_jobs $((512*1024*1024)) 3 || exit 1
  196.                 probe_paths
  197.                 build_clean
  198.                 build_cmake_config
  199.                 build_cmake_clean
  200.                 build_cmake_targets "$num_parallel_jobs"
  201.                 ;;
  202.         'build')
  203.                 calc_max_parallel_jobs num_parallel_jobs $((512*1024*1024)) 3 || exit 1
  204.                 probe_paths
  205.                 build_cmake_targets "$num_parallel_jobs"
  206.                 ;;
  207.         'clean')
  208.                 build_clean
  209.                 ;;
  210.         'run')
  211.                 ./rde
  212.                 exit $?
  213.                 ;;
  214.         *)
  215.                 printf $"%s: Unknown cmd %q\n" "$0" "${1-}" 1>&2
  216.                 exit 1
  217.                 ;;
  218. esac
  219.  
  220. exit 0
  221.  
  222. # EOF.

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with {%HIGHLIGHT}




All content is user-submitted.
The administrators of this site (kpaste.net) are not responsible for their content.
Abuse reports should be emailed to us at