forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
/
qb.libs.sh
251 lines (217 loc) · 6.94 KB
/
qb.libs.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
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
MAKEFILE_DEFINES=''
CONFIG_DEFINES=''
[ "$PREFIX" ] || PREFIX="/usr/local"
add_define() # $1 = MAKEFILE or CONFIG $2 = define $3 = value
{ eval "${1}_DEFINES=\"\${${1}_DEFINES} $2=$3\""; }
add_dirs() # $1 = INCLUDE or LIBRARY $@ = include or library paths
{ ADD="$1"; LINK="${1%"${1#?}"}"; shift
while [ "$1" ]; do
eval "${ADD}_DIRS=\"\${${ADD}_DIRS} -${LINK}${1}\""
shift
done
eval "${ADD}_DIRS=\"\${${ADD}_DIRS# }\""
}
check_compiler() # $1 = language $2 = function in lib
{ if [ "$1" = cxx ]; then
COMPILER="$CXX"
TEMP_CODE="$TEMP_CXX"
TEST_C="extern \"C\" { void $2(void); } int main() { $2(); }"
else
COMPILER="$CC"
TEMP_CODE="$TEMP_C"
TEST_C="void $2(void); int main(void) { $2(); return 0; }"
fi
}
check_lib() # $1 = language $2 = HAVE_$2 $3 = lib $4 = function in lib $5 = extralibs $6 = headers $7 = critical error message [checked only if non-empty]
{ tmpval="$(eval "printf %s \"\$HAVE_$2\"")"
[ "$tmpval" = 'no' ] && return 0
check_compiler "$1" "$4"
if [ "$4" ]; then
ECHOBUF="Checking function $4 in ${3% }"
if [ "$6" ]; then
printf %s\\n "$6" "int main(void) { void *p = (void*)$4; return 0; }" > "$TEMP_CODE"
else
printf %s\\n "$TEST_C" > "$TEMP_CODE"
fi
else
ECHOBUF="Checking existence of ${3% }"
printf %s\\n 'int main(void) { return 0; }' > "$TEMP_CODE"
fi
val="$2"
lib="$3"
error="${7:-}"
answer='no'
eval "set -- $INCLUDE_DIRS $LIBRARY_DIRS $5 $CFLAGS $LDFLAGS $3"
"$COMPILER" -o "$TEMP_EXE" "$TEMP_CODE" "$@" >>config.log 2>&1 && answer='yes'
eval "HAVE_$val=\"$answer\""
printf %s\\n "$ECHOBUF ... $answer"
rm -f -- "$TEMP_CODE" "$TEMP_EXE"
if [ "$answer" = 'no' ]; then
[ "$error" ] && die 1 "$error"
[ "$tmpval" = 'yes' ] && {
die 1 "Forced to build with library $lib, but cannot locate. Exiting ..."
}
else
eval "${val}_LIBS=\"$lib\""
PKG_CONF_USED="$PKG_CONF_USED $val"
fi
return 0
}
check_pkgconf() # $1 = HAVE_$1 $2 = package $3 = version $4 = critical error message [checked only if non-empty]
{ tmpval="$(eval "printf %s \"\$HAVE_$1\"")"
[ "$tmpval" = 'no' ] && return 0
ECHOBUF="Checking presence of package $2"
[ "$3" ] && ECHOBUF="$ECHOBUF >= $3"
[ "$PKG_CONF_PATH" = "none" ] && {
eval "HAVE_$1=no"
printf %s\\n "$ECHOBUF ... no"
return 0
}
answer='no'
version='no'
$PKG_CONF_PATH --atleast-version="${3:-0.0}" "$2" && {
answer='yes'
version="$("$PKG_CONF_PATH" --modversion "$2")"
eval "$1_CFLAGS=\"$("$PKG_CONF_PATH" "$2" --cflags)\""
eval "$1_LIBS=\"$("$PKG_CONF_PATH" "$2" --libs)\""
}
eval "HAVE_$1=\"$answer\""
printf %s\\n "$ECHOBUF ... $version"
if [ "$answer" = 'no' ]; then
[ "$4" ] && die 1 "$4"
[ "$tmpval" = 'yes' ] && \
die 1 "Forced to build with package $2, but cannot locate. Exiting ..."
else
PKG_CONF_USED="$PKG_CONF_USED $1"
fi
}
check_header() #$1 = HAVE_$1 $2..$5 = header files
{ tmpval="$(eval "printf %s \"\$HAVE_$1\"")"
[ "$tmpval" = 'no' ] && return 0
CHECKHEADER="$2"
printf %s\\n "#include <$2>" > "$TEMP_C"
[ "$3" != '' ] && CHECKHEADER="$3" && printf %s\\n "#include <$3>" >> "$TEMP_C"
[ "$4" != '' ] && CHECKHEADER="$4" && printf %s\\n "#include <$4>" >> "$TEMP_C"
[ "$5" != '' ] && CHECKHEADER="$5" && printf %s\\n "#include <$5>" >> "$TEMP_C"
printf %s\\n "int main(void) { return 0; }" >> "$TEMP_C"
answer='no'
val="$1"
header="$2"
eval "set -- $INCLUDE_DIRS"
"$CC" -o "$TEMP_EXE" "$TEMP_C" "$@" >>config.log 2>&1 && answer='yes'
eval "HAVE_$val=\"$answer\""
printf %s\\n "Checking presence of header file $CHECKHEADER ... $answer"
rm -f -- "$TEMP_C" "$TEMP_EXE"
[ "$tmpval" = 'yes' ] && [ "$answer" = 'no' ] && \
die 1 "Build assumed that $header exists, but cannot locate. Exiting ..."
}
check_macro() #$1 = HAVE_$1 $2 = macro name
{ tmpval="$(eval "printf %s \"\$HAVE_$1\"")"
[ "$tmpval" = 'no' ] && return 0
ECHOBUF="Checking presence of predefined macro $2"
cat << EOF > "$TEMP_C"
#ifndef $2
#error $2 is not defined
#endif
int main(void) { return 0; }
EOF
answer='no'
val="$1"
macro="$2"
eval "set -- $CFLAGS $INCLUDE_DIRS"
"$CC" -o "$TEMP_EXE" "$TEMP_C" "$@" >>config.log 2>&1 && answer='yes'
eval "HAVE_$val=\"$answer\""
printf %s\\n "$ECHOBUF ... $answer"
rm -f -- "$TEMP_C" "$TEMP_EXE"
[ "$tmpval" = 'yes' ] && [ "$answer" = 'no' ] && \
die 1 "Build assumed that $macro is defined, but it's not. Exiting ..."
}
check_switch() # $1 = language $2 = HAVE_$2 $3 = switch $4 = critical error message [checked only if non-empty]
{ check_compiler "$1" ''
ECHOBUF="Checking for availability of switch $3 in $COMPILER"
printf %s\\n 'int main(void) { return 0; }' > "$TEMP_CODE"
answer='no'
"$COMPILER" -o "$TEMP_EXE" "$TEMP_CODE" "$3" >>config.log 2>&1 && answer='yes'
eval "HAVE_$2=\"$answer\""
printf %s\\n "$ECHOBUF ... $answer"
rm -f -- "$TEMP_CODE" "$TEMP_EXE"
[ "$answer" = 'no' ] && {
[ "$4" ] && die 1 "$4"
}
}
check_val() # $1 = language $2 = HAVE_$2 $3 = lib
{ tmpval="$(eval "printf %s \"\$HAVE_$2\"")"
if [ "$tmpval" = 'no' ]; then
eval "HAVE_$2=auto"
check_lib "$1" "$2" "$3"
fi
}
create_config_header()
{ outfile="$1"; shift
printf %s\\n "Creating config header: $outfile"
name="$(printf %s "QB_${outfile}__" | tr '.[a-z]' '_[A-Z]')"
{ printf %s\\n "#ifndef $name" "#define $name" '' \
"#define PACKAGE_NAME \"$PACKAGE_NAME\""
while [ "$1" ]; do
case "$(eval "printf %s \"\$HAVE_$1\"")" in
'yes')
if [ "$(eval "printf %s \"\$C89_$1\"")" = 'no' ]; then
printf %s\\n '#if __cplusplus || __STDC_VERSION__ >= 199901L' \
"#define HAVE_$1 1" '#endif'
else
printf %s\\n "#define HAVE_$1 1"
fi
;;
'no') printf %s\\n "/* #undef HAVE_$1 */";;
esac
shift
done
eval "set -- $CONFIG_DEFINES"
for VAR do
printf %s\\n "#define ${VAR%%=*} ${VAR#*=}"
done
printf %s\\n '#endif'
} > "$outfile"
}
create_config_make()
{ outfile="$1"; shift
printf %s\\n "Creating make config: $outfile"
{ [ "$USE_LANG_C" = 'yes' ] && printf %s\\n "CC = $CC" "CFLAGS = $CFLAGS"
[ "$USE_LANG_CXX" = 'yes' ] && printf %s\\n "CXX = $CXX" "CXXFLAGS = $CXXFLAGS"
printf %s\\n "WINDRES = $WINDRES" \
"ASFLAGS = $ASFLAGS" \
"LDFLAGS = $LDFLAGS" \
"INCLUDE_DIRS = $INCLUDE_DIRS" \
"LIBRARY_DIRS = $LIBRARY_DIRS" \
"PACKAGE_NAME = $PACKAGE_NAME" \
"BUILD = $BUILD" \
"PREFIX = $PREFIX"
while [ "$1" ]; do
case "$(eval "printf %s \"\$HAVE_$1\"")" in
'yes')
if [ "$(eval "printf %s \"\$C89_$1\"")" = 'no' ]; then
printf %s\\n "ifneq (\$(C89_BUILD),1)" \
"HAVE_$1 = 1" 'endif'
else
printf %s\\n "HAVE_$1 = 1"
fi
;;
'no') printf %s\\n "HAVE_$1 = 0";;
esac
case "$PKG_CONF_USED" in
*$1*)
FLAG="$(eval "printf %s \"\$$1_CFLAGS\"")"
LIBS="$(eval "printf %s \"\$$1_LIBS\"")"
[ "${FLAG}" ] && printf %s\\n "$1_CFLAGS = ${FLAG%"${FLAG##*[! ]}"}"
[ "${LIBS}" ] && printf %s\\n "$1_LIBS = ${LIBS%"${LIBS##*[! ]}"}"
;;
esac
shift
done
eval "set -- $MAKEFILE_DEFINES"
for VAR do
printf %s\\n "${VAR%%=*} = ${VAR#*=}"
done
} > "$outfile"
}
. qb/config.libs.sh