Subversion Repositories DevTools

Rev

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