Subversion Repositories DevTools

Rev

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

Rev Author Line No. Line
227 dpurdie 1
# -*- mode: perl; indent-width: 4; show-tabs: yes; -*-
2
#
3
# Module name   : Sunworks
4
# Module type   : Makefile system
5
# Compiler(s)   : ANSI C
6
# Environment(s): CC
7
#   
8
# Description:
9
#   Sunworks C/C++ toolset
10
#
11
#.............................................................................
12
 
13
use strict;
14
use warnings;
15
use JatsError;
16
 
17
#
18
#   Table to provide the location of SUNWSPRO_SC
19
#   This is hardcoded ( not good ) based on build machine
20
#
21
#       Key: build machine type
22
#     Value: Per machine-type data
23
#
24
#   Per machine type data is a hash
25
#       compiler        - Path to the compiler
26
#       misalign        - Path (relative to compiler) to the misalign obj file
27
#                         If not present then misalign not supported
28
#
29
my %SunProLocation = (
30
    'solaris10_sparc32' => { 'compiler' => '/opt/SUNWspro/prod',
31
                             'misalign' => 'lib/misalign.o' },
32
 
33
    'solaris10_x86'     => { 'compiler' => '/opt/SUNWspro/prod' },
34
 
35
    'sparc'             => { 'compiler' => '/opt/SUNWspro/WS6U1',
36
                             'misalign' => 'lib/misalign.o' },
37
    );
38
 
39
#
40
#   Globals
41
#
42
our $GBE_MACHTYPE;
43
our $s;
44
our $o;
45
our $a;
46
our $so;
47
our $exe;
48
our @ScmToolsetArgs;
49
our @ScmPlatformArgs;
50
our %SHLIB_VER;
51
 
52
##############################################################################
53
#   ToolsetInit()
54
#       Runtime initialisation
55
#
56
##############################################################################
57
 
58
ToolsetInit();
59
 
60
my $toolsetccdepend      = 0;
61
 
62
sub ToolsetInit
63
{
64
#.. Standard.rul requirements
65
#   
66
    $s = 'asm';
67
    $o = 'o';
68
    $a = 'a';
69
    $so = 'so';
70
    $exe = '';
71
 
72
#.. Toolset configuration
73
#
74
    $::ScmToolsetVersion = "1.0.0";               # our version
75
    $::ScmToolsetGenerate = 0;                    # GEN generate optional
76
    $::ScmToolsetIFLAG3 = 1;                      # IFLAG3 supported
77
 
78
    my $ScmToolTarget = '';
79
 
80
    #
81
    #   Toolset args
82
    #
83
    foreach $_ ( @ScmToolsetArgs ) {
84
        if (/^--Target=(.*)/) {                # Target System
85
            $ScmToolTarget = $1;
86
 
87
        } else {
88
            Message( "sunworks toolset: unknown toolset option $_ -- ignored" );
89
        }
90
    }
91
 
92
    #
93
    #   Platform arguments
94
    #
95
    foreach $_ ( @ScmPlatformArgs ) {
96
        if (/^--product=(.*)/) {                # GBE product
97
 
98
        } else {
99
            Message( "sunworks toolset: unknown platform argument $_ -- ignored" );
100
        }
101
    } 
102
 
103
#.. Define environment
104
#    
105
    Init( "sunworks" );
106
    ToolsetDefines( "sunworks.def" );
107
    ToolsetRules( "sunworks.rul" );
108
    ToolsetRules( "standard.rul" );
109
 
110
#.. Cleanup rules
111
#
112
    ToolsetDirTree( "\$(LIBDIR)/SunWS_cache" );
113
    ToolsetDirTree( "\$(OBJDIR)/SunWS_cache" );
114
    ToolsetDirTree( "\$(BINDIR)/SunWS_cache" );
115
    ToolsetDirTree( "./SunWS_cache" );
116
 
117
    AddLibDir( '*', '/usr/lib', '--NoWarn', '--System' );
118
 
119
#.. Extend the CompilerOption directive
120
#   Create a standard data structure
121
#   This is a hash of hashes
122
#       The first hash is keyed by CompileOption keyword
123
#       The second hash contains pairs of values to set or remove
124
#
125
    %::ScmToolsetCompilerOptions =
126
    (
127
        #
128
        #   Control the thread model to use
129
        #   This will affect the compiler options and the linker options
130
        #
131
        'multithread'        => { 'THREADMODE' , '1' },      # -mt (default)
132
        'multithread_none'   => { 'THREADMODE' , undef },    # (none)
133
        'no_multithread'     => { 'THREADMODE' , undef },    # (none)
134
 
135
        'no_misalign'        => { 'MISALIGN', undef },       # (default)
136
        'misalign'           => { 'MISALIGN', '1' },
137
    );
138
 
139
    #
140
    #   Set default options
141
    #
142
    $::ScmCompilerOpts{'THREADMODE'} = '1';
143
 
144
 
145
    #
146
    #   Ensure that we know where the compiler is
147
    #
148
    if ( exists $SunProLocation{$GBE_MACHTYPE} )
149
    {
150
        my $sunpro = $SunProLocation{$GBE_MACHTYPE}{compiler};
151
        ToolsetDefine ( "SUNWSPRO_SC  = $sunpro" );
152
    }
153
    else
154
    {
155
        Error ("SunWorks compiler not configured for this type of machine",
156
               "GBE_MACHTYPE: $GBE_MACHTYPE" );
157
    }
158
 
159
    #
160
    #   Specify definitions to support 32 and 64 bit compilation
161
    #   Default operation is only intended for existing (solaris8) work
162
    #
163
    if ( $ScmToolTarget )
164
    {
165
        ToolsetDefine ( "COMPILE32  = 1" ) if ($ScmToolTarget =~ m/32$/);
166
        ToolsetDefine ( "COMPILE64  = 1" ) if ($ScmToolTarget =~ m/64$/);
167
    }
168
}
169
 
