forked from albertz/openlierox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
executable file
·104 lines (95 loc) · 2.64 KB
/
functions.sh
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
#!/bin/sh
# collection of helper-functions, mainly for compile.sh
# some simple existance-test-function
# searches for a header file in all include paths
# $1 - header file
# $INCLUDE_PATH - list of include paths
# returns 1 when not found
test_include_file() {
for p in $INCLUDE_PATH; do
[ -e "$p"/"$1" ] && return 0
done
return 1
}
# check if executable is there
# $1 - executable
# return 1 if not available
test_exec() {
which "$1" 1>/dev/null 2>/dev/null
return $?
}
# grep specific parameter out of input-stream
# $1 - parameter-name
# example: stdin=-Iinclude, $1=-I => stdout=include
grep_param() {
grepexpr=$(echo $1 | sed -e "s/-/[-]/")
for p in $(xargs); do
echo "$p" | grep "$grepexpr" | sed -e "s/$1//"
done
}
# simple own sdl-config
# tries to behave like sdl-config
# replacement for sdl-config if not available
# $1 = --libs => lib-flags for linker
# $1 = --cflags => compiler-flags
# $INCLUDE_PATH - used for include-paths for compiler flags
# prints out the flags on stdout
own_sdl_config() {
[ "$1" = "--libs" ] && echo "-lSDL"
if [ "$1" = "--cflags" ]; then
for d in $INCLUDE_PATH; do
[ -d "$d/SDL" ] && echo -n "-I$d/SDL "
done
echo ""
fi
}
# simply own xml2-config
# tries to behave like xml2-config
# replacement for xml2-config if not available
# $1 = --libs => lib-flags for linker
# $1 = --cflags => compiler-flags
# $INCLUDE_PATH - used for include-paths for compiler flags
# prints out the flags on stdout
own_xml2_config() {
[ "$1" = "--libs" ] && echo "-lz -lxml2"
if [ "$1" = "--cflags" ]; then
for d in $INCLUDE_PATH; do
[ -d "$d/libxml2" ] && echo -n "-I$d/libxml2 "
done
echo ""
fi
}
# get somehow a version-string (like "0.57_beta4_r1090")
# reads the file VERSION if available or else reads out from Version.h
# if SVN-data is available, it adds the revision number to the string
# prints out the version on stdout
get_olx_version() {
VERSION=""
if [ -e VERSION ]; then
VERSION="$(cat VERSION)"
else
VERSION="$(grep LX_VERSION src/common/Version.cpp | \
grep define | grep -o -e "\".*\"" | cut -d "\"" -f 2)"
fi
echo "$VERSION"
}
# builds a parameter string for a list of paths
# $1 - parameter prefix (like "-I ")
# $2 - list of paths/files
# $3 - list of path-suffixes which will be added to each entry of first list
# "$3" = "" => only $2 is used
# example: $* = -L "lib1 lib2 lib3" => stdout = "-L lib1 -L lib2 -L lib3"
# example: $* = -I "p1 p2" "/SDL /libxml2" => stdout = "-I p1/SDL -I p2/libxml"
# prints out the string on stdout
build_param_str() {
for p in $2; do
if [ "$3" = "" ]; then
echo -n "$1 ${p} "
else
for a in $3; do
echo -n "$1 ${p}${a} "
done
fi
done
echo ""
}