Recent

Author Topic: Command line build....  (Read 3792 times)

Prime

  • Jr. Member
  • **
  • Posts: 62
Command line build....
« on: November 15, 2021, 10:01:12 am »
Hi all,

If this is the wrong forum, feel free to move :)

I have a collection of related (text mode, command line) apps that II maintain in Lazarus.
I'd like to have a way of building those from the command line with something like a Makefile.
Is this possible, how would I go about this.

My folder structure is something like this :

Root
    Prog1
        prog1a.pas
        prog1b.pas
    Prog2
        prog2.pas
    lib1
        lib1.pas
        lib2.pas

Ideally I'd like to put the executables in a folder off the root.

Cheers.

Phill.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Command line build....
« Reply #1 on: November 15, 2021, 10:26:19 am »
I've got a number of things I build for both a GUI and as a command-line program targeting Linux. See e.g. https://github.com/MarkMLl/Mastech_ms2115b which includes a viable makefile... I'm not saying it's perfect, but it works and approximates "industry standard" expectations.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Roland57

  • Sr. Member
  • ****
  • Posts: 423
    • msegui.net
Re: Command line build....
« Reply #2 on: November 15, 2021, 10:35:51 am »
Hello.

As MarkMLI said, it is easy to write a Makefile to do that. Here is an example of mine.

Makefile
extrafpc.cfg

You can call lazbuild instead of fpc.

To choose the executables folder, you can use the -FE option. If it is a Lazarus project, you choose the executables folder in project options.

By the way, you shoud say what is your OS.
My projects are on Gitlab and on Codeberg.

Prime

  • Jr. Member
  • **
  • Posts: 62
Re: Command line build....
« Reply #3 on: November 15, 2021, 11:14:51 am »
By the way, you shoud say what is your OS.

Windows,  but my code should be cross platform, so I'd like to have it buildable on linux & macos too (though I realize this might require seperate makefiles).

Cheers.

Phill.

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1122
  • Professional amateur ;-P
Re: Command line build....
« Reply #4 on: November 15, 2021, 09:41:05 pm »
Hey Prime,

I have a collection of related (text mode, command line) apps that II maintain in Lazarus.

A makefile is good for languages that do not have a project aggregate file. Most C/C++ compilers do not have the equivalent of the *.lpi file.
I'm assuming you have one of those per project folder, since you mention that you maintain them under Lazarus.

My advice would be to have a batch file and a shell script on the root folder that contains all the project folders.

I'll give an example of the shell script, since I'm utter crap at batch files:
Code: Bash  [Select][+][-]
  1. #!/bin/bash
  2. lazbuild -B --bm=Release Prog1/prog1.lpi
  3. lazbuild -B --bm=Release Prog2/prog2.lpi
  4. lazbuild -B --bm=Release Lib1/lib1.lpi

I'm including the --bm=Release in case you have the Release Build Mode, if not just delete that part.

The wonderful thing about lazbuild is that it compiles your projects just like it's big brother Lazarus would.
And since the *.lpi file for lazbuild is the equivalent of the Makefile for make, why even use make?

Just my 2c.

Cheers,
Gus
« Last Edit: November 16, 2021, 12:43:02 am by Gustavo 'Gus' Carreno »
Lazarus 3.99(main) FPC 3.3.1(main) Ubuntu 23.10 64b Dark Theme
Lazarus 3.0.0(stable) FPC 3.2.2(stable) Ubuntu 23.10 64b Dark Theme
http://github.com/gcarreno

Seenkao

  • Hero Member
  • *****
  • Posts: 550
    • New ZenGL.
Re: Command line build....
« Reply #5 on: November 15, 2021, 11:30:31 pm »
Неплохой пример предоставил Andru в ZenGL в папке Demos/FreePascal. Выбираем любую демо версию и смотрим makefile. Данный makefile компилирует под разные платформы.

Google translate:
A good example was provided by Andru at ZenGL in Demos/FreePascal folder. We select any demo version and look at the makefile. This makefile compiles for different platforms.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

MarkMLl

  • Hero Member
  • *****
  • Posts: 6692
Re: Command line build....
« Reply #6 on: November 22, 2021, 01:51:15 pm »
Belatedly: Lazbuild has an option --create-makefile, but I can't get it to do anything useful.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Warfley

  • Hero Member
  • *****
  • Posts: 1499
Re: Command line build....
« Reply #7 on: November 22, 2021, 08:40:53 pm »
A while ago I've wrote a little script called lpm: Link

Basically it's a command line tool to build lazarus projects using lazbuild. The main advantage over just calling lazbuild directly is that lpm can also install packages, either via direct download link, git repos or from the OPM. It even does so automatically, so if you have a programm requireing let's say indy and you don't have indy installed in your lazarus, lpm will automatically download and install indy from OPM before building your project.
It also supports different build modes, e.g. for cross compiling.

It was developed to be used in conjunction with docker (see my dockerfiles here: https://github.com/Warfley/LPMDocker) so I could completely automate the building process of Lazarus applications.

 

TinyPortal © 2005-2018