170
##############################################################################
171
#   ToolsetPreprocess()
172
#       Process collected data before the makefile is generated
173
#       This, optional, routine is called from within MakefileGenerate()
174
#       It allows the toolset to massage any of the collected data before
175
#       the makefile is created
176
#
177
##############################################################################
178
 
179
sub ToolsetPreprocess
180
{
181
    #
182
    #   If the machine does not support misalignment and the user has requested
183
    #   it, then kill the option - it makes life easier later.
184
    #
185
    unless ( exists ($SunProLocation{$GBE_MACHTYPE}{misalign}) )
186
    {
187
        if ( $::ScmCompilerOpts{'MISALIGN'} )
188
        {
189
            Warning("Platform does not support MISALIGN option. Will be ignored");
190
            delete $::ScmCompilerOpts{'MISALIGN'};
191
        }
192
    }
193
}
194
 
195
###############################################################################
196
#   ToolsetCC( $source, $obj, \@args )
197
#       This subroutine takes the user options and builds the rule(s)
198
#       required to compile the source file 'source' to 'obj'
199
#
200
###############################################################################
201
 
202
sub ToolsetCC
203
{
204
    my( $source, $obj, $pArgs ) = @_;
205
    my( $cflags ) = "";
206
 
207
    Debug( "CC:  $source -> $obj" );
208
    foreach ( @$pArgs ) {
209
        Debug( "option:    $_" );
210
        if ( /--Shared$/ ) {                    # Building a 'shared' object
211
            $cflags = "$cflags \$(SHCFLAGS)";
212
            Debug( "CC:    as shared object" );
213
 
214
        } else {                                # unknown option
215
            Message( "CC: unknown option $_ -- ignored\n" );
216
        }
217
    }
218
 
219
    MakePrint( "\n\t\$(CC)\n" );
220
    if ( $cflags )
221
    {                                           # object specific CFLAGS
222
        MakePadded( 4, "\$(OBJDIR)/$obj.${o}:" );
223
        MakePrint( "\tCFLAGS +=$cflags\n" );
224
    }
225
}
226
 
227
 
228
###############################################################################
229
#   ToolsetCCDepend( $depend, \@sources )
230
#       This subroutine takes the user options and builds the
231
#       rule(s) required to build the dependencies for the source
232
#       files 'sources' to 'depend'.
233
#
234
###############################################################################
235
 
236
sub ToolsetCCDepend
237
{
238
    MakePrint( "\t\$(CCDEPEND)\n" );
239
    $toolsetccdepend = 1;
240
}
241
 
242
 
243
###############################################################################
244
#   ToolsetCXX( $source, $obj, \@args )
245
#       This subroutine takes the user options and builds the rule(s)
246
#       required to compile the source file 'source' to 'obj'
247
#
248
###############################################################################
249
 
