Subversion Repositories DevTools

Rev

Rev 1148 | Rev 1152 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1148 dpurdie 1
########################################################################
2
# Copyright (C) 2008 ERG Limited, All rights reserved
3
#
4
# Module name   : qt-builder.pm
5
# Module type   : Makefile system
6
# Compiler(s)   : Perl
7
# Environment(s): jats
8
#
9
# Description   : Provide JATS build support for the QT SDK
10
#                 This module hoosk into the internals of JATS
11
#                 It tries to be generic, buts its not easy
12
#
13
#......................................................................#
14
 
15
require 5.008_002;
16
use strict;
17
use warnings;
18
use MakeEntry;
19
 
20
#
21
#   Global Varibales
22
#
23
our %SRC_DEPEND;                        # Source file dependencies
24
our %SRC_ARGS;                          # Source file arguments
25
 
26
#
27
#   Local variables
28
#
29
my $qt_package;                         # Ref to package containing QT
30
my %qt_used;                            # Track Used items
31
 
32
#-------------------------------------------------------------------------------
33
# Function        : BEGIN
34
#
35
# Description     : Setup directive hooks
36
#                   Register to be told about source files that are QT specific
37
#
38
# Inputs          : None
39
#
40
# Returns         : None
41
#
42
BEGIN
43
{
44
    #
1150 dpurdie 45
    #   Locate the QT package
46
    #   Done by looking for the include/QtGui directory
47
    #       If we don't find it then don't install the Qt hooks
48
    #       Generate a warning when Qt is 'Used'
49
    #       This allows for the building of packages that have Qt and Non-Qt parts
50
    #
51
    foreach my $entry ( getPackageList() )
52
    {
53
        foreach my $path ( $entry->getIncDirs(1) )
54
        {
55
            if ( -d "$path/QtGui" )
56
            {
57
                $qt_package = $entry;
58
                last;
59
            }
60
        }
61
    }
62
 
63
    #
64
    #   Qt not supported in this type of a build
65
    #   Just exist now. Will create an error if QtUses is activated
66
    #
67
    return
68
        unless ( $qt_package );
69
 
70
 
71
    #
1148 dpurdie 72
    #   Define QT specfic rules.
73
    #   Will be found in the same directory as this file
74
    #
75
    Rules ( StripFileExt( __FILE__ ), 'qt.rul' );
76
 
77
    #
78
    #   Register interest in various types of source file
79
    #   Currently only header files are examined for MOC processing
80
    #
81
    RegisterSrcHook ('.qrc', \&src_hook_qrc );
82
    RegisterSrcHook ('.ui',  \&src_hook_ui );
83
    RegisterSrcHook ('.h',   \&src_hook_h );
84
    RegisterSrcHook ('.cpp', \&src_hook_cpp );
1150 dpurdie 85
    RegisterSrcHook ('.ts',  \&src_hook_ts );
1148 dpurdie 86
 
87
    #
88
    #   Files will be placed into the OBJDIR
89
    #   Ensure that the compiler searches this directory
90
    #
91
    AddIncDir( '*' , "\$(OBJDIR)", '--NoWarn' );
92
}
93
 
