program msebuild;

{$MODE OBJFPC}{$H+}
{$linklib c}

{
    MSEide+MSEgui project compilation tool.
    For GNU/Linux.
    Version: 1.
    Written on FreePascal (https://freepascal.org/).
    Copyright (C) 2026 Artyomov Alexander
    http://self-made-free.ru/
    aralni@mail.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as
    published by the Free Software Foundation, either version 3 of the
    License, or (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
}

uses sysutils,unix;

const
msedir:string='/usr/src/mseide-msegui/';
unitsdir:string='./units/';

var
projfn:string;

begin

if ParamCount < 1 then begin
WriteLn('Use: msebuild projectname.pas');
Halt;
end;

unitsdir := ExpandFileName(unitsdir);
projfn := ParamStr(1);
projfn := ExpandFileName(projfn);
WriteLn('Project main file name: ',projfn);
WriteLn('MSE directory: ',msedir);
WriteLn('Units directory: ',unitsdir);

fpSystem('rm -rf '+unitsdir);
MkDir(unitsdir);

fpSystem('fpc -B -Cg -k-pie -CfSSE64 -Fu./ -FU'+unitsdir+' -Fu./ -Fu'+msedir+'lib/common/* -Fu'+msedir+'lib/common/kernel/linux -Fu./* -CX -XX -O2 -Mobjfpc '+projfn);

//RmDir(unitsdir);
fpSystem('rm -r -f '+unitsdir);
end.