summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/gdbint/src/gdbver.pp
blob: f372ddfab0339bba91b2451b58f1ad02510eb04b (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
99
100
101
102
103
104
{

  Program to detect the version of libgdb that will be
  used for linking
}
program find_gdb_version;

{$R-}

{$ifdef unix}
  {$Linklib c}
{$endif}

{$LINKLIB libgdb.a}

uses
  strings;

const
  { This variable should be change with change in GDB CVS PM }
  Current_cvs_version : longint = 503;
  Max_version_length = 255;

const
  output_file:string='';

var
  version : array[0..0] of char;cvar;external;
  gdbversion : pchar;
  subver_str : string;
  i, version_number,
  subversion_number : longint;
  subsubversion_number : longint;
  error : word;
  only_ver : boolean;
  o : text;

begin
  only_ver:=(Paramcount>0) and (ParamStr(1)='-n');
  if (paramcount>=2) and (paramstr(1)='-o') then
    begin
      only_ver:=true;
      output_file:=paramstr(2);
    end;
  getmem(gdbversion,Max_version_length+1);
  strlcopy(gdbversion,@version,Max_version_length);
  gdbversion[Max_version_length]:=#0;
  if (gdbversion[0] in ['4','5','6','7','8','9']) and (gdbversion[1]='.') then
    begin
      if not only_ver then
        Writeln('GDB version is ',pchar(@version));
      version_number:=ord(gdbversion[0])-ord('0');
      i:=2;
      subver_str:='';
      while gdbversion[i] in ['0'..'9'] do
        begin
          subver_str:=subver_str+gdbversion[i];
          inc(i);
        end;
      val(subver_str,subversion_number,error);
      inc(i);
      subver_str:='';
      while gdbversion[i] in ['0'..'9'] do
        begin
          subver_str:=subver_str+gdbversion[i];
          inc(i);
        end;
      if subver_str<>'' then
        val(subver_str,subsubversion_number,error);
      { 5.02.90 is a pretest of 5.03.. PM }
      if subsubversion_number>=90 then
        inc(subversion_number);
      if (error=0) and (subversion_number>=0) and
         (subversion_number<=99) then
        version_number:=version_number*100+subversion_number;
    end
  else if (gdbversion[0]='2') and (gdbversion[1]='0') and
          (gdbversion[2] in ['0'..'9']) and (gdbversion[3] in ['0'..'9']) then
    begin
      { CVS version from 2000 to 2099,
        assume current_cvs_version  PM }
      version_number:=Current_cvs_version;
    end
  else
    begin
      if not only_ver then
        Writeln('Unsupported GDB version');
      version_number:=0;
    end;
  freemem(gdbversion);
  if output_file<>'' then
    begin
      assign(o,output_file);
      rewrite(o);
      writeln(o,'{$define GDB_V',version_number,'}');
      close(o);
    end
  else
    begin
      if only_ver then
        Write(version_number);
      Halt(version_number);
    end;
end.