summaryrefslogtreecommitdiff
path: root/compiler/utils/fpimpdef.pp
blob: 323cb3be958f1cb7c7a974657dcec5e1c8a42408 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
{$APPTYPE CONSOLE}
program FPimpdef;
{$DEFINE STANDALONE}
{$IFNDEF FPC}
uses
 dmisc,
 ImpDef;
{$ELSE}
uses
 DOS,
 ImpDef;
{$ENDIF}
var
binname:string;
function Ofound(const short,full:string):longint;
var
  i:longint;
begin
  Ofound:=-1;
  for i:=1 to ParamCount do
   if(paramstr(i)=short)or(paramstr(i)=full)then
    begin
     Ofound:=i;
     exit;
    end;
end;
function GetOption(const short,full:string):string;
var
  i:longint;
begin
  i:=Ofound(short,full);
  if i>0 then
   GetOption:=paramstr(succ(i))
  else
   GetOption:='';
end;
procedure help_info;
var
  fn:string[255];
  jj:cardinal;
begin
  fn:=paramstr(0);
  for jj:=length(fn)downto 1 do
   if fn[jj] in [':','\','/']then
    begin
     fn:=copy(fn,succ(jj),255);
     break;
    end;
  writeln('Usage: ',fn,' [options]');
  writeln('Options:');
  writeln('-i | --input     <file> - set input file;');
  writeln('-o | --output    <file> - set output .def file');
  writeln('-l | --library   <file> - set output static library');
  writeln('-s | --assembler <name> - use <name> for assembler (default asw)');
  writeln('-r | --archiver  <name> - use <name> for archiver (default arw)');
  writeln('-h | --help             - show this screen');
  halt;
end;
{$ifndef UNIX}
procedure AddExt(var s:string);
 var
  s1:string;
  i:longint;
 begin
  s1:=copy(s,length(s)-3,4);
  for i:=1 to length(s1)do
   s1[i]:=upcase(s1[i]);
  if s1<>'.EXE'then
   s:=s+'.EXE';
 end;
{$endif}
var
 EnvPath:string;
begin
binname:=GetOption('-i','--input');
if(binname='')or(Ofound('-h','--help')>0)then
  help_info;
 as_name:=GetOption('-s','--assembler');
 if as_name='' then
  as_name:='as';
 ar_name:=GetOption('-r','--archiver');
 if ar_name='' then
  ar_name:='ar';
{$ifndef UNIX}
 AddExt(as_name);
 AddExt(ar_name);
{$endif}
 EnvPath:=GetEnv('Path');
 if EnvPath='' then
  EnvPath:=GetEnv('PATH');
 as_name:=FSearch(as_name,EnvPath);
 ar_name:=FSearch(ar_name,EnvPath);
if not makedef(binname,GetOption('-o','--output'),GetOption('-l','--library'))then
  begin
   writeln('Export names not found');
   halt(1);
  end;
end.