250
sub ToolsetCXX
251
{
252
    my( $source, $obj, $pArgs ) = @_;
253
    my( $cflags ) = "";
254
 
255
    Debug( "CCX: $source -> $obj" );
256
    foreach ( @$pArgs ) {
257
        Debug( "option:    $_" );
258
        if ( /--Shared$/ ) {                    # Building a 'shared' object
259
            $cflags = "$cflags \$(SHCXXFLAGS)";
260
            Debug( "CCX:    as shared object" );
261
 
262
        } else {
263
            Message( "CCX: unknown option $_ -- ignored\n" );
264
        }
265
    }
266
 
267
    MakePrint( "\n\t\$(CXX)\n" );
268
    if ( $cflags )
269
    {                                           # object specific CFLAGS
270
        MakePadded( 4, "\$(OBJDIR)/$obj.${o}:" );
271
        MakePrint( "\tCXXFLAGS +=$cflags\n" );
272
    }
273
}
274
 
275
 
276
###############################################################################
277
#   ToolsetCXXDepend( $depend, \@sources )
278
#       This subroutine takes the user options and builds the
279
#       rule(s) required to build the dependencies for the source
280
#       files 'sources' to 'depend'.
281
#
282
###############################################################################
283
 
284
sub ToolsetCXXDepend
285
{
286
    MakePrint( "\t\$(CCDEPEND)\n" )
287
        if ( $toolsetccdepend == 0 );
288
}
289
 
290
 
291
###############################################################################
292
#   ToolsetAS( $source, $obj, \@args )
293
#       This subroutine takes the user options and builds the rule(s)
294
#       required to compile the source file 'source' to 'obj'
295
#
296
###############################################################################
297
 
298
sub ToolsetAS
299
{
300
    my( $source, $obj, $pArgs ) = @_;
301
 
302
    foreach $_ ( @$pArgs ) {
303
        Message( "CC: unknown option $_ -- ignored\n" );
304
    }
305
 
306
    MakePrint( "\n\t\$(AS)\n" );
307
}
308
 
309
sub ToolsetASDepend
310
{
311
}
312
 
313
 
314
###############################################################################
315
#   ToolsetAR( $name, \@args, \@objs )
316
#       This subroutine takes the user options and builds the rules
317
#       required to build the library 'name'.
318
#
319
#   Arguments:
320
#
321
#   Options:
322
#       n/a
323
#
324
#   Output:
325
#       [ $(LIBDIR)/name$.${a}:   .... ]
326
#           $(AR)
327
#
328
###############################################################################
329
 
330
sub ToolsetAR
331
{
332
    my( $name, $pArgs, $pObjs ) = @_;
333
 
334
#.. Parse arguments
335
#
336
    foreach $_ ( @$pArgs ) {
337
        Message( "AR: unknown option $_ -- ignored\n" );
338
    }
339
 
340
#.. Standard library builds
341
#
342
    MakeEntry( "\$(LIBDIR)/$name\$(GBE_TYPE).${a}:\t",
343
                  "", "\\\n\t\t", ".${o} ", @$pObjs );
344
    MakePrint( "\n\t\$(AR)\n\n" );
345
}
346
 
347
 
348
###############################################################################
349
#   ToolsetARMerge( $name, \@args, \@libs )
350
#       This subroutine takes the user options and builds the rules
351
#       required to build the library 'name' by merging the specified
352
#       libaries
353
#
354
#   Arguments:
355
#       --xxx                   No arguments currently defined
356
#
357
#   Output:
358
#       [ $(LIBDIR)/name$.${a}:   .... ]
359
#           ...
360
#
361
###############################################################################
362
 
363
sub ToolsetARMerge
364
{
365
    MakePrint( "\n\t\$(ARMERGE)\n\n" );
366
}
367
 
368
 
369
###############################################################################
370
#   ToolsetSHLD( $name, \@args, \@objs, \@libraries )
371
#       This subroutine takes the user options and builds the rules
372
#       required to link the program 'name'.
373
#
374
#   Arguments:
375
#       --WithMisalign
376
#
377
#   Output:
378
#       $(LIBDIR)/name:         $(LIBDIR)/shared
379
#               ln -s $shared $name
380
#
381
#       $(LIBDIR)/name.dep:     $(GBE_PLATFORM).mk
382
#               $(SHLDDEPEND)
383
#
384
#       $(LIBDIR)/shared:       SHLIB=name
385
#       $(LIBDIR)/shared:       $(LIBDIR)/name.dep      \
386
#               $(OBJECTS)
387
#                               
388
#       ifneq "$(findstring $(IFLAG),23)" ""
389
#       -include                "$(LIBDIR)/name.dep"
390
#       endif
391
#
392
#       name_ld += ...
393
#           :
394
#
395
###############################################################################
396
 
