C1="${MOCFILE##moc_}"# foo.cpp or foo_p.cpp or foo_p_p.cpp
case"$MOCFILE" in
moc_*_p_p.cpp)
C2="${C1/_p.cpp/.cpp}"# foo_p.cpp
C3="${C2/_p.cpp/.cpp}"# foo.cpp
CANDIDATES=("$C1""$C2""$C3")
;;
moc_*_p.cpp)
C2="${C1/_p.cpp/.cpp}"# foo.cpp
CANDIDATES=("$C1""$C2")
;;
moc_*.cpp)
CANDIDATES=("$C1")
;;
*)
die "Don't know how to handle moc-file \"$MOCFILE\"..."
;;
esac
log "CANDIDATES=(${CANDIDATES[@]})"
for CANDIDATE in "${CANDIDATES[@]}";do
CPPFILE="$(find "$SRCDIR" -name "$CANDIDATE")"
log "CPPFILE=$CPPFILE"
[[ -f "$CPPFILE"]]&&break
done
if[[ -f "$CPPFILE"]];then
log "going to include $MOCFILE into $CPPFILE"
if ! grep -qE '^QT_END_NAMESPACE$'"$CPPFILE";then
warn "Can't find QT_END_NAMESPACE in \"$CPPFILE\", simply appending the #include. Please check placement manually."
echo"#include \"$MOCFILE\"" >> "$CPPFILE"|| die "Failed to write to \"$CPPFILE\""
else
sed -i -e "1,/QT_END_NAMESPACE/ s/QT_END_NAMESPACE/QT_END_NAMESPACE\n\n#include \"$MOCFILE\"/""$CPPFILE"|| die "Failed to includemoc \"$MOCFILE\" into \"$CPPFILE\"."
fi
else
continue_or_die "Can't find a cpp file for $MOCFILE (not looking for .cxx .cc etc)."