RetroArch/qb/qb.libs.sh

264 lines
7.3 KiB
Bash
Raw Normal View History

MAKEFILE_DEFINES=''
CONFIG_DEFINES=''
2012-06-12 22:16:16 +02:00
[ "$PREFIX" ] || PREFIX="/usr/local"
2010-12-30 02:52:02 +01:00
add_define() # $1 = MAKEFILE or CONFIG $2 = define $3 = value
{ eval "${1}_DEFINES=\"\${${1}_DEFINES} $2=$3\""; }
2010-12-30 02:52:02 +01:00
add_include_dirs()
{ while [ "$1" ]; do INCLUDE_DIRS="$INCLUDE_DIRS -I$1"; shift; done
INCLUDE_DIRS="${INCLUDE_DIRS# }"
}
2010-12-30 02:52:02 +01:00
add_library_dirs()
{ while [ "$1" ]; do LIBRARY_DIRS="$LIBRARY_DIRS -L$1"; shift; done
LIBRARY_DIRS="${LIBRARY_DIRS# }"
}
2012-06-12 22:16:16 +02:00
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\"")"
2012-06-12 22:16:16 +02:00
[ "$tmpval" = 'no' ] && return 0
if [ "$1" = cxx ]; then
COMPILER="$CXX"
TEMP_CODE="$TEMP_CXX"
TEST_C="extern \"C\" { void $4(void); } int main() { $4(); }"
2012-06-12 22:16:16 +02:00
else
COMPILER="$CC"
TEMP_CODE="$TEMP_C"
TEST_C="void $4(void); int main(void) { $4(); return 0; }"
2012-06-12 22:16:16 +02:00
fi
2014-01-26 11:05:36 +00:00
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
2012-06-12 22:16:16 +02:00
else
ECHOBUF="Checking existence of ${3% }"
printf %s\\n 'int main(void) { return 0; }' > "$TEMP_CODE"
2012-06-12 22:16:16 +02:00
fi
answer='no'
"$COMPILER" -o \
"$TEMP_EXE" \
"$TEMP_CODE" \
$INCLUDE_DIRS \
$LIBRARY_DIRS \
$(printf %s "$5") \
$CFLAGS \
$LDFLAGS \
$(printf %s "$3") >>config.log 2>&1 && answer='yes'
eval "HAVE_$2=\"$answer\""
printf %s\\n "$ECHOBUF ... $answer"
2017-11-06 07:17:52 -08:00
rm -f -- "$TEMP_CODE" "$TEMP_EXE"
2012-06-12 22:16:16 +02:00
[ "$answer" = 'no' ] && {
[ "$7" ] && die 1 "$7"
2012-06-12 22:16:16 +02:00
[ "$tmpval" = 'yes' ] && {
die 1 "Forced to build with library $3, but cannot locate. Exiting ..."
2012-06-12 22:16:16 +02:00
}
2012-06-12 22:16:16 +02:00
}
2014-01-26 11:05:36 +00:00
return 0
2010-12-30 02:52:02 +01:00
}
2011-06-25 14:44:45 +02:00
check_code_c()
2012-06-12 22:16:16 +02:00
{ tmpval="$(eval echo \$HAVE_$1)"
[ "$tmpval" = 'no' ] && return 0
2011-06-25 14:44:45 +02:00
2012-06-12 22:16:16 +02:00
ECHOBUF="Checking C code snippet \"$3\""
answer='no'
2012-10-06 10:30:45 +02:00
"$CC" -o "$TEMP_EXE" "$TEMP_C" $INCLUDE_DIRS $LIBRARY_DIRS $2 $CFLAGS $LDFLAGS >>config.log 2>&1 && answer='yes'
2012-06-12 22:16:16 +02:00
eval HAVE_$1="$answer"; echo "$ECHOBUF ... $answer"
2017-11-06 07:17:52 -08:00
rm -f -- "$TEMP_C" "$TEMP_EXE"
2011-06-25 14:44:45 +02:00
}
2012-06-12 22:16:16 +02:00
check_code_cxx()
{ tmpval="$(eval echo \$HAVE_$1)"
[ "$tmpval" = 'no' ] && return 0
ECHOBUF="Checking C++ code snippet \"$3\""
answer='no'
2012-10-06 10:30:45 +02:00
"$CXX" -o "$TEMP_EXE" "$TEMP_CXX" $INCLUDE_DIRS $LIBRARY_DIRS $2 $CXXFLAGS $LDFLAGS >>config.log 2>&1 && answer='yes'
2012-06-12 22:16:16 +02:00
eval HAVE_$1="$answer"; echo "$ECHOBUF ... $answer"
2017-11-06 07:17:52 -08:00
rm -f -- "$TEMP_CXX" "$TEMP_EXE"
2012-06-12 22:16:16 +02:00
}
check_pkgconf() #$1 = HAVE_$1 $2 = package $3 = version $4 = critical error message [checked only if non-empty]
{ tmpval="$(eval echo \$HAVE_$1)"
[ "$tmpval" = 'no' ] && return 0
ECHOBUF="Checking presence of package $2"
2015-04-19 08:34:37 -03:00
[ "$3" ] && ECHOBUF="$ECHOBUF >= $3"
[ "$PKG_CONF_PATH" = "none" ] && {
2015-04-19 10:56:57 -03:00
eval HAVE_$1="no"
echo "$ECHOBUF ... no"
return 0
}
2012-06-12 22:16:16 +02:00
answer='no'
2015-04-19 08:34:37 -03:00
version='no'
2014-06-05 11:09:10 +02:00
$PKG_CONF_PATH --atleast-version="${3:-0.0}" "$2" && {
2012-06-12 22:16:16 +02:00
answer='yes'
2015-04-19 08:34:37 -03:00
version=$($PKG_CONF_PATH --modversion "$2")
eval $1_CFLAGS=\"$($PKG_CONF_PATH $2 --cflags)\"
eval $1_LIBS=\"$($PKG_CONF_PATH $2 --libs)\"
2012-06-12 22:16:16 +02:00
}
2015-04-19 08:34:37 -03:00
eval HAVE_$1="$answer";
echo "$ECHOBUF ... $version"
2012-06-12 22:16:16 +02:00
PKG_CONF_USED="$PKG_CONF_USED $1"
[ "$answer" = 'no' ] && {
[ "$4" ] && die 1 "$4"
[ "$tmpval" = 'yes' ] && \
die 1 "Forced to build with package $2, but cannot locate. Exiting ..."
2012-06-12 22:16:16 +02:00
}
}
2015-10-11 16:06:06 +02:00
check_header() #$1 = HAVE_$1 $2..$5 = header files
2012-06-12 22:16:16 +02:00
{ tmpval="$(eval echo \$HAVE_$1)"
[ "$tmpval" = 'no' ] && return 0
2015-10-11 16:06:06 +02:00
CHECKHEADER="$2"
echo "#include <$2>" > "$TEMP_C"
[ "$3" != "" ] && CHECKHEADER="$3" && echo "#include <$3>" >> "$TEMP_C"
[ "$4" != "" ] && CHECKHEADER="$4" && echo "#include <$4>" >> "$TEMP_C"
[ "$5" != "" ] && CHECKHEADER="$5" && echo "#include <$5>" >> "$TEMP_C"
echo "int main(void) { return 0; }" >> "$TEMP_C"
2012-06-12 22:16:16 +02:00
answer='no'
2012-10-06 10:30:45 +02:00
"$CC" -o "$TEMP_EXE" "$TEMP_C" $INCLUDE_DIRS >>config.log 2>&1 && answer='yes'
2015-10-11 16:06:06 +02:00
eval HAVE_$1="$answer"; echo "Checking presence of header file $CHECKHEADER ... $answer"
2017-11-06 07:17:52 -08:00
rm -f -- "$TEMP_C" "$TEMP_EXE"
[ "$tmpval" = 'yes' ] && [ "$answer" = 'no' ] && \
die 1 "Build assumed that $2 exists, but cannot locate. Exiting ..."
2012-06-12 22:16:16 +02:00
}
2012-12-09 17:28:49 +02:00
check_macro() #$1 = HAVE_$1 $2 = macro name
{ tmpval="$(eval echo \$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'
"$CC" -o "$TEMP_EXE" "$TEMP_C" $CFLAGS $INCLUDE_DIRS >>config.log 2>&1 && answer='yes'
eval HAVE_$1="$answer"; echo "$ECHOBUF ... $answer"
2017-11-06 07:17:52 -08:00
rm -f -- "$TEMP_C" "$TEMP_EXE"
[ "$tmpval" = 'yes' ] && [ "$answer" = 'no' ] && \
die 1 "Build assumed that $2 is defined, but it's not. Exiting ..."
2012-12-09 17:28:49 +02:00
}
2012-06-12 22:16:16 +02:00
check_switch_c() #$1 = HAVE_$1 $2 = switch $3 = critical error message [checked only if non-empty]
{ ECHOBUF="Checking for availability of switch $2 in $CC"
echo "int main(void) { return 0; }" > $TEMP_C
answer='no'
2012-10-06 10:30:45 +02:00
"$CC" -o "$TEMP_EXE" "$TEMP_C" $2 >>config.log 2>&1 && answer='yes'
2012-06-12 22:16:16 +02:00
eval HAVE_$1="$answer"; echo "$ECHOBUF ... $answer"
2017-11-06 07:17:52 -08:00
rm -f -- "$TEMP_C" "$TEMP_EXE"
2012-06-12 22:16:16 +02:00
[ "$answer" = 'no' ] && {
[ "$3" ] && die 1 "$3"
2012-06-12 22:16:16 +02:00
}
}
check_switch_cxx() #$1 = HAVE_$1 $2 = switch $3 = critical error message [checked only if non-empty]
{ ECHOBUF="Checking for availability of switch $2 in $CXX"
echo "int main() { return 0; }" > $TEMP_CXX
answer='no'
2012-10-06 10:30:45 +02:00
"$CXX" -o "$TEMP_EXE" "$TEMP_CXX" "$2" >>config.log 2>&1 && answer='yes'
2012-06-12 22:16:16 +02:00
eval HAVE_$1="$answer"; echo "$ECHOBUF ... $answer"
2017-11-06 07:17:52 -08:00
rm -f -- "$TEMP_CXX" "$TEMP_EXE"
2012-06-12 22:16:16 +02:00
[ "$answer" = 'no' ] && {
[ "$3" ] && die 1 "$3"
2012-06-12 22:16:16 +02:00
}
2010-12-30 02:52:02 +01:00
}
create_config_header()
2012-06-12 22:16:16 +02:00
{ outfile="$1"; shift
2010-12-30 02:52:02 +01:00
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\""
2010-12-30 02:52:02 +01:00
2012-06-12 22:16:16 +02:00
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 */";;
2012-06-12 22:16:16 +02:00
esac
shift
done
2010-12-30 02:52:02 +01:00
eval "set -- $CONFIG_DEFINES"
for VAR do
printf %s\\n "#define ${VAR%%=*} ${VAR#*=}"
done
2010-12-30 02:52:02 +01:00
printf %s\\n '#endif'
2012-06-12 22:16:16 +02:00
} > "$outfile"
2010-12-30 02:52:02 +01:00
}
2012-06-12 22:16:16 +02:00
create_config_make()
{ outfile="$1"; shift
printf %s\\n "Creating make config: $outfile"
2012-06-12 22:16:16 +02:00
{ [ "$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"
2012-06-12 22:16:16 +02:00
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";;
2012-06-12 22:16:16 +02:00
esac
case "$PKG_CONF_USED" in
*$1*)
FLAGS="$(eval "printf %s \"\$$1_CFLAGS\"")"
LIBS="$(eval "printf %s \"\$$1_LIBS\"")"
printf %s\\n "$1_CFLAGS = ${FLAGS%"${FLAGS##*[! ]}"}" \
"$1_LIBS = ${LIBS%"${LIBS##*[! ]}"}"
2012-06-12 22:16:16 +02:00
;;
esac
shift
done
eval "set -- $MAKEFILE_DEFINES"
for VAR do
printf %s\\n "${VAR%%=*} = ${VAR#*=}"
done
2012-06-12 22:16:16 +02:00
} > "$outfile"
}
. qb/config.libs.sh