Added internal-lirc-backend and stuff.
[irreco.git] / script / variables.sh
blob583f83155d480246aef5070381029212f05b54eb
3 # Variables
6 # Get the absolute path of a file.
7 # Args 1: Relative path to file
8 get_absolute_path() {
9 readlink -f "$1"
10 if [[ "$?" != "0" ]]; then
11 echo "Error: Could not get absolute path to \"$1\"." 1>&2
12 exit 1
16 SCRIPT_NAME=`basename "$0"`
17 SCRIPT_DIR=`get_absolute_path "$PWD"`
18 SCRIPT_TMP_DIR="$SCRIPT_DIR/tmp"
19 SCRIPT_PARENT_DIR=`get_absolute_path "$SCRIPT_DIR/.."`
20 SCRIPT_PATH="$SCRIPT_DIR/$SCRIPT_NAME"
21 BACKEND_DIR=`get_absolute_path ../backend`
22 IRRECO_DIR=`get_absolute_path ../irreco`
23 IRRECO_DATA="$IRRECO_DIR/data"
24 IRRECO_SRC="$IRRECO_DIR/src"
25 INSTALL_DIR=`get_absolute_path ".."`"/install"
26 MAKE_LOG_FILE="$SCRIPT_TMP_DIR/make_log"
27 RUN_LOG_FILE="$SCRIPT_TMP_DIR/run_log"
28 DEB_LOG_FILE="$SCRIPT_TMP_DIR/deb_log"
29 ERROR_CONTEXT=0
30 EXIT_CODE_FILE="$SCRIPT_TMP_DIR/exit_code"
31 ALL_BACKENDS_FILTER="(mythtv|irtrans)"
33 mkdir -p "$SCRIPT_TMP_DIR"
35 find_theme_dir()
37 #THEME_DIR='../../../../themes'
38 #if [ ! -d "$THEME_DIR" ]; then
39 # THEME_DIR='../../../themes'
40 # if [ ! -d "$THEME_DIR" ]; then
41 # THEME_DIR='../../themes'
42 # if [ ! -d "$THEME_DIR" ]; then
43 # echo "Cant find theme dir"
44 # exit 1
45 # fi
46 # fi
47 #fi
49 THEME_DIR='../themes'
50 if [ ! -d "$THEME_DIR" ]; then
51 echo "Cant find theme dir"
52 exit 1
55 THEME_DIR=`get_absolute_path "$THEME_DIR"`
58 find_irtrans_dir()
60 #IRTRANS_DIR='../../../../irtrans/'
61 #if [ ! -d "$IRTRANS_DIR" ]; then
62 # IRTRANS_DIR='../../../irtrans/'
63 # if [ ! -d "$IRTRANS_DIR" ]; then
64 # IRTRANS_DIR='../../irtrans/'
65 # if [ ! -d "$IRTRANS_DIR" ]; then
66 # echo "Cant find theme dir"
67 # exit 1
68 # fi
69 # fi
70 #fi
72 IRTRANS_DIR='../irtrans/'
73 if [ ! -d "$IRTRANS_DIR" ]; then
74 echo "Cant find theme dir"
75 exit 1
78 IRTRANS_DIR=`get_absolute_path "$IRTRANS_DIR"`
79 IRTRANS_SHLIB_DIR="$IRTRANS_DIR/shlib"
80 IRTRANS_IRSERVER_DIR="$IRTRANS_DIR/irserver"
85 # Utility functions
88 create_install_dir()
90 if [ ! -e "$INSTALL_DIR" ]; then
91 mkdir "$INSTALL_DIR"
92 check_exit_code "$?"
96 scratchbox_need()
98 if [[ "$_SBOX_DIR" == "" ||
99 "$_SBOX_RESTART_FILE" == "" ||
100 "$_SBOX_SHELL_PID" == "" ||
101 "$_SBOX_USER_GROUPNAME" == "" ]]; then
102 echo "Error: Need scratchbox."
103 exit 1
106 #which sb-conf &> /dev/null
107 #if [[ "$?" != "0" ]]; then
108 # echo "Error: Need scratchbox."
109 # exit 1
113 scratchbox_avoid()
115 if [[ "$_SBOX_DIR" != "" ||
116 "$_SBOX_RESTART_FILE" != "" ||
117 "$_SBOX_SHELL_PID" != "" ||
118 "$_SBOX_USER_GROUPNAME" != "" ]]; then
119 echo "Error: Cant run this command inside scratchbox."
120 exit 1
123 #which sb-conf &> /dev/null
124 #if [[ "$?" == "0" ]]; then
125 # echo "Error: Cant run this command inside scratchbox."
126 # exit 1
130 print_title()
132 TITLE="$1"
133 echo -en "\n___ "
134 echo -n "$TITLE "
136 LEN=`echo ${#TITLE}`
137 for ((LEN += 6; LEN <= 80; LEN++)); do
138 echo -n _
139 done
140 echo
144 # Check log for error & warnings
145 # Args 1: Log file
146 # 2: Exit on match
147 check_log()
149 REGEX_IGNORE='(^if gcc |^[[:space:]]*gcc |^/bin/sh |^if /bin/sh|^/usr/share/aclocal/audiofile\.m4)'
151 REGEX="(warning|error|cannot find"
152 REGEX="$REGEX|^[0-9a-zA-Z\/._-]+\.[cho]:"
153 REGEX="$REGEX|^[0-9a-zA-Z\/._-]+:[0-9]+"
154 REGEX="$REGEX|^[0-9a-zA-Z\/._-]+:[0-9]+:[0-9]+"
155 REGEX="$REGEX|^:[0-9a-zA-Z\/._-]+"
156 REGEX="${REGEX})"
158 cat "$1" | egrep -v "$REGEX_IGNORE" \
159 | egrep -i -A $ERROR_CONTEXT -B $ERROR_CONTEXT --color=yes "$REGEX"
160 EXIT_CODE="$?"
161 if [[ "$2" == "1" ]]; then
162 if [[ "$EXIT_CODE" != "0" ]]; then
163 echo "... none"
164 else
165 exit 1
170 save_exit_code()
172 "$@"
173 echo "$?" > "$EXIT_CODE_FILE"
176 get_exit_code()
178 EXIT_CODE=`cat "$EXIT_CODE_FILE"`
179 rm "$EXIT_CODE_FILE"
180 return $EXIT_CODE
184 # Stop script if exit code is not 0
186 # Usage: check_exit_code "$?"
187 check_exit_code()
189 if [[ "$1" != "0" ]]; then
190 if [[ "$2" != "" ]]; then
191 echo "Error:" "$2" "$3" "$4" "$5"
193 echo "Exit code: $1"
194 exit "$1"
198 scripts_src_pad()
200 while read LINE; do
201 echo "\\"
202 echo -n " $LINE"
203 LEN=32-${#LINE}
204 for ((; LEN > 0; LEN--)); do
205 echo -n " "
206 done
207 done
208 echo
214 # Generic build functions
217 generic_make()
219 MAKE_ARGS=("$@")
220 TITLE_FUNC="$1"
222 $TITLE_FUNC "MAKE"
223 save_exit_code make "${MAKE_ARGS[@]:1}" 2>&1 | tee "$MAKE_LOG_FILE"
225 $TITLE_FUNC "ERRORS"
226 check_log "$MAKE_LOG_FILE" "1"
227 get_exit_code
228 check_exit_code "$?"
231 generic_clean()
233 TITLE_FUNC="$1"
235 $TITLE_FUNC "CLEAN"
237 if [ -e "Makefile" ]; then
238 make uninstall
239 make clean
240 make distclean
243 if [ -e "autoclean.sh" ]; then
244 ./autoclean.sh
250 # Save current sb_target to file,
251 # and return 0 if it is the same as current target.
253 match_sb_target()
255 SB_TARGET_FILE="$1"
256 CURRENT_TARGET=`sb-conf current`
258 if [ -f "$SB_TARGET_FILE" ]; then
259 PREVIOUS_TARGET=`cat "$SB_TARGET_FILE"`
260 else
261 PREVIOUS_TARGET=""
264 #echo "SB_TARGET_FILE = $SB_TARGET_FILE"
265 #echo "CURRENT_TARGET = $CURRENT_TARGET"
266 #echo "PREVIOUS_TARGET = $PREVIOUS_TARGET"
268 if [[ "$CURRENT_TARGET" != "$PREVIOUS_TARGET" ]]; then
269 echo "Saving \"$CURRENT_TARGET\" to \"$SB_TARGET_FILE\""
270 echo "$CURRENT_TARGET" > "$SB_TARGET_FILE"
271 check_exit_code "$?"
272 #echo return 1
273 return 1
276 #echo return 0
277 return 0