[Up][Next] Reference for unit 'UPasConf' (#Pkg)

Simple example

As first example we are going use UPasConf to compile a helloworld program. Our program looks like :

{ helloworld.pas }
program HelloWorld;

{$mode objfpc}{$H+}

begin
  WriteLn('hello, world!');
end.

In order to compile our project with UPasConf we must first copy the UPasConf unit at the root of our project. Then we create a file named pasconf.pas in the project root with the following content:

{ pasconf.pas }
program pasconf;

{$mode objfpc}{$H+}

{$ifdef WINDOWS}
  {$apptype console}
{$endif}

uses
  Classes, SysUtils, UPasConf;

type

  { TApplication }

  TApplication = class(TPasConfApplication)
    procedure Initialize; override;
  end;

procedure TApplication.Initialize;
begin
  inherited;

  // project's name and version number
  SetVar(V_Project, 'helloworld');
  SetVar(V_MajorVersion, '1');
  SetVar(V_MinorVersion, '0');
  SetVar(V_MicroVersion, '0');

  // main program source file
  SetVar(V_FpcBinSrc, 'helloworld.pas');

  // We register a model that will generate a file named 'Makefile'
  // from the string '@AutoMakefile@'
  RegisterStringTemplate('@AutoMakefile@', 'Makefile');
end;

begin
  Application := TApplication.Create;
  Application.Initialize;
  Application.Run;
end.

Now our project tree should look like this:

.
|-- helloworld.pas
|-- pasconf.pas
`-- upasconf.pas

We can compile our project with the following commands:

~$ fpc pasconf    # <1>
~$ ./pasconf      # <2>
~$ make           # <3>
  1. We compile the configuration program.
  2. We run the configuration program. This generates a file named Makefile.
  3. We compile the project.

Passing arguments to the configuration program we can change how our project is built. For example:

Try './pasconf -h' for help.

For more informations on the generated makefile see AutomaticMakefiles.

More examples can be found in the examples directory.