#!/usr/bin/perl

open PRO, ">tmp.pro";
if ($ARGV[1]=="debug") {
    print PRO "CONFIG+=DEBUG\n";
} elsif ($argv[1]=="universal") {
print PRO "CONFIG+=x86 x86_64";
}
print PRO "QT+=opengl\n";
print PRO "QT+=sql\n";
print PRO "QT+=network\n";
if ($^O eq "darwin") {
    print PRO "QMAKE_MACOSX_DEPLOYMENT_TARGET = ".`sw_vers -productVersion | cut -d. -f 1-2`;
}
close PRO;

open MAKE, ">makefile.qt";
open QMAKE, "(qmake-qt4 -o - tmp.pro || qmake -o - tmp.pro ) |";
while ($line=<QMAKE>) {
    chomp($line);
    if ($line !~ /^#/) {
	($para, $val)=$line =~ /^(\w+)\s*=\s*(.+)/;
	if ($para=~"CXXFLAGS|LIBS|LFLAGS|INCPATH") {
	    print MAKE "QT_$para:=$val\n"; 
	    if ($para=~"INCPATH") {
		$val=~s/-I\.//g;
		$val=~s/-I/-isystem /g;
		print MAKE "QT_INCDEP:=$val\n";
	    }
	}
    }
}
close QMAKE;

unlink "tmp.pro";
