Subversion Repositories DevTools

Rev

Rev 4275 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4270 alewis 1
########################################################################
2
# Copyright (C) 2008 ERG Limited, All rights reserved
3
#
4
# Module name   : BuildQt.pl
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Script invoked by Makefile system to do the hard work
10
#                 of building QT for use with our development environment
11
#
12
#                 Perl has been used for this script because the Windows
13
#                 shell provided with JATS is not upto the task. The PATH
14
#                 variable has incorrect slashes for DOS programs
15
#
16
#......................................................................#
17
 
18
require 5.008_002;
19
use strict;
20
use warnings;
21
use File::Basename;
22
use File::Copy;
23
use File::Path;
24
 
25
 
26
use Pod::Usage;
27
use Getopt::Long;
28
use Cwd 'abs_path';
29
 
30
use JatsError;
31
use FileUtils;
32
use JatsSystem;
33
use JatsCopy;
34
 
35
Message('Hello!');
36
#
37
#   Options
38
#
39
my $opt_debug   = $ENV{'GBE_DEBUG'};        # Allow global debug
40
my $opt_verbose = $ENV{'GBE_VERBOSE'};      # Allow global verbose
41
my $opt_help = 0;
42
 
43
my $opt_CLEAN = '';
44
my $opt_SHELLBUILD = '';
45
my $opt_BUILD_NAME = '';
46
my $opt_BUILD_VERSION = '';
47
my $opt_PLATFORM = '';
48
my $opt_TYPE = '';
49
my $opt_MACHTYPE = '';
50
my $opt_BUILD_ROOT = '';
51
my $opt_INTERFACE_DIR = '';
52
my $opt_LOCAL_DIR = '';
53
my $opt_LOCAL_INC_DIR = '';
54
my $opt_LOCAL_LIB_DIR = '';
55
my $opt_LOCAL_BIN_DIR = '';
56
my $opt_BIN_DIR = '';
57
my $opt_OBJ_DIR = '';
58
my $opt_LIB_DIR = '';
59
my $opt_PKG_BIN_DIR = '';
60
my $opt_PKG_INC_DIR = '';
61
my $opt_PKG_LIB_DIR = '';
62
my $opt_PKG_PKG_DIR = '';
63
my $opt_PKG_DIR = '';
64
my $opt_PKG_TOOL_DIR = '';
65
my $opt_PKG_TOOL_BIN_DIR = '';
66
my $opt_PKG_TOOL_SCRIPT_DIR = '';
67
my $opt_DOWNLOAD_PKG = '';
68
 
69
my @ConfigMsg;
70
 
71
my $opt_SCRIPT=abs_path($0);
72
my $opt_SCRIPT_DIR=dirname($opt_SCRIPT);
73
 
74
 
75
#
76
#   Debug support
77
#   Allow the following build operations to be optionally performed
78
#
79
my $DO_CLEAN        = 1;
80
my $DO_DOWNLOAD     = 1;
81
my $DO_PATCHES      = 1;
82
my $DO_CONFIGURE    = 1;
83
my $DO_MAKE         = 1;
84
my $DO_INSTALL      = 1;
85
 
86
my $DO_BASH         = 0;
87
 
88
#-------------------------------------------------------------------------------
89
# Function        : ConfigMsg
90
#
91
# Description     : Display a simple message
92
#                   Retain message text for ue in config dump
93
#
94
# Inputs          : Array of message text
95
#
96
# Returns         : 
97
#
98
sub ConfigMsg
99
{
100
    Message (@_);
101
    push @ConfigMsg, @_;
102
}
103
 
104
#------------------------------------------------------------------------------
105
# Extract arguments - order not important except that the first argument is
106
# the launch script
107
#------------------------------------------------------------------------------
108
 
