gendef.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 : tstringlist;
  36. end;
  37. var
  38. deffile : tdeffile;
  39. implementation
  40. uses
  41. systems,cutils,globtype,globals;
  42. {******************************************************************************
  43. TDefFile
  44. ******************************************************************************}
  45. constructor tdeffile.create(const fn:string);
  46. begin
  47. fname:=fn;
  48. WrittenOnDisk:=false;
  49. is_empty:=true;
  50. importlist:=TStringList.Create;
  51. exportlist:=TStringList.Create;
  52. end;
  53. destructor tdeffile.destroy;
  54. begin
  55. if WrittenOnDisk and
  56. not(cs_link_extern in aktglobalswitches) then
  57. RemoveFile(FName);
  58. importlist.Free;
  59. exportlist.Free;
  60. end;
  61. procedure tdeffile.addexport(const s:string);
  62. begin
  63. exportlist.insert(s);
  64. is_empty:=false;
  65. end;
  66. procedure tdeffile.addimport(const s:string);
  67. begin
  68. importlist.insert(s);
  69. is_empty:=false;
  70. end;
  71. function tdeffile.empty : boolean;
  72. begin
  73. empty:=is_empty or DescriptionSetExplicity;
  74. end;
  75. procedure tdeffile.writefile;
  76. var
  77. t : text;
  78. begin
  79. If WrittenOnDisk then
  80. Exit;
  81. { open file }
  82. assign(t,fname);
  83. {$I+}
  84. rewrite(t);
  85. {$I-}
  86. if ioresult<>0 then
  87. exit;
  88. {$ifdef i386}
  89. case target_info.system of
  90. system_i386_Os2, system_i386_emx:
  91. begin
  92. write(t,'NAME '+inputfile);
  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, system_i386_wdosx :
  103. begin
  104. if description<>'' then
  105. writeln(t,'DESCRIPTION '+''''+description+'''');
  106. if dllversion<>'' then
  107. writeln(t,'VERSION '+dllversion);
  108. end;
  109. end;
  110. {$endif}
  111. {write imports}
  112. if not importlist.empty then
  113. begin
  114. writeln(t,'');
  115. writeln(t,'IMPORTS');
  116. while not importlist.empty do
  117. writeln(t,#9+importlist.getfirst);
  118. end;
  119. {write exports}
  120. if not exportlist.empty then
  121. begin
  122. writeln(t,'');
  123. writeln(t,'EXPORTS');
  124. while not exportlist.empty do
  125. writeln(t,#9+exportlist.getfirst);
  126. end;
  127. close(t);
  128. WrittenOnDisk:=true;
  129. end;
  130. end.