2
0

fpmake.pp 8.0 KB

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