summaryrefslogtreecommitdiff
path: root/build_compiz++
blob: 9889209505a561e6f9a1b21bfd101325ed989f71 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
#!/bin/bash

# ***************************************************************
#   A script to build compiz++ by Scott Moreau oreaus@gmail.com
# ***************************************************************

# Make sure we're being ran in bash
if [[ -z "$BASH_VERSION" ]]; then
   echo "Please run this script in a bash environment."
   exit 1
fi

# Don't run it as root
if [[ "$EUID" = 0 ]]; then
   echo "Run as user, without $SUDO and not as root."
   exit 1
fi

echo
echo
echo "*****************************"
echo "* $(tput setaf 1)The Compiz++$(tput sgr0) $(tput setaf 6)Build Script$(tput sgr0) *"
echo "*****************************"
echo

# Change these or pass them as args.
SRC_DIR=$HOME/src/compiz/compiz++
PREFIX=/opt/compiz++

KDE_ENABLED="false"
GNOME_ENABLED="true"
GTK_ENABLED="true"

DECORATOR="gtk-window-decorator"


# Functions

die ()
{
    echo "$(tput setaf 1)Failed to build component$(tput sgr0) "$1". $(tput setaf 1)Aborting$(tput sgr0). \
    Please report to #compiz-dev on irc.freenode.net"

    # Hack: Workaround for 'elements build fails first time around'
    if [[ "$1" != "plugins-unsupported" ]]; then
	exit 1
    fi
}

py_inst ()
{
    if $(which python2 &> /dev/null); then
		PKG_CONFIG_PATH=$PKG_CONFIG_PATH sudo -E python2 ./setup.py install --prefix=$PREFIX || die $COMPONENT
	elif $(which python2.6 &> /dev/null); then
		PKG_CONFIG_PATH=$PKG_CONFIG_PATH sudo -E python2.6 ./setup.py install --prefix=$PREFIX || die $COMPONENT
	elif $(which python2.7 &> /dev/null); then
		PKG_CONFIG_PATH=$PKG_CONFIG_PATH sudo -E python2.7 ./setup.py install --prefix=$PREFIX || die $COMPONENT
    else
		PKG_CONFIG_PATH=$PKG_CONFIG_PATH sudo -E python ./setup.py install --prefix=$PREFIX || die $COMPONENT
    fi
}

show_help ()
{
    echo
    echo "Usage: $0 [OPTIONS]"
    echo
    echo "-h / --help     - Show this help dialog and exit."
    echo
    echo "--gen-scripts   - Generate helper scripts and exit."
    echo "--prefix=/path  - Target install path. Default is --prefix=/opt/compiz++"
    echo "--src_dir=/path - Code storage path. Default is --src_dir=~/src/compiz/compiz++"
    echo "--dont-reset    - Don't attempt to reset and update the script repo."
    echo "--enable-kde    - Build kde4-window-decorator, kconfig4 backend and kde plugin."
    echo "--disable-gnome - Disable glib, gnomecompat plugin and gconf backend."
    echo "--disable-gtk   - Disable gtk-window-decorator and metacity theme support."
    echo "--list-targets  - List components that will be built when ran without this option."
    echo
    echo "An environment variable 'first_component' may be set to start building from this target."
    echo
}

# Check for ubuntu version if lsb_release exists
#if ! $(which lsb_release &> /dev/null); then
#	echo "This does not appear to be ubuntu."
#else
#	if		lsb_release -c|grep -q lucid; then
#		echo "Ubuntu codename: Lucid"
#		ubuntu_version=lucid
#	elif	lsb_release -c|grep -q maverick; then
#		echo "Ubuntu codename: Maverick"
#		ubuntu_version=maverick
#	elif	lsb_release -c|grep -q natty; then
#		echo "Ubuntu codename: Natty"
#		ubuntu_version=natty
#	fi
#fi

