gendef.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generation of a .def file for needed for Os2/Win32
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  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. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit gendef;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,cclasses;
  22. type
  23. tdeffile=class
  24. fname : string;
  25. constructor create(const fn:string);
  26. destructor destroy;override;
  27. procedure addexport(const s:TSymStr);
  28. procedure addimport(const s:TSymStr);
  29. procedure writefile;
  30. function empty : boolean;
  31. private
  32. is_empty : boolean;
  33. WrittenOnDisk : boolean;
  34. exportlist,
  35. importlist : TCmdStrList;
  36. end;
  37. var
  38. deffile : tdeffile;
  39. implementation
  40. uses
  41. SysUtils,
  42. systems,cutils,globals;
  43. {******************************************************************************
  44. TDefFile
  45. ******************************************************************************}
  46. constructor tdeffile.create(const fn:string);
  47. begin
  48. fname:=fn;
  49. WrittenOnDisk:=false;
  50. is_empty:=true;
  51. importlist:=TCmdStrList.Create;
  52. exportlist:=TCmdStrList.Create;
  53. end;
  54. destructor tdeffile.destroy;
  55. begin
  56. if WrittenOnDisk and
  57. ([cs_link_nolink,cs_link_deffile]*current_settings.globalswitches=[]) then
  58. DeleteFile(FName);
  59. importlist.Free;
  60. importlist := nil;
  61. exportlist.Free;
  62. exportlist := nil;
  63. end;
  64. procedure tdeffile.addexport(const s:TSymStr);
  65. begin
  66. exportlist.insert(s);
  67. is_empty:=false;
  68. end;
  69. procedure tdeffile.addimport(const s:TSymStr);
  70. begin
  71. importlist.insert(s);
  72. is_empty:=false;
  73. end;
  74. function tdeffile.empty : boolean;
  75. begin
  76. empty:=is_empty or DescriptionSetExplicity;
  77. end;
  78. procedure tdeffile.writefile;
  79. var
  80. t : text;
  81. begin
  82. If WrittenOnDisk then
  83. Exit;
  84. { open file }
  85. assign(t,fname);
  86. {$push}{$I-}
  87. rewrite(t);
  88. {$pop}
  89. if ioresult<>0 then
  90. exit;
  91. case target_info.system of
  92. system_i386_Os2, system_i386_emx:
  93. begin
  94. write(t,'NAME '+ChangeFileExt(inputfilename,''));
  95. if usewindowapi then
  96. write(t,' WINDOWAPI');
  97. writeln(t,'');
  98. writeln(t,'PROTMODE');
  99. writeln(t,'DESCRIPTION '+''''+description+'''');
  100. writeln(t,'DATA'#9'MULTIPLE');
  101. writeln(t,'STACKSIZE'#9+tostr(stacksize));
  102. writeln(t,'HEAPSIZE'#9+tostr(heapsize));
  103. end;
  104. system_i386_win32,
  105. system_x86_64_win64,
  106. system_aarch64_win64,
  107. obsolete_system_ia64_win64,
  108. system_arm_wince,
  109. system_i386_wince,
  110. system_i386_wdosx :
  111. begin
  112. if description<>'' then
  113. writeln(t,'DESCRIPTION '+''''+description+'''');
  114. if dllversion<>'' then
  115. writeln(t,'VERSION '+dllversion);
  116. end;
  117. else
  118. ;
  119. end;
  120. {write imports}
  121. if not importlist.empty then
  122. begin
  123. writeln(t,'');
  124. writeln(t,'IMPORTS');
  125. while not importlist.empty do
  126. writeln(t,#9+importlist.getfirst);
  127. end;
  128. {write exports}
  129. if not exportlist.empty then
  130. begin
  131. writeln(t,'');
  132. writeln(t,'EXPORTS');
  133. while not exportlist.empty do
  134. writeln(t,#9+exportlist.getfirst);
  135. end;
  136. close(t);
  137. WrittenOnDisk:=true;
  138. end;
  139. end.