3 # Copyright (c) 2013, Ford Motor Company
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
9 # Redistributions of source code must retain the above copyright notice, this
10 # list of conditions and the following disclaimer.
12 # Redistributions in binary form must reproduce the above copyright notice,
13 # this list of conditions and the following
14 # disclaimer in the documentation and/or other materials provided with the
17 # Neither the name of the Ford Motor Company nor the names of its contributors
18 # may be used to endorse or promote products derived from this software
19 # without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 # POSSIBILITY OF SUCH DAMAGE.
34 echo "Usage: $0 [-v <version>] [-b] [<file name>]"
36 echo " Look for file in Qt directory."
37 echo " If file name isn't set then look for bin directory."
39 echo " -v <version> look for Qt specific version x.x.x"
40 echo " -b look for binary file"
48 ver=$(( $ver * 32 + $i ))
56 # It's bash way to say "if ((version1 < version2) and (major1 == major2))
57 if [[ ( $v1 -le $v2 ) && ( $(( ($v1 / 1024) - ($v2 / 1024) )) == 0 ) ]]; then
65 $1 --version 2>/dev/null | grep "Using Qt version" | sed "s/.*Qt version \\([0-9\\.]*\\) in \\(.*\\)$/\\$2/"
69 local qt_binary="$1/$2" # check specified binary
70 if [[ -x $qt_binary && ! -d $qt_binary ]]; then # to be executable and not to be directory
71 echo -n $qt_binary # output without newline
78 local qt_file=$(find $1 -name "$2" -type f -print0 -quit 2>/dev/null) # check specified binary
79 if [[ -n $qt_file && ! -d $qt_file ]]; then # if found
80 echo -n $qt_file #output without newline
88 while getopts :v:b option; do
96 shift $(( OPTIND - 1 ))
103 ## First attempt - using locate
104 if command -v locate > /dev/null; then
105 for searchloc in $CUSTOM_QT_DIR ~ /opt /usr/local; do
106 qmake_list=$(locate $searchloc/*/bin/qmake)
107 for qmake in $qmake_list; do
108 if [[ ! -x $qmake || -d $qmake ]]; then
111 # called with "qmake 1" return qmake version
112 qt_version=$(qmake_data $qmake 1)
113 if ! version_match $version $qt_version; then
119 qt_dir=$(dirname $qmake 2> /dev/null)
120 if find_binary $qt_dir $file_name; then
125 # called with "qmake 2" return Qt installation dir
126 qt_installdir=$(qmake_data $qmake 2)
127 if find_file $qt_installdir $file_name; then
132 echo -n $(dirname $qmake 2>/dev/null)
140 ## Second attempt - using find
143 export -f version_match
144 export -f version2int
146 qmake=$(find -L $CUSTOM_QT_DIR ~ /opt /usr/local -name '.*' -prune \
147 -o -name qmake -type f \
149 -exec /bin/bash -c "version_qt=\$(qmake_data {} 1);version_match $version \$version_qt" {} \; -print -quit > /dev/null)
156 qt_dir=$(dirname $qmake 2>/dev/null)
157 if find_binary $qt_dir $file_name; then
162 # called with "qmake 2" return Qt installation dir
163 qt_installdir=$(qmake_data $qmake 2)
164 if find_file $qt_installdir $file_name; then
169 echo -n $(dirname $qmake 2>/dev/null)