109
my $result = GetOptions (
110
                "help+"                 => \$opt_help,
111
                "manual:3"              => \$opt_help,
112
                "verbose+"              => \$opt_verbose,
113
 
114
                "clean"                 => \$opt_CLEAN,
115
                "ShellBuild=s"          => \$opt_SHELLBUILD,
116
                "BuildName=s"           => \$opt_BUILD_NAME,
117
                "BuildVersion=s"        => \$opt_BUILD_VERSION,
118
                "Platform=s"            => \$opt_PLATFORM,
119
                "Type=s"                => \$opt_TYPE,
120
                "MachType=s"            => \$opt_MACHTYPE,
121
                "BuildRoot=s"           => \$opt_BUILD_ROOT,
122
                "InterfaceDir=s"        => \$opt_INTERFACE_DIR,
123
                "LocalDir=s"            => \$opt_LOCAL_DIR,
124
                "LocalIncDir=s"         => \$opt_LOCAL_INC_DIR,
125
                "LocalLibDir=s"         => \$opt_LOCAL_LIB_DIR,
126
                "LocalBinDir=s"         => \$opt_LOCAL_BIN_DIR,
127
                "BinDir=s"              => \$opt_BIN_DIR,
128
                "ObjDir=s"              => \$opt_OBJ_DIR,
129
                "LibDir=s"              => \$opt_LIB_DIR,
130
                "PackageBinDir=s"       => \$opt_PKG_BIN_DIR,
131
                "PackageIncDir=s"       => \$opt_PKG_INC_DIR,
132
                "PackageLibDir=s"       => \$opt_PKG_LIB_DIR,
133
                "PackagePkgDir=s"       => \$opt_PKG_PKG_DIR,
134
                "PackageDir=s"          => \$opt_PKG_DIR,
135
                "PackageToolDir=s"      => \$opt_PKG_TOOL_DIR,
136
                "PackageToolBin=s"      => \$opt_PKG_TOOL_BIN_DIR,
137
                "PackageToolScript=s"   => \$opt_PKG_TOOL_SCRIPT_DIR,
138
                "DownloadPkg=s"         => \$opt_DOWNLOAD_PKG,
139
 
140
                );
141
 
142
#
143
#   Configure the error reporting process now that we have the user options
144
#
145
ErrorConfig( 'name'    => 'ShellBuild',
146
             'verbose' => $opt_verbose );
147
InitFileUtils();
148
SystemConfig( 'ExitOnError' => 1);
149
 
150
 
151
#   Determine the location of the generated files
152
#   Will simplify processing later
153
#
154
$opt_SHELLBUILD=FullPath($opt_SHELLBUILD);
155
$opt_BUILD_ROOT=FullPath($opt_BUILD_ROOT);
156
$opt_INTERFACE_DIR=FullPath($opt_INTERFACE_DIR);
157
$opt_LOCAL_DIR=FullPath ($opt_LOCAL_DIR);
158
$opt_LOCAL_INC_DIR=FullPath ($opt_LOCAL_INC_DIR);
159
$opt_LOCAL_LIB_DIR=FullPath ($opt_LOCAL_LIB_DIR);
160
$opt_LOCAL_BIN_DIR=FullPath ($opt_LOCAL_BIN_DIR);
161
 
162
$opt_PKG_BIN_DIR=FullPath ($opt_PKG_BIN_DIR);
163
$opt_PKG_INC_DIR=FullPath ($opt_PKG_INC_DIR);
164
$opt_PKG_LIB_DIR=FullPath ($opt_PKG_LIB_DIR);
165
$opt_PKG_PKG_DIR=FullPath ($opt_PKG_PKG_DIR);
166
$opt_PKG_DIR=FullPath ($opt_PKG_DIR);
167
 
168
$opt_PKG_TOOL_DIR=FullPath ($opt_PKG_TOOL_DIR);
169
$opt_PKG_TOOL_BIN_DIR=FullPath($opt_PKG_TOOL_BIN_DIR);
170
$opt_PKG_TOOL_SCRIPT_DIR=FullPath($opt_PKG_TOOL_SCRIPT_DIR);
171
 
172
 