# Check for flags
if [ ! -z "$1" ]; then
while [[ $1 != "" ]]; do
    case "$1" in
	-h|--help|-\?) show_help; exit 0;;
	--disable-kde) KDE_ENABLED="false"; shift;;
	--enable-kde) KDE_ENABLED="true"; shift;;
	--disable-gnome) GNOME_ENABLED="false"; shift;;
	--enable-gnome) GNOME_ENABLED="true"; shift;;
	--disable-gtk) GTK_ENABLED="false"; shift;;
	--enable-gtk) GTK_ENABLED="true"; shift;;
	--gen-scripts) GEN_SCRIPTS="true"; shift;;
	--dont-reset) DONT_RESET="true"; shift;;
	--prefix=*) PREFIX=${1#--prefix=}; shift;;
	--src_dir=*) SRC_DIR=${1#--src_dir=}; shift;;
	--list-targets) list_targets="true"; shift;;
	--) shift; break;;
	*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
    esac
done
fi

# Do not change these.
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PREFIX/lib64/pkgconfig:$PREFIX/lib32/pkgconfig:$PKG_CONFIG_PATH
LD_LIBRARY_PATH=$PREFIX/lib:$PREFIX/lib64:$PREFIX/lib32:$LD_LIBRARY_PATH
CWD="$(dirname "$(readlink /proc/$$/fd/255)")"

# Only set components if we're just listing targets
if [[ "$list_targets" != "true" ]]; then

# Only attempt update if --dont-reset isn't passed
if [[ "$DONT_RESET" != "true" ]]; then

	# Check for git
	if ! $(which git &> /dev/null); then
		if $(which apt-get &> /dev/null); then
			sudo apt-get install git-core
		else
			show_help
			echo
			echo "$(tput setaf 1)WARNING$(tput sgr0): This script is designed to install dependencies on deb-based linux distributions."
			echo "       : You will need to make sure the following packages are installed for your distribution:"
			echo
			echo "git"
			echo
			echo "Cannot continue."
			exit 1
		fi
	fi

    # Attempt self-update
    cd $CWD
    git reset --hard origin/master
    git checkout master
    git clean -fdx
    if ! output=$(git pull); then
	echo "Problem detected when attempting update. Will not continue."
	echo "Make sure you are running this script from the directory cloned"
	echo "with: \"git clone git://anongit.compiz.org/users/soreau/scripts\""
	exit 1
    fi
    if [[ "$output" != "Already up-to-date." ]]; then
	echo "The script may have changed, please re-run it."
	exit 1
    fi
fi

# The script is designed to only use escalated permissions
# when installing components if $PREFIX is outside of $HOME
if [[ $PREFIX = "$HOME"* ]]; then
    unset SUDO;
else
    SUDO="sudo -E"
fi

# If $SRC_DIR is anywhere other than $HOME,
# assume $USER does not have write access.
if [[ $SRC_DIR != "$HOME"* ]]; then
    sudo mkdir -p $SRC_DIR
    sudo chown $USER -R $SRC_DIR
fi

# Master make command
MAKE=make

# These are the dependencies for ubuntu. This script should work on other distributions provided the dependencies are met
if echo $(python --version 2>&1)|grep -q 2.6; then
echo "Python 2.6 detected"
    DEPENDENCIES="git-core cmake libcairo2-dev librsvg2-dev libpng12-dev libjpeg62-dev libdbus-1-dev libboost-dev libboost-serialization-dev libxml2-dev libgl1-mesa-dev libglu1-mesa-dev libx11-xcb-dev libxslt1-dev xsltproc libglibmm-2.4-dev libnotify-dev libprotobuf-dev intltool cython python2.6-dev"
elif echo $(python --version 2>&1)|grep -q 2.7; then
echo "Python 2.7 detected"
    DEPENDENCIES="git-core cmake libcairo2-dev librsvg2-dev libpng12-dev libjpeg62-dev libdbus-1-dev libboost-dev libboost-serialization-dev libxml2-dev libgl1-mesa-dev libglu1-mesa-dev libx11-xcb-dev libxslt1-dev xsltproc libglibmm-2.4-dev libnotify-dev libprotobuf-dev intltool cython python2.7-dev"
else
echo "Python version detection failed."
    DEPENDENCIES="git-core cmake libcairo2-dev librsvg2-dev libpng12-dev libjpeg62-dev libdbus-1-dev libboost-dev libboost-serialization-dev libxml2-dev libgl1-mesa-dev libglu1-mesa-dev libx11-xcb-dev libxslt1-dev xsltproc libglibmm-2.4-dev libnotify-dev libprotobuf-dev intltool cython python2.7-dev"
