1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
|
// For license information, see the COPYING file in the qconf base directory.
#include<stdio.h>
#include<stdlib.h>
#include<qstring.h>
#include<qdict.h>
#include<qptrlist.h>
#include<qfileinfo.h>
#include<qfile.h>
#include<qdir.h>
#include<qstringlist.h>
#include<qobject.h>
class MocTestObject : public QObject
{
Q_OBJECT
public:
MocTestObject() {}
};
class Conf;
class ConfObj
{
public:
ConfObj(Conf *c);
virtual ~ConfObj();
virtual QString name() const=0;
virtual QString shortname() const=0;
virtual QString checkString() const;
virtual QString resultString() const;
virtual bool exec()=0;
Conf *conf;
bool required;
bool disabled;
};
typedef QPtrList<ConfObj> ConfObjList;
typedef QPtrListIterator<ConfObj> ConfObjListIt;
class Conf
{
public:
Conf() : vars(17)
{
list.setAutoDelete(true);
vars.setAutoDelete(true);
vars.insert("QMAKE_INCDIR_X11", new QString(X11_INC));
vars.insert("QMAKE_LIBDIR_X11", new QString(X11_LIBDIR));
vars.insert("QMAKE_LIBS_X11", new QString(X11_LIB));
vars.insert("QMAKE_CC", new QString(CC));
vars.insert("QMAKE_CXX", new QString(CXX));
do_debug = false;
done_debug = false;
}
~Conf()
{
}
void added(ConfObj *o)
{
list.append(o);
}
QString getenv(const QString &var)
{
char *p = ::getenv(var.latin1());
if(!p)
return QString::null;
return QString(p);
}
void debug(const QString &s)
{
if(do_debug) {
if(!done_debug)
printf("\n");
done_debug = true;
printf(" * %s\n", s.latin1());
}
}
bool exec()
{
if(getenv("QC_VERBOSE") == "Y")
do_debug = true;
ConfObjListIt it(list);
for(ConfObj *o; (o = it.current()); ++it) {
// if this was a disabled-by-default option, check if it was enabled
if(o->disabled) {
QString v = QString("QC_ENABLE_") + o->shortname();
if(getenv(v) != "Y")
continue;
}
// and the opposite?
else {
QString v = QString("QC_DISABLE_") + o->shortname();
if(getenv(v) == "Y")
continue;
}
QString check = o->checkString();
if(check.isEmpty())
check = QString("Checking for %1 ...").arg(o->name());
printf("%s", check.latin1());
fflush(stdout);
done_debug = false;
bool ok = o->exec();
QString result = o->resultString();
if(result.isEmpty()) {
if(ok)
result = "yes";
else
result = "no";
}
if(done_debug)
printf(" -> %s\n", result.latin1());
else
printf(" %s\n", result.latin1());
if(!ok && o->required) {
printf("\nError: need %s!\n", o->name().latin1());
return false;
}
}
return true;
}
const QString & qvar(const QString &s)
{
QString *p = vars.find(s);
if(p)
return *p;
else
return blank;
}
QString expandIncludes(const QString &inc)
{
return QString("-I") + inc;
}
QString expandLibs(const QString &lib)
{
return QString("-L") + lib;
}
int doCommand(const QString &s)
{
debug(QString("[%1]").arg(s));
QString fullcmd;
if(do_debug)
fullcmd = s;
else
fullcmd = s + " 1>/dev/null 2>/dev/null";
int r = system(fullcmd.latin1());
debug(QString("returned: %1").arg(r));
return r;
}
bool doCompileAndLink(const QString &filedata, const QString &flags, int *retcode=0)
{
QDir dir(".");
QString fname = "atest.c";
QString out = "atest";
QFile f(fname);
QCString cs = filedata.latin1();
if(!f.open(IO_WriteOnly | IO_Truncate)) {
debug("unable to open atest.c for writing");
return false;
}
if(f.writeBlock(cs.data(), cs.length()) == -1) {
debug("error writing to atest.c");
return false;
}
f.close();
debug(QString("Wrote atest.c:\n%1").arg(filedata));
QString str = qvar("QMAKE_CXX") + ' ' + fname + " -o " + out;
if(!flags.isEmpty()) {
str += ' ';
str += flags;
}
int r = doCommand(str);
if(r == 0 && retcode)
*retcode = doCommand(QString("./") + out);
dir.remove(fname);
dir.remove(out);
if(r != 0)
return false;
return true;
}
bool checkHeader(const QString &path, const QString &h)
{
QFileInfo fi(path + '/' + h);
if(fi.exists())
return true;
return false;
}
bool findHeader(const QString &h, const QStringList &ext, QString *inc)
{
if(checkHeader("/usr/include", h)) {
*inc = "";
return true;
}
QStringList dirs;
dirs += "/usr/local/include";
dirs += ext;
for(QStringList::ConstIterator it = dirs.begin(); it != dirs.end(); ++it) {
if(checkHeader(*it, h)) {
*inc = *it;
return true;
}
}
return false;
}
bool checkLibrary(const QString &path, const QString &name)
{
QString str =
"int main()\n"
"{\n"
" return 0;\n"
"}\n";
QString extra;
if(!path.isEmpty())
extra += QString("-L") + path + ' ';
extra += QString("-l") + name;
if(!doCompileAndLink(str, extra))
return false;
return true;
}
bool findLibrary(const QString &name, QString *lib)
{
if(checkLibrary("", name)) {
*lib = "";
return true;
}
if(checkLibrary("/usr/local/lib", name)) {
*lib = "/usr/local/lib";
return true;
}
return false;
}
void addDefine(const QString &str)
{
if(DEFINES.isEmpty())
DEFINES = str;
else
DEFINES += QString(" ") + str;
debug(QString("DEFINES += %1").arg(str));
}
void addLib(const QString &str)
{
if(LIBS.isEmpty())
LIBS = str;
else
LIBS += QString(" ") + str;
debug(QString("LIBS += %1").arg(str));
}
void addIncludePath(const QString &str)
{
if(INCLUDEPATH.isEmpty())
INCLUDEPATH = str;
else
INCLUDEPATH += QString(" ") + str;
debug(QString("INCLUDEPATH += %1").arg(str));
}
void addExtra(const QString &str)
{
extra += str + '\n';
debug(QString("extra += %1").arg(str));
}
QString DEFINES;
QString INCLUDEPATH;
QString LIBS;
QString extra;
private:
ConfObjList list;
QDict<QString> vars;
QString blank;
bool do_debug, done_debug;
};
ConfObj::ConfObj(Conf *c)
{
conf = c;
conf->added(this);
required = false;
disabled = false;
}
ConfObj::~ConfObj()
{
}
QString ConfObj::checkString() const
{
return QString();
}
QString ConfObj::resultString() const
{
return QString();
}
#include"modules.cpp"
//----------------------------------------------------------------------------
// main
//----------------------------------------------------------------------------
int main()
{
Conf *conf = new Conf;
ConfObj *o;
o = 0;
#include"modules_new.cpp"
printf("ok\n");
bool success = false;
if(conf->exec()) {
QFile f("conf.pri");
if(!f.open(IO_WriteOnly | IO_Truncate)) {
printf("Error writing %s\n", f.name().latin1());
return 1;
}
QString str;
str += "# qconf\n";
str += "QT_PATH_PLUGINS = " + QString(qInstallPathPlugins()) + '\n';
if(!conf->DEFINES.isEmpty())
str += "DEFINES += " + conf->DEFINES + '\n';
if(!conf->INCLUDEPATH.isEmpty())
str += "INCLUDEPATH += " + conf->INCLUDEPATH + '\n';
if(!conf->LIBS.isEmpty())
str += "LIBS += " + conf->LIBS + '\n';
if(!conf->extra.isEmpty())
str += conf->extra;
str += '\n';
char *p = getenv("BINDIR");
if(p) {
str += QString("target.path = ") + p + '\n';
str += "INSTALLS += target\n";
}
QCString cs = str.latin1();
f.writeBlock(cs.data(), cs.length());
f.close();
success = true;
}
delete conf;
if(success)
return 0;
else
return 1;
}
#include"conf.moc"
|