397
 
398
sub ToolsetSHLD
399
{
400
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
401
    my( $shared, $merge_obj );
402
 
403
#.. Parse arguments
404
#
405
    foreach $_ ( @$pArgs )
406
    {
407
        if ( m~^--WithMisalign~ ) {
408
            if ( exists $SunProLocation{$GBE_MACHTYPE}{misalign} ) {
409
                $merge_obj = $SunProLocation{$GBE_MACHTYPE}{misalign};
410
            }
411
 
412
        } else {
413
            Message( "SHLD: unknown option $_ -- ignored\n" );
414
        }
415
    }
416
 
417
#.. Full name of shared library
418
#
419
    $shared = "$name\$(GBE_TYPE).${so}.$SHLIB_VER{ $name }";
420
 
421
#.. Install and package the shared libraries that are generated
422
#
423
    PackageShlibAddFiles( $name, "\$(LIBDIR)/${name}\$(GBE_TYPE).$::so" );
424
    PackageShlibAddFiles( $name, "\$(LIBDIR)/$shared" );
425
#.. Cleanup rules
426
#
427
#   dep     Dependency file
428
#   map     Map file
429
#   ln      Link from LIBDIR to BINDIR
430
#
431
    ToolsetProg( "\$(LIBDIR)/${name}.dep" );
432
    ToolsetProg( "\$(LIBDIR)/${shared}.map" );
433
    ToolsetProg( "\$(LIBDIR)/${shared}" );
434
    ToolsetProg( "\$(BINDIR)/${shared}" );
435
    ToolsetDirTree( "\$(LIBDIR)/${name}/SunWS_cache" );
436
    ToolsetDirTree( "\$(OBJDIR)/${name}/SunWS_cache" );
437
 
438
#.. Build rules
439
#
440
#   name        Base name
441
#   shared      Library name, includes GBE_TYPE specification
442
#
443
    my ($io) = ToolsetPrinter::New();
444
 
445
    $io->Label( "Shared library", $name );
446
 
447
    $io->Prt( "\$(LIBDIR)/${name}\$(GBE_TYPE).$::so:\t\\\n" .
448
              "\t\t\$(GBE_BINDIR)\\\n" .
449
              "\t\t\$(LIBDIR)/${shared}\n" .
450
              "\t\@(rm -f \$@; ln -s ./$shared \$@)\n" .
451
              "\t\@(rm -f \$(BINDIR)/$shared; ln -s ../\$(LIBDIR)/$shared \$(BINDIR)/$shared)\n\n" );
452
 
453
    $io->SHLDDEPEND($name, $name, $shared);     # std SHLDDEPEND rules
454
 
455
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHBASE=${name}\n" );
456
    $io->Prt( "\$(LIBDIR)/${shared}:\tSHNAME=${shared}\n" );
457
    $io->Entry( "\$(LIBDIR)/${shared}:\t", "", "\\\n\t\t", ".$::o", @$pObjs );
458
    $io->Prt( "\\\n\t\t\$(LIBDIR)/${name}.dep\n" );
459
    $io->Prt( "\t\$(SHLD)\n\n" );
460
 
461
 
462
#.. Linker command file
463
#
464
#       Now the fun part... piecing together a variable $(name_shld)
465
#       which ends up in the command file.
466
#
467
    $io->SetTag( "${name}_ld" );              # command tag
468
    $io->SetTerm( "\n" );
469
 
470
    $io->Label( "Linker commands", $name );     # label
471
 
472
                                                # object list
473
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );
474
 
475
    if ( $merge_obj )
476
    {
477
        $io->PrtLn( "ifdef MISALIGN" );
478
        $io->Cmd( "\$(SUNWSPRO_SC)/$merge_obj" );
479
        $io->PrtLn( "endif" );
480
    }
481
    ToolsetLibStd( $pLibs );                    # push standard libraries
482
 
483
                                                # library list
484
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );
485
 
486
    $io->Newline();
487
 
488
#.. Dependency link,
489
#
490
#       Now piece together a variable $(name_dp) which ends up in
491
#       the command file building the application dependency list.
492
#
493
    $io->SetTag( "${name}_dp" );              # command tag
494
    $io->SetTerm();
495
 
496
    $io->DepRules( $name, $pLibs,               # library depends rules
497
        \&ToolsetLibRecipe, "$shared" );
498
 
499
    $io->Newline();
500
}
501
 
502
 
