| 1 |
#!/bin/sh |
| 2 |
# Copyright 2007-2008 David Johnson |
| 3 |
# Configuration script for use with qt/qmake projects. This configure |
| 4 |
# script is free software; the author gives unlimited permission to |
| 5 |
# copy, distribute and modify it. Portions of this script adapted |
| 6 |
# from the Qt configuration script. |
| 7 |
|
| 8 |
PACKAGE=qbrew |
| 9 |
PROFILE=qbrew.pro |
| 10 |
PREFIX=/usr/local |
| 11 |
QTMINVER=4.3.0 |
| 12 |
LOGFILE=config.log |
| 13 |
BUILDDIR=.config |
| 14 |
|
| 15 |
### Messages ######################################################## |
| 16 |
|
| 17 |
usage() { |
| 18 |
cat <<EOT |
| 19 |
Usage: $0 [OPTION]... |
| 20 |
|
| 21 |
This script creates the necessary configuration files for building |
| 22 |
|
| 23 |
Main options: |
| 24 |
--prefix=[path] Base path for build/install. Default: /usr/local |
| 25 |
--bindir=[path] Directory for binaries. Default: PREFIX/bin |
| 26 |
--datadir=[path] Directory for data. Default: PREFIX/share |
| 27 |
--docdir=[path] Directory for docs. Default: PREFIX/share/doc |
| 28 |
--qtdir=[path] Directory where Qt is installed |
| 29 |
--spec=[spec] Spec to use for QMAKESPEC |
| 30 |
--debug Enable debug output |
| 31 |
--help This help text |
| 32 |
|
| 33 |
EOT |
| 34 |
} |
| 35 |
|
| 36 |
qt_info() { |
| 37 |
cat <<EOF |
| 38 |
Be sure you have a properly configured Qt build environment. This application |
| 39 |
requires a Qt library version of $QTMINVER or greater. Some systems split Qt |
| 40 |
into separate runtime and development packages. If this is your case, make sure |
| 41 |
you have both. The 'qmake' command should be in your path, and you may need to |
| 42 |
use either the QTDIR environment variable or the --qtdir configure option. It |
| 43 |
may be necessary to use the --spec option if qmake cannot determine your build |
| 44 |
system. If your qmake has been installed under a different name, then it may be |
| 45 |
necessary to use the QMAKE variable. |
| 46 |
EOF |
| 47 |
} |
| 48 |
|
| 49 |
### Tests ########################################################### |
| 50 |
|
| 51 |
make_test() { |
| 52 |
if [ -z "$MAKE" ] ; then |
| 53 |
for mk in gmake make; do |
| 54 |
if which $mk >/dev/null 2>&1; then |
| 55 |
MAKE=`which $mk` |
| 56 |
break |
| 57 |
fi |
| 58 |
done |
| 59 |
if [ -z "$MAKE" ] ; then |
| 60 |
echo "ERROR: cannot find 'make' or 'gmake'. Exiting" |
| 61 |
echo "ERROR: cannot find 'make' or 'gmake'. Exiting" >> $LOGFILE |
| 62 |
exit 1 |
| 63 |
fi |
| 64 |
fi |
| 65 |
} |
| 66 |
|
| 67 |
qmake_test() { |
| 68 |
echo -n "Checking for qmake..." |
| 69 |
|
| 70 |
# check QTDIR |
| 71 |
if [ -z "$QMAKE" ] ; then |
| 72 |
result=$QTDIR/bin/qmake |
| 73 |
if [ -x "$result" ] ; then |
| 74 |
QMAKE=$result |
| 75 |
fi |
| 76 |
fi |
| 77 |
|
| 78 |
# check PATH |
| 79 |
if [ -z "$QMAKE" ] ; then |
| 80 |
result=`which qmake 2>/dev/null` |
| 81 |
if [ -x "$result" ] ; then |
| 82 |
QMAKE=$result |
| 83 |
fi |
| 84 |
fi |
| 85 |
|
| 86 |
# check common rename |
| 87 |
if [ -z "$QMAKE" ] ; then |
| 88 |
result=`which qmake-q4 2>/dev/null` |
| 89 |
if [ -x "$result" ] ; then |
| 90 |
QMAKE=$result |
| 91 |
fi |
| 92 |
fi |
| 93 |
|
| 94 |
# check pkg-config |
| 95 |
if [ -z "$QMAKE" ] ; then |
| 96 |
result=`pkg-config QtCore --variable=exec_prefix 2>/dev/null` |
| 97 |
if [ ! -z "$result" ] ; then |
| 98 |
result=$result/bin/qmake |
| 99 |
if [ -x "$result" ] ; then |
| 100 |
QMAKE=$result |
| 101 |
fi |
| 102 |
fi |
| 103 |
fi |
| 104 |
|
| 105 |
if [ -z "$QMAKE" ] ; then |
| 106 |
echo "no!" |
| 107 |
echo "ERROR: unable to find the 'qmake' tool" |
| 108 |
echo "ERROR: unable to find the 'qmake' tool" >> $LOGFILE |
| 109 |
qt_info |
| 110 |
exit 1; |
| 111 |
fi |
| 112 |
|
| 113 |
echo "yes" |
| 114 |
echo "found qmake at $QMAKE" >> $LOGFILE |
| 115 |
} |
| 116 |
|
| 117 |
qtversion_test() { |
| 118 |
echo -n "Checking Qt version..." |
| 119 |
|
| 120 |
result=`$QMAKE -query QT_VERSION` |
| 121 |
if [ "$result" '<' "$QTMINVER" ] ; then |
| 122 |
echo "no!" |
| 123 |
echo "ERROR: incorrect Qt version found: $result" |
| 124 |
echo "ERROR: incorrect Qt version found: $result" >> $LOGFILE |
| 125 |
qt_info |
| 126 |
exit 1; |
| 127 |
fi |
| 128 |
echo "$result" |
| 129 |
echo "found Qt version $result" >> $LOGFILE |
| 130 |
} |
| 131 |
|
| 132 |
build_test() { |
| 133 |
echo -n "Checking if a simple Qt program builds..." |
| 134 |
cwd=`pwd` |
| 135 |
rm -rf $BUILDDIR |
| 136 |
mkdir -p $BUILDDIR |
| 137 |
cd $BUILDDIR |
| 138 |
|
| 139 |
# write it |
| 140 |
cat >config.pro <<EOT |
| 141 |
TARGET = config |
| 142 |
CONFIG += qt $BUILDMODE |
| 143 |
CONFIG -= app_bundle |
| 144 |
QT -= gui |
| 145 |
HEADERS += config.h |
| 146 |
SOURCES += config.cpp |
| 147 |
EOT |
| 148 |
|
| 149 |
cat >config.h <<EOT |
| 150 |
#include <QtCore> |
| 151 |
class Config : public QCoreApplication { |
| 152 |
public: |
| 153 |
Config(int &argc, char **argv); |
| 154 |
}; |
| 155 |
EOT |
| 156 |
|
| 157 |
cat >config.cpp <<EOT |
| 158 |
#include "config.h" |
| 159 |
Config::Config(int &argc, char **argv) |
| 160 |
: QCoreApplication(argc,argv) {setApplicationName("config");} |
| 161 |
int main(int argc, char **argv) |
| 162 |
{ |
| 163 |
Config app(argc,argv); |
| 164 |
return 0; |
| 165 |
} |
| 166 |
EOT |
| 167 |
|
| 168 |
# build it |
| 169 |
$QMAKE config.pro > /dev/null |
| 170 |
$MAKE >>$LOGFILE 2>&1 |
| 171 |
result=$? |
| 172 |
|
| 173 |
cd $cwd |
| 174 |
rm -rf $BUILDDIR |
| 175 |
|
| 176 |
if [ "$result" != "0" ] ; then |
| 177 |
echo "no!" |
| 178 |
echo "ERROR: could not build a simple Qt program. See config.log" |
| 179 |
echo "ERROR: could not build a simple Qt program" >> $LOGFILE |
| 180 |
qt_info |
| 181 |
exit 1; |
| 182 |
fi |
| 183 |
echo "yes" |
| 184 |
echo "built simple Qt program" >> $LOGFILE |
| 185 |
} |
| 186 |
|
| 187 |
### Parse options ################################################### |
| 188 |
|
| 189 |
parse_options() { |
| 190 |
while [ $# -gt 0 ] ; do |
| 191 |
case "$1" in |
| 192 |
--prefix=*) |
| 193 |
PREFIX="${1#--prefix=}" |
| 194 |
shift |
| 195 |
;; |
| 196 |
|
| 197 |
--bindir=*) |
| 198 |
BINDIR="${1#--bindir=}" |
| 199 |
shift |
| 200 |
;; |
| 201 |
|
| 202 |
--datadir=*) |
| 203 |
DATADIR="${1#--datadir=}" |
| 204 |
shift |
| 205 |
;; |
| 206 |
|
| 207 |
--docdir=*) |
| 208 |
DOCDIR="${1#--docdir=}" |
| 209 |
shift |
| 210 |
;; |
| 211 |
|
| 212 |
--qtdir=*) |
| 213 |
QTDIR="${1#--qtdir=}" |
| 214 |
shift |
| 215 |
;; |
| 216 |
|
| 217 |
--spec=*) |
| 218 |
QMAKESPEC="${1#--spec=}" |
| 219 |
shift |
| 220 |
;; |
| 221 |
|
| 222 |
--debug=*) |
| 223 |
ENABLE_DEBUG="${1#--debug=}" |
| 224 |
shift |
| 225 |
;; |
| 226 |
|
| 227 |
--debug) |
| 228 |
ENABLE_DEBUG="yes" |
| 229 |
shift |
| 230 |
;; |
| 231 |
|
| 232 |
--help) usage; exit ;; |
| 233 |
*) usage; exit 1 ;; |
| 234 |
esac |
| 235 |
done |
| 236 |
} |
| 237 |
|
| 238 |
### Main ############################################################ |
| 239 |
|
| 240 |
echo "Configuring $PACKAGE package..." |
| 241 |
|
| 242 |
### initialize |
| 243 |
|
| 244 |
SOURCEPATH=`dirname $0` |
| 245 |
SOURCEPATH=`(cd $SOURCEPATH; /bin/pwd)` |
| 246 |
BUILDDIR=$SOURCEPATH/$BUILDDIR |
| 247 |
LOGFILE=$SOURCEPATH/$LOGFILE |
| 248 |
|
| 249 |
if [ -e $LOGFILE ] ; then rm $LOGFILE ; fi |
| 250 |
echo "configure command: $0 $@" > $LOGFILE |
| 251 |
echo `date` >>$LOGFILE |
| 252 |
|
| 253 |
### parse command options |
| 254 |
|
| 255 |
parse_options $@ |
| 256 |
|
| 257 |
QMAKE=${QMAKE:-} |
| 258 |
PREFIX=${PREFIX:-/usr/local} |
| 259 |
BINDIR=${BINDIR:-$PREFIX/bin} |
| 260 |
DATADIR=${DATADIR:-$PREFIX/share/$PACKAGE} |
| 261 |
DOCDIR=${DOCDIR:-$PREFIX/share/doc/$PACKAGE} |
| 262 |
|
| 263 |
if [ "$ENABLE_DEBUG" = "yes" ] ; then |
| 264 |
BUILDMODE="debug" |
| 265 |
else |
| 266 |
BUILDMODE="release" |
| 267 |
fi |
| 268 |
|
| 269 |
echo >> $LOGFILE |
| 270 |
echo PREFIX=$PREFIX >> $LOGFILE |
| 271 |
echo BINDIR=$BINDIR >> $LOGFILE |
| 272 |
echo DATADIR=$DATADIR >> $LOGFILE |
| 273 |
echo DOCDIR=$DOCDIR >> $LOGFILE |
| 274 |
echo QTDIR=$QTDIR >> $LOGFILE |
| 275 |
echo QMAKESPEC=$QMAKESPEC >> $LOGFILE |
| 276 |
echo ENABLE_DEBUG=$ENABLE_DEBUG >> $LOGFILE |
| 277 |
echo BUILDMODE=$BUILDMODE >> $LOGFILE |
| 278 |
echo >> $LOGFILE |
| 279 |
|
| 280 |
### tests |
| 281 |
|
| 282 |
make_test |
| 283 |
qmake_test |
| 284 |
qtversion_test |
| 285 |
build_test |
| 286 |
|
| 287 |
### export variables |
| 288 |
|
| 289 |
export BINDIR |
| 290 |
export DATADIR |
| 291 |
export DOCDIR |
| 292 |
if [ ! -z $QTDIR ] ; then |
| 293 |
export QTDIR |
| 294 |
fi |
| 295 |
if [ ! -z $QMAKESPEC ] ; then |
| 296 |
export QMAKESPEC |
| 297 |
fi |
| 298 |
|
| 299 |
### create Makefile |
| 300 |
|
| 301 |
echo "Creating Makefile" |
| 302 |
|
| 303 |
$QMAKE -o $SOURCEPATH/Makefile "CONFIG+=$BUILDMODE configure" $PROFILE > /dev/null 2>> $LOGFILE |
| 304 |
|
| 305 |
if [ $? != "0" ] ; then |
| 306 |
echo "ERROR: could not create Makefile. See config.log" |
| 307 |
echo "ERROR: could not create Makefile." >> $LOGFILE |
| 308 |
echo "Command: $QMAKE -o $SOURCEPATH/Makefile \"CONFIG+=$BUILDMODE\" $PROFILE" >> $LOGFILE |
| 309 |
exit 1 |
| 310 |
fi |
| 311 |
|
| 312 |
### finished |
| 313 |
|
| 314 |
echo |
| 315 |
echo "$PACKAGE configured successfully" |
| 316 |
echo "Relax, don't worry, have a homebrew!" |
| 317 |
echo |