Subversion Repositories DevTools

Rev

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