fi

# endif [[ "$list_targets" != "true" ]]
fi

# Components to build
components=(core libcompizconfig compizconfig-python ccsm)

# Configure flags to cmake
# TODO: Conditional for LIB_SUFFIX
CMAKE_FLAGS="-DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_BUILD_TYPE=Debug -DCOMPIZ_PLUGIN_INSTALL_TYPE=compiz" # -DLIB_SUFFIX=64
CORE_CMAKE_FLAGS="$CMAKE_FLAGS"

# Adjust deps and flags
if [[ "$GNOME_ENABLED" = "true" ]]; then
    DEPENDENCIES="$DEPENDENCIES libmetacity-dev libgnome-window-settings-dev libgnome-desktop-dev gnome-control-center-dev libglib2.0-dev"
    components+=(compizconfig-backend-gconf)
    CORE_CMAKE_FLAGS="$CORE_CMAKE_FLAGS -DBUILD_GNOME=ON -DBUILD_GNOME_KEYBINDINGS=ON -DBUILD_METACITY=ON -DBUILD_GTK=ON -DCOMPIZ_DISABLE_PLUGIN_GNOMECOMPAT=OFF"
else
    CORE_CMAKE_FLAGS="$CORE_CMAKE_FLAGS -DBUILD_GNOME=OFF -DBUILD_GNOME_KEYBINDINGS=OFF -DBUILD_METACITY=ON -DBUILD_GTK=ON -DCOMPIZ_DISABLE_PLUGIN_GNOMECOMPAT=ON -DCOMPIZ_DISABLE_PLUGIN_GLIB=ON"
fi

if [[ "$GTK_ENABLED" = "true" ]]; then
    DEPENDENCIES="$DEPENDENCIES libmetacity-dev libgtk2.0-dev libwnck-dev libgconf2-dev"
    CORE_CMAKE_FLAGS="$CORE_CMAKE_FLAGS -DBUILD_METACITY=ON -DBUILD_GTK=ON -DUSE_GCONF=ON"
else
    CORE_CMAKE_FLAGS="$CORE_CMAKE_FLAGS -DBUILD_METACITY=OFF -DBUILD_GTK=OFF"
fi

if [[ "$KDE_ENABLED" = "true" ]]; then
    DEPENDENCIES="$DEPENDENCIES kde-devel kdebase-workspace-dev"
#    components+=(compizconfig-backend-kconfig4)
    DECORATOR="kde4-window-decorator"
    CORE_CMAKE_FLAGS="$CORE_CMAKE_FLAGS -DBUILD_KDE4=ON -DCOMPIZ_DISABLE_PLUGIN_KDE=OFF"
else
    CORE_CMAKE_FLAGS="$CORE_CMAKE_FLAGS -DBUILD_KDE4=OFF -DCOMPIZ_DISABLE_PLUGIN_KDE=ON"
fi

# Additional components to build.
# plugins-unsupported is deliberately built twice as a workaround to elements failing the first time
components+=(plugins-main plugins-extra plugins-unsupported plugins-unsupported)

if [[ "$list_targets" != "true" ]]; then

if [[ "$GEN_SCRIPTS" = "true" ]]; then
    echo
    echo "Generating scripts in $CWD/"
else
    echo
    echo "Script Config:"
    echo
    echo "PREFIX           = $PREFIX"
    echo "SRC_DIR          = $SRC_DIR"
    echo "KDE_ENABLED      = $KDE_ENABLED"
    echo "GNOME_ENABLED    = $GNOME_ENABLED"
    echo "GTK_ENABLED      = $GTK_ENABLED"
    echo
#    echo "components = ${components[@]}"
#    echo
#    echo "CORE_CMAKE_FLAGS = $CORE_CMAKE_FLAGS
#    echo
fi

