Subversion Repositories DevTools

Rev

Rev 1154 | 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
    #
1155 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 );
85
 
86
    #
87
    #   Files will be placed into the OBJDIR
88
    #   Ensure that the compiler searches this directory
89
    #
90
    AddIncDir( '*' , "\$(OBJDIR)", '--NoWarn' );
91
}
92
 
93
#-------------------------------------------------------------------------------
94
# Function        : QtUses
95
#
96
# Description     : User directive to provide information as to which parts of
97
#                   Qt are being used.
98
#
99
#                   Done this way for two reasons:
100
#                       1) Allow the Include path to be extended
101
#                          Qt has a lot of subdirs in 'include'
102
#                          Placing all of these in the include path
103
#                          slows down the compilation
104
#
105
#                       2) Allow JATS to provide a '--Uses' construct for
106
#                          programs and shared libraries taht provide a machine
107
#                          independent mechanism for adding the required libs
108
#
109
# Inputs          : $platforms          - Platform predicate
110
#                   @components         - Compoents to use
111
#
112
# Returns         : 
113
#
114
sub QtUses
115
{
116
    my ($platforms, @components) = @_;
117
    Debug( "QtUses: ",$platforms, @components );
118
    return if ( ! ActivePlatform($platforms) );
119
 
1155 dpurdie 120
    Error ("Cannot find the Qt Base Package, or Qt is not supported", "on this platform") unless ( $qt_package );
121
 
1148 dpurdie 122
    foreach my $component ( @components )
123
    {
124
        #
125
        #   Only do it once
126
        #
127
        next if ( exists $qt_used{$component} );
128
        $qt_used{$component} = 1;
129
 
130
        #
131
        #   Extend the header search path to include the required headers
132
        #
133
        my $dir;
134
        foreach my $path ( $qt_package->getIncDirs(2) )
135
        {
136
            if ( -d "$path/$component" )
137
            {
138
                $dir = "$path/$component";
139
                last;
140
            }
141
        }
142
        Error ("Qt component not supported: $component")
143
             unless ( $dir );
144
        AddIncDir ('*', '--NoWarn','--System', $dir );
145
 
146
 
147
################################################################################
148
#
149
#   Following code currently not active
150
#   There is no one-one relationship between QT include dirs and libraries
151
#
152
#   Dont know how Trolltech  do it. Might be hard coded
153
#
154
################################################################################
155
#
156
#        #
157
#        #   Extend a --Users(QT) definition to provide libraries for the user
158
#        #   There are problems
159
#        #       Under windows, some of the libraries have a 4 suffix
160
#        #   Need to determine the exact name of the library
161
#        #   Normally this knowledge is buried within the compiler/linker and
162
#        #   some JATS tools.
163
#        #
164
#        #   Algorithm:
165
#        #       Given a library name, determine if the file exists
166
#        #       under both windows and linux
167
#        #           If Unix - prefix with lib
168
#        #           If Unix - try shared-lib, static lib suffix
169
#        #           If Windows - try static lib suffix
170
#        #
171
#        my @prefix = ('', 'lib');
172
#        my @suffix = ($::so, $::a );
173
#        my $found;
174
#        HUNT:
175
#        foreach my $qtsuf ( '4', '' )
176
#        {
177
#            foreach my $suffix ( @suffix )
178
#            {
179
#                foreach my $prefix ( @prefix )
180
#                {
181
#                    my $cname = $prefix . $component . $qtsuf . '.' . $suffix;
182
#                    foreach my $path ( $qt_package->getLibDirs(2) )
183
#                    {
184
#                        if ( -f "$path/$cname" )
185
#                        {
186
#                            $found = $component . $qtsuf;
187
#                            last HUNT;
188
#                        }
189
#                    }
190
#                }
191
#            }
192
#        }
193
#
194
#        Error ("QT library component not supported: $component")
195
#            unless ( $found );
196
#
197
#        MakeIf::Libaries ( 'QT', '*', "-L$found");
198
################################################################################
199
    }
200
}
201
 
