RetroArch/qb/qb.moc.sh
orbea 13cf3cdef2 qb: Refactor how config.h and config.mk are created.
This is a potential security issue.

The problem is that config.h and config.mk are populated with
all variables prefixed with 'HAVE_' from the user's environment.

Example:

  $ HAVE_FOO=yes ./configure
  $ grep FOO config.mk
  HAVE_FOO = 1
  $ grep FOO config.h
  #define HAVE_FOO 1

After this commit these files will only use variables set by
qb configure process and not from the user's environment. This
issue could result in hard to diagnose undefined behavior or
maybe worse?

The user should experience no change in behavior, but
developers should be more careful about setting 'HAVE_'
variables manually.

Unless the FOO variable is used by check_enabled ($2 only),
check_platform, check_lib, check_pkgconf, check_header,
check_macro or check_switch functions it should be set at
least once by the new add_opt function. The first argument
should be 'FOO' which matches the HAVE_FOO variable and the
second argument should contain 'auto', 'no' or 'yes'.

Example:

  add_opt FOO yes

When in doubt its safe to use add_opt. This will also fix a
few potential issues where configure arguments used by the
user are ignored.

When the second argument is not set the FOO variable will only
be used to populate config.h and config.mk with its current
value. This should only be done in qb/qb.libs.sh in functions
that set 'HAVE_' variables.
2019-07-28 07:59:41 -07:00

61 lines
1.2 KiB
Bash

. qb/config.moc.sh
TEMP_MOC=.moc.h
TEMP_CPP=.moc.cpp
MOC="${MOC:-}"
# Checking for working moc
cat << EOF > "$TEMP_MOC"
#include <QTimeZone>
class Test : public QObject
{
public:
Q_OBJECT
QTimeZone tz;
};
EOF
add_opt MOC no
if [ "$HAVE_QT" = "yes" ]; then
moc_works=0
if [ "$MOC" ]; then
QT_SELECT="$QT_VERSION" \
"$MOC" -o "$TEMP_CPP" "$TEMP_MOC" >/dev/null 2>&1 &&
"$CXX" -o "$TEMP_EXE" $(printf %s "$QT_FLAGS") \
-fPIC -c "$TEMP_CPP" >/dev/null 2>&1 &&
moc_works=1
else
for moc in "moc-$QT_VERSION" moc; do
MOC="$(exists "$moc")" || MOC=""
if [ "$MOC" ]; then
QT_SELECT="$QT_VERSION" \
"$MOC" -o "$TEMP_CPP" "$TEMP_MOC" >/dev/null 2>&1 ||
continue
"$CXX" -o "$TEMP_EXE" $(printf %s "$QT_FLAGS") \
-fPIC -c "$TEMP_CPP" >/dev/null 2>&1 && {
moc_works=1
break
}
fi
done
fi
moc_status='does not work'
if [ "$moc_works" = '1' ]; then
moc_status='works'
HAVE_MOC='yes'
elif [ -z "$MOC" ]; then
moc_status='not found'
fi
printf %s\\n "Checking for moc ... $MOC $moc_status"
if [ "$HAVE_MOC" != 'yes' ]; then
HAVE_QT='no'
die : 'Warning: moc not found, Qt companion support will be disabled.'
fi
fi
rm -f -- "$TEMP_CPP" "$TEMP_EXE" "$TEMP_MOC"