if [[ "$GEN_SCRIPTS" != "true" ]]; then
    # Attempt dependency installation with apt
    if $(which apt-get &> /dev/null); then

	dep_list=($DEPENDENCIES)

	for dep in "${dep_list[@]}"; do
	    if ! dpkg --get-selections "$dep" 2>/dev/null | grep -qE '\<install$' > /dev/null; then
		echo "Installing dependencies.."
		sudo apt-get install $DEPENDENCIES || { echo "Failed to install dependencies."; exit 1; }
		break
	    fi
	done
    else
		show_help
		echo
		echo "$(tput setaf 1)WARNING$(tput sgr0): This script is designed to install dependencies on deb-based linux distributions."
		echo "       : You will need to make sure the following packages are installed for your distribution:"
		echo
		echo "$(tput setaf 4)$DEPENDENCIES$(tput sgr0)"
		echo
		echo
		echo -n "Press Ctrl+C to stop.."

		for (( i = 5; i > 0; i-- )); do
			echo -n "$i"
			sleep 0.33
			echo -n "."
			sleep 0.33
			echo -n "."
			sleep 0.33
		done
    fi
fi

echo

if [[ ! -d $PREFIX/bin ]]; then
    $SUDO mkdir -p $PREFIX/bin
fi

FILE="$CWD/ccsm++"

cat << EOF > $FILE
#!/bin/bash

# Kill any running instance of ccsm
pkill -x ccsm

PREFIX=$PREFIX
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:\$LD_LIBRARY_PATH
if \$(which python2.6 &> /dev/null); then
	export PYTHONPATH=\$PREFIX/lib/python2.6/site-packages:\$PREFIX/lib64/python2.6/site-packages:\$PREFIX/lib32/python2.6/site-packages:$PYTHONPATH:\$PYTHONPATH
else
	export PYTHONPATH=\$PREFIX/lib/python2.7/site-packages:\$PREFIX/lib64/python2.7/site-packages:\$PREFIX/lib32/python2.7/site-packages:$PYTHONPATH:\$PYTHONPATH
fi

# Hack to fix ccsm from complaining and causing incorrect plugin config option ordering
rm -rf $HOME/.cache/compizconfig-1 2&1>/dev/null

\$PREFIX/bin/ccsm
EOF

chmod +x $FILE
if [[ "$GEN_SCRIPTS" != "true" ]]; then
    echo "Installing ccsm++ starter script to $PREFIX/bin/"
    $SUDO cp $FILE $PREFIX/bin/
else
    echo "${FILE##*/}"
fi

FILE="$CWD/compiz++"

cat <<EOF > $FILE
#!/bin/bash

PREFIX=$PREFIX

# Kill all decorators in case an incompatible (0.8) decorator is running
if ps ax | grep gtk-window-decorator | grep -v grep &> /dev/null; then
    echo "Killing gtk-window-decorator"
    killall gtk-window-decorator &> /dev/null
fi
if ps ax | grep kde4-window-decorator | grep -v grep &> /dev/null; then
    echo "Killing kde4-window-decorator"
    killall kde4-window-decorator &> /dev/null
fi
if ps ax | grep emerald | grep -v grep &> /dev/null; then
    echo "Killing emerald"
    killall emerald &> /dev/null
fi

\$PREFIX/bin/compiz --replace ccp "\$@" &
\$PREFIX/bin/$DECORATOR --replace &
\$PREFIX/bin/ccsm++ &
EOF

chmod +x $FILE
if [[ "$GEN_SCRIPTS" != "true" ]]; then
    echo "Installing compiz++ starter script to $PREFIX/bin/"
    $SUDO mv $FILE $PREFIX/bin/
else
    echo "${FILE##*/}"
fi

FILE="$CWD/install_single_plugin"

cat <<EOF > $FILE
#!/bin/bash

#
# A script to build individual compiz++ plugins by Scott Moreau oreaus@gmail.com
#

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:\$PKG_CONFIG_PATH

if [[ -d ./build ]]; then
    rm -rf build
fi
mkdir build
cd build
cmake .. -DCOMPIZ_PLUGIN_INSTALL_TYPE="local"
make
make install
EOF

chmod +x $FILE
if [[ "$GEN_SCRIPTS" = "true" ]]; then
    echo "${FILE##*/}"
else
    echo "Generated ${FILE##*/}"
fi

FILE="$CWD/compiz_addons++"

cat <<EOF > $FILE
#!/bin/bash

