/*
-----BEGIN QCMOD-----
name: XMMS
arg: with-xmms-inc=[path],Path to XMMS include files (for XMMS)
arg: with-xmms-lib=[path],Path to XMMS library files (for XMMS)
arg: with-glib-inc=[path],Path to GLib include files (for XMMS)
arg: with-glib-lib=[path],Path to GLib library files (for XMMS)
arg: with-glibconfig-inc=[path],Path to glibconfig include file (for XMMS)
-----END QCMOD-----
*/

//----------------------------------------------------------------------------
// qc_xmms
//----------------------------------------------------------------------------
class qc_xmms : public ConfObj
{
public:
    qc_xmms(Conf *c) : ConfObj(c) {}
    QString name() const { return "XMMS"; }
    QString shortname() const { return "xmms"; }
    bool exec()
    {
                QString str =
                        "extern \"C\" void g_source_set_callback();"
                        "\n"
                        "int main()\n"
                        "{\n"
                        "        g_source_set_callback();\n"
                        "        return 0;\n"
                        "}\n";
                int ret;
                if (conf->doCompileAndLink(str, QStringList(), QString(), "CONFIG += qt", 0)) {
    		qWarning("XMMS is not compatible with a QT linked with glib 2.x");
                        return false;
    	}
    	QString s;

    	// XMMS
    	s = conf->getenv("QC_WITH_XMMS_INC");
    	if(!s.isEmpty()) {
    		if(!conf->checkHeader(s, "xmms/util.h")) {
    			qWarning("XMMS includes not found!");
    			return false;
    		}
    		conf->addIncludePath(s);
    	}
    	else {
    		QStringList sl;
    		sl += "/usr/include";
    		sl += "/usr/local/include";
    		sl += "/sw/include";
    		if(!conf->findHeader("xmms/util.h", sl, &s)) {
    			qWarning("XMMS includes not found!");
    			return false;
    		}
    		conf->addIncludePath(s);
    	}

    	s = conf->getenv("QC_WITH_XMMS_LIB");
    	if(!s.isEmpty()) {
    		if(!conf->checkLibrary(s, "xmms")) {
    			qWarning("XMMS libraries not found!");
    			return false;
    		}
    		conf->addLib(QString("-L") + s);
    	}
    	else {
    		if(!conf->findLibrary("xmms", &s)) {
    			qWarning("XMMS libraries not found!");
    			return false;
    		}
    		if (!s.isEmpty())
    			conf->addLib(QString("-L") + s);
    	}

    	conf->addLib("-lxmms");


    	// GLib
    	s = conf->getenv("QC_WITH_GLIB_INC");
    	if(!s.isEmpty()) {
    		if(conf->checkHeader(s, "glib.h")) {
    			conf->addIncludePath(s);
    		}
    		else {
    			qWarning("GLib includes not found!");
    			return false;
    		}
    	}
    	else {
    		QStringList sl;
    		sl += "/usr/include/glib";
    		sl += "/usr/local/include/glib";
    		sl += "/usr/include/glib-1.2";
    		sl += "/sw/include/glib-1.2";
    		if(conf->findHeader("glib.h", sl, &s)) {
    			conf->addIncludePath(s);
    		}
    		else {
    			qWarning("GLib includes not found!");
    			return false;
    		}
    	}

    	s = conf->getenv("QC_WITH_GLIB_LIB");
    	if(!s.isEmpty()) {
    		if(conf->checkLibrary(s, "glib")) {
    			conf->addLib(QString("-L") + s);
    		}
    		else {
    			qWarning("GLib 1.2.0 libraries not found!");
    			return false;
    		}
    	}
    	else {
    		if(conf->findLibrary("glib", &s)) {
    			if (!s.isEmpty())
    				conf->addLib(QString("-L") + s);
    		}
    		else {
    			qWarning("GLib 1.2 libraries not found!");
    			return false;
    		}
    	}

    	conf->addLib("-lglib");

    	// Glibconfig
    	s = conf->getenv("QC_WITH_GLIBCONFIG_INC");
    	if(!s.isEmpty()) {
    		if(conf->checkHeader(s, "glibconfig.h")) {
    			conf->addIncludePath(s);
    		}
    		else {
    			qWarning("glibconfig.h includes not found!");
    			return false;
    		}
    	}
    	else {
    		if(conf->findHeader("glibconfig.h", QStringList("/usr/lib/glib/include"), &s)) {
    			conf->addIncludePath(s);
    		}
    		else {
    			qWarning("glibconfig.h not found!");
    			return false;
    		}
    	}

    	// Finish
    	conf->addExtra("CONFIG += tc_xmms");

    	return true;
    }
};
