pkgfpmake.pp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. unit pkgfpmake;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils,pkghandler;
  6. type
  7. { TFPMakeCompiler }
  8. TFPMakeCompiler = Class(TPackagehandler)
  9. Private
  10. Procedure CompileFPMake;
  11. Public
  12. Function Execute(const Args:TActionArgs):boolean;override;
  13. end;
  14. { TFPMakeRunner }
  15. TFPMakeRunner = Class(TPackagehandler)
  16. Protected
  17. Function RunFPMake(const Command:string):Integer;
  18. end;
  19. { TFPMakeRunnerBuild }
  20. TFPMakeRunnerBuild = Class(TFPMakeRunner)
  21. Public
  22. Function Execute(const Args:TActionArgs):boolean;override;
  23. end;
  24. { TFPMakeRunnerInstall }
  25. TFPMakeRunnerInstall = Class(TFPMakeRunner)
  26. Public
  27. Function Execute(const Args:TActionArgs):boolean;override;
  28. end;
  29. implementation
  30. uses
  31. pkgmessages;
  32. { TFPMakeCompiler }
  33. Procedure TFPMakeCompiler.CompileFPMake;
  34. Var
  35. O,C : String;
  36. FPMakeBin,
  37. FPMakeSrc : string;
  38. HaveFpmake : boolean;
  39. begin
  40. SetCurrentDir(PackageBuildPath);
  41. { Check for fpmake source }
  42. FPMakeBin:='fpmake'+ExeExt;
  43. FPMakeSrc:='fpmake.pp';
  44. HaveFpmake:=FileExists(FPMakeSrc);
  45. If Not HaveFPMake then
  46. begin
  47. HaveFPMake:=FileExists('fpmake.pas');
  48. If HaveFPMake then
  49. FPMakeSrc:='fpmake.pas';
  50. end;
  51. { Need to compile fpmake executable? }
  52. if not FileExists(FPMakeBin) or
  53. (FileAge(FPMakeBin)<FileAge(FPMakeSrc)) then
  54. begin
  55. if Not HaveFPMake then
  56. Error(SErrMissingFPMake);
  57. { Call compiler }
  58. C:=Defaults.Compiler;
  59. O:=FPmakeSrc;
  60. If ExecuteProcess(C,O)<>0 then
  61. Error(SErrFailedToCompileFPCMake)
  62. end
  63. else
  64. Log(vCommands,SLogNotCompilingFPMake);
  65. end;
  66. function TFPMakeCompiler.Execute(const Args:TActionArgs):boolean;
  67. begin
  68. {$warning TODO Check arguments}
  69. CompileFPMake;
  70. result:=true;
  71. end;
  72. { TFPMakeRunner }
  73. Function TFPMakeRunner.RunFPMake(const Command:string) : Integer;
  74. Var
  75. I : integer;
  76. FPMakeBin : string;
  77. begin
  78. FPMakeBin:='fpmake'+ExeExt;
  79. SetCurrentDir(PackageBuildPath);
  80. Result:=ExecuteProcess(FPMakeBin,Command);
  81. end;
  82. function TFPMakeRunnerBuild.Execute(const Args:TActionArgs):boolean;
  83. begin
  84. result:=(RunFPMake('--build')=0);
  85. end;
  86. function TFPMakeRunnerInstall.Execute(const Args:TActionArgs):boolean;
  87. begin
  88. result:=(RunFPMake('--install')=0);
  89. end;
  90. initialization
  91. RegisterPkgHandler('compilefpmake',TFPMakeCompiler);
  92. RegisterPkgHandler('fpmakebuild',TFPMakeRunnerBuild);
  93. RegisterPkgHandler('fpmakeinstall',TFPMakeRunnerInstall);
  94. end.