PREFIX=$PREFIX
SRC_DIR=$SRC_DIR/plugins
CWD=$CWD
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:\$PKG_CONFIG_PATH

plugin_list=(anaglyph animationjc dialog extra-animations freewins ghost glsl photowheel screensaver showrepaint simple-animations snowglobe sound stackswitch startup static swap throw toggle-decoration trip vidcap vignetting winreflect wizard workspacenames)

anaglyph_url=git://anongit.compiz.org/users/wodor/anaglyph
animationjc_url=git://anongit.compiz.org/users/jc/animationjc
dialog_url=git://anongit.compiz.org/users/rcxdude/dialog
extra_animations_url=git://anongit.compiz.org/users/kdubois/extra-animations
freewins_url=git://anongit.compiz.org/users/warlock/freewins
ghost_url=git://anongit.compiz.org/users/rcxdude/ghost
glsl_url=git://anongit.compiz.org/users/alex/glsl
photowheel_url=git://anongit.compiz.org/users/b0le/photowheel
screensaver_url=git://anongit.compiz.org/users/pafy/screensaver
showrepaint_url=git://anongit.compiz.org/compiz/plugins/showrepaint
simple_animations_url=git://anongit.compiz.org/users/smspillaz/simple-animations
snowglobe_url=git://anongit.compiz.org/users/metastability/snowglobe
sound_url=git://anongit.compiz.org/users/smspillaz/sound
stackswitch_url=git://anongit.compiz.org/compiz/plugins/stackswitch
startup_url=git://anongit.compiz.org/users/soreau/startup
static_url=git://anongit.compiz.org/users/smspillaz/static
swap_url=git://anongit.compiz.org/users/edgurgel/swap
throw_url=git://anongit.compiz.org/users/smspillaz/throw
toggle_decoration_url=git://anongit.compiz.org/users/edgurgel/toggle-decoration
trip_url=git://anongit.compiz.org/users/soreau/trip
vignetting_url=git://anongit.compiz.org/users/smspillaz/vignetting
vidcap_url=git://anongit.compiz.org/users/soreau/vidcap
winreflect_url=git://anongit.compiz.org/users/smspillaz/winreflect
wizard_url=git://anongit.compiz.org/users/soreau/wizard
workspacenames_url=git://anongit.compiz.org/users/maniac/workspacenames

mkdir -p \$SRC_DIR