173
#------------------------------------------------------------------------------
174
# Dump JATS information for debugging purposes
175
#------------------------------------------------------------------------------
176
Message "================================================================================";
177
Message "   JATS SUPPLIED FIELDS";
178
Message "================================================================================";
179
ConfigMsg " BuildName         = $opt_BUILD_NAME $opt_BUILD_VERSION";
180
ConfigMsg " Script            = $opt_SCRIPT";
181
ConfigMsg " ScriptDir         = $opt_SCRIPT_DIR";
182
ConfigMsg " ShellBuild        = $opt_SHELLBUILD";
183
ConfigMsg " Platform          = $opt_PLATFORM";
184
ConfigMsg " Type              = $opt_TYPE";
185
ConfigMsg " MachType          = $opt_MACHTYPE";
186
ConfigMsg " BuildRoot         = $opt_BUILD_ROOT";
187
ConfigMsg " InterfaceDir      = $opt_INTERFACE_DIR";
188
ConfigMsg " LocalDir          = $opt_LOCAL_DIR";
189
ConfigMsg " LocalIncDir       = $opt_LOCAL_INC_DIR";
190
ConfigMsg " LocalLibDir       = $opt_LOCAL_LIB_DIR";
191
ConfigMsg " LocalBinDir       = $opt_LOCAL_BIN_DIR";
192
ConfigMsg " BinDir            = $opt_BIN_DIR";
193
ConfigMsg " ObjDir            = $opt_OBJ_DIR";
194
ConfigMsg " LibDir            = $opt_LIB_DIR";
195
ConfigMsg " PackageBinDir     = $opt_PKG_BIN_DIR";
196
ConfigMsg " PackageIncDir     = $opt_PKG_INC_DIR";
197
ConfigMsg " PackageLibDir     = $opt_PKG_LIB_DIR";
198
ConfigMsg " PackagePkgDir     = $opt_PKG_PKG_DIR";
199
ConfigMsg " PackageDir        = $opt_PKG_DIR";
200
ConfigMsg " PackageToolDir    = $opt_PKG_TOOL_DIR";
201
ConfigMsg " PackageToolBin    = $opt_PKG_TOOL_BIN_DIR";
202
ConfigMsg " PackageToolScript = $opt_PKG_TOOL_SCRIPT_DIR";
203
ConfigMsg " DownloadPkg       = $opt_DOWNLOAD_PKG";
204
Message "================================================================================";
205
 
206
 
207
 
208
# Calculate the relative directory locations
209
my $BASE_DIR=$opt_BUILD_ROOT;
210
my $DOWNLOADS_DIR="$BASE_DIR/downloads";
211
my $SRC_DIR="$BASE_DIR/src";
212
 
213
# Find the downloaded package
214
my $TARBALL_FILE="$DOWNLOADS_DIR/$opt_DOWNLOAD_PKG";
215
my $TAR_DECOMP_ARG;
216
my $ZIP_DECOMP_ARG;
217
my $ext;
218
 
219
if ( -e $TARBALL_FILE . ".tar.bz2" ) {
220
    $TARBALL_FILE=$TARBALL_FILE . ".tar.bz2";
221
    $TAR_DECOMP_ARG='j';
222
    $ext = '.bz2';
223
} elsif ( -e $TARBALL_FILE . ".tar.gz" ) {
224
    $TARBALL_FILE=$TARBALL_FILE . ".tar.gz";
225
    $TAR_DECOMP_ARG='z';
226
    $ext = '.tar.gz';
227
} elsif ( $TARBALL_FILE . ".tgz" ) {
228
    $TARBALL_FILE=$TARBALL_FILE . ".tgz";
229
    $TAR_DECOMP_ARG='z';
230
    $ext = '.tgz';
231
} elsif ( $TARBALL_FILE . ".zip" ) {
232
    $TARBALL_FILE=$TARBALL_FILE . ".zip";
233
    $ZIP_DECOMP_ARG='x';
234
    $ext = '.zip';
235
} else {
236
    Error ("Could not find download file $TARBALL_FILE.<tar.gz|tar.bz2|tgz|zip>");
237
}
238
 
239
my $UNTAR_DIR="$SRC_DIR/$opt_DOWNLOAD_PKG";
240
my $WORK_DIR = "$UNTAR_DIR.$opt_PLATFORM$opt_TYPE";
241
my $PATCH_DIR= "$BASE_DIR/patches";
242
 
243
# Dump configuration
244
Message "================================================================================";
245
Message "   BUILD CONFIGURATION";
246
Message "================================================================================";
247
ConfigMsg " Base Dir       = $BASE_DIR";
248
ConfigMsg " Tarball File   = $TARBALL_FILE";
249
ConfigMsg " Working Dir    = $WORK_DIR";
250
Message "================================================================================";
251
 
252
# Prepare the environment
253
Message " --> Preparing environment";
254
 
255
#
256
#   Clean it up - if requested
257
#
258
if ( $opt_CLEAN )
259
{
260
    Message " --> Cleaning generated files";
261
    DeleteDir( $UNTAR_DIR );
262
    DeleteDir( $WORK_DIR );
263
    if ( -d $UNTAR_DIR)
264
    {
265
        Error("Could not delete directory $UNTAR_DIR");
266
    }
267
    if ( -d $WORK_DIR)
268
    {
269
        Error("Could not delete directory $WORK_DIR");
270
    }
271
    exit (0);
272
}
273
 
274
#
275
#   Download and unzip/untar the source package
276
#
277
$DO_DOWNLOAD = 1
278
    if ( ! -d  $WORK_DIR );
279
 
