comprsrc.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Handles the resource files handling
  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 comprsrc;
  18. {$i fpcdefs.inc}
  19. interface
  20. type
  21. presourcefile=^tresourcefile;
  22. tresourcefile=object
  23. private
  24. fname : string;
  25. public
  26. constructor Init(const fn:string);
  27. destructor Done;
  28. procedure Compile;virtual;
  29. end;
  30. procedure CompileResourceFiles;
  31. implementation
  32. uses
  33. SysUtils,
  34. Systems,cutils,cfileutils,
  35. Globtype,Globals,Verbose,Fmodule,
  36. Script;
  37. {****************************************************************************
  38. TRESOURCEFILE
  39. ****************************************************************************}
  40. constructor tresourcefile.init(const fn:string);
  41. begin
  42. fname:=fn;
  43. end;
  44. destructor tresourcefile.done;
  45. begin
  46. end;
  47. procedure tresourcefile.compile;
  48. var
  49. respath,
  50. srcfilepath,
  51. n,
  52. s,
  53. resobj,
  54. resbin : TCmdStr;
  55. resfound,
  56. objused : boolean;
  57. begin
  58. resbin:='';
  59. resfound:=false;
  60. if utilsdirectory<>'' then
  61. resfound:=FindFile(utilsprefix+target_res.resbin+source_info.exeext,utilsdirectory,false,resbin);
  62. if not resfound then
  63. resfound:=FindExe(utilsprefix+target_res.resbin,false,resbin);
  64. { get also the path to be searched for the windres.h }
  65. respath:=ExtractFilePath(resbin);
  66. if (not resfound) and not(cs_link_nolink in current_settings.globalswitches) then
  67. begin
  68. Message(exec_e_res_not_found);
  69. current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
  70. end;
  71. srcfilepath:=ExtractFilePath(current_module.mainsource^);
  72. if not path_absolute(fname) then
  73. fname:=srcfilepath+fname;
  74. resobj:=ChangeFileExt(fname,target_info.resobjext);
  75. s:=target_res.rescmd;
  76. ObjUsed:=(pos('$OBJ',s)>0);
  77. Replace(s,'$OBJ',maybequoted(resobj));
  78. Replace(s,'$RES',maybequoted(fname));
  79. { windres doesn't like empty include paths }
  80. if respath='' then
  81. respath:='.';
  82. Replace(s,'$INC',maybequoted(respath));
  83. if (target_info.system = system_i386_win32) and
  84. (srcfilepath<>'') then
  85. s:=s+' --include '+maybequoted(srcfilepath);
  86. { Execute the command }
  87. if not (cs_link_nolink in current_settings.globalswitches) then
  88. begin
  89. Message1(exec_i_compilingresource,fname);
  90. Message2(exec_d_resbin_params,resbin,s);
  91. FlushOutput;
  92. try
  93. if ExecuteProcess(resbin,s) <> 0 then
  94. begin
  95. Message(exec_e_error_while_linking);
  96. current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
  97. end;
  98. except
  99. on E:EOSError do
  100. begin
  101. Message(exec_e_cant_call_linker);
  102. current_settings.globalswitches:=current_settings.globalswitches+[cs_link_nolink];
  103. end
  104. end;
  105. end;
  106. { Update asmres when externmode is set }
  107. if cs_link_nolink in current_settings.globalswitches then
  108. AsmRes.AddLinkCommand(resbin,s,'');
  109. if ObjUsed then
  110. current_module.linkotherofiles.add(resobj,link_always);
  111. end;
  112. procedure CompileResourceFiles;
  113. var
  114. hr : presourcefile;
  115. begin
  116. { OS/2 (EMX) must be processed elsewhere (in the linking/binding stage).
  117. same with MacOS}
  118. if not (target_info.system in [system_i386_os2,
  119. system_i386_emx,system_powerpc_macos]) then
  120. While not current_module.ResourceFiles.Empty do
  121. begin
  122. if target_info.res<>res_none then
  123. begin
  124. hr:=new(presourcefile,init(current_module.ResourceFiles.getfirst));
  125. hr^.compile;
  126. dispose(hr,done);
  127. end
  128. else
  129. Message(scan_e_resourcefiles_not_supported);
  130. end;
  131. end;
  132. end.