for COMPONENT in "\${plugin_list[@]}"; do
    echo "COMPONENT = \$COMPONENT"
    url="\${COMPONENT//-/_}_url"
    if [[ ! -d \$SRC_DIR/\$COMPONENT ]]; then
	cd \$SRC_DIR
	git clone "\${!url}"
    else
	cd \$SRC_DIR/\$COMPONENT
	git checkout master
	git reset --hard master
	sudo git clean -fdx
	git pull
    fi
    if [[ "\$COMPONENT" = "swap" ]]; then
	cd \$SRC_DIR/\$COMPONENT
	git checkout compiz++
    fi
    if [[ ! -f "\$CWD"/"install_single_plugin" ]]; then
	echo "\$CWD/install_single_plugin does not exist. Please retrieve the script set with 'git clone git://anongit.compiz.org/users/soreau/scripts' and run build_compiz++ to generate the script."
	exit 1
    else if [[ "\$COMPONENT" = "glsl" ]]; then
	echo
	echo "\$(tput setaf 1)WARNING\$(tput sgr0): The next three plugins may fail to build, crash your system or burn multiple kittens simultaneously."
	echo "       : Building CompizFBO, CompizShader and CompizBullet.."
	echo
	glsl_plugin_list=(CompizFBO CompizShader CompizBullet)
	for PLUGIN in "\${glsl_plugin_list[@]}"; do
	    # Bullet build is currently broken
	    if [[ "\$PLUGIN" = "CompizBullet" ]]; then
		continue
	    fi
	    if [[ "\$PLUGIN" = "CompizBullet" ]] && ! \$(pkg-config --exists bullet); then
		echo
		echo "\$(tput setaf 1)WARNING\$(tput sgr0): Attempting to install bullet to /usr, required for CompizBullet."
		echo
		if \$(which apt-get &> /dev/null); then
		    echo "Installing freeglut3-dev and subversion..."
		    sudo apt-get install freeglut3-dev subversion || { echo "Failed to install dependencies for bullet."; }
		else
		    echo
		    echo "\$(tput setaf 1)WARNING\$(tput sgr0): You will need freeglut3-dev and subversion, required by bullet."
		    echo
		fi
		if [[ -d \$HOME/src/bullet ]]; then
		    cd \$HOME/src/bullet
		    svn up
		else
		    cd \$HOME/src
		    svn checkout http://bullet.googlecode.com/svn/trunk/ bullet
		    cd \$HOME/src/bullet
		fi
		cmake . -DCMAKE_INSTALL_PREFIX=/usr
		$MAKE || { echo; echo "Bullet failed to build. CompizBullet will not be installed."; continue; }
		$SUDO make install
	    fi
	    cd \$SRC_DIR/\$COMPONENT/\$PLUGIN
		\$CWD/install_single_plugin
	done
    else
	if [[ "\$COMPONENT" = "sound" ]]; then
	    if \$(which apt-get &> /dev/null); then
		echo "Installing libgstreamer0.10-dev..."
		sudo apt-get install libgstreamer0.10-dev || { echo "Failed to install dependencies for sound plugin."; }
	    else
		echo
		echo "\$(tput setaf 1)WARNING\$(tput sgr0): You will need libgstreamer0.10-dev, required by sound plugin."
		echo
	    fi
	fi
	if [[ "\$COMPONENT" = "screensaver" ]]; then
	    if \$(which apt-get &> /dev/null); then
		echo "Installing libxss-dev..."
		sudo apt-get install libxss-dev || { echo "Failed to install dependencies for screensaver plugin."; }
	    else
		echo
		echo "\$(tput setaf 1)WARNING\$(tput sgr0): You will need libxss-dev, required by screensaver plugin."
		echo
	    fi
	fi
	if [[ "\$COMPONENT" = "vidcap" ]] && ! \$(pkg-config --exists seom); then
	    echo
	    echo "\$(tput setaf 1)WARNING\$(tput sgr0): Attempting to install seom to /usr, required by vidcap."
	    echo
	    if \$(which apt-get &> /dev/null); then
		echo "Installing subversion, libxv-dev and yasm..."
		sudo apt-get install subversion yasm libxv-dev || { echo "Failed to install dependencies for seom, required by vidcap."; }
	    else
		echo
		echo "\$(tput setaf 1)WARNING\$(tput sgr0): You will need subversion and yasm, required for seom."
		echo
	    fi
	    if [[ -d \$HOME/src/seom ]]; then
		cd \$HOME/src/seom
		svn up
	    else
		cd \$HOME/src
		svn co https://devel.neopsis.com/svn/seom/trunk seom --trust-server-cert --non-interactive
		cd \$HOME/src/seom
	    fi
	    ./configure --prefix=/usr
	    $MAKE || { echo; echo "seom failed to build. Vidcap will not be installed."; }
	    $SUDO make install
	fi
	cd \$SRC_DIR/\$COMPONENT
	\$CWD/install_single_plugin
    fi
    fi
done

echo "Make sure to restart compiz and ccsm after installing any plugins."
EOF

chmod +x $FILE
if [[ "$GEN_SCRIPTS" = "true" ]]; then
    echo "${FILE##*/}"
    exit 0
else
    echo "Generated ${FILE##*/}"
fi

chmod +x $FILE

mkdir -p $SRC_DIR

# if [[ "$list_targets" != "true" ]]
else
	echo
	echo "The following components will be built:"
	echo
fi

