Advertisement
barjac

build-kdenlive.sh

Feb 14th, 2011
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 51.45 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # This script builds kdenlive from a configuration file
  4.  
  5. # It is meant to be called from Kdenlive Builder Wizard, but can also
  6. # be called from the cli
  7.  
  8. # List of programs used:
  9. # bash, test, tr, awk, ps, make, cmake, cat, sed, possibly others
  10.  
  11. # Note on feedback:
  12. # The caller can provide a dcop reference to a kmdr-executor running kdenlive builder wizard,
  13. # or just the word kdialog, or nothing
  14.  
  15. # Compilation instructions more or less taken from http://kdenlive.org/compile
  16.  
  17. # Author: Mads Bondo Dydensborg, mads@dydensborg.dk
  18. # License: GPL2
  19.  
  20. ################################################################################
  21. # ARGS AND GLOBALS
  22. ################################################################################
  23.  
  24. # Location of config file - if not overriden on command line
  25. CONFIGFILE=$HOME/.kdenliveBuilderWizard.rc
  26.  
  27. # If defined to 1, outputs trace log lines
  28. TRACE=1
  29.  
  30. # If defined to 1, outputs debug log lines
  31. DEBUG=1
  32.  
  33. # This is the minimum version of Qt and KDE required by kdenlive 4
  34. KDE4_MIN_QT=4.4.0
  35. KDE4_MIN_KDE=4.1.0
  36.  
  37. # We need to set LANG to C to avoid e.g. svn from getting to funky
  38. export LANG=C
  39.  
  40. # These are all of the configuration variables with defaults
  41. # You can also copy these into a config file to supply as a command line option.
  42. INSTALL_DIR="$HOME/kdenlive"
  43. AUTO_APPEND_DATE=1
  44. SOURCE_DIR="$INSTALL_DIR/src"
  45. ACTION_GET_COMPILE_INSTALL=1
  46. ACTION_GET_ONLY=0
  47. ACTION_COMPILE_INSTALL=0
  48. SOURCES_CLEAN=1
  49. INSTALL_AS_ROOT=0
  50. CREATE_STARTUP_SCRIPT=1
  51. KDENLIVE_HEAD=1
  52. KDENLIVE_REVISION=
  53. ENABLE_FREI0R=1
  54. FREI0R_HEAD=1
  55. FREI0R_REVISION=
  56. X264_HEAD=1
  57. X264_REVISION=
  58. LIBVPX_HEAD=1
  59. LIBVPX_REVISION=
  60. FFMPEG_HEAD=1
  61. FFMPEG_REVISION=
  62. FFMPEG_SUPPORT_H264=1
  63. FFMPEG_SUPPORT_XVID=1
  64. FFMPEG_SUPPORT_LIBVPX=1
  65. FFMPEG_SUPPORT_THEORA=1
  66. FFMPEG_SUPPORT_MP3=1
  67. FFMPEG_SUPPORT_FAAC=1
  68. FFMPEG_ADDITIONAL_OPTIONS= --enable-libgsm --enable-libdc1394 --disable-stripping --enable-avfilter --enable-libschroedinger --enable-libopencore-amrnb --enable-libopencore-amrwb
  69. MLT_HEAD=1
  70. MLT_REVISION=
  71. # QT_INCLUDE_DIR="$(pkg-config --variable=prefix QtCore)/include"
  72. QT_INCLUDE_DIR=
  73. # QT_LIB_DIR="$(pkg-config --variable=prefix QtCore)/lib"
  74. QT_LIB_DIR=
  75. MLT_DISABLE_SOX=0
  76.  
  77. ################################################################################
  78. # FUNCTION SECTION
  79. ################################################################################
  80.  
  81. #################################################################
  82. # usage
  83. # Reports legal options to this script
  84. function usage {
  85. echo "Usage: $0 [-c config-file] [-d dcop-ref] [-t] [-h]"
  86. echo "Where:"
  87. echo -e "\t-c config-file\tDefaults to $HOME/.kdenliveBuilderWizard.rc"
  88. echo -e "\t-d dcop-ref\tOne of 'kdialog' or dcop reference to existing kmdr-executor instance"
  89. echo -e "\t-t\t\tSpawn into sep. process"
  90. }
  91.  
  92. #################################################################
  93. # parse_args
  94. # Parses the arguments passed in $@ and sets some global vars
  95. function parse_args {
  96. CONFIGFILEOPT=""
  97. DCOPREF="none"
  98. DETACH=0
  99. while getopts ":tc:d:l:" OPT; do
  100. case $OPT in
  101. c ) CONFIGFILEOPT=$OPTARG
  102. echo Setting configfile to $CONFIGFILEOPT
  103. ;;
  104. d ) DCOPREF=$OPTARG
  105. echo Setting dcopref to $DCOPREF
  106. ;;
  107. t ) DETACH=1;;
  108. h ) usage
  109. exit 0;;
  110. * ) echo "Unknown option $OPT"
  111. usage
  112. exit 1;;
  113. esac
  114. done
  115.  
  116. # Check configfile
  117. if test "$CONFIGFILEOPT" != ""; then
  118. if test ! -r "$CONFIGFILEOPT" ; then
  119. echo "Unable to read config-file $CONFIGFILEOPT"
  120. exit 1
  121. fi
  122. CONFIGFILE="$CONFIGFILEOPT"
  123. fi
  124.  
  125. # Massage DCOP-REF
  126. case $DCOPREF in
  127. none)
  128. ;;
  129. kdialog)
  130. # Start kdialog instance, if DISPLAY is set
  131. if test "" = "$DISPLAY" ; then
  132. echo "DISPLAY not set, can not use -d kdialog"
  133. exit 1
  134. fi
  135. KDIALOG=`kdialog --title "Performing actions" --progressbar "Please wait" 0`
  136. if test 0 != $? ; then
  137. echo "Unable to start kdialog"
  138. exit 1
  139. fi
  140. DCOPREF=`echo $KDIALOG | awk -F\( '{print $2}' | awk -F\, '{print $1}'`
  141. if test 0 != $? -o "" = "$KDIALOG" -o "" = "$DCOPREF" ; then
  142. echo "Unable to understand kdialog response. Lost connection to it. Please kill it using xkill, if needed"
  143. exit 1
  144. fi
  145. ;;
  146. kmdr*)
  147. # Just plain OK.
  148. ;;
  149. *)
  150. echo "Illegal value for -d: $DCOPREF"
  151. exit -1
  152. ;;
  153. esac
  154. }
  155. ######################################################################
  156. # DATA HANDLING FUNCTIONS
  157. ######################################################################
  158.  
  159. #################################################################
  160. # to_key
  161. # Returns a numeric key from a known subproject
  162. # $1 : string: ffmpeg, mlt, mlt++ or kdenlive
  163. function to_key {
  164. case $1 in
  165. ffmpeg)
  166. echo 0
  167. ;;
  168. mlt)
  169. echo 1
  170. ;;
  171. kdenlive)
  172. echo 2
  173. ;;
  174. frei0r)
  175. echo 3
  176. ;;
  177. x264)
  178. echo 4
  179. ;;
  180. libvpx)
  181. echo 5
  182. ;;
  183. *)
  184. echo UNKNOWN
  185. ;;
  186. esac
  187. }
  188.  
  189. #################################################################
  190. # lookup - lookup a value from an array and return it
  191. # $1 array name, $2 subdir name, that is, text string
  192. function lookup {
  193. eval echo "\${${1}[`to_key $2`]}"
  194. }
  195.  
  196. ######################################################################
  197. # LOG FUNCTIONS
  198. ######################################################################
  199.  
  200. #################################################################
  201. # init_log_file
  202. # Write some init stuff
  203. function init_log_file {
  204. log `date`
  205. log $0 starting
  206. log Using $DCOPREF for feedback
  207. }
  208.  
  209. #################################################################
  210. # trace
  211. # Function that prints a trace line
  212. # $@ : arguments to be printed
  213. function trace {
  214. if test "1" = "$TRACE" ; then
  215. echo "KBWTRACE: $@"
  216. fi
  217. }
  218.  
  219. #################################################################
  220. # debug
  221. # Function that prints a debug line
  222. # $@ : arguments to be printed
  223. function debug {
  224. if test "1" = "$DEBUG" ; then
  225. echo "KBWDEBUG: $@"
  226. fi
  227. }
  228.  
  229. #################################################################
  230. # log
  231. # Function that prints a log line
  232. # $@ : arguments to be printed
  233. function log {
  234. echo "KBWLOG: $@"
  235. }
  236.  
  237. #################################################################
  238. # log warning
  239. # Function that prints a warning line
  240. # $@ : arguments to be printed
  241. function warn {
  242. echo "KBWWARN: $@"
  243. }
  244.  
  245. #################################################################
  246. # die
  247. # Function that prints a line and exists
  248. # $@ : arguments to be printed
  249. function die {
  250. echo "KBWERROR: $@"
  251. feedback_result FAILURE "Some kind of error occured: $@"
  252. exit -1
  253. }
  254.  
  255. #################################################################
  256. # cmd
  257. # Function that does a (non-background, non-outputting) command, after logging it
  258. function cmd {
  259. trace "Entering cmd @ = $@"
  260. log About to run command: "$@"
  261. "$@"
  262. }
  263.  
  264.  
  265. ######################################################################
  266. # SETUP FUNCTIONS
  267. ######################################################################
  268.  
  269. #################################################################
  270. # read_configuration
  271. # Reads $CONFIGFILE, parses it, and exports global variables reflecting the
  272. # content. Aborts, if the file does not exist or is not readable
  273. CONFIGURATION=""
  274. function read_configuration {
  275. trace "Entering read_configuration @ = $@"
  276. if test ! -r "$CONFIGFILE"; then
  277. warn "Unable to read config file $CONFIGFILE"
  278. return
  279. fi
  280. debug "Reading configuration from $CONFIGFILE"
  281. # This is for replacement in kdenlive_start
  282. for LINE in `tr "\t" "=" < $CONFIGFILE`; do
  283. debug Setting $LINE
  284. CONFIGURATION="$CONFIGURATION$LINE "
  285. export $LINE || die "Invalid export line: $LINE. Unable to set configuration options from CONFIGFILE"
  286. done ||\
  287. die "Unable to set configuration options from CONFIGFILE"
  288. }
  289.  
  290. #################################################################
  291. # set_globals
  292. # Set up globals based on configuration
  293. # This is where the configuration options for each subproject is assembled
  294. function set_globals {
  295. trace "Entering set_globals @ = $@"
  296. # Set two convenience variables.
  297. if test 1 = "$ACTION_GET_ONLY" -o 1 = "$ACTION_GET_COMPILE_INSTALL" ; then
  298. GET=1
  299. else
  300. GET=0
  301. fi
  302. NEED_SUDO=0
  303. if test 1 = "$ACTION_GET_COMPILE_INSTALL" -o 1 = "$ACTION_COMPILE_INSTALL" ; then
  304. COMPILE_INSTALL=1
  305. if test 1 = $INSTALL_AS_ROOT ; then
  306. NEED_SUDO=1
  307. fi
  308. else
  309. COMPILE_INSTALL=0
  310. fi
  311. debug "GET=$GET, COMPILE_INSTALL=$COMPILE_INSTALL, NEED_SUDO=$NEED_SUDO"
  312.  
  313. # The wizard sets CREATE_STARTUP_SCRIPT to true always, disable if not COMPILE_INSTALL
  314. if test 0 = "$COMPILE_INSTALL" ; then
  315. CREATE_STARTUP_SCRIPT=0
  316. fi
  317. debug "CREATE_STARTUP_SCRIPT=$CREATE_STARTUP_SCRIPT"
  318.  
  319. # Subdirs list, for number of common operations
  320. # Note, the function to_key depends on this
  321. #SUBDIRS="ffmpeg mlt kdenlive"
  322. SUBDIRS="ffmpeg mlt kdenlive"
  323. if test "$ENABLE_FREI0R" = 1 ; then
  324. SUBDIRS="frei0r $SUBDIRS"
  325. fi
  326. if test "$FFMPEG_SUPPORT_H264" = 1 && test "$X264_HEAD" = 1 -o "$X264_REVISION" != ""; then
  327. SUBDIRS="x264 $SUBDIRS"
  328. fi
  329. if test "$FFMPEG_SUPPORT_LIBVPX" = 1 && test "$LIBVPX_HEAD" = 1 -o "$LIBVPX_REVISION" != ""; then
  330. SUBDIRS="libvpx $SUBDIRS"
  331. fi
  332. debug "SUBDIRS = $SUBDIRS"
  333.  
  334. # REPOLOCS Array holds the repo urls
  335. #REPOLOCS[0]="svn://svn.mplayerhq.hu/ffmpeg/trunk"
  336. REPOLOCS[0]="git://git.ffmpeg.org/ffmpeg.git"
  337. REPOLOCS[1]="git://mltframework.org/mlt.git"
  338. REPOLOCS[2]="http://kdenlive.svn.sourceforge.net/svnroot/kdenlive/trunk/kdenlive"
  339. REPOLOCS[3]="git://code.dyne.org/frei0r.git"
  340. REPOLOCS[4]="git://git.videolan.org/x264.git"
  341. REPOLOCS[5]="git://review.webmproject.org/libvpx.git"
  342.  
  343. # REPOTYPE Array holds the repo types. (Yes, this might be redundant, but easy for me)
  344. REPOTYPES[0]="git"
  345. REPOTYPES[1]="git"
  346. REPOTYPES[2]="svn"
  347. REPOTYPES[3]="git"
  348. REPOTYPES[4]="git"
  349. REPOTYPES[5]="git"
  350.  
  351. # And, set up the revisions
  352. REVISIONS[0]=""
  353. if test 0 = "$FFMPEG_HEAD" -a "$FFMPEG_REVISION" ; then
  354. REVISIONS[0]="$FFMPEG_REVISION"
  355. fi
  356. # Git, just use blank or the hash.
  357. REVISIONS[1]=""
  358. if test 0 = "$MLT_HEAD" -a "$MLT_REVISION" ; then
  359. REVISIONS[1]="$MLT_REVISION"
  360. fi
  361. REVISIONS[2]="-r HEAD"
  362. if test 0 = "$KDENLIVE_HEAD" -a "$KDENLIVE_REVISION" ; then
  363. REVISIONS[2]="-r $KDENLIVE_REVISION"
  364. fi
  365. REVISIONS[3]=""
  366. if test 0 = "$FREI0R_HEAD" -a "$FREI0R_REVISION" ; then
  367. REVISIONS[3]="$FREI0R_REVISION"
  368. fi
  369. REVISIONS[4]=""
  370. if test 0 = "$X264_HEAD" -a "$X264_REVISION" ; then
  371. REVISIONS[4]="$X264_REVISION"
  372. fi
  373. REVISIONS[5]=""
  374. if test 0 = "$LIBVPX_HEAD" -a "$LIBVPX_REVISION" ; then
  375. REVISIONS[5]="$LIBVPX_REVISION"
  376. fi
  377.  
  378. # Figure out the install dir - we may not install, but then we know it.
  379. FINAL_INSTALL_DIR=$INSTALL_DIR
  380. if test 1 = "$AUTO_APPEND_DATE" ; then
  381. FINAL_INSTALL_DIR="$INSTALL_DIR/`date +'%Y%m%d'`"
  382. fi
  383. debug "Using install dir FINAL_INSTALL_DIR=$FINAL_INSTALL_DIR"
  384.  
  385. # Figure out the number of cores in the system. Used both by make and startup script
  386. TARGET_OS="$(uname -s)"
  387. if test "$TARGET_OS" = "Darwin"; then
  388. CPUS=$(sysctl -a hw | grep "ncpu:" | cut -d ' ' -f 2)
  389. else
  390. CPUS=$(grep "processor.*:" /proc/cpuinfo | wc -l)
  391. fi
  392. # Sanity check
  393. if test 0 = $CPUS ; then
  394. CPUS=1
  395. fi
  396. MAKEJ=$(( $CPUS + 1 ))
  397. debug "Using make -j$MAKEJ for compilation"
  398.  
  399. # CONFIG Array holds the ./configure (or equiv) command for each project
  400. # CFLAGS_ Array holds additional CFLAGS for the configure/make step of a given project
  401. # LDFLAGS_ Array holds additional LDFLAGS for the configure/make step of a given project
  402.  
  403. #####
  404. # ffmpeg
  405. CONFIG[0]="./configure --prefix=$FINAL_INSTALL_DIR --disable-doc --disable-network --disable-ffserver --enable-gpl --enable-version3 --enable-shared --enable-debug --enable-pthreads"
  406. if test 1 = "$FFMPEG_SUPPORT_THEORA" ; then
  407. CONFIG[0]="${CONFIG[0]} --enable-libtheora --enable-libvorbis"
  408. fi
  409. if test 1 = "$FFMPEG_SUPPORT_MP3" ; then
  410. CONFIG[0]="${CONFIG[0]} --enable-libmp3lame"
  411. fi
  412. if test 1 = "$FFMPEG_SUPPORT_FAAC" ; then
  413. # CONFIG[0]="${CONFIG[0]} --enable-libfaac --enable-libfaad --enable-nonfree"
  414. CONFIG[0]="${CONFIG[0]} --enable-libfaac --enable-nonfree"
  415. fi
  416.  
  417. if test 1 = "$FFMPEG_SUPPORT_XVID" ; then
  418. CONFIG[0]="${CONFIG[0]} --enable-libxvid"
  419. fi
  420.  
  421. if test 1 = "$FFMPEG_SUPPORT_H264" ; then
  422. CONFIG[0]="${CONFIG[0]} --enable-libx264"
  423. fi
  424. if test 1 = "$FFMPEG_SUPPORT_LIBVPX" ; then
  425. CONFIG[0]="${CONFIG[0]} --enable-libvpx"
  426. fi
  427. # Add optional parameters
  428. CONFIG[0]="${CONFIG[0]} $FFMPEG_ADDITIONAL_OPTIONS"
  429. CFLAGS_[0]="-I$FINAL_INSTALL_DIR/include $CFLAGS"
  430. LDFLAGS_[0]="-L$FINAL_INSTALL_DIR/lib $LDFLAGS"
  431.  
  432. #####
  433. # mlt
  434. #CONFIG[1]="./configure --prefix=$FINAL_INSTALL_DIR --enable-gpl --avformat-swscale --enable-motion-est --enable-debug"
  435. CONFIG[1]="./configure --prefix=$FINAL_INSTALL_DIR --enable-gpl --avformat-swscale --enable-motion-est --enable-debug"
  436. # Remember, if adding more of these, to update the post-configure check.
  437. [ "$TARGET_OS" = "Darwin" ] && CONFIG[1]="${CONFIG[1]} --disable-jackrack"
  438. [ "$QT_INCLUDE_DIR" ] && CONFIG[1]="${CONFIG[1]} --qimage-includedir=$QT_INCLUDE_DIR"
  439. [ "$QT_LIB_DIR" ] && CONFIG[1]="${CONFIG[1]} --qimage-libdir=$QT_LIB_DIR"
  440. if test "1" = "$MLT_DISABLE_SOX" ; then
  441. CONFIG[1]="${CONFIG[1]} --disable-sox"
  442. fi
  443. CFLAGS_[1]="-I$FINAL_INSTALL_DIR/include $CFLAGS"
  444. # Temporary patch until makefile for MLT corrected?
  445. #CFLAGS_[1]="${CFLAGS_[1]} -I$FINAL_INSTALL_DIR/include/libavcodec/ -I$FINAL_INSTALL_DIR/include/libavformat/ -I$FINAL_INSTALL_DIR/include/libswscale/ -I$FINAL_INSTALL_DIR/include/libavdevice"
  446. LDFLAGS_[1]="-L$FINAL_INSTALL_DIR/lib $LDFLAGS"
  447. # Note in the above, that we always looks for frei0r. User can do own install
  448. # it will be picked up.
  449.  
  450. #####
  451. # kdenlive
  452. CONFIG[2]="cmake -DCMAKE_INSTALL_PREFIX=$FINAL_INSTALL_DIR -DCMAKE_BUILD_TYPE=debugfull"
  453. [ "$TARGET_OS" = "Darwin" ] && CONFIG[2]="${CONFIG[2]} -DNO_JOGSHUTTLE=1"
  454. #CFLAGS_[2]="${CFLAGS_[1]}"
  455. CFLAGS_[2]="-I$FINAL_INSTALL_DIR/include $CFLAGS"
  456. LDFLAGS_[2]=$LDFLAGS
  457. # And a very special bonus for kdenlivebuildwizard
  458. LD_LIBRARY_PATH_[2]="$FINAL_INSTALL_DIR/lib:$LD_LIBRARY_PATH"
  459.  
  460. ####
  461. # frei0r
  462. CONFIG[3]="./configure --prefix=$FINAL_INSTALL_DIR"
  463. CFLAGS_[3]=$CFLAGS
  464. LDFLAGS_[3]=$LDFLAGS
  465.  
  466. ####
  467. # x264
  468. CONFIG[4]="./configure --prefix=$FINAL_INSTALL_DIR --disable-lavf --disable-ffms --disable-gpac --disable-swscale --enable-shared"
  469. CFLAGS_[4]=$CFLAGS
  470. [ "$TARGET_OS" = "Darwin" ] && CFLAGS_[4]="-I. -fno-common -read_only_relocs suppress ${CFLAGS_[4]} "
  471. LDFLAGS_[4]=$LDFLAGS
  472.  
  473. ####
  474. # libvpx
  475. CONFIG[5]="./configure --prefix=$FINAL_INSTALL_DIR --enable-vp8 --enable-postproc --enable-multithread --disable-install-docs --disable-debug-libs --disable-examples"
  476. [ "$TARGET_OS" = "Linux" ] && CONFIG[5]="${CONFIG[5]} --enable-shared"
  477. CFLAGS_[5]=$CFLAGS
  478. # [ "$TARGET_OS" = "Darwin" ] && CFLAGS_[5]="-I. -fno-common -read_only_relocs suppress ${CFLAGS_[5]} "
  479. LDFLAGS_[5]=$LDFLAGS
  480. }
  481.  
  482. ######################################################################
  483. # FEEDBACK FUNCTIONS
  484. ######################################################################
  485.  
  486. #################################################################
  487. # feedback_init
  488. # $1 : ProgressBar maximum
  489. # Resets the progressbar or textual output based on DCOPREF
  490. function feedback_init {
  491. trace "Entering feedback_init @ = $@"
  492. case $DCOPREF in
  493. none)
  494. log Total number of steps needed to complete $1
  495. log Press Ctrl+C to abort
  496. ;;
  497. kdialog*)
  498. cmd dcop $DCOPREF ProgressDialog setTotalSteps $1 || \
  499. warn Unable to setTotalSteps on ProgressBar
  500. cmd dcop $DCOPREF ProgressDialog showCancelButton true || \
  501. warn Unable to show Cancel button on kdialog instance
  502. ;;
  503. kmdr*)
  504. cmd dcop $DCOPREF KommanderIf setMaximum ProgressBar $1 || \
  505. warn Unable to setMaximum on ProgressBar
  506. ;;
  507. esac
  508. PROGRESS=0
  509. feedback_set_progress $PROGRESS
  510. }
  511.  
  512. #################################################################
  513. # feedback_progress
  514. # $1 : ProgressBar position
  515. # Sets the progressbar position or textual output based on DCOPREF
  516. function feedback_set_progress {
  517. trace "Entering feedback_set_progress @ = $@"
  518. case $DCOPREF in
  519. none)
  520. log Number of steps completed : $1
  521. ;;
  522. kdialog*)
  523. cmd dcop $DCOPREF ProgressDialog setProgress $1 || \
  524. warn Unable to setProgress on ProgressBar
  525. ;;
  526. kmdr*)
  527. cmd dcop $DCOPREF KommanderIf setText ProgressBar $1 || \
  528. warn Unable to setProgress on ProgressBar
  529. ;;
  530. esac
  531. }
  532.  
  533. #################################################################
  534. # feedback_status
  535. # $@ status information
  536. # Displays/Appends status, based on DCOPREF
  537. function feedback_status {
  538. trace "Entering feedback_status @ = $@"
  539. # Need to collect $@ in a single variable for cmd to work
  540. ARG=$@
  541. case $DCOPREF in
  542. none)
  543. log "$ARG"
  544. ;;
  545. kdialog*)
  546. cmd dcop $DCOPREF ProgressDialog setLabel "$ARG" || \
  547. warn Unable to setLabel on ProgressDialog
  548. ;;
  549. kmdr*)
  550. cmd dcop $DCOPREF KommanderIf setText LabelFeedback "$ARG" || \
  551. warn Unable to update gui status
  552. cmd dcop $DCOPREF KommanderIf execute ScriptObjectAddStatusLine || \
  553. warn Unable to update gui status - execute failed
  554. ;;
  555. esac
  556. }
  557.  
  558. #################################################################
  559. # feedback_result
  560. # $1 : SUCCESS, FAILURE, ABORTED
  561. # $2 : Additional information
  562. # Does the relevant feedback, and terminates.
  563. function feedback_result {
  564. trace "Entering feedback_result @ = $@"
  565.  
  566. # If needed, kill the checker process
  567. if test "" != "$CHECKERPID" ; then
  568. # Kill the checker process
  569. kill -9 $CHECKERPID &> /dev/null
  570. fi
  571.  
  572. case $DCOPREF in
  573. none)
  574. log "Process has finished. Reason: $@"
  575. ;;
  576. kdialog*)
  577. cmd dcop $DCOPREF ProgressDialog close || \
  578. warn Unable to close feedback dialog
  579. ARG=$@
  580. cmd kdialog --title "Process has finished" --msgbox '<html><p>Reason: '"$ARG"'.</p><p>Click OK to continue.</p><p>Consult the output for more information.</p>'
  581. ;;
  582. kmdr*)
  583. ARG=$@
  584. feedback_status $ARG
  585. cmd dcop $DCOPREF KommanderIf setText LabelFinalResult "$ARG" ||
  586. warn Unable to notify GUI of final result status
  587. cmd dcop $DCOPREF KommanderIf execute ScriptObjectDone || \
  588. warn Unable to notify GUI that I am done
  589. ;;
  590. esac
  591. }
  592.  
  593.  
  594. #################################################################
  595. # feedback_progress
  596. # $@ : Description of task completed
  597. # Increases the progressbar with 1 and sets the status to $@
  598. function feedback_progress {
  599. trace "Entering feedback_progress @ = $@"
  600. PROGRESS=$(( $PROGRESS + 1 ))
  601. feedback_status $@
  602. feedback_set_progress $PROGRESS
  603. }
  604.  
  605. #################################################################
  606. # prepare_feedback
  607. # Function to prepare the feedback. E.g. set up max progress steps
  608. # Based on configuration read and the DCOPREF variable
  609. function prepare_feedback {
  610. trace "Entering prepare_feedback @ = $@"
  611. # Figure out the number of steps
  612. # Get adds 8 if cleaning, 4 otherwise (2/1 pr. proj)
  613. # Compile/Install adds 12 (3/proj)
  614. # Script install adds 1
  615. NUMSTEPS=0
  616. if test 1 = "$GET" ; then
  617. debug Adding 3 steps for get
  618. NUMSTEPS=$(( $NUMSTEPS + 3 ))
  619. if test 1 = "$ENABLE_FREI0R" ; then
  620. debug Adding 1 step for get frei0r
  621. NUMSTEPS=$(( $NUMSTEPS + 1 ))
  622. fi
  623. fi
  624. if test 1 = "$GET" -a 1 = "$SOURCES_CLEAN" ; then
  625. debug Adding 3 steps for clean on get
  626. NUMSTEPS=$(( $NUMSTEPS + 3 ))
  627. if test 1 = "$ENABLE_FREI0R" ; then
  628. debug Adding 1 step for clean frei0r
  629. NUMSTEPS=$(( $NUMSTEPS + 1 ))
  630. fi
  631. fi
  632. if test 1 = "$COMPILE_INSTALL" ; then
  633. debug Adding 9 steps for compile-install
  634. NUMSTEPS=$(( $NUMSTEPS + 9 ))
  635. if test 1 = "$ENABLE_FREI0R" ; then
  636. debug Adding 3 steps for compile-install frei0r
  637. NUMSTEPS=$(( $NUMSTEPS + 3 ))
  638. fi
  639. fi
  640. if test 1 = "$CREATE_STARTUP_SCRIPT" ; then
  641. debug Adding 1 step for script creating
  642. NUMSTEPS=$(( $NUMSTEPS + 1 ))
  643. fi
  644. log Number of steps determined to $NUMSTEPS
  645. feedback_init $NUMSTEPS
  646. }
  647.  
  648. #################################################################
  649. # check_abort
  650. # Function that checks if the user wanted to cancel what we are doing.
  651. # returns "stop" or "cont" as appropiate
  652. function check_abort {
  653. case $DCOPREF in
  654. none)
  655. # log "$ARG"
  656. ;;
  657. kdialog*)
  658. wasCancelled=`dcop $DCOPREF ProgressDialog wasCancelled`
  659. if test 0 != $? -o "true" == $wasCancelled ; then
  660. # Assume it failed, because the user killed the dialog
  661. echo stop
  662. else
  663. echo cont
  664. fi
  665. ;;
  666. kmdr*)
  667. wasCancelled=`dcop $DCOPREF KommanderIf text LabelAbort`
  668. if test 0 != $? ; then
  669. # Assume it failed, because the user killed the dialog
  670. echo stop
  671. else
  672. echo $wasCancelled
  673. fi
  674. ;;
  675. esac
  676. }
  677.  
  678. ######################################################################
  679. # GLOBAL TEST FUNCTIONS
  680. ######################################################################
  681.  
  682. #################################################################
  683. # is_newer_equal
  684. # Compares versions strings, and returns 1 if $1 is newer than $2
  685. # This is highly ineffective, I am sorry to say...
  686. function is_newer_equal {
  687. trace "Entering is_newer_equal @ = $@"
  688. A1=`echo $1 | cut -d. -f1`
  689. A2=`echo $1 | cut -d. -f2`
  690. A3=`echo $1 | cut -d. -f3 | sed 's/^\([0-9]\{1,3\}\).*/\1/'`
  691. B1=`echo $2 | cut -d. -f1`
  692. B2=`echo $2 | cut -d. -f2`
  693. B3=`echo $2 | cut -d. -f3 | sed 's/^\([0-9]\{1,3\}\).*/\1/'`
  694. debug "A = $A1 $A2 $A3, B = $B1 $B2 $B3"
  695. test "$A1" -gt "$B1" -o \( "$A1" = "$B1" -a "$A2" -gt "$B2" \) -o \( "$A1" = "$B1" -a "$A2" = "$B2" -a "$A3" -ge "$B3" \)
  696. }
  697.  
  698. #################################################################
  699. # test_kde4_available
  700. # Tests that qt and kde is high enough version to enable kde4
  701. function test_kde4_available {
  702. trace "Entering test_kde4_available @ = $@"
  703. cmd kde4-config -v || die "Unable to run kde4-config"
  704. QT_VER=`kde4-config -v | grep -i Qt: | awk '{print $2}'`
  705. KDE_VER=`kde4-config -v | grep -i KDE: | awk '{print $2}'`
  706. debug "Versions found: QT: $QT_VER, KDE: $KDE_VER"
  707. is_newer_equal $QT_VER $KDE4_MIN_QT && is_newer_equal $KDE_VER $KDE4_MIN_KDE
  708. if test 0 != $? ; then
  709. die "Building kdenlive for KDE4 was selected, but sufficiently new versions of KDE4 and Qt4 was not found. Needed KDE version $KDE4_MIN_KDE, found $KDE_VER. Needed Qt version $KDE4_MIN_QT, found $QT_VER"
  710. fi
  711. }
  712.  
  713. ######################################################################
  714. # ACTION GET FUNCTIONS
  715. ######################################################################
  716.  
  717. #################################################################
  718. # make_clean_dir
  719. # Make clean in a specific directory
  720. # $1: The directory to make clean in.
  721. # Any errors are ignored. Make clean is only called if cd success.
  722. # Assumes cwd is common parent dir
  723. function make_clean_dir {
  724. trace "Entering make_clean_dir @ = $@"
  725. log Make clean for $1 called
  726. feedback_status "Cleaning out sources for $1"
  727. cmd pushd .
  728. # Special hack for ffmpeg, it sometimes requires distclean to work.
  729. if test "ffmpeg" = "$1" ; then
  730. cmd cd $1 && cmd make distclean
  731. else
  732. cmd cd $1 && cmd make clean
  733. fi
  734. feedback_progress Cleaned up in $1
  735. cmd popd
  736. }
  737.  
  738. #################################################################
  739. # clean_dirs
  740. # Make clean in all directories
  741. function clean_dirs {
  742. trace "Entering clean_dirs @ = $@"
  743. feedback_status Cleaning out all subdirs
  744. cmd cd $SOURCE_DIR || mkdir -p $SOURCE_DIR
  745. cmd cd $SOURCE_DIR || die "Unable to change to directory $SOURCE_DIR"
  746. for DIR in $SUBDIRS ; do
  747. make_clean_dir $DIR
  748. done
  749. feedback_status Done cleaning out in source dirs
  750. }
  751.  
  752. #################################################################
  753. # get_subproject
  754. # $1 The sourcedir to get sources for
  755. # Get the sources for a single project
  756. # Assumes cwd is common parent dir
  757. # Errors abort
  758. function get_subproject {
  759. trace "Entering get_subproject @ = $@"
  760. feedback_status Getting or updating source for $1 - this could take some time
  761. cmd pushd .
  762.  
  763. # Check for repository setyp
  764. REPOTYPE=`lookup REPOTYPES $1`
  765. REPOLOC=`lookup REPOLOCS $1`
  766. REVISION=`lookup REVISIONS $1`
  767. debug "REPOTYPE=$REPOTYPE, REPOLOC=$REPOLOC, REVISION=$REVISION"
  768.  
  769. # Note that svn can check out to current directory, whereas git will not. Sigh.
  770. if test "git" = "$REPOTYPE" ; then
  771. # If the dir is there, check if it is a git repo
  772. if test -d "$1" ; then
  773. # Change to it
  774. cmd cd $1 || die "Unable to change to directory $1"
  775. debug "About to look for git repo"
  776. git --no-pager status 2>&1 | grep "fatal" &> /dev/null
  777. if test 0 != $? ; then
  778. # Found git repo
  779. debug "Found git repo, will update"
  780. feedback_status "Pulling git sources for $1"
  781. cmd git --no-pager pull $REPOLOC master || die "Unable to git pull sources for $1"
  782. cmd git --no-pager checkout $REVISION || die "Unable to git checkout $REVISION"
  783. else
  784. # A dir with the expected name, but not a git repo, bailing out
  785. PWD=`pwd`
  786. die "Found a dir with the expected name $1 ($PWD), but it was not a git repo. Unable to proceed. If you have old mlt/mlt++ sources, please delete these directories, before rerunning the wizard."
  787. fi
  788. else
  789. # No git repo
  790. debug "No git repo, need to check out"
  791. feedback_status "Cloning git sources for $1"
  792. cmd git --no-pager clone $REPOLOC || die "Unable to git clone source for $1 from $REPOLOC"
  793. cmd cd $1 || die "Unable to change to directory $1"
  794. cmd git --no-pager checkout $REVISION || die "Unable to git checkout $REVISION"
  795. fi
  796. else
  797. # Create subdir if not exist
  798. if test ! -d "$1" ; then
  799. cmd mkdir -p $1 || die "Unable to create directory $1"
  800. fi
  801. # Change to it
  802. cmd cd $1 || die "Unable to change to directory $1"
  803. FIND_STR="\(Revision\|Last\ Changed\ Date\)"
  804. debug "About to look for SVN revision info for $REPOLOC $REVISION"
  805. svn --non-interactive info | grep "$FIND_STR"
  806. if test 0 = $? ; then
  807. debug "Found existing SVN checkout"
  808. # Found svn info
  809. # For KDENLIVE: If the svn info URL matches the one we have in the REPOLOCS array, do an update, otherwise, do a switch.
  810. REPOLOCURL=`svn --non-interactive info | grep URL | awk '{print $2}'`
  811. # Now, we have to be a bit clever here, because if the user originally checked it out using
  812. # https, we can not change to http. So, we check for https in the current URL
  813. # Note, that beeing clever almost always fails at some point. But, at least we give it a try...
  814. if test "${REPOLOCURL:0:5}" = "https" ; then
  815. REPOLOC=${REPOLOC/http/https}
  816. fi
  817. if test "kdenlive" = "$1" -a $REPOLOCURL != $REPOLOC ; then
  818. warn "Existing url $REPOLOCURL for $1 does not match the url for selected version: $REPOLOC. Trying svn switch to update"
  819. feedback_status "Trying to switch repo url for $1"
  820. cmd svn --non-interactive switch $REPOLOC $REVISION || die "Unable to switch svn repo from $REPOLOCURL to $REPOLOC $REVISION"
  821. else
  822. feedback_status "Updating SVN sources for $1"
  823. cmd svn --non-interactive update $REVISION || die "Unable to update SVN repo in $1 to $REVISION"
  824. fi
  825. else
  826. # No svn info
  827. feedback_status "Getting SVN sources for $1"
  828. cmd svn --non-interactive co $REPOLOC . $REVISION || die "Unable to get SVN source for $1 from $REPOLOC $REVISION"
  829. fi
  830. fi # git/svn
  831.  
  832. feedback_progress Done getting or updating source for $1
  833. cmd popd
  834. }
  835.  
  836. #################################################################
  837. # get_all_sources
  838. # Gets all the sources for all subprojects
  839. function get_all_sources {
  840. trace "Entering get_all_sources @ = $@"
  841. feedback_status Getting all sources
  842. log Changing to $SOURCE_DIR
  843. cd $SOURCE_DIR || mkdir -p "$SOURCE_DIR"
  844. cd $SOURCE_DIR || die "Unable to change to directory $SOURCE_DIR"
  845. for DIR in $SUBDIRS ; do
  846. get_subproject $DIR
  847. done
  848. feedback_status Done getting all sources
  849. }
  850.  
  851. ######################################################################
  852. # ACTION COMPILE-INSTALL FUNCTIONS
  853. ######################################################################
  854.  
  855. #################################################################
  856. # mlt_format_required
  857. # log a string that expresses a requirement
  858. function mlt_format_required {
  859. log 'MLTDISABLED <b>'$1'</b> : this is a <b>required</b> module. '$2'Will abort compilation.'
  860. }
  861.  
  862. #################################################################
  863. # mlt_format_optional
  864. # log a string that expresses missing an optional
  865. function mlt_format_optional {
  866. log 'MLTDISABLED <b>'$1'</b> : this is an <b>optional</b> module that provides '$2'. To enable it, try installing a package called something like '$3'.'
  867. }
  868.  
  869. #################################################################
  870. # mlt_check_configure
  871. # This is a special hack for mlt. Mlt does not allow --enable, or abort
  872. # if something is missing, so we check all the disable files. Some are
  873. # optional, some are required. We stop compilation if a required file is
  874. # missing. For optionals, we report them to the log
  875. # Oh, and it is assumed we are in the toplevel mlt source directory, when
  876. # this is called.
  877. function mlt_check_configure {
  878. trace "Entering check_mlt_configure @ = $@"
  879. cmd pushd .
  880. DODIE=0
  881. cmd cd src/modules || die "Unable to check mlt modules list"
  882. for FILE in `ls disable-* 2>/dev/null` ; do
  883. debug "Checking $FILE"
  884. case $FILE in
  885. # REQUIRED
  886. disable-core)
  887. mlt_format_required core "I have no idea why this was disabled. "
  888. DODIE=1
  889. ;;
  890. disable-avformat)
  891. mlt_format_required avformat "Did ffmpeg installation fail? "
  892. DODIE=1
  893. ;;
  894. disable-xml)
  895. mlt_format_required xml "Please install libxml2-dev. "
  896. DODIE=1
  897. ;;
  898. disable-sdl)
  899. mlt_format_required sdl "Please install libsdl1.2-dev. "
  900. DODIE=1
  901. ;;
  902. disable-qimage)
  903. mlt_format_required qimage "Please provide paths for QImage on the 'Compile options' page. "
  904. DODIE=1
  905. ;;
  906.  
  907. # AUDIO
  908. disable-sox)
  909. if test "0" = "$MLT_DISABLE_SOX" ; then
  910. mlt_format_optional sox "sound effects/operations" "sox-dev"
  911. DODIE=1
  912. fi
  913. ;;
  914. disable-jackrack)
  915. mlt_format_optional jackrack "sound effects/operations" "libjack-dev"
  916. ;;
  917. disable-resample)
  918. mlt_format_optional resample "audio resampling" "libsamplerate0-dev"
  919. ;;
  920.  
  921. # IMAGE
  922. disable-gtk2)
  923. mlt_format_optional gtk2 "some additional image loading support" "libgtk2-dev?"
  924. ;;
  925. disable-kdenlive)
  926. mlt_format_optional kdenlive "slow motion and freeze effects" "??"
  927. ;;
  928. disable-frei0r)
  929. mlt_format_optional frei0r "plugin architecture. Several additional effects and transitions" "see http://www.piksel.org/frei0r"
  930. ;;
  931.  
  932. # OTHERS
  933. disable-dv)
  934. mlt_format_optional dv "loading and saving of DV files" "libdv/libdv-dev"
  935. ;;
  936. disable-vorbis)
  937. mlt_format_optional vorbis "loading and saving ogg/theora/vorbis files" "libvorbis-dev"
  938. ;;
  939.  
  940. # FALLBACK
  941. disable-*)
  942. mlt_format_optional ${FILE/disable-} "... dunno ... " "... dunno ..."
  943. ;;
  944. esac
  945. done
  946. if test 1 = "$DODIE" ; then
  947. die "One or more required MLT modules could not be enabled"
  948. fi
  949. cmd popd
  950. }
  951.  
  952. #################################################################
  953. # configure_compile_install_subproject
  954. # $1 The sourcedir to configure, compile, and install
  955. # Configures, compiles, and installs a single subproject.
  956. # Assumes cwd is common parent dir
  957. # Errors abort
  958. function configure_compile_install_subproject {
  959. trace "Entering configure_compile_install_subproject @ = $@"
  960. feedback_status Configuring, compiling, and installing $1
  961.  
  962. OLDCFLAGS=$CFLAGS
  963. OLDLD_LIBRARY_PATH=$LD_LIBRARY_PATH
  964. cmd pushd .
  965.  
  966. # Change to right directory
  967. cmd cd $1 || die "Unable to change to directory $1"
  968.  
  969. # Set cflags, log settings
  970. log PATH=$PATH
  971. log LD_RUN_PATH=$LD_RUN_PATH
  972. log PKG_CONFIG_PATH=$PKG_CONFIG_PATH
  973. export CFLAGS=`lookup CFLAGS_ $1`
  974. log CFLAGS=$CFLAGS
  975. export LDFLAGS=`lookup LDFLAGS_ $1`
  976. log LDFLAGS=$LDFLAGS
  977.  
  978. # Configure
  979. feedback_status Configuring $1
  980. # Special hack for kdenlive
  981. if test "kdenlive" = "$1" ; then
  982. cmd rm -f CMakeCache.txt || die "Unable to configure $1"
  983. fi
  984. # Special hack for frei0r
  985. if test "frei0r" = "$1" -a ! -e configure ; then
  986. debug "Need to crate configure for frei0r"
  987. cmd ./autogen.sh || die "Unable to create configure file for $1"
  988. if test ! -e configure ; then
  989. die "Unable to confirm presence of configure file for $1"
  990. fi
  991. fi
  992. cmd `lookup CONFIG $1` || die "Unable to configure $1"
  993. feedback_progress Done configuring $1
  994.  
  995. # Special hack for mlt, post-configure
  996. if test "mlt" = "$1" ; then
  997. mlt_check_configure
  998. fi
  999.  
  1000. # Compile
  1001. feedback_status Building $1 - this could take some time
  1002. cmd make -j$MAKEJ || die "Unable to build $1"
  1003. feedback_progress Done building $1
  1004.  
  1005. # Install
  1006. feedback_status Installing $1
  1007. # This export is only for kdenlive, really, and only for the install step
  1008. export LD_LIBRARY_PATH=`lookup LD_LIBRARY_PATH_ $1`
  1009. log "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
  1010. if test "1" = "$NEED_SUDO" ; then
  1011. debug "Needs to be root to install - trying"
  1012. log About to run $SUDO make install
  1013. TMPNAME=`mktemp -t kbw.installoutput.XXXXXXXXX`
  1014. # At least kdesudo does not return an error code if the program fails
  1015. # Filter output for error, and dup it to the log
  1016. $SUDO make install > $TMPNAME 2>&1
  1017. cat $TMPNAME 2>&1
  1018. # If it contains error it returns 0. 1 matches, 255 errors
  1019. # Filter X errors out too
  1020. grep -v "X Error" $TMPNAME | grep -i error 2>&1
  1021. if test 0 = $? ; then
  1022. die "Unable to install $1"
  1023. fi
  1024. else
  1025. cmd make install || die "Unable to install $1"
  1026. fi
  1027. feedback_progress Done installing $1
  1028.  
  1029. # Reestablish
  1030. cmd popd
  1031. export CFLAGS=$OLDCFLAGS
  1032. export LD_LIBRARY_PATH=$OLDLD_LIBRARY_PATH
  1033. }
  1034.  
  1035.  
  1036. #################################################################
  1037. # configure_compile_install_all
  1038. # Configures, compiles, and installs all subprojects
  1039. function configure_compile_install_all {
  1040. trace "Entering configure_compile_install_all @ = $@"
  1041. feedback_status Configuring, compiling and installing all sources
  1042.  
  1043. # Set some more vars for this operation
  1044. log "Using install dir $FINAL_INSTALL_DIR"
  1045. log "Found $CPUS cpus. Will use make -j $MAKEJ for compilation"
  1046.  
  1047. # set global settings for all jobs
  1048. export PATH="$FINAL_INSTALL_DIR/bin:$PATH"
  1049. export LD_RUN_PATH="$FINAL_INSTALL_DIR/lib"
  1050. export PKG_CONFIG_PATH="$FINAL_INSTALL_DIR/lib/pkgconfig:$PKG_CONFIG_PATH"
  1051.  
  1052. log Changing to $SOURCE_DIR
  1053. cd $SOURCE_DIR || die "Unable to change to directory $SOURCE_DIR"
  1054. for DIR in $SUBDIRS ; do
  1055. configure_compile_install_subproject $DIR
  1056. done
  1057. feedback_status Done configuring, compiling and installing all sources
  1058. }
  1059.  
  1060. ######################################################################
  1061. # ACTION CREATE_STARTUP_SCRIPT
  1062. ######################################################################
  1063.  
  1064.  
  1065. #################################################################
  1066. # get_dir_info
  1067. # Helper function for startup script creating - returns svn rev information
  1068. # for a given directory
  1069. function get_dir_info {
  1070. # trace "Entering get_dir_info @ = $@"
  1071. pushd . &> /dev/null
  1072. cd $1 || die "Unable to change directory to $1"
  1073. REPOTYPE=`lookup REPOTYPES $1`
  1074. if test "xgit" = "x$REPOTYPE" ; then
  1075. FIND_STR="\(commit\|Date\)"
  1076. INFO_TEXT=`git --no-pager log -n1 | grep "$FIND_STR"`
  1077. else
  1078. FIND_STR="\(Revision\|Last\ Changed\ Date\)"
  1079. INFO_TEXT=`svn info | grep "$FIND_STR"`
  1080. fi
  1081. echo
  1082. echo -e $1: ${INFO_TEXT:-Warning: No $REPOTYPE information found in $SOURCE_DIR/$1.}
  1083. echo
  1084. popd &> /dev/null
  1085. }
  1086.  
  1087. #################################################################
  1088. # sys_info
  1089. # Returns some information about the system
  1090. function sys_info {
  1091. echo
  1092. echo uname -a at time of compilation:
  1093. uname -a
  1094. echo Information about cc at the time of compilation:
  1095. LANG=C cc -v 2>&1
  1096. if which dpkg ; then
  1097. echo Found dpkg - running dpkg -l to grep libc6
  1098. dpkg -l | grep libc6
  1099. else
  1100. if which rpm ; then
  1101. echo Found rpm - running rpm -qa to grep libc6
  1102. rpm -qa | grep libc
  1103. else
  1104. echo Found neither dpkg or rpm...
  1105. fi
  1106. fi
  1107. if test 1 = "$USE_KDE4" ; then
  1108. echo Information about kde 4 at the time of compilation:
  1109. kde4-config -v
  1110. else
  1111. echo Information about kde 3 at the time of compilation:
  1112. kde-config -v
  1113. fi
  1114. }
  1115.  
  1116. #################################################################
  1117. # create_startup_script
  1118. # Creates a startup script. Note, that the actual script gets
  1119. # embedded by the Makefile
  1120. function create_startup_script {
  1121. trace "Entering create_startup_script @ = $@"
  1122. pushd .
  1123.  
  1124. log Changing to $SOURCE_DIR
  1125. cd $SOURCE_DIR || die "Unable to change to directory $SOURCE_DIR"
  1126. INFO=$INFO"Information about revisions of modules at the time of compilation:"
  1127. for DIR in $SUBDIRS ; do
  1128. INFO=$INFO`get_dir_info $DIR`
  1129. done
  1130. INFO=$INFO`sys_info`
  1131.  
  1132. TMPFILE=`mktemp -t kbw.start.XXXXXXXXX`
  1133. log Creating startup script in $TMPFILE
  1134. # Note, the content of the template below is inserted by embed_start.pl
  1135. cat > $TMPFILE <<End-of-startup-script-template
  1136. #!/bin/bash
  1137.  
  1138. # Script to start kdenlive as installed by Kdenlive Builder Wizard.
  1139. # The user can select to start kdenlive in two different ways: using gdb or non-gdb
  1140.  
  1141. # Check for arguments:
  1142. # This script answers to --version and then passes it to kdenlive
  1143. # --help is passed directly to kdenlive
  1144. # all other, uses the gui questions
  1145. # If none is given, pass verything to kdenlive proper
  1146.  
  1147. # Set up environment
  1148. export INSTALL_DIR=$FINAL_INSTALL_DIR
  1149. export PATH=\$INSTALL_DIR/bin:\$PATH
  1150. export LD_LIBRARY_PATH=\$INSTALL_DIR/lib:\$INSTALL_DIR/lib/frei0r-1:\$LD_LIBRARY_PATH
  1151. if [ "$TARGET_OS" = "Darwin" ]; then
  1152. export PATH="\$INSTALL_DIR/bin/kdenlive.app/Contents/MacOS:\$PATH"
  1153. export DYLD_LIBRARY_PATH="\$LD_LIBRARY_PATH"
  1154. CPUS=\$(sysctl -a hw | grep "ncpu:" | cut -d ' ' -f 2)
  1155. else
  1156. CPUS=\$(grep "processor\s*:" /proc/cpuinfo | wc -l)
  1157. fi
  1158. export MLT_AVFORMAT_THREADS=\$((\$CPUS - 1))
  1159. export MLT_PATH=\$INSTALL_DIR
  1160. export MLT_REPOSITORY=\$INSTALL_DIR/lib/mlt
  1161. export MLT_DATA=\$INSTALL_DIR/share/mlt
  1162. export MLT_PROFILES_PATH=\$INSTALL_DIR/share/mlt/profiles
  1163. export MLT_FREI0R_PLUGIN_PATH=\$INSTALL_DIR/lib/frei0r-1/:/usr/lib/frei0r-1:/usr/local/lib/frei0r-1:/opt/local/lib/frei0r-1
  1164. export MANPATH=\$MANPATH:\$INSTALL_DIR/share/man/
  1165. export PKG_CONFIG_PATH=\$INSTALL_DIR/lib/pkgconfig/:\$PKG_CONFIG_PATH
  1166.  
  1167. # We need to set LANG to C to avoid e.g. kde4-config from getting to
  1168. # funky, but we do not want kdenlive to run with it, so store the
  1169. # true lang too.
  1170. export TRUE_LANG=\$LANG
  1171. export LANG=C
  1172.  
  1173. ################################################################################
  1174. # Usage
  1175. function usage() {
  1176. echo "\$0 [options] files"
  1177. echo
  1178. echo " -v, --version Show version information"
  1179. echo " --help-start Show this help"
  1180. echo " -g, --gdb Start in gdb mode (no dialog)"
  1181. echo " -n, --normal Start in normal mode (no dialog)"
  1182. }
  1183.  
  1184. WAY_TO_RUN=""
  1185. declare -a kdenlive_args
  1186. while test "" != "\$1" ; do
  1187. case \$1 in
  1188. -v|--version)
  1189. echo "Kdenlive Builder Wizard version: $VERSION"
  1190. grep -e "Revision:" -e "commit" \$0 | grep -v grep
  1191. kdenlive "\$@"
  1192. exit 0
  1193. ;;
  1194. -h|--help)
  1195. echo "For kdenlive_start options, use --help-start"
  1196. kdenlive "\$@"
  1197. exit 0
  1198. ;;
  1199. --help-start)
  1200. usage
  1201. exit 0
  1202. ;;
  1203. -g|--gdb)
  1204. WAY_TO_RUN="GDB"
  1205. shift
  1206. ;;
  1207. -n|--normal)
  1208. WAY_TO_RUN="Normal"
  1209. shift
  1210. ;;
  1211. *)
  1212. kdenlive_args=(\${kdenlive_args[@]} "\$1")
  1213. shift
  1214. ;;
  1215. esac
  1216. done
  1217.  
  1218. # We need kdialog and gdb to provide the user with an option to run it in gdb.
  1219. # If kdialog is not present, nevermind.
  1220. if test "\$WAY_TO_RUN" == "" ; then
  1221. which gdb kdialog &> /dev/null
  1222. if test 0 = \$? ; then
  1223. # Found gdb, ask for way to run it
  1224. WAY_TO_RUN=\`kdialog --combobox "<html><p><b>Starting kdenlive from \$INSTALL_DIR</b></p><p>Kdenlive can be started in two different ways, please select the way you wish to use.</p><p><b>Normal</b> Normal mode, for normal use</p><p><b>GDB output capture</b> Capture output from kdenlive in the Gnu Debugger in a format suitable for a crash report. Use when trying to isolate a bug</p><p>If in doubt, just click the Ok button.</p></html>" "Normal" "GDB output capture"\`
  1225. if test 0 != \$? ; then
  1226. # User clicked cancel
  1227. exit
  1228. fi
  1229. else
  1230. WAY_TO_RUN="Normal"
  1231. fi
  1232. fi
  1233.  
  1234. echo Way to run = \$WAY_TO_RUN
  1235.  
  1236. case \$WAY_TO_RUN in
  1237. GDB*)
  1238. INFILE=\`mktemp -t kbw.gdb.input.XXXXXXXX\`
  1239. OUTFILE=\`mktemp -t kbw.gdb.output.XXXXXXXX\`
  1240. echo "Logging to \$OUTFILE"
  1241. cat > \$INFILE <<End-of-cmds
  1242. echo
  1243. echo set pagination off\n
  1244. set pagination off
  1245. echo set environment LANG = \$TRUE_LANG
  1246. set environment LANG = \$TRUE_LANG
  1247. echo run\n
  1248. run
  1249. echo bt\n
  1250. bt
  1251. echo thread apply all bt\n
  1252. thread apply all bt
  1253. echo where full\n
  1254. where full
  1255. End-of-cmds
  1256. {
  1257. echo This is a logfile of running kdenlive through gdb. You may want to visit http://www.kdenlive.org/mantis/view_all_bug_page.php and attach this file to a proper bug
  1258. echo Kdenlive was installed by Kdenlive Builder Wizard $VERSION
  1259. echo The following configuration variables was used
  1260. cat <<End-of-configuration
  1261. $CONFIGURATION
  1262. End-of-configuration
  1263. cat <<End-of-info
  1264. $INFO
  1265. End-of-info
  1266. echo uname -a at runtime:
  1267. uname -a
  1268. if test -a /etc/lsb-release ; then
  1269. echo Catting etc/lsb-release
  1270. cat /etc/lsb-release
  1271. else
  1272. echo /etc/lsb-release not found
  1273. fi
  1274. echo Information about kde 4 at runtime:
  1275. kde4-config -v
  1276. echo Information about kde 3 at runtime:
  1277. kde-config -v
  1278. echo INSTALL_DIR=\$INSTALL_DIR
  1279. echo PATH=\$PATH
  1280. echo LD_LIBRARY_PATH=\$LD_LIBRARY_PATH
  1281. echo MLT_AVFORMAT_THREADS=\$MLT_AVFORMAT_THREADS
  1282. echo MLT_PATH=\$MLT_PATH
  1283. echo MLT_REPOSITORY=\$MLT_REPOSITORY
  1284. echo MLT_DATA=\$MLT_DATA
  1285. echo MLT_PROFILES_PATH=\$MLT_PROFILES_PATH
  1286. echo MLT_FREI0R_PLUGIN_PATH=\$MLT_FREI0R_PLUGIN_PATH
  1287. echo PKG_CONFIG_PATH=\$PKG_CONFIG_PATH
  1288. echo Running ldd \$INSTALL_DIR/bin/kdenlive
  1289. ldd \$INSTALL_DIR/bin/kdenlive
  1290. KDENLIVE_BIN="\$INSTALL_DIR/bin/kdenlive"
  1291. [ "$TARGET_OS" = "Darwin" ] && KDENLIVE_BIN="\$INSTALL_DIR/bin/kdenlive.app/Contents/MacOS/kdenlive"
  1292. echo Running gdb -batch -x "\$INFILE" --args "\$KDENLIVE_BIN" --nocrashhandler "\${kdenlive_args[@]}"
  1293. gdb -batch -x "\$INFILE" --args "\$KDENLIVE_BIN" --nocrashhandler "\${kdenlive_args[@]}"
  1294. } >\$OUTFILE 2>&1
  1295. which kdialog &> /dev/null
  1296. if test 0 = \$? ; then
  1297. if test 0 != \$? ; then
  1298. kdialog --error "There was an error running gdb on \$INSTALL_DIR/bin/kdenlive. Please try a normal run"
  1299. exit;
  1300. fi
  1301. if ! grep "Program exited normally." \$OUTFILE ; then
  1302. if kdialog --yesno "Kdenlive appear to have crashed. Do you want to review the log?" ; then
  1303. kdialog --geometry 800x600 --title "\$OUTFILE" --textbox \$OUTFILE || kwrite \$OUTFILE || kioclient exec \$OUTFILE || kfmclient exec \$OUTFILE || gedit \$OUTFILE || emacs \$OUTFILE || kdialog --error "Unable to open logfile - please open \$OUTFILE yourself"
  1304. exit;
  1305. fi
  1306. fi
  1307. fi
  1308. ;;
  1309. *)
  1310. echo running kdenlive "\${kdenlive_args[@]}"
  1311. export LANG=\$TRUE_LANG
  1312. kdenlive "\${kdenlive_args[@]}"
  1313. ;;
  1314. esac
  1315. End-of-startup-script-template
  1316. if test 0 != $? ; then
  1317. die "Unable to create startup script"
  1318. fi
  1319. chmod 755 $TMPFILE || die "Unable to make startup script executable"
  1320. $SUDO cp $TMPFILE $FINAL_INSTALL_DIR/bin/start_kdenlive || die "Unable to create startup script - cp failed"
  1321.  
  1322. TMPFILE=`mktemp -t kbw.env.XXXXXXXXX`
  1323. log Creating environment script in $TMPFILE
  1324. # Note that if you change any of this, you may also want to change kdenlive_start
  1325. cat > $TMPFILE <<End-of-environment-setup-template
  1326. # Set up environment
  1327. # Source this file using a bash/sh compatible shell, to get an environment,
  1328. # where you address the binaries and libraries used by your custom Kdenlive build
  1329. export INSTALL_DIR=$FINAL_INSTALL_DIR
  1330. export PATH=\$INSTALL_DIR/bin:\$PATH
  1331. export LD_LIBRARY_PATH=\$INSTALL_DIR/lib:\$INSTALL_DIR/lib/frei0r-1:\$LD_LIBRARY_PATH
  1332. if [ "$TARGET_OS" = "Darwin" ]; then
  1333. export PATH="\$INSTALL_DIR/bin/kdenlive.app/Contents/MacOS:\$PATH"
  1334. export DYLD_LIBRARY_PATH="\$LD_LIBRARY_PATH"
  1335. CPUS=\$(sysctl -a hw | grep "ncpu:" | cut -d ' ' -f 2)
  1336. else
  1337. CPUS=\$(grep "processor\s*:" /proc/cpuinfo | wc -l)
  1338. fi
  1339. export MLT_AVFORMAT_THREADS=\$((\$CPUS - 1))
  1340. export MLT_PATH=\$INSTALL_DIR
  1341. export MLT_REPOSITORY=\$INSTALL_DIR/lib/mlt
  1342. export MLT_DATA=\$INSTALL_DIR/share/mlt
  1343. export MLT_PROFILES_PATH=\$INSTALL_DIR/share/mlt/profiles
  1344. export MLT_FREI0R_PLUGIN_PATH=\$INSTALL_DIR/lib/frei0r-1/:/usr/lib/frei0r-1:/usr/local/lib/frei0r-1:/opt/local/lib/frei0r-1
  1345. export MANPATH=\$MANPATH:\$INSTALL_DIR/share/man/
  1346. export PKG_CONFIG_PATH=\$INSTALL_DIR/lib/pkgconfig/:\$PKG_CONFIG_PATH
  1347. End-of-environment-setup-template
  1348. if test 0 != $? ; then
  1349. die "Unable to create environment script"
  1350. fi
  1351. chmod 755 $TMPFILE || die "Unable to make environment script executable"
  1352. $SUDO cp $TMPFILE "$FINAL_INSTALL_DIR/bin/kdenlive_env" || die "Unable to create environment script - cp failed"
  1353.  
  1354. feedback_progress Done creating startup and environment script
  1355. popd
  1356. }
  1357.  
  1358. #################################################################
  1359. # perform_action
  1360. # Actually do what the user wanted
  1361. function perform_action {
  1362. trace "Entering perform_action @ = $@"
  1363. # Test that may fail goes here, before we do anything
  1364. if test 1 = "$USE_KDE4" ; then
  1365. test_kde4_available
  1366. fi
  1367. if test 1 = "$GET" -a 1 = "$SOURCES_CLEAN"; then
  1368. clean_dirs
  1369. fi
  1370. if test 1 = "$GET"; then
  1371. get_all_sources
  1372. fi
  1373. if test 1 = "$COMPILE_INSTALL" ; then
  1374. sys_info
  1375. configure_compile_install_all
  1376. fi
  1377. if test 1 = "$CREATE_STARTUP_SCRIPT" ; then
  1378. create_startup_script
  1379. fi
  1380. feedback_result SUCCESS "Everything succeeded"
  1381. }
  1382.  
  1383. ################################################################################
  1384. # MAIN AND FRIENDS
  1385. ################################################################################
  1386.  
  1387. #################################################################
  1388. # kill_recursive
  1389. # The intention of this is to be able to kill all children, whenever the
  1390. # user aborts.
  1391. # This does not really work very very well, but its the best I can offer.
  1392. # It may leave some defunct around(?)
  1393. # $1 pid
  1394. function kill_recursive {
  1395. trace "Entering kill_recursive @ = $@"
  1396. if test "$1" != "$$"; then
  1397. # Stop it from spawning more kids
  1398. kill -9 $1 &> /dev/null
  1399. wait $1
  1400. for CP in `ps --ppid $1 -o pid=` ; do
  1401. kill_recursive $CP
  1402. done
  1403. fi
  1404. }
  1405.  
  1406. #################################################################
  1407. # keep_checking_abort
  1408. # Checks if the user indicated an abort through
  1409. function keep_checking_abort {
  1410. while test x`check_abort` = "xcont" ; do
  1411. sleep 1
  1412. done
  1413. feedback_result ABORTED "User requested abort"
  1414. # If we reach here, user aborted, kill everything in sight...
  1415. kill_recursive $MAINPID
  1416. exit
  1417. }
  1418.  
  1419. #################################################################
  1420. # main
  1421. # Collects all the steps
  1422. function main {
  1423. {
  1424. sleep 1
  1425. init_log_file
  1426. read_configuration
  1427. set_globals
  1428. } 2>&1
  1429.  
  1430. # Setup abort handling
  1431. # If anyone know of a better way to get ones pid from within a subshell, let me know...
  1432. MAINPID=`/bin/bash -c "echo \\$PPID"`
  1433. # debug "Main is running with pid $MAINPID"
  1434. keep_checking_abort &
  1435. CHECKERPID=$!
  1436. # debug "Checker process is running with pid=$CHECKERPID"
  1437.  
  1438. # Special case for sudo getting
  1439. SUDO=""
  1440. log "Checking for sudo requirement" 2>&1
  1441. if test "1" = "$NEED_SUDO" ; then
  1442. log "sudo is needed"
  1443. case $DCOPREF in
  1444. none)
  1445. log "DCOPREF is $DCOPREF, using ordinary sudo"
  1446. echo You have chosen to install as root.
  1447. echo
  1448. echo 'Please provide your sudo password below. (If you have recently provided your sudo password to this wizard, you may not have to do that, because the password is cached).'
  1449. echo
  1450. echo The password will be handled securely by the sudo program.
  1451. echo
  1452. echo If you fail to provide the password, you will have to provide it later when installing the different projects.
  1453. sudo -v
  1454. if test 0 != $? ; then
  1455. die "Unable to proceed"
  1456. fi
  1457. SUDO=sudo
  1458. ;;
  1459. kdialog*|kmdr*)
  1460. log "DCOPREF is $DCOPREF, using kdesudo or kdesu"
  1461. SUDO=`which kdesudo`
  1462. if test 0 != $? ; then
  1463. SUDO=`which kdesu`
  1464. if test 0 != $? ; then
  1465. die "You have choosen to install as root, but I could not find neither kdesu or kdesudo in your path. Dunno what to do"
  1466. fi
  1467. fi
  1468. if test "kdesu" = "$SUDO" ; then
  1469. $SUDO -c /bin/true
  1470. else
  1471. # This is kdesudo, but it may not support the --comment option. Try and figure it out
  1472. log "Checking for --comment option to kdesudo"
  1473. $SUDO --help | grep -- --comment &> /dev/null
  1474. if test 0 == $? ; then
  1475. debug "$SUDO supports --comment"
  1476. $SUDO --caption "Please provide sudo password" --comment "<html><p>You have chosen to install as root.</p><p>Please provide your sudo password below.</p><p>The password will be handled securely by the KDE kdesudo program.</p><p>If you fail to provide the password, you will have to provide it later when installing the different projects. Providing it now allows the program to run unsupervised.</p></html>" -c /bin/true
  1477. else
  1478. debug "$SUDO does not support --comment"
  1479. $SUDO --caption "Please provide sudo password" -c /bin/true
  1480. fi
  1481. fi
  1482. # If the user fails to provide password, it is OK, but if running kdesudo fails, stop
  1483. if test 0 != $?; then
  1484. die "Some kind of error occured while calling $SUDO. Unable to proceed"
  1485. fi
  1486. ;;
  1487. esac
  1488. fi
  1489. log "Done checking for sudo requirement" 2>&1
  1490.  
  1491. {
  1492. prepare_feedback
  1493. perform_action
  1494. } 2>&1
  1495.  
  1496. # All is well, that ends well
  1497. exit 0
  1498. }
  1499.  
  1500. parse_args "$@"
  1501. # Call main, but if detach is given, put it in the background
  1502. if test 1 = "$DETACH"; then
  1503. main &
  1504. # Note, that we assume caller has setup stdin & stdout redirection
  1505. disown -a
  1506. else
  1507. main
  1508. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement