-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-flags
executable file
·146 lines (125 loc) · 4.04 KB
/
build-flags
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
#!/bin/bash
# Currently only Linux and Mac OSX are supported platforms
ALL=( "python" "numpy" "gr" )
SUPPORTED_OS=( "Darwin" "Linux" )
OS=$(uname -s)
array_contains() {
# first argument: key, other arguments: array contains (passing by ${array[@]})
local e
for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
python_flags() {
local DARWIN_CONDA_INCLUDE="${CONDA_PREFIX}/include/python2.7"
local DARWIN_CONDA_LIB="${CONDA_PREFIX}/lib"
local DARWIN_LOCAL_FRAMEWORK="/usr/local/Library/Frameworks"
local DARWIN_FRAMEWORK="/System/Library/Frameworks"
local DARWIN_LOCAL_INCLUDE="/usr/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7"
local DARWIN_INCLUDE="/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7"
local LINUX_LOCAL_INCLUDE="/usr/local/include/python2.7"
local LINUX_INCLUDE="/usr/include/python2.7"
local LINUX_LOCAL_LIB="/usr/local/lib/python2.7"
local LINUX_LIB="/usr/lib/python2.7"
local INC_FLAGS
local LIB_FLAGS
case "${OS}" in
Darwin)
if [ -n "${CONDA_PREFIX}" ]; then
INC_FLAGS="-I${DARWIN_CONDA_INCLUDE}"
LIB_FLAGS="-L${DARWIN_CONDA_LIB} -lpython2.7"
elif [ -d "${DARWIN_LOCAL_FRAMEWORK}" ]; then
INC_FLAGS="-F${DARWIN_LOCAL_FRAMEWORK} -I${DARWIN_LOCAL_INCLUDE}"
LIB_FLAGS="-F${DARWIN_LOCAL_FRAMEWORK} -framework Python"
else
INC_FLAGS="-F${DARWIN_FRAMEWORK} -I${DARWIN_INCLUDE}"
LIB_FLAGS="-F${DARWIN_FRAMEWORK} -framework Python"
fi
;;
Linux)
if [ -d "${LINUX_LOCAL_INCLUDE}" ]; then
INC_FLAGS="-I${LINUX_LOCAL_INCLUDE}"
LIB_FLAGS="-L${LINUX_LOCAL_LIB} -lpython2.7"
else
INC_FLAGS="-I${LINUX_INCLUDE}"
LIB_FLAGS="-L${LINUX_LIB} -lpython2.7"
fi
;;
esac
eval "${1}=\"${INC_FLAGS}\""
eval "${2}=\"${LIB_FLAGS}\""
}
numpy_flags() {
local REL_NUMPY_INCLUDE="core/include"
local PYTHON_EXEC
local INC_FLAGS
if [ -f "/usr/local/bin/python" ]; then
PYTHON_EXEC="/usr/local/bin/python"
else
PYTHON_EXEC=$(which python)
fi
INC_FLAGS=$(${PYTHON_EXEC} <<EOF
import numpy
import os.path
numpy_package_path = os.path.dirname(numpy.__file__)
print('-I{}'.format(os.path.join(numpy_package_path, 'core/include')))
EOF
)
eval "${1}=\"${INC_FLAGS}\""
eval "${2}=\"\""
}
gr_flags() {
local POSSIBLE_GR_DIRS=( "/usr/local/gr" "/usr/gr" "/opt/gr" )
local INC_FLAGS
local LIB_FLAGS
for i in ${POSSIBLE_GR_DIRS[@]}; do
if [ -d "${i}" ]; then
INC_FLAGS="-I${i}/include"
LIB_FLAGS="-L${i}/lib -lGR -lGR3"
break
fi
done
eval "${1}=\"${INC_FLAGS}\""
eval "${2}=\"${LIB_FLAGS}\""
}
help() {
echo "${0} [options] [libraries]"
echo "Prints compiler flags for given libraries."
echo "Possible libraries: ${ALL[*]}"
echo "Possible options: --include-flags, --lib-flags"
echo
}
main() {
if ! array_contains "${OS}" "${SUPPORTED_OS[@]}"; then
echo "Sorry, your operating system is currently not supported."
exit 1
fi
if array_contains "--help" "$@"; then
help
exit 0
fi
if [ ! -z "${*//--*/}" ]; then
FLAGS_FOR=( ${*/#--*/} )
else
FLAGS_FOR=( "${ALL[@]}" )
fi
OPTIONS=( ${*/#[a-z]*/} )
INC_FLAGS=
LIB_FLAGS=
for i in ${FLAGS_FOR[@]}; do
eval "${i}_flags CURRENT_INC_FLAGS CURRENT_LIB_FLAGS"
INC_FLAGS="${INC_FLAGS} ${CURRENT_INC_FLAGS}"
LIB_FLAGS="${LIB_FLAGS} ${CURRENT_LIB_FLAGS}"
done
if [ -z "${OPTIONS[*]}" ]; then
echo "${INC_FLAGS} ${LIB_FLAGS}"
else
if array_contains "--include-flags" "${OPTIONS[@]}"; then
echo -n "${INC_FLAGS} "
fi
if array_contains "--lib-flags" "${OPTIONS[@]}"; then
echo -n "${LIB_FLAGS} "
fi
echo
fi
}
main $*