gendef.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generation of a .def file for needed for Os2/Win32
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit gendef;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses;
  23. type
  24. tdeffile=class
  25. fname : string;
  26. constructor create(const fn:string);
  27. destructor destroy;override;
  28. procedure addexport(const s:string);
  29. procedure addimport(const s:string);
  30. procedure writefile;
  31. function empty : boolean;
  32. private
  33. is_empty : boolean;
  34. WrittenOnDisk : boolean;
  35. exportlist,
  36. importlist : tstringlist;
  37. end;
  38. var
  39. deffile : tdeffile;
  40. implementation
  41. uses
  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:=TStringList.Create;
  52. exportlist:=TStringList.Create;
  53. end;
  54. destructor tdeffile.destroy;
  55. begin
  56. if WrittenOnDisk and
  57. not(cs_link_extern in aktglobalswitches) 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 and (description='');
  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. {$I+}
  85. rewrite(t);
  86. {$I-}
  87. if ioresult<>0 then
  88. exit;
  89. {$ifdef i386}
  90. case target_info.system of
  91. system_i386_Os2, system_i386_emx:
  92. begin
  93. write(t,'NAME '+inputfile);
  94. if usewindowapi then
  95. write(t,' WINDOWAPI');
  96. writeln(t,'');
  97. writeln(t,'PROTMODE');
  98. writeln(t,'DESCRIPTION '+''''+description+'''');
  99. writeln(t,'DATA'#9'MULTIPLE');
  100. writeln(t,'STACKSIZE'#9+tostr(stacksize));
  101. writeln(t,'HEAPSIZE'#9+tostr(heapsize));
  102. end;
  103. system_i386_win32, system_i386_wdosx :
  104. begin
  105. if description<>'' then
  106. writeln(t,'DESCRIPTION '+''''+description+'''');
  107. if dllversion<>'' then
  108. writeln(t,'VERSION '+dllversion);
  109. end;
  110. end;
  111. {$endif}
  112. {write imports}
  113. if not importlist.empty then
  114. begin
  115. writeln(t,'');
  116. writeln(t,'IMPORTS');
  117. while not importlist.empty do
  118. writeln(t,#9+importlist.getfirst);
  119. end;
  120. {write exports}
  121. if not exportlist.empty then
  122. begin
  123. writeln(t,'');
  124. writeln(t,'EXPORTS');
  125. while not exportlist.empty do
  126. writeln(t,#9+exportlist.getfirst);
  127. end;
  128. close(t);
  129. WrittenOnDisk:=true;
  130. end;
  131. end.
  132. {
  133. $Log$
  134. Revision 1.12 2003-03-23 23:20:38 hajny
  135. + emx target added
  136. Revision 1.11 2002/07/26 21:15:38 florian
  137. * rewrote the system handling
  138. Revision 1.10 2002/05/18 13:34:08 peter
  139. * readded missing revisions
  140. Revision 1.9 2002/05/16 19:46:36 carl
  141. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  142. + try to fix temp allocation (still in ifdef)
  143. + generic constructor calls
  144. + start of tassembler / tmodulebase class cleanup
  145. Revision 1.7 2002/04/04 18:36:46 carl
  146. + added wdosx support (patch from Pavel)
  147. }