Subversion Repositories DevTools

Rev

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