BuildLinux.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #!/bin/bash
  2. export ROOT=`pwd`
  3. export NCORES=`nproc --all`
  4. FOUND_GTK2=$(dpkg -l libgtk* | grep gtk2)
  5. FOUND_GTK3=$(dpkg -l libgtk* | grep gtk-3)
  6. unset name
  7. while getopts ":dsiuhgb" opt; do
  8. case ${opt} in
  9. u )
  10. UPDATE_LIB="1"
  11. ;;
  12. i )
  13. BUILD_IMAGE="1"
  14. ;;
  15. d )
  16. BUILD_DEPS="1"
  17. ;;
  18. s )
  19. BUILD_SLIC3R="1"
  20. ;;
  21. b )
  22. BUILD_DEBUG="1"
  23. ;;
  24. g )
  25. FOUND_GTK3=""
  26. ;;
  27. h ) echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
  28. echo " -i: Generate appimage (optional)"
  29. echo " -g: force gtk2 build"
  30. echo " -b: build in debug mode"
  31. echo " -d: build deps (optional)"
  32. echo " -s: build slic3r (optional)"
  33. echo " -u: only update clock & dependency packets (optional and need sudo)"
  34. echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  35. echo " and then './BuildLinux.sh -dsi'"
  36. exit 0
  37. ;;
  38. esac
  39. done
  40. if [ $OPTIND -eq 1 ]
  41. then
  42. echo "Usage: ./BuildLinux.sh [-i][-u][-d][-s][-b][-g]"
  43. echo " -i: Generate appimage (optional)"
  44. echo " -g: force gtk2 build"
  45. echo " -b: build in debug mode"
  46. echo " -d: build deps (optional)"
  47. echo " -s: build slic3r (optional)"
  48. echo " -u: only update clock & dependency packets (optional and need sudo)"
  49. echo "For a first use, you want to 'sudo ./BuildLinux.sh -u'"
  50. echo " and then './BuildLinux.sh -dsi'"
  51. exit 0
  52. fi
  53. # mkdir build
  54. if [ ! -d "build" ]
  55. then
  56. mkdir build
  57. fi
  58. if [[ -n "$UPDATE_LIB" ]]
  59. then
  60. echo -n -e "Updating linux ...\n"
  61. hwclock -s
  62. apt update
  63. apt install g++ m4
  64. if [[ -z "$FOUND_GTK3" ]]
  65. then
  66. echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
  67. apt install libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext
  68. else
  69. echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
  70. apt install libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext
  71. fi
  72. # for ubuntu 22.04:
  73. ubu_version="$(cat /etc/issue)"
  74. if [[ $ubu_version == "Ubuntu 22.04"* ]]
  75. then
  76. apt install curl libssl-dev libcurl4-openssl-dev m4
  77. fi
  78. if [[ -n "$BUILD_DEBUG" ]]
  79. then
  80. echo -e "\nInstalling: libssl-dev libcurl4-openssl-dev\n"
  81. apt install libssl-dev libcurl4-openssl-dev
  82. fi
  83. echo -e "done\n"
  84. exit 0
  85. fi
  86. FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
  87. FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
  88. echo "FOUND_GTK2=$FOUND_GTK2)"
  89. if [[ -z "$FOUND_GTK2_DEV" ]]
  90. then
  91. if [[ -z "$FOUND_GTK3_DEV" ]]
  92. then
  93. echo "Error, you must install the dependencies before."
  94. echo "Use option -u with sudo"
  95. exit 0
  96. fi
  97. fi
  98. echo "[1/9] Updating submodules..."
  99. {
  100. # update submodule profiles
  101. pushd resources/profiles
  102. git submodule update --init
  103. popd
  104. }
  105. echo "[2/9] Changing date in version..."
  106. {
  107. # change date in version
  108. sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
  109. }
  110. echo "done"
  111. # mkdir in deps
  112. if [ ! -d "deps/build" ]
  113. then
  114. mkdir deps/build
  115. fi
  116. if [[ -n "$BUILD_DEPS" ]]
  117. then
  118. echo "[3/9] Configuring dependencies..."
  119. BUILD_ARGS=""
  120. if [[ -n "$FOUND_GTK3_DEV" ]]
  121. then
  122. BUILD_ARGS="-DDEP_WX_GTK3=ON"
  123. fi
  124. if [[ -n "$BUILD_DEBUG" ]]
  125. then
  126. # have to build deps with debug & release or the cmake won't find evrything it needs
  127. mkdir deps/build/release
  128. pushd deps/build/release
  129. cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
  130. make -j$NCORES
  131. popd
  132. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  133. fi
  134. # cmake deps
  135. pushd deps/build
  136. cmake .. $BUILD_ARGS
  137. echo "done"
  138. # make deps
  139. echo "[4/9] Building dependencies..."
  140. make -j$NCORES
  141. echo "done"
  142. # rename wxscintilla
  143. echo "[5/9] Renaming wxscintilla library..."
  144. pushd destdir/usr/local/lib
  145. if [[ -z "$FOUND_GTK3_DEV" ]]
  146. then
  147. cp libwxscintilla-3.1.a libwx_gtk2u_scintilla-3.1.a
  148. else
  149. cp libwxscintilla-3.1.a libwx_gtk3u_scintilla-3.1.a
  150. fi
  151. popd
  152. echo "done"
  153. # clean deps
  154. echo "[6/9] Cleaning dependencies..."
  155. rm -rf dep_*
  156. popd
  157. echo "done"
  158. fi
  159. if [[ -n "$BUILD_SLIC3R" ]]
  160. then
  161. echo "[7/9] Configuring Slic3r..."
  162. BUILD_ARGS=""
  163. if [[ -n "$FOUND_GTK3_DEV" ]]
  164. then
  165. BUILD_ARGS="-DSLIC3R_GTK=3"
  166. fi
  167. if [[ -n "$BUILD_DEBUG" ]]
  168. then
  169. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  170. fi
  171. # cmake
  172. pushd build
  173. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  174. echo "done"
  175. # make Slic3r
  176. echo "[8/9] Building Slic3r..."
  177. make -j$NCORES Slic3r
  178. # make .mo
  179. make gettext_po_to_mo
  180. popd
  181. echo "done"
  182. fi
  183. # Give proper permissions to script
  184. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  185. echo "[9/9] Generating Linux app..."
  186. pushd build
  187. if [[ -n "$BUILD_IMAGE" ]]
  188. then
  189. $ROOT/build/src/BuildLinuxImage.sh -i
  190. else
  191. $ROOT/build/src/BuildLinuxImage.sh
  192. fi
  193. popd
  194. echo "done"