202
#-------------------------------------------------------------------------------
203
# Function        : src_hook_qrc
204
#
205
# Description     : This function will be invoked when a .QRC file
206
#                   is encountered in the Src directive
207
#
208
#                   .qrc file are QT resource files
209
#                   These need to be processed into .cpp file
210
#                   and the .cpp file needs to be converted into an object file
211
#
212
# Inputs          : $path           - Source path
213
#                   $path           - Source file name
214
#                   $obj            - Base file name (no dir or ext)
215
#                   $ext            - Extension
216
#
217
# Returns         : 
218
#
219
sub src_hook_qrc
220
{
221
    Debug ("src_hook_qrc: @_");
222
    my ( $srcfile ,$path, $obj, $ext ) = @_;
223
    my @dlist = ();
224
 
225
    #
226
    #   The .qrc file will be converted into a cpp file
227
    #   Treat the .cpp file as a source file in its own right
228
    #
229
    $obj = 'qrc_' . $obj;
230
    my $csource = '$(OBJDIR)/' . $obj . '.cpp' ;
231
    GenerateSrcFile ( 1, $csource  );
232
 
233
    #
234
    #   The user may have specified some dependencies
235
    #   Create a list of these to be a part of the generated Rule
236
    #
237
    @dlist = split( /$;/, $SRC_DEPEND{$path} )
238
        if ( exists $SRC_DEPEND{$path} );
239
 
240
    #
241
    #   Parse the source file and extract dependencies
242
    #       The file is of a known XML format
243
    #       Depenedencies are not nested
244
    #       Implement a simple parser
245
    #
246
    #   Look for lines of the form:
247
    #       <file ....>FileName</file>
248
    #
249
    #   The source file may not acually exist. It may be symbolic
250
    #   If the file doesn't exist, then don't complain.
251
    #
252
    if ( -e $srcfile )
253
    {
254
        if (open (SF, '<', $srcfile ))
255
        {
256
            my $srcdir = StripFileExt( $srcfile );
257
            $srcdir .= '/' if ( $srcdir );
258
            while ( <SF> )
259
            {
260
                if ( m~<file.*>(.*)</file>~ )
261
                {
262
                    my $name = $1;
263
                    $name =~ s~([ ,])~\\$1~g;
264
                    push @dlist, "$srcdir$name";
265
                }
266
            }
267
            close SF;
268
        }
269
    }
270
 
271
    #
272
    #   Create a Rule to build this file
273
    #   Will be placed in the Rules section
274
    #
275
    my $var;
276
    my $me = MakeEntry::New (\$var, $csource );
277
#    $me->AddComment ("QT Resource Compiler: $path" );
278
    $me->AddDependancy ( $srcfile );
279
    $me->AddDependancy ( @dlist );
280
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
281
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
282
    $me->AddRecipe     ( '$(XX_PRE)$(QT_RCC)' );
283
    $me->Print();
284
 
285
    ToolsetRule ( $var );
286
}
287
 
288
#-------------------------------------------------------------------------------
289
# Function        : src_hook_ui
290
#
291
# Description     : This function will be invoked when a .UI file
292
#                   is encountered in the Src directive
293
#
294
#                   .ui file are QT User Interface files
295
#                   These need to be processed into header files
296
#                   by the User Interface Compiler
297
#
298
# Inputs          : $path           - Source path
299
#                   $path           - Source file name
300
#                   $obj            - Base file name (no dir or ext)
301
#                   $ext            - Extension
302
#
303
# Returns         : 
304
#
305
sub src_hook_ui
306
{
307
    Debug ("src_hook_ui: @_");
308
    my ( $srcfile ,$path, $obj, $ext ) = @_;
309
 
310
    #
311
    #   Convert the UI file into a header file
312
    #   Place the header file in the OBJ directory
313
    #
314
    my $target = "\$(OBJDIR)/ui_$obj.h";
315
    GenerateSrcFile ( 1, $target  );
316
 
317
    #
318
    #   The user may have specified some dependencies
319
    #   Create a list of these to be a part of the generated Rule
320
    #
321
    my @dlist = split( /$;/, $SRC_DEPEND{$path} )
322
        if ( exists $SRC_DEPEND{$path} );
323
 
324
    #
325
    #   Create a Rule to build this file
326
    #   Will be placed in the Rules section
327
    #
328
    my $var;
329
    my $me = MakeEntry::New (\$var, $target );
330
#    $me->AddComment ("QT User Interface File: $path" );
331
    $me->AddDependancy ( $srcfile );
332
    $me->AddDependancy ( @dlist );
333
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
334
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
335
    $me->AddRecipe     ( '$(XX_PRE)$(QT_UIC)' );
336
    $me->Print();
337
 
338
    ToolsetRule ( $var );
339
}
340
 
