#!/usr/bin/perl
#
# Creates new platform configuration files from a tmake config file.
# 
# Copyright (C) 1999 by Troll Tech AS.  All rights reserved.
#
# Example of use:
#
#     makeconfig /local/tmake/lib/solaris-cc
#
# This will create the file solaris-cc-shared, solaris-cc-shared-debug
# etc. in your qt/configs folder.
#


$tmakedir = $ARGV[0];

if ( ! $tmakedir ) {
    print STDERR "Usage:\n\tmakeconfig <tmake directory>\n";
    exit 1;
}
$tmakedir =~ s-/$--;

$confdir = $ENV{"QTDIR"} . "/configs";
if ( ! -d $confdir ) {
    print STDERR "Error: No such directory $confdir\n";
    exit 1;
}

$platform = $tmakedir;
$platform =~ s-.*/--;
$tmakeconf = "$tmakedir/tmake.conf";
$can_do_shared = 0;
$can_do_debug  = 0;

if ( !open(F,$tmakeconf) ) {
    print STDERR "Error: Cannot open file $tmakeconf\n";
    exit 1;
}
while ( <F> ) {
    /TMAKE_LINK_SHLIB/ && ($can_do_shared = 1);
    /TMAKE_CXXFLAGS_DEBUG/ && ($can_do_debug = 1);
}
close(F);

$tmakedir = $confdir . ":" . $tmakedir;
chdir($confdir);
mkconf($platform,"static");
if ( $can_do_debug ) {
    mkconf($platform,"static-debug");
}
if ( $can_do_shared ) {
    mkconf($platform,"shared");
    if ( $can_do_debug ) {
	mkconf($platform,"shared-debug");
    }
}
exit 0;


sub mkconf {
    my($p,$c) = @_;
    `tmake "TMAKEDIR=$tmakedir" -t $c -o $p-$c /dev/null`;
    print "Created \$(QTDIR)/configs/$p-$c\n";
}
