#!/usr/bin/perl
use strict;
use warnings;

use File::Copy;
use File::Path;
use File::Basename;
use lib ( dirname($0) );
use Qtopia::Paths;
use Qtopia::Vars;
use Qtopia::Opt;

Qtopia::Paths::get_paths();

# Windows depot builds use the perl scripts directly rather than the compiled code
if ( $isWindows ) {
    check_script($0, "$depotpath/src/build/bin", $ARGV[0]);
}

Qtopia::Opt::read_config_cache();


use constant DEBUG => 0;

my $prefix = opt("prefix");
my $destdir = shift(@ARGV);
for my $source ( @ARGV ) {
    my $destfile = "$destdir/".basename($source);
    open IN, "$source" or die "Can't read $source";
    my @data = <IN>;
    close IN;
    for ( @data ) {
        s/^(\s*QTOPIA_INSTALL_PREFIX=).*/$1$prefix/;
    }
    mkpath(dirname($destfile));
    if ( -f $destfile ) {
        unlink($destfile);
    }
    open OUT, ">$destfile" or die "Can't write $destfile";
    print OUT @data;
    close OUT;
    chmod 0555, $destfile;
}

exit 0;

