Subversion Repositories DevTools

Rev

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