94
#-------------------------------------------------------------------------------
95
# Function        : QtUses
96
#
97
# Description     : User directive to provide information as to which parts of
98
#                   Qt are being used.
99
#
100
#                   Done this way for two reasons:
101
#                       1) Allow the Include path to be extended
102
#                          Qt has a lot of subdirs in 'include'
103
#                          Placing all of these in the include path
104
#                          slows down the compilation
105
#
106
#                       2) Allow JATS to provide a '--Uses' construct for
107
#                          programs and shared libraries taht provide a machine
108
#                          independent mechanism for adding the required libs
109
#
110
# Inputs          : $platforms          - Platform predicate
111
#                   @components         - Compoents to use
112
#
113
# Returns         : 
114
#
115
sub QtUses
116
{
117
    my ($platforms, @components) = @_;
118
    Debug( "QtUses: ",$platforms, @components );
119
    return if ( ! ActivePlatform($platforms) );
120
 
1150 dpurdie 121
    Error ("Cannot find the Qt Base Package, or Qt is not supported", "on this platform") unless ( $qt_package );
122
 
1148 dpurdie 123
    foreach my $component ( @components )
124
    {
125
        #
126
        #   Only do it once
127
        #
128
        next if ( exists $qt_used{$component} );
129
        $qt_used{$component} = 1;
130
 
131
        #
132
        #   Extend the header search path to include the required headers
133
        #
134
        my $dir;
135
        foreach my $path ( $qt_package->getIncDirs(2) )
136
        {
137
            if ( -d "$path/$component" )
138
            {
139
                $dir = "$path/$component";
140
                last;
141
            }
142
        }
143
        Error ("Qt component not supported: $component")
144
             unless ( $dir );
145
        AddIncDir ('*', '--NoWarn','--System', $dir );
146
 
147
 
148
################################################################################
149
#
150
#   Following code currently not active
151
#   There is no one-one relationship between QT include dirs and libraries
152
#
153
#   Dont know how Trolltech  do it. Might be hard coded
154
#
155
################################################################################
156
#
157
#        #
158
#        #   Extend a --Users(QT) definition to provide libraries for the user
159
#        #   There are problems
160
#        #       Under windows, some of the libraries have a 4 suffix
161
#        #   Need to determine the exact name of the library
162
#        #   Normally this knowledge is buried within the compiler/linker and
163
#        #   some JATS tools.
164
#        #
165
#        #   Algorithm:
166
#        #       Given a library name, determine if the file exists
167
#        #       under both windows and linux
168
#        #           If Unix - prefix with lib
169
#        #           If Unix - try shared-lib, static lib suffix
170
#        #           If Windows - try static lib suffix
171
#        #
172
#        my @prefix = ('', 'lib');
173
#        my @suffix = ($::so, $::a );
174
#        my $found;
175
#        HUNT:
176
#        foreach my $qtsuf ( '4', '' )
177
#        {
178
#            foreach my $suffix ( @suffix )
179
#            {
180
#                foreach my $prefix ( @prefix )
181
#                {
182
#                    my $cname = $prefix . $component . $qtsuf . '.' . $suffix;
183
#                    foreach my $path ( $qt_package->getLibDirs(2) )
184
#                    {
185
#                        if ( -f "$path/$cname" )
186
#                        {
187
#                            $found = $component . $qtsuf;
188
#                            last HUNT;
189
#                        }
190
#                    }
191
#                }
192
#            }
193
#        }
194
#
195
#        Error ("QT library component not supported: $component")
196
#            unless ( $found );
197
#
198
#        MakeIf::Libaries ( 'QT', '*', "-L$found");
199
################################################################################
200
    }
201
}
202
 
203
#-------------------------------------------------------------------------------
204
# Function        : src_hook_qrc
205
#
206
# Description     : This function will be invoked when a .QRC file
207
#                   is encountered in the Src directive
208
#
209
#                   .qrc file are QT resource files
210
#                   These need to be processed into .cpp file
211
#                   and the .cpp file needs to be converted into an object file
212
#
213
# Inputs          : $path           - Source path
214
#                   $path           - Source file name
215
#                   $obj            - Base file name (no dir or ext)
216
#                   $ext            - Extension
217
#
218
# Returns         : 
219
#
220
sub src_hook_qrc
221
{
222
    Debug ("src_hook_qrc: @_");
223
    my ( $srcfile ,$path, $obj, $ext ) = @_;
224
    my @dlist = ();
225
 
226
    #
227
    #   The .qrc file will be converted into a cpp file
228
    #   Treat the .cpp file as a source file in its own right
229
    #
230
    $obj = 'qrc_' . $obj;
231
    my $csource = '$(OBJDIR)/' . $obj . '.cpp' ;
232
    GenerateSrcFile ( 1, $csource  );
233
 
234
    #
235
    #   The user may have specified some dependencies
236
    #   Create a list of these to be a part of the generated Rule
237
    #
238
    @dlist = split( /$;/, $SRC_DEPEND{$path} )
239
        if ( exists $SRC_DEPEND{$path} );
240
 
241
    #
242
    #   Parse the source file and extract dependencies
243
    #       The file is of a known XML format
244
    #       Depenedencies are not nested
245
    #       Implement a simple parser
246
    #
247
    #   Look for lines of the form:
248
    #       <file ....>FileName</file>
249
    #
250
    #   The source file may not acually exist. It may be symbolic
251
    #   If the file doesn't exist, then don't complain.
252
    #
253
    if ( -e $srcfile )
254
    {
255
        if (open (SF, '<', $srcfile ))
256
        {
257
            my $srcdir = StripFileExt( $srcfile );
258
            $srcdir .= '/' if ( $srcdir );
259
            while ( <SF> )
260
            {
261
                if ( m~<file.*>(.*)</file>~ )
262
                {
263
                    my $name = $1;
264
                    $name =~ s~([ ,])~\\$1~g;
265
                    push @dlist, "$srcdir$name";
266
                }
267
            }
268
            close SF;
269
        }
270
    }
271
 
272
    #
273
    #   Create a Rule to build this file
274
    #   Will be placed in the Rules section
275
    #
276
    my $var;
277
    my $me = MakeEntry::New (\$var, $csource );
278
#    $me->AddComment ("QT Resource Compiler: $path" );
279
    $me->AddDependancy ( $srcfile );
280
    $me->AddDependancy ( @dlist );
281
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
282
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
283
    $me->AddRecipe     ( '$(XX_PRE)$(QT_RCC)' );
284
    $me->Print();
285
 
286
    ToolsetRule ( $var );
287
}
288
 