280
if ( $DO_DOWNLOAD )
281
{
282
    Message " --> Deleting existing build objects directory";
283
    DeleteDir( $UNTAR_DIR );
284
    DeleteDir( $WORK_DIR );
285
    if ( -d $UNTAR_DIR )
286
    {
287
        Error("Could not delete directory $UNTAR_DIR");
288
    }
289
    if ( -d $WORK_DIR )
290
    {
291
        Error("Could not delete directory $WORK_DIR");
292
    }
293
}
294
else
295
{
296
    Message " --> Keep downloaded package";
297
}
298
 
299
if ( $DO_DOWNLOAD )
300
{
301
    Message " --> Extracting $TARBALL_FILE";
302
    $DO_PATCHES = 1;
303
    chdir $SRC_DIR || Error ("Cannot cd to $SRC_DIR");
304
    if ( $TAR_DECOMP_ARG )
305
    {
306
        #
307
        # Extract tar from archive
308
        # Extract files from tar
309
        #
310
        my $tfile = $opt_DOWNLOAD_PKG ;
311
        $tfile =~ s~\Q$ext~~;
312
        $tfile .= '.tar';
313
 
314
        System ('7z', 'e', $TARBALL_FILE, '-y');
315
        System ('7z', 'x', $tfile, '-y' );
316
        unlink $tfile;
317
    }
318
    else
319
    {
320
        System ('7z', 'x', $TARBALL_FILE, '-y' );
321
    }
322
 
323
    # Make sure it exists in the expected directory.
324
    if ( ! -d $UNTAR_DIR ) {
325
        Error ("Decompression to $UNTAR_DIR did not occur as expected");
326
    }
327
 
328
    # It does exist, so move it to the TARBALL directory we expect.
329
    rename $UNTAR_DIR,$WORK_DIR || Error("Could not move $UNTAR_DIR to $WORK_DIR");
330
 
331
}
332
chdir $WORK_DIR || Error ("Cannot cd to $WORK_DIR");
333
 
334
#
335
#   Apply local patches
336
#
337
if ( $DO_PATCHES )
338
{
339
    my $patch_script = "$opt_SCRIPT_DIR/patch.pl";
340
    Message " --> Patch script found at $patch_script";
341
    my @patches = glob("$PATCH_DIR/*.patch");
342
    @patches = sort @patches;
343
    foreach (@patches) {
344
        my $patch=$_;
345
        Message " --> Applying $patch";
346
        System ("perl $patch_script -p1 < $patch");
347
 
348
    }
349
}
350
 
351
#
352
#   Call the build script - first setup the environment, then enter the script.
353
#
354
$opt_SHELLBUILD=~tr{/}{\\};
355
$WORK_DIR=~tr{/}{\\};
356
$opt_PKG_BIN_DIR=~tr{/}{\\};
357
$opt_PKG_INC_DIR=~tr{/}{\\};
358
$opt_PKG_LIB_DIR=~tr{/}{\\};
359
$opt_PKG_PKG_DIR=~tr{/}{\\}; 
360
$opt_INTERFACE_DIR=~tr{/}{\\}; 
361
 
362
$ENV{WORK_DIR}=$WORK_DIR;
363
$ENV{DOWNLOAD_PKG}=$opt_BUILD_NAME;
364
$ENV{PLATFORM}=$opt_PLATFORM;
365
$ENV{PKG_BIN_DIR}=$opt_PKG_BIN_DIR;
366
$ENV{PKG_INC_DIR}=$opt_PKG_INC_DIR;
367
$ENV{PKG_LIB_DIR}=$opt_PKG_LIB_DIR;
368
$ENV{PKG_PKG_DIR}=$opt_PKG_PKG_DIR;
369
 
370
$ENV{INTERFACE_LIB_DIR}="$opt_INTERFACE_DIR\\lib\\$opt_PLATFORM";
371
$ENV{INTERFACE_INC_DIR}="$opt_INTERFACE_DIR\\include";
372
 
373
# Clean-up the various flags that can impact nmake.
374
my $cur_MAKEFLAGS=$ENV{MAKEFLAGS};
375
my $cur_MAKE=$ENV{MAKE};
376
 
377
$ENV{MAKEFLAGS}='';
378
$ENV{MAKE}='';
379
 
380
$result=System("$opt_SHELLBUILD");
381
if ($result != 0 ) 
382
{
383
    Error("Shell build failed with code $result");
384
}
385
 
386
# Restore the flags.
387
$ENV{MAKEFLAGS}=$cur_MAKEFLAGS;
388
$ENV{MAKE}=$cur_MAKE;
389
 
390
 
391
Message " --> All Done";
392
exit 0;