comprsrc.pas 4.5 KB

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