-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbash_setup_programming
276 lines (240 loc) · 7.31 KB
/
bash_setup_programming
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
#!/bin/bash
###############################################################
# KDE DEVELOPMENT
#
# If you just want to setup your environment for kde
# development, download this file and save it somewhere
# now put the following line (with the path pointing to
# your just downloaded file) into your ~/.bashrc:
#
# . ~/path/to/this/file
#
# Example (the leading # has to be ommitted of course!)
# . ~/.bash_setup_programming
###############################################################
function prepend {
if [ -d "$2" ]; then
p=$(readlink -f $2)
eval $1=\"$p\$\{$1:+':'\$$1\}\" && export $1
fi
}
export -f prepend
function add_env {
local d="$(readlink -f $1)"
if [[ ! -z "$d" && -d "$d" ]]; then
prepend PATH $d/bin
prepend LD_LIBRARY_PATH $d/lib
prepend LD_LIBRARY_PATH $d/lib64
prepend LIBEXEC_PATH $d/lib/libexec
prepend LIBEXEC_PATH $d/lib64/libexec
if [ -d "$d/plugins/sqldrivers" ]; then
prepend LD_LIBRARY_PATH "$d/plugins/sqldrivers/"
fi
prepend PKG_CONFIG_PATH "$d/lib/pkgconfig"
prepend CMAKE_PREFIX_PATH "$d"
prepend CMAKE_LIBRARY_PATH "$d/lib"
prepend CMAKE_INCLUDE_PATH "$d/include"
prepend QT_PLUGIN_PATH "$d/plugins"
prepend QT_PLUGIN_PATH "$d/lib/plugins"
prepend QT_PLUGIN_PATH "$d/lib64/plugins"
prepend QT_PLUGIN_PATH "$d/lib/x86_64-linux-gnu/plugins"
prepend QML2_IMPORT_PATH "$d/qml"
prepend QML2_IMPORT_PATH "$d/lib/qml"
prepend QML2_IMPORT_PATH "$d/lib64/qml"
prepend QML2_IMPORT_PATH "$d/lib/x86_64-linux-gnu/qml"
prepend XDG_DATA_DIRS "$d/share"
prepend XDG_CONFIG_DIRS "$d/etc/xdg"
fi
}
export -f add_env
export SRC_ROOT=$HOME/projects
export CS_PATHS=(
${CS_PATH[@]}
$SRC_ROOT/src
$SRC_ROOT/qt5
)
# Make
# set your common make flags here, so all scripts can benefit from them
# general rule-of-thumb for -j: #cpucores + 1
export MAKEFLAGS=" -j$(($(nproc)+1)) "
# Make
# Tell many scripts how to switch from source dir to build dir:
# requires makeobj from kdesdk and replaces src with build
export SRC_TO_BUILD="s,/src/,/build/,"
export BUILD_TO_SRC="s,/build/,/src/,"
export OBJ_REPLACEMENT="$SRC_TO_BUILD"
# you might have to change the actual filename in the path below
# in my git repo the file is called kf5_setup.sh
# NOTE: it's important this lies in ~/.kde/env so it gets
# called at KDE startup. This makes compiled applications
# available via KRunner etc.
. ~/.bin/kf5_setup.sh
# A function to easily build the current directory of KDE.
#
# This builds only the sources in the current ~/{src,build}/ subdirectory.
# Usage: cs somewhere && cmakekde
# will build/rebuild the sources in ~/src/somewhere
function cmakekde {
local srcFolder current switched fail
switched=0
# get srcFolder for current dir
srcFolder=$(pwd | sed -e "$BUILD_TO_SRC")
# we are in the src folder, change to build directory
# Alternatively, we could just use makeobj in the commands below...
current=$(pwd)
if [ "$srcFolder" = "$current" ]; then
cb
switched=1
fi
fail=0
cmake "$srcFolder" -DCMAKE_INSTALL_PREFIX=$CMAKE_INSTALL_PREFIX \
'-DCMAKE_CXX_FLAGS:STRING=-pipe -DQT_STRICT_ITERATORS -DQURL_NO_CAST_FROM_STRING -Wformat -Werror=format-security -Werror=return-type -Wno-variadic-macros' \
-DBUILD_TESTING=TRUE -DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -G Ninja || fail=1
if [[ $fail == 1 ]]; then
return 1
fi
make install
if test $switched -eq 1; then
cs
fi
}
export -f cmakekde
# A function to easily change to the build directory.
# Usage: cb
# will simply go to the build folder if you are currently in a src folder
# Example:
# $ pwd
# /home/user/src/KDE/kdebase
# $ cb && pwd
# /home/user/build/KDE/kdebase
function cb {
local dest
if [[ "$(pwd)" == *"/build"* ]]; then
return 0
fi
# substitute src dir with build dir
dest=$(pwd | sed -e "$SRC_TO_BUILD")
current=$(pwd)
if [ "$dest" = "$current" ]; then
echo "no build dir found for path $current."
return 1
fi
if test ! -d "$dest"; then
# build directory does not exist, create
mkdir -p "$dest"
fi
cd "$dest"
}
export -f cb
# Change to the source directory. Same as cb, except this
# switches to the source folder instead of the build folder.
# Usage: cs
# will simply go to the source folder if you are currently in a build folder
# Example:
# $ pwd
# /home/user/build/KDE/kdebase
# $ cs && pwd
# /home/user/src/KDE/kdebase
function cs {
local dest current
# command line argument
if test -n "$1"; then
cd "$SRC_ROOT/$1"
else
# substitute build dir with src dir
dest=$(pwd | sed -e "$BUILD_TO_SRC")
current=$(pwd)
if [ "$dest" = "$current" ]; then
cd "$SRC_ROOT"
else
cd "$dest"
fi
fi
}
export -f cs
# Add autocompletion to cs function
function _cs_scandir
{
local base ext
base=$1
ext=$2
if [ -d $base ]; then
for d in `ls $base`; do
if [ -d $base/$d ]; then
dirs="$dirs $ext$d/"
fi
done
fi
}
function _cs()
{
local cur dirs dir
for dir in ${CS_PATHS[@]}; do
_cs_scandir "$dir" "${dir/$SRC_ROOT\//}/"
done
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "${dirs}" -- ${cur}) )
}
# Remove comment on next line to enable cs autocompletion
complete -F _cs cs
# see http://ftp.hu.freebsd.org/pub/linux/distributions/frugalware/frugalware-testing/t/functions.sh
function in_array
{
local i
needle=$1
shift 1
# array() undefined
[ -z "$1" ] && return 1
for i in $*
do
[ "$i" == "$needle" ] && return 0
done
return 1
}
export -f in_array
# see http://stackoverflow.com/questions/1527049/bash-join-elements-of-an-array
function join_array
{
local IFS="$1";
shift;
echo "$*";
}
export -f join_array
# completion for kdetest
function _kdetest
{
local tests;
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
old_pwd=$(pwd)
cb
tests=$(listCTests ${COMP_WORDS[1]})
if [[ "$prev" == "kdetest" || "$prev" == "--debug" ]]; then
# completion of tests
COMPREPLY=( $(compgen -W "${tests}" -- ${cur}) )
elif in_array "$prev" $tests; then
# completion of available functions
COMPREPLY=( $(compgen -W "$(./$prev -functions 2>/dev/null | cut -f 1 -d \( )" -- ${cur}) )
fi
cd "$old_pwd"
}
# removes .shell from the end of each test file
function listCTests {
local tests;
tests=""
tests=$(LANG=en_US.UTF-8 ctest -N -V | grep "Test command:" | grep -E -o ' [^ ]+$' | xargs readlink -f | cut -c $(echo $(readlink -f $(pwd))"/" | wc -c)-)
if [[ "$1" == "--debug" ]]; then
# remove trailing .shell
for t in $tests; do
echo -n ${t/.shell/}" "
done
echo
else
echo $tests
fi
}
export -f listCTests
alias kdetest="sh ~/.bin/kdetest.sh"
complete -F _kdetest kdetest