289
#-------------------------------------------------------------------------------
290
# Function        : src_hook_ui
291
#
292
# Description     : This function will be invoked when a .UI file
293
#                   is encountered in the Src directive
294
#
295
#                   .ui file are QT User Interface files
296
#                   These need to be processed into header files
297
#                   by the User Interface Compiler
298
#
299
# Inputs          : $path           - Source path
300
#                   $path           - Source file name
301
#                   $obj            - Base file name (no dir or ext)
302
#                   $ext            - Extension
303
#
304
# Returns         : 
305
#
306
sub src_hook_ui
307
{
308
    Debug ("src_hook_ui: @_");
309
    my ( $srcfile ,$path, $obj, $ext ) = @_;
310
 
311
    #
312
    #   Convert the UI file into a header file
313
    #   Place the header file in the OBJ directory
314
    #
315
    my $target = "\$(OBJDIR)/ui_$obj.h";
316
    GenerateSrcFile ( 1, $target  );
317
 
318
    #
319
    #   The user may have specified some dependencies
320
    #   Create a list of these to be a part of the generated Rule
321
    #
322
    my @dlist = split( /$;/, $SRC_DEPEND{$path} )
323
        if ( exists $SRC_DEPEND{$path} );
324
 
325
    #
326
    #   Create a Rule to build this file
327
    #   Will be placed in the Rules section
328
    #
329
    my $var;
330
    my $me = MakeEntry::New (\$var, $target );
331
#    $me->AddComment ("QT User Interface File: $path" );
332
    $me->AddDependancy ( $srcfile );
333
    $me->AddDependancy ( @dlist );
334
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
335
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
336
    $me->AddRecipe     ( '$(XX_PRE)$(QT_UIC)' );
337
    $me->Print();
338
 
339
    ToolsetRule ( $var );
340
}
341
 
342
#-------------------------------------------------------------------------------
343
# Function        : src_hook_h
344
#
345
# Description     : This function will be invoked when a .h file
346
#                   is encountered in the Src directive
347
#
348
#                   If the file is flagged as --Moc then it will treated
349
#                   by the MOC processor
350
#
351
# Inputs          : $path           - Source path
352
#                   $path           - Source file name
353
#                   $obj            - Base file name (no dir or ext)
354
#                   $ext            - Extension
355
#
356
# Returns         : 
357
#
358
sub src_hook_h
359
{
360
    Debug ("src_hook_h: @_");
361
    my ( $srcfile ,$path, $obj, $ext ) = @_;
362
 
363
    #
364
    #   Only interested in files that are flagged as --Moc
365
    #
366
    return unless ( $SRC_ARGS{ $path } && grep (/^--Moc$/i, split( /$;/, $SRC_ARGS{$path} ) ) );
367
 
368
    #
369
    #   The file will be converted into a cpp file
370
    #   Treat the .cpp file as a source file in its own right
371
    #
372
    $obj = 'moc_' . $obj;
373
    my $csource = '$(OBJDIR)/' . $obj . '.cpp' ;
374
    GenerateSrcFile ( 1, $csource  );
375
 
376
    #
377
    #   The user may have specified some dependencies
378
    #   Create a list of these to be a part of the generated Rule
379
    #
380
    my @dlist = split( /$;/, $SRC_DEPEND{$path} )
381
        if ( exists $SRC_DEPEND{$path} );
382
 
383
    #
384
    #   Create a Rule to build this file
385
    #   Will be placed in the Rules section
386
    #
387
    my $var;
388
    my $me = MakeEntry::New (\$var, $csource );
389
#    $me->AddComment ("QT Meta Object Compiler: $path" );
390
    $me->AddDependancy ( $srcfile );
391
    $me->AddDependancy ( @dlist );
392
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
393
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
394
    $me->AddRecipe     ( '$(XX_PRE)$(QT_MOC)' );
395
    $me->Print();
396
 
397
    ToolsetRule ( $var );
398
 
399
}
400
 
