Advertisement
barjac

build script

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