Project

General

Profile

qt5-check.sh

Ulrich von der Ohe, 11 Oct 2022 17:58

 
1
#!/usr/bin/env bash
2

    
3
# This script checks sufficiency of installed Qt5 system for the CoCoA5 GUI.
4
# Exit code is 0 iff sufficient, o/w non-zero.
5

    
6
# This script expects no arguments.
7

    
8
SCRIPT_NAME="[[$(basename "$0")]]"
9
SCRIPT_DIR="$(dirname "$0")"
10

    
11
if [ $# -ne 0 ]; then
12
    echo "ERROR: expected no args   $SCRIPT_NAME" > /dev/stderr
13
    exit 1
14
fi
15

    
16
# Create tmp directory, put test prog in it, compile and run.
17
umask 22
18
# shellcheck source=shell-fns.sh
19
. "$SCRIPT_DIR/shell-fns.sh"
20
TMP_DIR="$(mktempdir qt5-check)"
21

    
22
pushd "$TMP_DIR" > /dev/null || exit 255
23

    
24
# Check for qmake
25
echo "qmake -v" > LogFile
26
if ! qmake -v >> LogFile 2>&1; then
27
    # Deliberately leave $TMP_DIR to assist debugging.
28
    echo "ERROR: qmake does not work   $SCRIPT_NAME" > /dev/stderr
29
    exit 2
30
fi
31

    
32
# Create profile file for qmake
33
cat > qt5-check.pro <<EOF
34
QMAKE_MAKEFILE = qt5-check-makefile
35

    
36
TEMPLATE = app
37
TARGET = qt5-check
38
QT += xml webkitwidgets printsupport # crucial line with dependencies
39
SOURCES += qt5-check.cpp
40
EOF
41

    
42
# Create C++ file
43
cat > qt5-check.cpp <<EOF
44
#include <iostream>
45
#include <QtWidgets/QApplication> // a header file necessary for QCodeEdit
46

    
47
int main() {
48
    std::cout << "Qt5 version " << qVersion() << " found" << std::endl;
49
    return 0;
50
}
51
EOF
52

    
53
# Set qmake flag for macOS (see src/CoCoA-5/make-c5makefile.sh
54
#                           and src/CoCoA-5/make-qcodeeditmakefile.sh)
55
if [ "$(uname)" = "Darwin" ]; then
56
    DARWIN_OPTS="-spec macx-g++"
57
fi
58

    
59
# Use qmake to create makefile
60
echo "qmake $DARWIN_OPTS qt5-check.pro" > LogFile
61
if ! qmake $DARWIN_OPTS qt5-check.pro >> LogFile 2>&1; then
62
    # Deliberately leave $TMP_DIR to assist debugging.
63
    echo "ERROR: qmake exited abnormally --> see LogFile.   $SCRIPT_NAME" \
64
    > /dev/stderr
65
    exit 3
66
fi
67

    
68
# Use make to compile cpp file
69
echo "make --file=qt5-check-makefile" > LogFile
70
if ! make --file=qt5-check-makefile >> LogFile 2>&1; then
71
    # Deliberately leave $TMP_DIR to assist debugging.
72
    echo "ERROR: make exited abnormally --> see LogFile.   $SCRIPT_NAME" \
73
    > /dev/stderr
74
    exit 4
75
fi
76

    
77
# Run Qt5 program
78
echo "./qt5-check" > LogFile
79
if ! ./qt5-check >> LogFile 2>&1; then
80
    # Deliberately leave $TMP_DIR to assist debugging.
81
    echo "ERROR: qt5-check exited abnormally --> see LogFile.   $SCRIPT_NAME" \
82
     > /dev/stderr
83
    exit 5
84
fi
85

    
86
# Clean up $TMP_DIR
87
popd > /dev/null || exit 255
88
rm -rf "$TMP_DIR"
89

    
90
exit 0