401
#-------------------------------------------------------------------------------
402
# Function        : src_hook_cpp
403
#
404
# Description     : This function will be invoked when a .cpp file
405
#                   is encountered in the Src directive
406
#
407
#                   If the file is flagged as --Moc then it will treated
408
#                   by the MOC processor
409
#
410
# Inputs          : $path           - Source path
411
#                   $path           - Source file name
412
#                   $obj            - Base file name (no dir or ext)
413
#                   $ext            - Extension
414
#
415
# Returns         : 
416
#
417
sub src_hook_cpp
418
{
419
    Debug ("src_hook_cpp: @_");
420
    my ( $srcfile ,$path, $obj, $ext ) = @_;
421
 
422
    #
423
    #   Only interested in files that are flagged as --Moc
424
    #
425
    return unless ( $SRC_ARGS{ $path } && grep (/^--Moc$/i, split( /$;/, $SRC_ARGS{$path} ) ) );
426
 
427
    #
428
    #   The file will be converted into a .moc file as shown in the QT doco
429
    #   Treat the .moc file as a source file in its own right
430
    #
431
    my $csource = '$(OBJDIR)/' . $obj . '.moc' ;
432
    GenerateSrcFile ( 1, $csource  );
433
 
434
    #
435
    #   The user may have specified some dependencies
436
    #   Create a list of these to be a part of the generated Rule
437
    #
438
    my @dlist = split( /$;/, $SRC_DEPEND{$path} )
439
        if ( exists $SRC_DEPEND{$path} );
440
 
441
    #
442
    #   Create a Rule to build this file
443
    #   Will be placed in the Rules section
444
    #
445
    my $var;
446
    my $me = MakeEntry::New (\$var, $csource );
447
#    $me->AddComment ("QT Meta Object Compiler: $path" );
448
    $me->AddDependancy ( $srcfile );
449
    $me->AddDependancy ( @dlist );
450
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
451
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
452
    $me->AddRecipe     ( '$(XX_PRE)$(QT_MOC)' );
453
    $me->Print();
454
 
455
    ToolsetRule ( $var );
456
}
457
 
1150 dpurdie 458
#-------------------------------------------------------------------------------
459
# Function        : src_hook_ts
460
#
461
# Description     : This function will be invoked when a .TS file
462
#                   is encountered in the Src directive
463
#
464
#                   .TS file are QT Translation Source Files
465
#                   These need to be processed into .qm files
466
#                   by the lrelease tool
467
#
468
# Inputs          : $path           - Source path
469
#                   $path           - Source file name
470
#                   $base           - Base file name (no dir or ext)
471
#                   $ext            - Extension
472
#
473
# Returns         : 
474
#
475
sub src_hook_ts
476
{
477
    Debug ("src_hook_ts: @_");
478
    my ( $srcfile ,$path, $base, $ext ) = @_;
1148 dpurdie 479
 
1150 dpurdie 480
    #
481
    #   Convert the TS file into a QM file
482
    #   Place the QM file in the BIN directory
483
    #
484
    my $target = "\$(BINDIR)/${base}.qm";
485
    GenerateSrcFile ( 1, $target  );
486
 
487
    #
488
    #   The user may have specified some dependencies
489
    #   Create a list of these to be a part of the generated Rule
490
    #
491
    my @dlist = split( /$;/, $SRC_DEPEND{$path} )
492
        if ( exists $SRC_DEPEND{$path} );
493
 
494
    #
495
    #   Create a Rule to build this file
496
    #   Will be placed in the Rules section
497
    #
498
    my $var;
499
    my $me = MakeEntry::New (\$var, $target );
500
    $me->AddComment ("QT Translation File: $path" );
501
    $me->AddDependancy ( $srcfile );
502
    $me->AddDependancy ( @dlist );
503
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
504
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
505
    $me->AddRecipe     ( '$(XX_PRE)$(QT_TRANSLATE)' );
506
    $me->Print();
507
 
508
    ToolsetRule ( $var );
509
 
510
    #
511
    #   Append the generated file to a list
512
    #
513
    push( @::QT_PMFILES, "${base}.qm" );
514
}
515
 
516
 
1148 dpurdie 517
1;