imgtools/imaker/src/imaker.pl
changeset 1 be27ed110b50
child 584 56dd7656a965
equal deleted inserted replaced
0:044383f39525 1:be27ed110b50
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Symbian Foundation License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: iMaker main Perl script
       
    15 #
       
    16 
       
    17 
       
    18 
       
    19 #
       
    20 $(error >>>MAKECMDGOALS=$(MAKECMDGOALS)<<<)
       
    21 #
       
    22 #!perl
       
    23 
       
    24 use strict;
       
    25 use warnings;
       
    26 use Getopt::Long qw(:config pass_through no_auto_abbrev);
       
    27 
       
    28 my $error = "";
       
    29 my $perlver;
       
    30 my $start;
       
    31 
       
    32 BEGIN {
       
    33     ($start, $perlver) = (time(), sprintf("%vd", $^V));
       
    34     select(STDERR); $|++;
       
    35     select(STDOUT); $|++;
       
    36     if (!@ARGV) {
       
    37         warn("Warning: iMaker is running under Cygwin!\n")
       
    38             if (!$ENV{IMAKER_CYGWIN} && $^O =~ /cygwin/i);
       
    39         warn("Warning: iMaker uses Perl version $perlver! Recommended versions are 5.6.1 and 5.8.8.\n")
       
    40             if ($perlver !~ /^5\.(6\.1|8\.8)$/);
       
    41     }
       
    42     unshift(@INC, defined($ENV{IMAKER_DIR}) ? $ENV{IMAKER_DIR} : ($0 =~ /^(.*)[\/\\]/ ? $1 : "."));
       
    43 }
       
    44 
       
    45 use imaker;
       
    46 
       
    47 
       
    48 ###############################################################################
       
    49 # Main program
       
    50 
       
    51 {
       
    52     if (!@ARGV) {
       
    53         $ENV{CONFIGROOT} = imaker::GetAbsDirname($ENV{CONFIGROOT});
       
    54         $ENV{ITOOL_DIR}  = imaker::GetAbsDirname($ENV{ITOOL_DIR}, 0, 1);
       
    55         $ENV{IMAKER_DIR} = imaker::GetAbsDirname($ENV{IMAKER_DIR}, 0, 1);
       
    56         $ENV{PATH} = join(";", grep(!/[\\\/]cygwin[\\\/]/i, split(/;+/, $ENV{PATH})))
       
    57             if $imaker::gWinOS && !$ENV{IMAKER_CYGWIN};
       
    58 
       
    59         my ($version, $verfile) = ("", "$ENV{IMAKER_DIR}/imaker_version.mk");
       
    60         open(FILE, "<$verfile") and map { $version = $1 if /^\s*IMAKER_VERSION\s*[+:?]?=\s*(.*?)\s*$/ } <FILE>;
       
    61         close(FILE);
       
    62         $version and print("$version\n") or
       
    63             warn("Can't read iMaker version from `$verfile'.\n");
       
    64 
       
    65         my $cmdarg  = " " . imaker::HandleCmdArg($ENV{IMAKER_CMDARG}) . " ";
       
    66         my $makecmd = "$ENV{IMAKER_MAKE} -R --no-print-directory" .
       
    67             ($ENV{IMAKER_MAKESHELL} ? " SHELL=\"$ENV{IMAKER_MAKESHELL}\"" : "");
       
    68         my $cmdout  = qx($makecmd -f $0 $cmdarg 2>&1);
       
    69         my $targets = ($cmdout =~ />>>MAKECMDGOALS=(.*?)<<</ ? $1 : undef);
       
    70 
       
    71         die("Can't run `$ENV{IMAKER_MAKE}' properly:\n$cmdout") if !defined($targets);
       
    72         map { $cmdarg =~ s/\s+\Q$_\E\s+/ / } split(/\s+/, $targets);
       
    73 
       
    74         my $tmptarg = $targets = " $targets";
       
    75         my $hptarg  = 0;
       
    76         while ($tmptarg =~ /(\s+(help-\S+))/g) {
       
    77             $hptarg = $1, $targets =~ s/\Q$hptarg\E(.*)$/ $1$hptarg/ if $2 ne "help-config";
       
    78         }
       
    79         $hptarg = $1, $targets =~ s/\Q$hptarg\E(.*)$/ $1$hptarg/ while $tmptarg =~ /(\s+print-\S+)/g;
       
    80         $targets =~ s/^\s+|\s+(?=\s)|\s$//g;
       
    81 
       
    82         my $mainmk = "-f $ENV{IMAKER_DIR}/imaker.mk";
       
    83         $makecmd .= " -I " . imaker::GetAbsDirname($ENV{CONFIGROOT}, 0, 1) . " $mainmk";
       
    84 
       
    85         foreach my $target ($hptarg || $targets eq "" ? $targets : split(/\s/, $targets)) {
       
    86             ($cmdarg, $target) = imaker::Menu($makecmd, $mainmk, $cmdarg) if $target eq "menu";
       
    87             system($ENV{IMAKER_MAKECMD} = "$makecmd TIMESTAMP=" . imaker::GetTimestamp() . " $cmdarg $mainmk $target")
       
    88                 if $target ne "menu";
       
    89             $error = ($? >> 8) if ($? >> 8);
       
    90         }
       
    91 
       
    92 #        imaker::DPrint(1, "\nTotal duration: " . imaker::Sec2Min(time() - $start) . "\n");
       
    93         exit($error || 0);
       
    94     }
       
    95 
       
    96     #==========================================================================
       
    97 
       
    98     my ($opt_cmdfile, $opt_incdir, $opt_logfile, $opt_printcmd, $opt_step, $opt_verbose, $opt_workdir) =
       
    99        ( "",           "",          "",           0,             "",        1,            ".");
       
   100     Getopt::Long::GetOptions(
       
   101         "cmdfile=s" => \$opt_cmdfile,
       
   102         "incdir=s"  => \$opt_incdir,
       
   103         "logfile=s" => \$opt_logfile,
       
   104         "printcmd"  => \$opt_printcmd,
       
   105         "step=s"    => \$opt_step,
       
   106         "verbose=s" => \$opt_verbose,
       
   107         "workdir=s" => \$opt_workdir,
       
   108         "<>"        => sub { $error .= ($error ? ", `@_'" : "Unknown imaker.pl option: `@_'") });
       
   109 
       
   110     if ($opt_incdir) {
       
   111         my $bsf = ($opt_incdir =~ s/:bsf$//);
       
   112         print(map("$_\n", imaker::GetFeatvarIncdir($opt_incdir, $bsf)));
       
   113         exit;
       
   114     }
       
   115 
       
   116     $opt_verbose = imaker::SetVerbose($opt_verbose);
       
   117 
       
   118     imaker::DPrint(2, "=" x 79 . "\nTIME: " . localtime() . ", USER: " . getlogin() .
       
   119         ", HOST: " . ($ENV{HOSTNAME} || $ENV{COMPUTERNAME} || "?") . "\n$^X (v$perlver-$^O)\n");
       
   120 
       
   121     imaker::SetLogfile($opt_logfile);
       
   122     die("$error.\n") if $error;
       
   123 
       
   124     foreach (split(/-+/, $opt_step)) {
       
   125         $error .= ($error ? ", `$_'" : "Unknown imaker.pl step: `$_'")
       
   126             if (!/^\w+:?([cbk\d]+)?$/i) || $1 && ($1 =~ /c.*c|b.*b|k.*k|\d[^\d]+\d/i);
       
   127     }
       
   128     die("$error.\n") if $error;
       
   129 
       
   130     imaker::SetWorkdir($opt_workdir);
       
   131     imaker::ReadICmdFile($opt_cmdfile);
       
   132 
       
   133     my (@step, @stepdur) = (split(/-+/, lc($opt_step)), ());
       
   134     my ($durstr, $maxslen, $maxdlen) = ("", 6, 8);
       
   135 
       
   136     foreach my $stepnum (0 .. $#step) {
       
   137         $step[$stepnum] =~ /^(\w+):?([cbk\d]+)?$/;
       
   138         my $step = uc($1);
       
   139         $_ = (defined($2) ? $2 : "");
       
   140         my @dur = imaker::MakeStep($step, /c/, /b/, /k/, /(\d+)/ ? $1 : $opt_verbose, $opt_printcmd);
       
   141         imaker::SetVerbose($opt_verbose);
       
   142         my ($cmddur, $stepdur) = (0, pop(@dur));
       
   143         $durstr = imaker::Sec2Min($stepdur);
       
   144         if (@dur) {
       
   145             $durstr .= " (";
       
   146             foreach my $dur (@dur) {
       
   147                 $cmddur += $dur;
       
   148                 $durstr .= imaker::Sec2Min($dur) . " + ";
       
   149             }
       
   150             $durstr .= imaker::Sec2Min($stepdur - $cmddur) . ")";
       
   151         }
       
   152         $step = sprintf("%" . length(@step."") . "s", $stepnum + 1) . ". $step";
       
   153         push(@stepdur, $step, $durstr);
       
   154         $maxslen = imaker::Max($maxslen, length($step));
       
   155         $maxdlen = imaker::Max($maxdlen, length($durstr));
       
   156     }
       
   157 
       
   158     imaker::DPrint(2, "=" x 79 . "\n");
       
   159     @stepdur = ("Step", "Duration", "=" x $maxslen, "=" x $maxdlen, @stepdur,
       
   160         "-" x $maxslen, "-" x $maxdlen, "Total", imaker::Sec2Min(time() - $start));
       
   161     imaker::DPrint(2, sprintf("%-${maxslen}s %-${maxdlen}s ", shift(@stepdur), shift(@stepdur)) . "\n")
       
   162         while(@stepdur);
       
   163 
       
   164     imaker::CloseLog();
       
   165 }
       
   166 
       
   167 __END__ # OF IMAKER.PL