target.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. {
  2. FPCRes - Free Pascal Resource Converter
  3. Part of the Free Pascal distribution
  4. Copyright (C) 2008 by Giulio Bernardi
  5. Target selection and definitions
  6. See the file COPYING, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. unit target;
  13. {$MODE OBJFPC}
  14. interface
  15. type
  16. TMachineType = (mtnone, mti386,mtx86_64,mtppc,mtppc64,mtarm,mtarmeb,mtm68k,
  17. mtsparc,mtalpha,mtia64,mtBigEndian,mtLittleEndian);
  18. TMachineTypes = set of TMachineType;
  19. TObjFormat = (ofNone, ofRes, ofElf, ofCoff, ofMachO, ofExt);
  20. TObjFormats = set of TObjFormat;
  21. TMachineInfo = record
  22. name : string;
  23. formats : TObjFormats;
  24. end;
  25. TFormatInfo = record
  26. name : string;
  27. ext : string;
  28. machines : TMachineTypes;
  29. end;
  30. TResTarget = record
  31. machine : TMachineType;
  32. objformat : TObjFormat;
  33. end;
  34. function GetDefaultMachineForFormat(aFormat : TObjFormat) : TMachineType;
  35. function TargetToStr(const aTarget : TResTarget) : string;
  36. function MachineToStr(const aMachine : TMachineType) : string;
  37. function ObjFormatToStr(const aFormat : TObjFormat) : string;
  38. var
  39. Machines : array[TMachineType] of TMachineInfo =
  40. (
  41. (name : ''; formats : [ofRes]), //mtnone
  42. (name : 'i386'; formats : [ofElf, ofCoff, ofMachO]), //mti386
  43. (name : 'x86_64'; formats : [ofElf, ofCoff, ofMachO]), //mtx86_64
  44. (name : 'powerpc'; formats : [ofElf, ofMachO]), //mtppc
  45. (name : 'powerpc64'; formats : [ofElf, ofMachO]), //mtppc64
  46. (name : 'arm'; formats : [ofElf, ofCoff, ofMachO]), //mtarm
  47. (name : 'armeb'; formats : [ofElf]), //mtarmeb
  48. (name : 'm68k'; formats : [ofElf]), //mtm68k
  49. (name : 'sparc'; formats : [ofElf]), //mtsparc
  50. (name : 'alpha'; formats : [ofElf]), //mtalpha
  51. (name : 'ia64'; formats : [ofElf]), //mtia64
  52. (name : 'bigendian'; formats : [ofExt]), //mtBigEndian
  53. (name : 'littleendian'; formats : [ofExt]) //mtLittleEndian
  54. );
  55. ObjFormats : array[TObjFormat] of TFormatInfo =
  56. (
  57. (name : ''; ext : ''; machines : []),
  58. (name : 'res'; ext : '.res'; machines : [mtnone]),
  59. (name : 'elf'; ext : '.or'; machines : [mti386,mtx86_64,mtppc,
  60. mtppc64,mtarm,mtarmeb,
  61. mtm68k,mtsparc,mtalpha,
  62. mtia64]),
  63. (name : 'coff'; ext : '.o'; machines : [mti386,mtx86_64,mtarm]),
  64. (name : 'mach-o'; ext : '.or'; machines : [mti386,mtx86_64,mtppc,
  65. mtppc64,mtarm]),
  66. (name : 'external'; ext : '.fpcres'; machines : [mtBigEndian,mtLittleEndian])
  67. );
  68. CurrentTarget : TResTarget =
  69. (
  70. {$IFDEF CPUI386}
  71. machine : mti386;
  72. {$ELSE}
  73. {$IFDEF CPUX86_64}
  74. machine : mtx86_64;
  75. {$ELSE}
  76. {$IFDEF CPUPOWERPC32}
  77. machine : mtppc;
  78. {$ELSE}
  79. {$IFDEF CPUPOWERPC64}
  80. machine : mtppc64;
  81. {$ELSE}
  82. {$IFDEF CPUARM}
  83. {$IFDEF ENDIAN_LITTLE}
  84. machine : mtarm;
  85. {$ELSE}
  86. machine : mtarmeb;
  87. {$ENDIF}
  88. {$ELSE}
  89. {$IFDEF CPU68K}
  90. machine : mtm68k;
  91. {$ELSE}
  92. {$IFDEF CPUSPARC}
  93. machine : mtsparc;
  94. {$ELSE}
  95. {$IFDEF CPUALPHA}
  96. machine : mtalpha;
  97. {$ELSE}
  98. {$IFDEF CPUIA64}
  99. machine : mtia64;
  100. {$ELSE}
  101. machine : mti386; //default i386
  102. {$ENDIF}
  103. {$ENDIF}
  104. {$ENDIF}
  105. {$ENDIF}
  106. {$ENDIF}
  107. {$ENDIF}
  108. {$ENDIF}
  109. {$ENDIF}
  110. {$ENDIF}
  111. {$IFDEF WINDOWS}
  112. objformat : ofCoff;
  113. {$ELSE}
  114. {$IFDEF DARWIN}
  115. objformat : ofMachO;
  116. {$ELSE}
  117. objformat : ofElf;
  118. {$ENDIF}
  119. {$ENDIF}
  120. );
  121. implementation
  122. function GetDefaultMachineForFormat(aFormat : TObjFormat) : TMachineType;
  123. begin
  124. case aFormat of
  125. ofNone : Result:=mtnone;
  126. ofRes : Result:=mtnone;
  127. ofElf : Result:=mti386;
  128. ofCoff : Result:=mti386;
  129. ofMachO: Result:=mti386;
  130. {$IFDEF ENDIAN_BIG}
  131. ofExt : Result:=mtBigEndian;
  132. {$ELSE}
  133. ofExt : Result:=mtLittleEndian;
  134. {$ENDIF}
  135. end;
  136. end;
  137. function MachineToStr(const aMachine : TMachineType) : string;
  138. begin
  139. Result:=Machines[aMachine].name;
  140. end;
  141. function ObjFormatToStr(const aFormat : TObjFormat) : string;
  142. begin
  143. Result:=ObjFormats[aFormat].name;
  144. end;
  145. function TargetToStr(const aTarget : TResTarget) : string;
  146. var s1, s2 : string;
  147. begin
  148. s1:=MachineToStr(aTarget.machine);
  149. s2:=ObjFormatToStr(aTarget.objformat);
  150. if (s1='') or (s2='') then Result:=s1+s2
  151. else Result:=s1+' - '+s2;
  152. end;
  153. end.