Understanding PB Compiler Toolchain

Just starting out? Need help? Post your questions and find answers here.
User avatar
Tristano
Enthusiast
Enthusiast
Posts: 190
Joined: Thu Nov 26, 2015 6:52 pm
Location: Italy
Contact:

Understanding PB Compiler Toolchain

Post by Tristano »

[EDITED: 2017/12/25]

I need some help to get a clearer picture of how PureBasic compiler toolchain works in detail.

Recently, I’ve started working on a customized version of Horst Schaeffer’s PBasmUI — a PureBASIC IDE tool to create, view, edit and re-assemble the intermediate assembly code from PureBASIC source files:
Since this tool interfaces with PB’s command line compiler, I’m getting a chance to look closer at how the PBcompiler CLI options work; but I’m also facing problems in trying to implement all the compiler options found in PB’s IDE; and didn’t manage to find answers in PB Documentation or the SDK.

I’ve been documenting my findings (so far) in the project’s Wiki:
Specifically, the following are the issues and questions I’m facing (probably still quite vague questions, due to lack of a clear picture).

Binary Tools

On Windows, the “Compilers” directory inside PureBASIC installation dir contains the following tools:
  • pbcompiler.exe — The PureBASIC compiler
  • PBDebugger.exe — The PureBASIC Debuger
  • FAsm.exe — flat assembler v1.71.39
  • polib.exe — Pelles Library Manager v6.00.1
  • polink.exe — Pelles Linker v5.00.1
  • porc.exe — Pelles Resource Compiler v7.00.0
I’d like to better understand how the IDE uses these tools (their order, input and output, etc), and how the various options from the IDE’s “Compiler Options…” relate to these tools — so that I can implement them in a custom IDE tool.

If I’ve understood correctly, pbcompiler.exe always translates the pb source to Assembly, and then passes it to FAsm.exe to produce a binary file. But I’m not quite sure how the other tools fit in the toolchain (ie: in relation to pureLibs, IDE options, custom resources, etc.).

I’ve also downloaded the Pelles C suite, which contains the documentation of some of the above binary tools. Hopefully it might help, but right now I still don’t know how they fit in the picture.

Asm and ReAsm

While testing with the CLI compiler, I realized that when producing the “PureBasic.asm” file via the /COMMENTED switch, the presence of other switches (eg: /USER, /CONSOLE, and others) will create different asm sources. From this, I’m assuming that these switches are therefore not required when using the /REASM option (as they’ve already done their job in the productin of the asm file). But while this might be true for some switches, it’s unlikely to apply to others (eg: the /ICON switch shouldn’t affect the “PureBasic.asm” file, and should be passed with /REASM option).

What I’m missing out here is how /COMMENTED and /REASM actually work behind the scene — which tools they invoke, in which order, and (most important) which of the IDE’s options are being passed to which tool, and which options should be passed or left-out when invoking the compiler with /COMMENTED and /REASM.

Version Information

On Windows, PBCompiler supports version information, but I haven’t worked out how to handle this via command line. I’ve seen some Visual Studio projects that use a “*.RC” resource file to store version information.

The Version Info of a pb source file can be easily recovered from its settings (either at the end of file, or from a “*.cfg” file); but how can I include this info in the final executable via command line?

How does the PB IDE handle Version Info? Does it create a temporary resource file, or does it pass the info via CLI options?



I’m confident that advanced users will be able to grasp from my questions what I’m missing out of the global picture, and that they could provide some answers or direct me toward some external resources that can help me fill the knowldege gaps.
Last edited by Tristano on Mon Dec 25, 2017 11:21 am, edited 1 time in total.
The PureBASIC Archives: FOSS Resources:
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Understanding PB Compiler Toolchain

Post by Josh »

Tristano wrote:How does the PB IDE handle Version Info? Does it create a temporary resource file, or does it pass the info via CLI options?
Pb-Ide sends Versions-Infos as constants like 'PB_Editor_FileVersionNumeric' to the compiler. How to send constants to the compiler is written in CompilerInterface.txt
sorry for my bad english
User avatar
Tristano
Enthusiast
Enthusiast
Posts: 190
Joined: Thu Nov 26, 2015 6:52 pm
Location: Italy
Contact:

Re: Understanding PB Compiler Toolchain

Post by Tristano »

Josh wrote:Pb-Ide sends Versions-Infos as constants like 'PB_Editor_FileVersionNumeric' to the compiler. How to send constants to the compiler is written in CompilerInterface.txt
Thanks a lot Josh! I couldn't find any references to this from my searches ("version information" are too generic keywords); all I had found where Visual Studio projects that used resource files to set these, but I guess that this is VS IDE's way of handling it.

As for compiler constansts, I had a chance to experiment with them via command line, and are well documented.
The PureBASIC Archives: FOSS Resources:
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Understanding PB Compiler Toolchain

Post by Josh »

You can create a resource-file too and the infos are shown in file properties. Sending constants to the compiler is the better way, so you can use the versions-infos in your code, i.e. for a about-box.
sorry for my bad english
User avatar
Tristano
Enthusiast
Enthusiast
Posts: 190
Joined: Thu Nov 26, 2015 6:52 pm
Location: Italy
Contact:

