BuildLinux.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. if [[ -n "$FOUND_GTK3" ]]
  54. then
  55. echo "Found GTK3"
  56. else
  57. if [[ -n "$FOUND_GTK2" ]]
  58. then
  59. echo "Found GTK2"
  60. fi
  61. fi
  62. if [[ -n "$UPDATE_LIB" ]]
  63. then
  64. echo -n -e "Updating linux ...\n"
  65. hwclock -s
  66. apt update
  67. apt install g++ m4
  68. if [[ -z "$FOUND_GTK3" ]]
  69. then
  70. echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse\n"
  71. apt install libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse
  72. else
  73. echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse\n"
  74. apt install libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git gettext fuse
  75. fi
  76. # for ubuntu 22.04:
  77. ubu_version="$(cat /etc/issue)"
  78. if [[ $ubu_version == "Ubuntu 22.04"* ]]
  79. then
  80. apt install curl libssl-dev libcurl4-openssl-dev m4
  81. fi
  82. if [[ -n "$BUILD_DEBUG" ]]
  83. then
  84. echo -e "\nInstalling: libssl-dev libcurl4-openssl-dev\n"
  85. apt install libssl-dev libcurl4-openssl-dev
  86. fi
  87. echo -e "done\n"
  88. exit 0
  89. fi
  90. FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
  91. FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
  92. echo "FOUND_GTK2=$FOUND_GTK2)"
  93. if [[ -z "$FOUND_GTK2_DEV" ]]
  94. then
  95. if [[ -z "$FOUND_GTK3_DEV" ]]
  96. then
  97. echo "Error, you must install the dependencies before."
  98. echo "Use option -u with sudo"
  99. exit 0
  100. fi
  101. fi
  102. echo "[1/9] Updating submodules..."
  103. {
  104. # update submodule profiles
  105. pushd resources/profiles
  106. git submodule update --init
  107. popd
  108. }
  109. echo "[2/9] Changing date in version..."
  110. {
  111. # change date in version
  112. sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
  113. }
  114. echo "done"
  115. # mkdir build
  116. if [ ! -d "build" ]
  117. then
  118. mkdir build
  119. fi
  120. # mkdir in deps
  121. if [ ! -d "deps/build" ]
  122. then
  123. mkdir deps/build
  124. fi
  125. if [[ -n "$BUILD_DEPS" ]]
  126. then
  127. echo "[3/9] Configuring dependencies..."
  128. BUILD_ARGS=""
  129. if [[ -n "$FOUND_GTK3_DEV" ]]
  130. then
  131. BUILD_ARGS="-DDEP_WX_GTK3=ON"
  132. fi
  133. if [[ -n "$BUILD_DEBUG" ]]
  134. then
  135. # have to build deps with debug & release or the cmake won't find evrything it needs
  136. mkdir deps/build/release
  137. pushd deps/build/release
  138. cmake ../.. -DDESTDIR="../destdir" $BUILD_ARGS
  139. make -j$NCORES
  140. popd
  141. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  142. fi
  143. # cmake deps
  144. pushd deps/build
  145. cmake .. $BUILD_ARGS
  146. echo "done"
  147. # make deps
  148. echo "[4/9] Building dependencies..."
  149. make -j$NCORES
  150. echo "done"
  151. # rename wxscintilla
  152. echo "[5/9] Renaming wxscintilla library..."
  153. pushd destdir/usr/local/lib
  154. if [[ -z "$FOUND_GTK3_DEV" ]]
  155. then
  156. cp libwxscintilla-3.1.a libwx_gtk2u_scintilla-3.1.a
  157. else
  158. cp libwxscintilla-3.1.a libwx_gtk3u_scintilla-3.1.a
  159. fi
  160. popd
  161. echo "done"
  162. # clean deps
  163. echo "[6/9] Cleaning dependencies..."
  164. rm -rf dep_*
  165. popd
  166. echo "done"
  167. fi
  168. if [[ -n "$BUILD_SLIC3R" ]]
  169. then
  170. echo "[7/9] Configuring Slic3r..."
  171. BUILD_ARGS=""
  172. if [[ -n "$FOUND_GTK3_DEV" ]]
  173. then
  174. BUILD_ARGS="-DSLIC3R_GTK=3"
  175. fi
  176. if [[ -n "$BUILD_DEBUG" ]]
  177. then
  178. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  179. fi
  180. # cmake
  181. pushd build
  182. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  183. echo "done"
  184. #make avrdude-slic3r
  185. make avrdude-slic3r
  186. # make Slic3r
  187. echo "[8/9] Building Slic3r..."
  188. make -j$NCORES Slic3r
  189. # make .mo
  190. make gettext_po_to_mo
  191. # make OCCTWrapper.so
  192. make OCCTWrapper
  193. popd
  194. echo "done"
  195. fi
  196. # Give proper permissions to script
  197. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  198. echo "[9/9] Generating Linux app..."
  199. pushd build
  200. if [[ -n "$BUILD_IMAGE" ]]
  201. then
  202. $ROOT/build/src/BuildLinuxImage.sh -i
  203. else
  204. $ROOT/build/src/BuildLinuxImage.sh
  205. fi
  206. popd
  207. echo "done"