2
0

fpmake.pp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. {$IFDEF MORPHOS}
  2. {$DEFINE NO_UNIT_PROCESS}
  3. {$DEFINE NO_THREADING}
  4. {$ENDIF}
  5. {$IFDEF AROS}
  6. {$DEFINE NO_UNIT_PROCESS}
  7. {$DEFINE NO_THREADING}
  8. {$ENDIF}
  9. {$IFDEF OS2}
  10. {$DEFINE NO_UNIT_PROCESS}
  11. {$ENDIF OS2}
  12. {$IFDEF GO32V2}
  13. {$DEFINE NO_UNIT_PROCESS}
  14. {$ENDIF GO32V2}
  15. {$ifndef NO_UNIT_PROCESS}
  16. {$define HAS_UNIT_PROCESS}
  17. {$endif NO_UNIT_PROCESS}
  18. {$ifndef ALLPACKAGES}
  19. {$mode objfpc}{$H+}
  20. program fpmake;
  21. uses
  22. fpmkunit,
  23. {$IFDEF HAS_UNIT_PROCESS}
  24. process,
  25. {$ENDIF HAS_UNIT_PROCESS}
  26. sysutils;
  27. {$endif ALLPACKAGES}
  28. {$ifdef HAS_UNIT_PROCESS}
  29. procedure fpcm_update_revision_info(Sender: TObject);
  30. function ReadSVNLine(AProcess: TProcess; var ALine: string): boolean;
  31. var
  32. b,i: byte;
  33. begin
  34. result := true;
  35. ALine := '';
  36. i := 1;
  37. repeat
  38. if i = 0 then
  39. sleep(100);
  40. i := AProcess.Output.Read(b,1);
  41. if i > 0 then
  42. begin
  43. if b = 13 then
  44. continue;
  45. if b = 10 then
  46. exit;
  47. ALine := ALine + chr(b);
  48. end;
  49. until not AProcess.Running and (i=0);
  50. result := (ALine <> '');
  51. end;
  52. var
  53. P : TPackage;
  54. SVNBin : String;
  55. SVNProcess: TProcess;
  56. f: text;
  57. fileurl, line, date, lastdate,
  58. revision, oldrevstring, olddate : string;
  59. i, io : longint;
  60. rev, lastrev, oldrev : longint;
  61. begin
  62. // If revision.inc does exist, try to update the file with the latest
  63. // revision from svn. And include this information in the fpcmake
  64. // executable.
  65. With installer do
  66. begin
  67. if not FileExists(BuildEngine.AddPathPrefix(P,'revision.inc')) then
  68. begin
  69. BuildEngine.Log(vlWarning, 'File revision.inc not found. Svn-revision will not be included in fpcmake executable.');
  70. Exit;
  71. end;
  72. // Run svn info, and catch output.
  73. P := sender as TPackage;
  74. P.Options.Add('-dREVINC');
  75. SVNBin := ExeSearch(AddProgramExtension('svn', Defaults.BuildOS), GetEnvironmentvariable('PATH'));
  76. if SVNBin<>'' then
  77. begin
  78. SVNProcess := TProcess.create(nil);
  79. try
  80. SVNProcess.Executable := SVNBin;
  81. SVNProcess.Parameters.Add('info');
  82. SVNProcess.Parameters.Add('-R');
  83. SVNProcess.Parameters.Add(BuildEngine.AddPathPrefix(P,'fpcmpkg.pp'));
  84. SVNProcess.Parameters.Add(BuildEngine.AddPathPrefix(P,'fpcmake.pp'));
  85. SVNProcess.Parameters.Add(BuildEngine.AddPathPrefix(P,'fpcmwr.pp'));
  86. SVNProcess.Parameters.Add(BuildEngine.AddPathPrefix(P,'fpcmmain.pp'));
  87. SVNProcess.Parameters.Add(BuildEngine.AddPathPrefix(P,'fpcmdic.pp'));
  88. SVNProcess.Parameters.Add(BuildEngine.AddPathPrefix(P,'fpcmake.ini'));
  89. SVNProcess.Parameters.Add(BuildEngine.AddPathPrefix(P,'Makefile.fpc'));
  90. SVNProcess.Options:=[poUsePipes];
  91. SVNProcess.Execute;
  92. // Search for latest revision in output:
  93. lastrev:=0;
  94. lastdate:='0';
  95. while ReadSVNLine(SVNProcess, Line) do
  96. begin
  97. i:=pos('URL: ',line);
  98. if i>0 then
  99. begin
  100. fileurl:=copy(line,i+length('URL: '),length(line));
  101. BuildEngine.Log(vlCommand,'fileurl='+fileurl);
  102. end;
  103. i:=pos('Last Changed Date: ',line);
  104. if i>0 then
  105. begin
  106. date:=copy(line,i+length('Last Changed Date: '),length(line));
  107. i:=pos(' ',date);
  108. if i>0 then
  109. date:=copy(date,1,i-1);
  110. BuildEngine.Log(vlCommand,'date='+date);
  111. if date>lastdate then
  112. lastdate:=date;
  113. end;
  114. i:=pos('Last Changed Rev: ',line);
  115. if i>0 then
  116. begin
  117. revision:=copy(line,i+length('Last Changed Rev: '),length(line));
  118. BuildEngine.Log(vlCommand,'rev='+revision);
  119. val(revision,rev);
  120. if rev>lastrev then
  121. lastrev:=rev;
  122. end;
  123. end;
  124. finally
  125. SVNProcess.Free;
  126. end;
  127. // Write the latest change-date and revision to file revision.inc
  128. system.assign(f,BuildEngine.AddPathPrefix(P,'revision.inc'));
  129. io:=ioresult;
  130. reset(f);
  131. io:=ioresult;
  132. if io<>0 then
  133. begin
  134. BuildEngine.Log(vlWarning,'revision.inc reset failed, io='+IntToStr(io));
  135. end
  136. else
  137. begin
  138. readln(f,oldrevstring);
  139. close(f);
  140. BuildEngine.Log(vlCommand, 'oldrevstring '+oldrevstring);
  141. if oldrevstring[1]='''' then
  142. oldrevstring:=copy(oldrevstring,2,length(oldrevstring));
  143. i:=length(oldrevstring);
  144. if oldrevstring[i]='''' then
  145. oldrevstring:=copy(oldrevstring,1,i-1);
  146. i:=pos(' rev ',oldrevstring);
  147. if i>0 then
  148. begin
  149. val(copy(oldrevstring,i+5,length(oldrevstring)),oldrev);
  150. olddate:=copy(oldrevstring,1,i-1);
  151. BuildEngine.Log(vlCommand,'Old values '+olddate+' '+IntToStr(oldrev));
  152. if (olddate >= lastdate) and (oldrev >= lastrev) then
  153. begin
  154. BuildEngine.Log(vlCommand,'New values '+lastdate+' '+IntToStr(lastrev));
  155. BuildEngine.Log(vlCommand,'Keeping old values');
  156. lastrev:=oldrev;
  157. lastdate:=olddate;
  158. end;
  159. end;
  160. end;
  161. BuildEngine.Log(vlCommand,'revision.inc set to '''+lastdate+' rev '+IntToStr(lastrev)+'''');
  162. system.assign(f,BuildEngine.AddPathPrefix(P,'revision.inc'));
  163. rewrite(f);
  164. io:=ioresult;
  165. if io <> 0 then
  166. begin
  167. BuildEngine.Log(vlError, 'Error opening revision.inc for writing');
  168. halt(3);
  169. end;
  170. Writeln(f,'''',lastdate,' rev ',lastrev,'''');
  171. close(f);
  172. end
  173. else
  174. BuildEngine.Log(vlWarning,'Subversion executable (svn) not found. Svn-revision in fpcmake executable might be out of date.');
  175. end;
  176. end;
  177. {$endif HAS_UNIT_PROCESS}
  178. procedure add_fpcm(const ADirectory: string);
  179. Var
  180. P : TPackage;
  181. T : TTarget;
  182. Data2IncBin : String;
  183. begin
  184. With Installer do
  185. begin
  186. P:=AddPackage('fpcm');
  187. P.Author := '<various>';
  188. P.License := 'LGPL with modification';
  189. P.HomepageURL := 'www.freepascal.org';
  190. P.Email := '';
  191. P.Description := 'Tool to generate Makefile''s out of Makefile.fpc files';
  192. P.NeedLibC:= false;
  193. {$ifdef ALLPACKAGES}
  194. P.Directory:=ADirectory;
  195. {$endif ALLPACKAGES}
  196. P.Version:='2.7.1';
  197. P.Dependencies.Add('fcl-base');
  198. T:=P.Targets.AddProgram('fpcmake.pp');
  199. {$ifdef HAS_UNIT_PROCESS}
  200. P.BeforeCompileProc:=@fpcm_update_revision_info;
  201. {$else HAS_UNIT_PROCESS}
  202. writeln('Process-unit not available. Svn-revision in fpmake executable might be out-of-date.');
  203. {$endif HAS_UNIT_PROCESS}
  204. Data2IncBin := AddProgramExtension('data2inc',Defaults.BuildOS);
  205. p.Commands.AddCommand(caBeforeCompile, Data2IncBin, '-b -s fpcmake.ini fpcmake.inc fpcmakeini','fpcmake.inc','fpcmake.ini');
  206. T:=P.Targets.AddUnit('fpcmmain.pp');
  207. T.install:=false;
  208. T.ResourceStrings:=true;
  209. P.Targets.AddUnit('fpcmdic.pp').install:=false;
  210. P.Targets.AddUnit('fpcmwr.pp').install:=false;
  211. P.Targets.AddUnit('fpcmpkg.pp').install:=false;
  212. // P.Sources.AddSrc('fpcmake.ini');
  213. P.Sources.AddSrc('fpcmake.inc');
  214. end;
  215. end;
  216. {$ifndef ALLPACKAGES}
  217. begin
  218. add_fpcm('');
  219. Installer.Run;
  220. end.
  221. {$endif ALLPACKAGES}