Re: Understanding PB Compiler Toolchain

Post by Tristano »

I've found an interest post by user @helpy where he describes how he managed to get hold of the temporary RC file created by PB IDE when creating an executable:


http://www.purebasic.fr/english/viewtop ... 04#p353104

So I've tried it out, and I can confirm that PB IDE creates a "PB_Resources.rc" file inside %TMP% folder.

See also:

https://github.com/tajmone/PBasmUI/wiki ... on-options

... at the above link I provide the screenshot of a test file where every Version Info fields is filled in, on how these are represented in the actual source file saved settings. The saved settings seem to be for IDE internal use only, and don't have any relation with the actual constants used at compiler time.

The contents of the "PB_Resources.rc" file produced by the example of the above link are quite complex. Beside defining some constants, there are also some blocks (and nested blocks) with definitions which I'm not sure how they could be passed as constants only.

Here are the contents of the RC produced by PB IDE for the example of the above link:

Code: Select all

#define VOS_UNKNOWN  0x00000000
#define VOS_DOS  0x00010000
#define VOS_OS216  0x00020000
#define VOS_OS232  0x00030000
#define VOS_NT  0x00040000
#define VOS_DOS_WINDOWS16  0x00010001
#define VOS_DOS_WINDOWS32  0x00010004
#define VOS_OS216_PM16  0x00020002
#define VOS_OS232_PM32  0x00030003
#define VOS_NT_WINDOWS32  0x00040004
#define VFT_UNKNOWN  0
#define VFT_APP  1
#define VFT_DLL  2
#define VFT_DRV  3
#define VFT_FONT  4
#define VFT_VXD  5
#define VFT_STATIC_LIB  7

1 VERSIONINFO
FILEVERSION 1,2,3,4
PRODUCTVERSION 1,2,3,4
FILEOS VOS_NT_WINDOWS32
FILETYPE VFT_APP
{
  BLOCK "StringFileInfo"
  {
    BLOCK "080904b0"
    {
      VALUE "CompanyName", "My Company\0"
      VALUE "ProductName", "My Super Product\0"
      VALUE "ProductVersion", "v1\0"
      VALUE "FileVersion", "v1.0.1\0"
      VALUE "FileDescription", "Super Product EXE\0"
      VALUE "InternalName", "SuperProduct\0"
      VALUE "OriginalFilename", "SuperProduct.exe\0"
      VALUE "LegalCopyright", "(c) Tristano Ajmone\0"
      VALUE "LegalTrademarks", "Trademark\0"
      VALUE "PrivateBuild", "Developers Test Pre-Release\0"
      VALUE "SpecialBuild", "Test all Bug Fixes before release\0"
      VALUE "Email", "mymail@super.com\0"
      VALUE "Website", "http://www.super-product.com\0"
      VALUE "CustomField1", "Custom field 1 value\0"
      VALUE "CustomField2", "Custom field 2 value\0"
      VALUE "CustomField3", "Custom field 3 value\0"
    }
  }
  BLOCK "VarFileInfo"
  {
    VALUE "Translation", 0x0809, 0x4b0
  }
}
The PureBASIC Archives: FOSS Resources:
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: Understanding PB Compiler Toolchain

Post by Sicro »

Maybe that's also helpful for you:
http://www.purebasic.fr/german/viewtopi ... =8&t=30440

This code creates the manifest file that contains the compiler options:
  • Enable modern theme support
  • Request Administrator mode for Windows Vista and above
  • Enable DPI-Aware (normally not configurable in PB; the reason I wrote this code)
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
Tristano
Enthusiast
Enthusiast
Posts: 190
Joined: Thu Nov 26, 2015 6:52 pm
Location: Italy
Contact:

Re: Understanding PB Compiler Toolchain

Post by Tristano »

Sicro wrote:Maybe that's also helpful for you:
http://www.purebasic.fr/german/viewtopi ... =8&t=30440
Yes @Sicro, this is very useful! Thank you.
The PureBASIC Archives: FOSS Resources:
User avatar
Tristano
Enthusiast
Enthusiast
Posts: 190
Joined: Thu Nov 26, 2015 6:52 pm
Location: Italy
Contact:

Re: Understanding PB Compiler Toolchain

Post by Tristano »

Josh wrote:
Tristano wrote:How does the PB IDE handle Version Info? Does it create a temporary resource file, or does it pass the info via CLI options?
Pb-Ide sends Versions-Infos as constants like 'PB_Editor_FileVersionNumeric' to the compiler. How to send constants to the compiler is written in CompilerInterface.txt
I was wondering about the "PB_Resources.rc" that it's created in the temporary directory; is it created by PBCompiler.exe tool (ie: it accepts the Version Info constants as input, and the creates the RC file by itself) or does it rely on one of the Pelles binary tools for the creation of the RC file?
The PureBASIC Archives: FOSS Resources:
Post Reply