503
######################################################
504
#   ToolsetLD( $name, \@args, \@objs, \@libraries )
505
#       This subroutine takes the user options and builds the rules
506
#       required to link the program 'name'.
507
#
508
#   Arguments:
509
#       n/a
510
#
511
#   Output:
512
#       $(BINDIR)/name:
513
#                       $(BINDIR)/name.dep
514
#           $(LD)
515
#       $(BINDIR)/name.dep:     $(GBE_PLATFORM).mk
516
#               $(LDDEPEND)
517
#
518
#       ifeq "$(IFLAG)" "3"
519
#       -include        "$(BINDIR)/name.dep"
520
#       endif
521
#
522
#       name_ld += ...
523
#           :
524
#
525
###############################################################################
526
 
527
sub ToolsetLD
528
{
529
    my( $name, $pArgs, $pObjs, $pLibs ) = @_;
530
 
531
#.. Parse arguments
532
#
533
    foreach $_ ( @$pArgs )
534
    {
535
        Message( "LD: unknown option $_ -- ignored\n" );
536
    }
537
 
538
#.. Cleanup rules
539
#
540
#       dep     Dependency file
541
#       map     Mape file
542
#
543
    ToolsetProg( "\$(BINDIR)/${name}.dep" );
544
    ToolsetProg( "\$(BINDIR)/${name}.map" );
545
 
546
 
547
#.. Build rules
548
#
549
    my ($io) = ToolsetPrinter::New();
550
 
551
    $io->Prt( "\\\n\t\t\$(BINDIR)/${name}.dep\n" .
552
              "\t\$(LD)\n\n" );
553
    $io->LDDEPEND( $name );                     # standard LDDEPEND rules
554
    $io->Newline();
555
 
556
#.. Linker command file
557
#
558
#       Now the fun part... piecing together a variable $(name_ld)
559
#       which ends up in the command file.
560
#
561
    $io->SetTag( "${name}_ld" );                        # macro tag
562
    $io->SetTerm( "\n" );
563
 
564
    $io->Label( "Linker commands", $name );             # label
565
    $io->ObjList( $name, $pObjs, \&ToolsetObjRecipe );  # object list
566
    ToolsetLibStd( $pLibs );                            # push standard libraries
567
    $io->LibList( $name, $pLibs, \&ToolsetLibRecipe );  # library list
568
    $io->Newline();
569
 
570
#.. Dependency link,
571
#
572
#       Now piece together a variable $(name_dp) which ends up in
573
#       the command file building the application dependency list.
574
#
575
    $io->SetTag( "${name}_dp" );                        # macro tag
576
    $io->SetTerm();
577
 
578
    $io->DepRules( $name, $pLibs,                       # library depends rules
579
        \&ToolsetLibRecipe, "\$(BINDIR)/${name}" );
580
 
581
    $io->Newline();
582
}
583
 
584
 
585
########################################################################
586
#
587
#   Push standard "system" libraries. This is a helper function
588
#   used within this toolset.
589
#
590
#   Arguments:
591
#       $plib       Reference to library array.
592
#
593
########################################################################
594
 
595
sub ToolsetLibStd
596
{
597
}
598
 
599
########################################################################
600
#
601
#   Generate a linker object recipe.  This is a helper function used 
602
#   within this toolset.
603
#
604
#   Arguments:
605
#       $io         I/O stream
606
#
607
#       $target     Name of the target
608
#
609
#       $obj        Library specification
610
#
611
########################################################################
612
 
613
sub ToolsetObjRecipe
614
{
615
    my ($io, $target, $obj) = @_;
616
 
617
    $io->Cmd( "\$(strip $obj).$::o" );
618
}
619
 
620
 
621
###############################################################################
622
#
623
#   Parse a linker lib list
624
#   This is a helper function used within this toolset
625
#
626
#   Arguments:
627
#       $target     Name of the target
628
#
629
#       $lib        Library specification
630
#
631
#       $tag        Tag (user specified)
632
#
633
#       $dp         If building a depend list, the full target name.
634
#
635
###############################################################################
636
 
637
sub ToolsetLibRecipe
638
{
639
    my ($io, $target, $lib, $dp) = @_;
640
 
641
    if ( ! defined($dp) ) {                     # linker
642
        $lib =~ s/^lib//;                       # .. remove leading 'lib'
643
        $io->Cmd( "-l $lib" );
644
 
645
    } else {                                    # depend
646
        $io->Cmd( "$dp:\t@(vlib2,$lib,CC_LIB)" );
647
 
648
    }
649
}
650
#.. Successful termination
651
 
652
1;