gendef.pas 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. cclasses;
  22. type
  23. tdeffile=class
  24. fname : string;
  25. constructor create(const fn:string);
  26. destructor destroy;override;
  27. procedure addexport(const s:string);
  28. procedure addimport(const s:string);
  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,globtype,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. not(cs_link_nolink in current_settings.globalswitches) then
  58. DeleteFile(FName);
  59. importlist.Free;
  60. exportlist.Free;
  61. end;
  62. procedure tdeffile.addexport(const s:string);
  63. begin
  64. exportlist.insert(s);
  65. is_empty:=false;
  66. end;
  67. procedure tdeffile.addimport(const s:string);
  68. begin
  69. importlist.insert(s);
  70. is_empty:=false;
  71. end;
  72. function tdeffile.empty : boolean;
  73. begin
  74. empty:=is_empty or DescriptionSetExplicity;
  75. end;
  76. procedure tdeffile.writefile;
  77. var
  78. t : text;
  79. begin
  80. If WrittenOnDisk then
  81. Exit;
  82. { open file }
  83. assign(t,fname);
  84. {$push}{$I-}
  85. rewrite(t);
  86. {$pop}
  87. if ioresult<>0 then
  88. exit;
  89. case target_info.system of
  90. system_i386_Os2, system_i386_emx:
  91. begin
  92. write(t,'NAME '+ChangeFileExt(inputfilename,''));
  93. if usewindowapi then
  94. write(t,' WINDOWAPI');
  95. writeln(t,'');
  96. writeln(t,'PROTMODE');
  97. writeln(t,'DESCRIPTION '+''''+description+'''');
  98. writeln(t,'DATA'#9'MULTIPLE');
  99. writeln(t,'STACKSIZE'#9+tostr(stacksize));
  100. writeln(t,'HEAPSIZE'#9+tostr(heapsize));
  101. end;
  102. system_i386_win32,
  103. system_x86_64_win64,
  104. system_ia64_win64,
  105. system_arm_wince,
  106. system_i386_wince,
  107. system_i386_wdosx :
  108. begin
  109. if description<>'' then
  110. writeln(t,'DESCRIPTION '+''''+description+'''');
  111. if dllversion<>'' then
  112. writeln(t,'VERSION '+dllversion);
  113. end;
  114. end;
  115. {write imports}
  116. if not importlist.empty then
  117. begin
  118. writeln(t,'');
  119. writeln(t,'IMPORTS');
  120. while not importlist.empty do
  121. writeln(t,#9+importlist.getfirst);
  122. end;
  123. {write exports}
  124. if not exportlist.empty then
  125. begin
  126. writeln(t,'');
  127. writeln(t,'EXPORTS');
  128. while not exportlist.empty do
  129. writeln(t,#9+exportlist.getfirst);
  130. end;
  131. close(t);
  132. WrittenOnDisk:=true;
  133. end;
  134. end.