#!/bin/bash

DIR='aaa'
QMAKE='/data/dev/qt-5/qtbase/bin/qmake'

rm -rf $DIR
mkdir $DIR
cd $DIR

killall label-b
killall label-c

cat > label.ui << EOT
<ui version="4.0">
 <class>Label</class>
  <widget class="QLabel" name="Label">
   <property name="text"><string>BBB</string></property>
 </widget>
</ui>
EOT

cat > label.h << EOT
#include <QLabel>
struct Label : public QLabel { Label(); };
EOT

cat > label.cpp << EOT
#include "label.h"
#include "ui_label.h"
Label::Label() { (new Ui::Label)->setupUi(this); }
EOT

cat > main.cpp << EOT
#include "label.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Label dlg;
    dlg.show();
    return a.exec();
}
EOT

cat > label.pro << EOT
CONFIG -= gdb_dwarf_index
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
SOURCES = main.cpp label.cpp 
HEADERS = label.h 
FORMS   = label.ui 
EOT

$QMAKE

cp ./Makefile Makefile-a
make

echo
echo Change:

perl -pi -e 's/BBB/CCC/' label.ui
/usr/bin/make
mv ./label ./label-b
cp ./Makefile Makefile-b
./label-b &

echo
echo Rebuild:

/usr/bin/make clean
/usr/bin/make
mv ./label ./label-c
cp ./Makefile Makefile-c
./label-c &

echo
echo "BBB appears in:"
grep BBB * 

echo
echo "CCC appears in:"
grep CCC *

echo
echo "Diff between Makefile-b and Makefile-c:"
diff Makefile-{b,c}
