BuildLinux.sh 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. if [[ -z "$FOUND_GTK3" ]]
  64. then
  65. echo -e "\nInstalling: libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
  66. apt install libgtk2.0-dev libglew-dev libudev-dev libdbus-1-dev cmake git
  67. else
  68. echo -e "\nFind libgtk-3, installing: libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git\n"
  69. apt install libgtk-3-dev libglew-dev libudev-dev libdbus-1-dev cmake git
  70. fi
  71. echo -e "done\n"
  72. exit 0
  73. fi
  74. FOUND_GTK2_DEV=$(dpkg -l libgtk* | grep gtk2.0-dev)
  75. FOUND_GTK3_DEV=$(dpkg -l libgtk* | grep gtk-3-dev)
  76. echo "FOUND_GTK2=$FOUND_GTK2)"
  77. if [[ -z "$FOUND_GTK2_DEV" ]]
  78. then
  79. if [[ -z "$FOUND_GTK3_DEV" ]]
  80. then
  81. echo "Error, you must install the dependencies before."
  82. echo "Use option -u with sudo"
  83. exit 0
  84. fi
  85. fi
  86. echo "[1/9] Updating submodules..."
  87. {
  88. # update submodule profiles
  89. pushd resources/profiles
  90. git submodule update --init
  91. popd
  92. }
  93. echo "[2/9] Changing date in version..."
  94. {
  95. # change date in version
  96. sed -i "s/+UNKNOWN/_$(date '+%F')/" version.inc
  97. }
  98. echo "done"
  99. # mkdir in deps
  100. if [ ! -d "deps/build" ]
  101. then
  102. mkdir deps/build
  103. fi
  104. if [[ -n "$BUILD_DEPS" ]]
  105. then
  106. echo "[3/9] Configuring dependencies..."
  107. BUILD_ARGS=""
  108. if [[ -n "$FOUND_GTK3_DEV" ]]
  109. then
  110. BUILD_ARGS="-DDEP_WX_GTK3=ON"
  111. fi
  112. if [[ -n "$BUILD_DEBUG" ]]
  113. then
  114. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  115. fi
  116. # cmake deps
  117. pushd deps/build
  118. cmake .. $BUILD_ARGS
  119. echo "done"
  120. # make deps
  121. echo "[4/9] Building dependencies..."
  122. make -j$NCORES
  123. echo "done"
  124. # rename wxscintilla
  125. echo "[5/9] Renaming wxscintilla library..."
  126. pushd destdir/usr/local/lib
  127. if [[ -z "$FOUND_GTK3_DEV" ]]
  128. then
  129. cp libwxscintilla-3.1.a libwx_gtk2u_scintilla-3.1.a
  130. else
  131. cp libwxscintilla-3.1.a libwx_gtk3u_scintilla-3.1.a
  132. fi
  133. popd
  134. echo "done"
  135. # clean deps
  136. echo "[6/9] Cleaning dependencies..."
  137. rm -rf dep_*
  138. popd
  139. echo "done"
  140. fi
  141. if [[ -n "$BUILD_SLIC3R" ]]
  142. then
  143. echo "[7/9] Configuring Slic3r..."
  144. BUILD_ARGS=""
  145. if [[ -n "$FOUND_GTK3_DEV" ]]
  146. then
  147. BUILD_ARGS="-DSLIC3R_GTK=3"
  148. fi
  149. if [[ -n "$BUILD_DEBUG" ]]
  150. then
  151. BUILD_ARGS="${BUILD_ARGS} -DCMAKE_BUILD_TYPE=Debug"
  152. fi
  153. # cmake
  154. pushd build
  155. cmake .. -DCMAKE_PREFIX_PATH="$PWD/../deps/build/destdir/usr/local" -DSLIC3R_STATIC=1 ${BUILD_ARGS}
  156. echo "done"
  157. # make Slic3r
  158. echo "[8/9] Building Slic3r..."
  159. make -j$NCORES Slic3r
  160. # make .mo
  161. make gettext_po_to_mo
  162. popd
  163. echo "done"
  164. fi
  165. # Give proper permissions to script
  166. chmod 755 $ROOT/build/src/BuildLinuxImage.sh
  167. echo "[9/9] Generating Linux app..."
  168. pushd build
  169. if [[ -n "$BUILD_IMAGE" ]]
  170. then
  171. $ROOT/build/src/BuildLinuxImage.sh -i
  172. else
  173. $ROOT/build/src/BuildLinuxImage.sh
  174. fi
  175. popd
  176. echo "done"