Subversion Repositories DevTools

Rev

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

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