for COMPONENT in "${components[@]}"; do

	if [[ "$list_targets" = "true"  ]]; then
		echo "$COMPONENT"
		continue
	fi

	if [[ -n "$first_component" ]]; then
		if [[ "$first_component" != "$COMPONENT" ]]; then
			ubset first_component
			continue
		fi
	fi

    unset config_component

    if [[ "$COMPONENT" = "libcompizconfig" || "$COMPONENT" = "compizconfig-python" || "$COMPONENT" = "ccsm" || "$COMPONENT" = "compizconfig-backend-gconf" || "$COMPONENT" = "compizconfig-backend-kconfig4" ]]; then
	config_component="true"
    fi

    cd $SRC_DIR

    if [[ ! -d $SRC_DIR/$COMPONENT ]]; then
	echo "Cloning $COMPONENT..."
	if [[ "$config_component" = "true" ]]; then
	    git clone git://anongit.compiz.org/compiz/compizconfig/$COMPONENT
	else
	    git clone git://anongit.compiz.org/compiz/$COMPONENT
	fi
    else
	echo "Updating $COMPONENT..."
	cd $SRC_DIR/$COMPONENT
	git checkout master
	git reset --hard origin/master
	sudo git clean -fdx
	sudo rm -rf build
	if ! git pull; then
	    echo "Error occured while trying to update $COMPONENT. Attempting fresh clone.."
	    $SUDO rm -rf $SRC_DIR/$COMPONENT
	    cd $SRC_DIR
	    if [[ "$config_component" = "true" ]]; then
		if ! git clone git://anongit.compiz.org/compiz/compizconfig/$COMPONENT; then
		    echo "Failed to clone git clone git://anongit.compiz.org/compiz/compizconfig/$COMPONENT."
		    echo "Is your network connection configured and working?."
		    die $COMPONENT
		fi
	    else
		if ! git clone git://anongit.compiz.org/compiz/$COMPONENT; then
		    echo "Failed to clone git clone git://anongit.compiz.org/compiz/$COMPONENT."
		    echo "Is your network connection configured and working?."
		    die $COMPONENT
		fi
	    fi
	fi
    fi
    if [[ "$COMPONENT" = "plugins-main" || "$COMPONENT" = "plugins-extra" || "$COMPONENT" = "plugins-unsupported" ]]; then
	cd $SRC_DIR/$COMPONENT
	if [[ ! -d $SRC_DIR/$COMPONENT ]]; then
	    $SUDO rm -rf $SRC_DIR/$COMPONENT/*/build
	fi
	git submodule foreach git remote update
	git submodule foreach git merge origin/master
	git submodule foreach git reset --hard origin/master
	git submodule init
	git submodule update
    fi
    if [[ "$COMPONENT" = "compizconfig-python" || "$COMPONENT" = "ccsm" ]]; then
	cd $SRC_DIR/$COMPONENT
	echo "Installing $COMPONENT..."
	py_inst
    else
	mkdir $SRC_DIR/$COMPONENT/build
	cd $SRC_DIR/$COMPONENT/build
	echo "Building $COMPONENT..."
	if [[ "$COMPONENT" = "core" ]]; then
	    cmake .. $CORE_CMAKE_FLAGS
	elif [[ ! "$KDE_ENABLED" = "true" && "$COMPONENT" = "plugins-main" ]]; then
	    cmake .. $CMAKE_FLAGS -DCOMPIZ_DISABLE_PLUGIN_KDECOMPAT=ON
	else
	    cmake .. $CMAKE_FLAGS
	fi
	make clean
	$MAKE || die $COMPONENT
	echo "Installing $COMPONENT..."
	$SUDO make install
    fi
    if [[ "$COMPONENT" = "core" ]]; then
	echo "Running sudo make findcompiz_install:"
	sudo make findcompiz_install
    fi
    if [[ "$COMPONENT" = "libcompizconfig" ]]; then
	echo "Running sudo make findcompizconfig_install:"
	sudo make findcompizconfig_install
    fi
done

if [[ "$list_targets" != "true" ]]; then
	echo
	echo
	echo "By default, there are no plugins enabled. You will want at least"
	echo "Window Decoration and Move Window loaded to do anything useful."
	echo "A few others to enable are Place Windows, Resize Window and Application Switcher,"
	echo "all of which are in the Window Management category."
	echo
	read -p "Would you like to start ccsm++ now? y/n: " response

	if [[ $response = "y" ]]; then
	$PREFIX/bin/ccsm++ &
	elif [[ $response = "n" ]]; then
	echo "Done. Run $PREFIX/bin/compiz++ to start compiz or $PREFIX/bin/ccsm++ to start ccsm."
	else
	echo "Invalid response, assuming 'no'. If you want to start compiz++ run $PREFIX/bin/compiz++"
	fi
fi