Advertisement
barjac

Untitled

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