/*
-----BEGIN QCMOD-----
name: buildmode_framework
section: project
arg: no-framework,Do not build as a Mac framework.
arg: framework,Build as a Mac framework (default).
-----END QCMOD-----
*/

#define QC_BUILDMODE_FRAMEWORK
bool qc_buildmode_framework_enabled = false;

class qc_buildmode_framework : public ConfObj
{
public:
	qc_buildmode_framework(Conf *c) : ConfObj(c) {}
	QString name() const { return "buildmode_framework"; }
	QString shortname() const { return "buildmode_framework"; }

	// no output
	QString checkString() const { return QString(); }

	bool exec()
	{
		// first, parse out the options
		bool opt_no_framework = false;
		bool opt_framework = false;

		if(conf->getenv("QC_NO_FRAMEWORK") == "Y")
			opt_no_framework = true;
		if(conf->getenv("QC_FRAMEWORK") == "Y")
			opt_framework = true;

		bool staticmode = false;
		if(conf->getenv("QC_STATIC") == "Y")
			staticmode = true;

#ifndef Q_OS_MAC
		if(opt_framework)
		{
			printf("\nError: The --framework option is for mac only.\n");
			exit(1);
		}
#endif

		if(opt_framework && qc_buildmode_debug)
		{
			printf("\nError: Cannot use both --framework and --debug.\n");
			exit(1);
		}

		// sanity check exclusive options
		int x;

		// framework
		if(opt_framework && staticmode)
		{
			printf("\nError: Cannot use both --framework and --static.\n");
			exit(1);
		}

		x = 0;
		if(opt_no_framework)
			++x;
		if(opt_framework)
			++x;
		if(x > 1)
		{
			printf("\nError: Use only one of --framework or --no-framework.\n");
			exit(1);
		}

#ifdef Q_OS_MAC
		// now process the options

		if(opt_framework)
			qc_buildmode_framework_enabled = true;
		else if(opt_no_framework)
		{
			// nothing to do
		}
		else // default
		{
			if(!staticmode && !qc_buildmode_debug)
				qc_buildmode_framework_enabled = true;
		}

		if(qc_buildmode_framework_enabled)
			conf->addExtra("CONFIG += lib_bundle");
#endif

		return true;
	}
};