341
#-------------------------------------------------------------------------------
342
# Function        : src_hook_h
343
#
344
# Description     : This function will be invoked when a .h file
345
#                   is encountered in the Src directive
346
#
347
#                   If the file is flagged as --Moc then it will treated
348
#                   by the MOC processor
349
#
350
# Inputs          : $path           - Source path
351
#                   $path           - Source file name
352
#                   $obj            - Base file name (no dir or ext)
353
#                   $ext            - Extension
354
#
355
# Returns         : 
356
#
357
sub src_hook_h
358
{
359
    Debug ("src_hook_h: @_");
360
    my ( $srcfile ,$path, $obj, $ext ) = @_;
361
 
362
    #
363
    #   Only interested in files that are flagged as --Moc
364
    #
365
    return unless ( $SRC_ARGS{ $path } && grep (/^--Moc$/i, split( /$;/, $SRC_ARGS{$path} ) ) );
366
 
367
    #
368
    #   The file will be converted into a cpp file
369
    #   Treat the .cpp file as a source file in its own right
370
    #
371
    $obj = 'moc_' . $obj;
372
    my $csource = '$(OBJDIR)/' . $obj . '.cpp' ;
373
    GenerateSrcFile ( 1, $csource  );
374
 
375
    #
376
    #   The user may have specified some dependencies
377
    #   Create a list of these to be a part of the generated Rule
378
    #
379
    my @dlist = split( /$;/, $SRC_DEPEND{$path} )
380
        if ( exists $SRC_DEPEND{$path} );
381
 
382
    #
383
    #   Create a Rule to build this file
384
    #   Will be placed in the Rules section
385
    #
386
    my $var;
387
    my $me = MakeEntry::New (\$var, $csource );
388
#    $me->AddComment ("QT Meta Object Compiler: $path" );
389
    $me->AddDependancy ( $srcfile );
390
    $me->AddDependancy ( @dlist );
391
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
392
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
393
    $me->AddRecipe     ( '$(XX_PRE)$(QT_MOC)' );
394
    $me->Print();
395
 
396
    ToolsetRule ( $var );
397
 
398
}
399
 
400
#-------------------------------------------------------------------------------
401
# Function        : src_hook_cpp
402
#
403
# Description     : This function will be invoked when a .cpp file
404
#                   is encountered in the Src directive
405
#
406
#                   If the file is flagged as --Moc then it will treated
407
#                   by the MOC processor
408
#
409
# Inputs          : $path           - Source path
410
#                   $path           - Source file name
411
#                   $obj            - Base file name (no dir or ext)
412
#                   $ext            - Extension
413
#
414
# Returns         : 
415
#
416
sub src_hook_cpp
417
{
418
    Debug ("src_hook_cpp: @_");
419
    my ( $srcfile ,$path, $obj, $ext ) = @_;
420
 
421
    #
422
    #   Only interested in files that are flagged as --Moc
423
    #
424
    return unless ( $SRC_ARGS{ $path } && grep (/^--Moc$/i, split( /$;/, $SRC_ARGS{$path} ) ) );
425
 
426
    #
427
    #   The file will be converted into a .moc file as shown in the QT doco
428
    #   Treat the .moc file as a source file in its own right
429
    #
430
    my $csource = '$(OBJDIR)/' . $obj . '.moc' ;
431
    GenerateSrcFile ( 1, $csource  );
432
 
433
    #
434
    #   The user may have specified some dependencies
435
    #   Create a list of these to be a part of the generated Rule
436
    #
437
    my @dlist = split( /$;/, $SRC_DEPEND{$path} )
438
        if ( exists $SRC_DEPEND{$path} );
439
 
440
    #
441
    #   Create a Rule to build this file
442
    #   Will be placed in the Rules section
443
    #
444
    my $var;
445
    my $me = MakeEntry::New (\$var, $csource );
446
#    $me->AddComment ("QT Meta Object Compiler: $path" );
447
    $me->AddDependancy ( $srcfile );
448
    $me->AddDependancy ( @dlist );
449
    $me->AddDependancy ( '$(SCM_MAKEFILE)' );
450
    $me->AddDependancy ( '$(GBE_OBJDIR)' );
451
    $me->AddRecipe     ( '$(XX_PRE)$(QT_MOC)' );
452
    $me->Print();
453
 
454
    ToolsetRule ( $var );
455
}
456
 
457
 
458
1;