Recent

Author Topic: Include version in target file name?  (Read 257 times)

Graham1

  • New Member
  • *
  • Posts: 47
Include version in target file name?
« on: November 27, 2022, 02:44:42 am »
Probably a stupid (Linux) beginners question, but how to I set up the "Target file name (-o)" line in the Project Options (Compiler Options / Paths) so that it will include the version number? So instead of having just "MyProg" when I compile my project I want to have "MyProg-1.0" where the version numbers are those on the Version info screen for the project.

Thank you!
Windows 10 Home 64-bit
Lazarus 2.0.12 / FPC 3.2.0

VTwin

  • Hero Member
  • *****
  • Posts: 1172
  • Former Turbo Pascal 3 user
Re: Include version in target file name?
« Reply #1 on: November 27, 2022, 04:54:28 am »
I'm not sure why you would want to do that, as it seems unusual for any applications that I am aware of. The version numbers can be used for display in about dialogs. I assume you would have to rename your application for each release.

Maybe someone else has another idea.
“Talk is cheap. Show me the code.” -Linus Torvalds

Free Pascal Compiler 3.2.2
macOS 12.1: Lazarus 2.2.4 (64 bit Cocoa M1)
Ubuntu 18.04.3: Lazarus 2.2.4 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.2.4 (64 bit on VBox)

MarkMLl

  • Hero Member
  • *****
  • Posts: 5866
Re: Include version in target file name?
« Reply #2 on: November 27, 2022, 09:59:17 am »
I'm not sure why you would want to do that, as it seems unusual for any applications that I am aware of.

The fact is that he does want to do it, so let's do him the courtesy of assuming that he's got a good reason.

I'm not sure that you can do it directly. By and large you can do things like adding the target processor by putting e.g.

jds6600-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType)

into "Target file name" noting that the support for this being used with "Set compiler options as default" is patchy.

If you look at the IDE's Tools -> Configure External Tools -> Add -> Macros you can see what's usable in that context, although I think there's additional subtleties in some of the naming.

You can also use the IDE's Compiler Commands -> Execute after -> Command to do various stuff, which suggests that if your target program had a --version option which output the build numbers, then you could filter that using a script and rename the binary.

An alternative would be to hold the build numbers in some sort of external file and inject them into the IDE's files (probably the .lpi) but if you attempted this you would be infringing on the developers' prerogatives by assuming that they would never change that file's format which would be extremely rash. For that same reason, I would suggest not attempting to have your final renaming operation not attempting to extract the build version from the IDE files itself.

See e.g. https://github.com/MarkMLl/Mastech_ms2115b for an example of processing the --version option in a project's .lpr and extracting the build version from the executable.

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

dbannon

  • Hero Member
  • *****
  • Posts: 2292
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Include version in target file name?
« Reply #3 on: November 27, 2022, 10:32:32 am »
Graham, I'd suggest that having the version number in the Packaging name rather the binary is a good idea. And many apps, the binary, will report their version with a -v or --version command line or in an About box.

When I compile my app, for release, I set an Environment Variable that is read during compile so that the version number is available. So, in the app there is some code like -

Code: Pascal  [Select][+][-]
  1. const Version_string  = {$I %TOMBOY_NG_VER};
  2. ...
  3. ...
  4.     if Application.HasOption('v', 'version') then begin
  5.         debugln('tomboy-ng version ' + Version_String);
  6.         exit(False);
  7.      end;

And when I compile, I do -

Code: Bash  [Select][+][-]
  1. TOMBOY_NG_VERSION=0.35   fpc ......

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

 

TinyPortal © 2005-2018