~ubuntu-branches/ubuntu/feisty/fpc/feisty

« back to all changes in this revision

Viewing changes to compiler/utils/ppumove.pp

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Werner
  • Date: 2007-01-27 20:08:50 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070127200850-9mrptaqqjsx9nwa7
Tags: 2.0.4-5
* Fixed Build-Depends.
* Add myself to Uploaders in debian/control.
* Make sure that the sources are really patched before building them.
* Build unit 'libc' on powerpc too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
{
2
 
    $Id: ppumove.pp,v 1.8 2005/02/14 17:13:10 peter Exp $
3
2
    Copyright (c) 1999-2002 by the FPC Development Team
4
3
 
5
4
    Add multiple FPC units into a static/shared library
24
23
{$endif}
25
24
Program ppumove;
26
25
uses
 
26
  sysutils,
27
27
{$ifdef unix}
28
 
  {$ifdef ver1_0}
29
 
  linux,
30
 
  {$else}
31
28
  Baseunix,Unix, UnixUtil,
32
 
  {$endif}
33
29
{$else unix}
34
30
  dos,
35
31
{$endif unix}
37
33
  getopts;
38
34
 
39
35
const
40
 
  Version   = 'Version 1.00';
 
36
  Version   = 'Version 2.0.2';
41
37
  Title     = 'PPU-Mover';
42
 
  Copyright = 'Copyright (c) 1998-2002 by the Free Pascal Development Team';
 
38
  Copyright = 'Copyright (c) 1998-2006 by the Free Pascal Development Team';
43
39
 
44
 
  ShortOpts = 'o:e:d:qhsvbw';
 
40
  ShortOpts = 'o:e:d:i:qhsvbw';
45
41
  BufSize = 4096;
46
42
  PPUExt = 'ppu';
47
43
  ObjExt = 'o';
70
66
 
71
67
Var
72
68
  ArBin,LDBin,StripBin,
 
69
  OutputFileForPPU,
73
70
  OutputFile,
74
71
  OutputFileForLink,  { the name of the output file needed when linking }
 
72
  InputPath,
75
73
  DestPath,
76
74
  PPLExt,
77
75
  LibExt      : string;
 
76
  DoStrip,
78
77
  Batch,
79
78
  Quiet,
80
79
  MakeStatic  : boolean;
81
80
  Buffer      : Pointer;
82
81
  ObjFiles    : PLinkOEnt;
83
82
  BatchFile   : Text;
 
83
  Libs        : ansistring;
84
84
 
85
85
{*****************************************************************************
86
86
                                 Helpers
113
113
     exit;
114
114
   end;
115
115
{$ifdef unix}
116
 
  Shell:={$ifdef ver1_0}linux{$else}unix{$endif}.shell(s);
 
116
  Shell:=unix.shell(s);
117
117
{$else}
118
118
  exec(getenv('COMSPEC'),'/C '+s);
119
119
  Shell:=DosExitCode;
133
133
{$endif}
134
134
begin
135
135
{$ifdef unix}
136
 
  FileExists:={$ifdef VER1_0}FStat{$ELSE}FpStat{$endif} (F,Info){$ifndef VER1_0}=0{$endif};
 
136
  FileExists:=FpStat(F,Info)=0;
137
137
{$else}
138
138
  FindFirst (F,anyfile,Info);
139
139
  FileExists:=DosError=0;
239
239
  untilb : byte;
240
240
  l,m    : longint;
241
241
  f      : file;
 
242
  ext,
242
243
  s      : string;
243
244
begin
244
245
  DoPPU:=false;
357
358
{ just add a new entry with the new lib }
358
359
  if MakeStatic then
359
360
   begin
360
 
     outppu.putstring(outputfileforlink);
 
361
     outppu.putstring(OutputfileForPPU);
361
362
     outppu.putlongint(link_static);
362
363
     outppu.writeentry(iblinkunitstaticlibs)
363
364
   end
364
365
  else
365
366
   begin
366
 
     outppu.putstring(outputfileforlink);
 
367
     outppu.putstring(OutputfileForPPU);
367
368
     outppu.putlongint(link_shared);
368
369
     outppu.writeentry(iblinkunitsharedlibs);
369
370
   end;
373
374
  { don't write ibend, that's written automaticly }
374
375
    if b<>ibend then
375
376
     begin
376
 
       repeat
377
 
         inppu.getdatabuf(buffer^,bufsize,l);
378
 
         outppu.putdata(buffer^,l);
379
 
       until l<bufsize;
 
377
       if b=iblinkothersharedlibs then
 
378
         begin
 
379
           while not inppu.endofentry do
 
380
             begin
 
381
               s:=inppu.getstring;
 
382
               m:=inppu.getlongint;
 
383
 
 
384
               outppu.putstring(s);
 
385
 
 
386
               { strip lib prefix }
 
387
               if copy(s,1,3)='lib' then
 
388
                 delete(s,1,3);
 
389
 
 
390
               { strip lib prefix }
 
391
               if copy(s,1,3)='lib' then
 
392
                 delete(s,1,3);
 
393
               ext:=ExtractFileExt(s);
 
394
               if ext<>'' then
 
395
                 delete(s,length(s)-length(ext)+1,length(ext));
 
396
 
 
397
               libs:=libs+' -l'+s;
 
398
 
 
399
               outppu.putlongint(m);
 
400
             end;
 
401
         end
 
402
       else
 
403
         repeat
 
404
           inppu.getdatabuf(buffer^,bufsize,l);
 
405
           outppu.putdata(buffer^,l);
 
406
         until l<bufsize;
380
407
       outppu.writeentry(b);
381
408
     end;
382
409
  until b=ibend;
413
440
{$endif}
414
441
begin
415
442
{$ifdef unix}
416
 
  DoFile:=DoPPU(FileName,ForceExtension(FileName,PPLExt));
 
443
  DoFile:=DoPPU(InputPath+FileName,InputPath+ForceExtension(FileName,PPLExt));
417
444
{$else}
418
445
  DoFile:=false;
419
446
  findfirst(filename,$20,dir);
420
447
  while doserror=0 do
421
448
   begin
422
 
     if not DoPPU(Dir.Name,ForceExtension(Dir.Name,PPLExt)) then
 
449
     if not DoPPU(InputPath+Dir.Name,InputPath+ForceExtension(Dir.Name,PPLExt)) then
423
450
      exit;
424
451
     findnext(dir);
425
452
   end;
431
458
 
432
459
Procedure DoLink;
433
460
{
434
 
  Link the object files together to form a (shared) library, the only
435
 
  problem here is the 255 char limit of Names
 
461
  Link the object files together to form a (shared) library
436
462
}
437
463
Var
438
 
  Names : String;
 
464
  Names : ansistring;
439
465
  f     : file;
440
466
  Err   : boolean;
441
467
  P     : PLinkOEnt;
447
473
  While p<>nil do
448
474
   begin
449
475
     if Names<>'' then
450
 
      Names:=Names+' '+P^.name
 
476
      Names:=Names+' '+InputPath+P^.name
451
477
     else
452
 
      Names:=p^.Name;
 
478
      Names:=InputPath+p^.Name;
453
479
     p:=p^.next;
454
480
   end;
455
481
  if Names='' then
459
485
     exit;
460
486
   end;
461
487
  If not Quiet then
462
 
   WriteLn(names);
 
488
    WriteLn(names+Libs);
463
489
{ Run ar or ld to create the lib }
464
490
  If MakeStatic then
465
491
   Err:=Shell(arbin+' rs '+outputfile+' '+names)<>0
466
492
  else
467
493
   begin
468
 
     Err:=Shell(ldbin+' -shared -o '+OutputFile+' '+names)<>0;
469
 
     if not Err then
 
494
     Err:=Shell(ldbin+' -shared -E -o '+OutputFile+' '+names+' '+libs)<>0;
 
495
     if (not Err) and dostrip then
470
496
      Shell(stripbin+' --strip-unneeded '+OutputFile);
471
497
   end;
472
498
  If Err then
473
499
   Error('Fatal: Library building stage failed.',true);
474
500
{ fix permission to 644, so it's not 755 }
475
501
{$ifdef unix}
476
 
  {$ifdef VER1_0}ChMod{$ELSE}FPChmod{$endif}(OutputFile,420);
 
502
  FPChmod(OutputFile,420);
477
503
{$endif}
478
504
{ Rename to the destpath }
479
505
  if DestPath<>'' then
480
506
   begin
481
507
     Assign(F, OutputFile);
482
 
     Rename(F,DestPath+'/'+OutputFile);
 
508
     Rename(F,DestPath+DirectorySeparator+OutputFile);
483
509
   end;
484
510
end;
485
511
 
489
515
  Print usage and exit.
490
516
}
491
517
begin
492
 
  Writeln(paramstr(0),': [-qhwvbs] [-e ext] [-o name] [-d path] file [file ...]');
 
518
  Writeln(paramstr(0),': [-qhwvbsS] [-e ext] [-o name] [-d path] file [file ...]');
493
519
  Halt(0);
494
520
end;
495
521
 
508
534
  ObjFiles:=Nil;
509
535
  Quiet:=False;
510
536
  Batch:=False;
 
537
  DoStrip:=False;
511
538
  OutputFile:='';
512
539
  PPLExt:='ppu';
513
540
  ArBin:='ar';
517
544
    c:=Getopt (ShortOpts);
518
545
    Case C of
519
546
      EndOfOptions : break;
520
 
      's' : MakeStatic:=True;
 
547
      'S' : MakeStatic:=True;
521
548
      'o' : OutputFile:=OptArg;
522
549
      'd' : DestPath:=OptArg;
 
550
      'i' : begin
 
551
              InputPath:=OptArg;
 
552
              if InputPath[length(InputPath)]<>DirectorySeparator then
 
553
                InputPath:=InputPath+DirectorySeparator;
 
554
            end;
523
555
      'e' : PPLext:=OptArg;
524
556
      'q' : Quiet:=True;
525
557
      'w' : begin
527
559
              LdBin:='ldw';
528
560
            end;
529
561
      'b' : Batch:=true;
 
562
      's' : DoStrip:=true;
530
563
      '?' : Usage;
531
564
      'h' : Usage;
532
565
    end;
546
579
var
547
580
  i : longint;
548
581
begin
 
582
  Libs:='';
549
583
  ProcessOpts;
550
584
{ Write Header }
551
585
  if not Quiet then
568
602
  else
569
603
   LibExt:=SharedLibExt;
570
604
  if OutputFile='' then
571
 
   OutPutFile:=Paramstr(OptInd);
 
605
   OutputFile:=Paramstr(OptInd);
 
606
  OutputFileForPPU:=OutputFile;
572
607
{ fix filename }
573
608
{$ifdef unix}
574
609
  if Copy(OutputFile,1,3)<>'lib' then
605
640
      Writeln('Writing pmove'+BatchExt);
606
641
     Close(BatchFile);
607
642
{$ifdef unix}
608
 
  {$ifdef VER1_0}ChMod{$ELSE}FPChmod{$endif}('pmove'+BatchExt,493);
 
643
  FPChmod('pmove'+BatchExt,493);
609
644
{$endif}
610
645
   end;
611
646
{ The End }
612
647
  if Not Quiet then
613
648
   Writeln('Done.');
614
649
end.
615
 
{
616
 
  $Log: ppumove.pp,v $
617
 
  Revision 1.8  2005/02/14 17:13:10  peter
618
 
    * truncate log
619
 
 
620
 
}