Advertisement
barjac

Untitled

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