Author Topic: Novice: Compilling FreeBASIC compiler for OS/2 Warp CMD...  (Read 2472 times)

pagetelegram

  • Newbie
  • *
  • Posts: 10
  • Karma: +2/-0
  • OS/2 user since 1995
    • View Profile
    • OS/2 History and Timeline Dev / Petition etc
Novice: Compilling FreeBASIC compiler for OS/2 Warp CMD...
« on: August 13, 2024, 04:55:35 pm »
The only product I have enjoyed from the Microsoft Universe was QuickBASIC. When I learned that the codebase for QuickBASIC was supported with fbc I started thinking about what it would take to compile fbc (just the OS/2-CMD level no gui) and so I emailed the fbc developer for the DOS port and this is what he had to say/write:

Code: [Select]
Hi Jason,

As you have probably discovered, the FreeBASIC compiler itself is written in FreeBASIC, so the bootstrapping process is a little bit tricky.

I haven't worked on FreeBASIC in quite a while, so some of this may be outdated, but my porting process for other platforms was something like this:

- Add the new target to the top-level makefile; for OS/2, this can probably be quite similar to the DOS or Windows targets.
- Get a minimal version of rtlib (the FreeBASIC runtime library) built on the target platform. The compiler itself only needs some basic startup and file I/O routines to work, so anything else can be stubbed out for now; just do enough to make the library compile successfully, even if some of the platform-specific parts won't work yet. The rtlib is written in C, so this part should be relatively easy, as long as there is a GNU toolchain (GCC and related tools) available for your target platform, which I believe is the case for OS/2.
- Add support for the new target in the fbc compiler code. If I remember correctly, this is mostly just adding the new platform to a few Select Case statements in the main fbc.bas to choose the appropriate name mangling conventions, path separators, C system libraries to link against, and similar details.
- Compile the updated fbc on a supported platform (probably Linux or Windows would be the easiest). This produces a new fbc compiler binary that still runs on Linux/Windows/... but now knows about the new OS/2 target added in the previous step.
- Use the updated fbc to cross-compile fbc itself, but now targeting OS/2 (with the fbc -target option), and make it only generate the .asm assembly source files rather than trying to assemble and link them. I believe there is a fbc -r command line option for this purpose.
- Copy the .asm files to the target platform and assemble them with the GNU assembler (as) from the native OS/2 toolchain into .o object files.
- Link the .o object files plus the rtlib compiled in the first step with the OS/2 toolchain into a minimal working native version of fbc.exe (probably easiest to avoid the ld linker itself and instead use gcc, since it will include the necessary C runtime library startup files by default).

At that point, you should have a working version of the fbc compiler that runs on the new target platform, and it should be able to compile itself again natively on the new OS without any help from the previous platform.

I'm afraid I won't be able to work directly on the porting effort myself, but please let me know if you run into any roadblocks and I can try to help point you in the right direction.

Just searching around a bit, I did find that there is a wiki page about bootstrapping fbc - this may automate some of the steps above, though I haven't tried it myself (I think it was written after I stopped working on FreeBASIC): https://www.freebasic.net/wiki/DevBootstrap

Good luck in your endeavors - I haven't used OS/2 since about 1995, but I have fond memories of running it on an IBM Aptiva with a 486!

-- Daniel

I have compiled stuff requiring some simple steps however this nature of compiling I am not skilled in. So wondering if anyone can walk me through the processes here that are unique to the OS/2 environment.

Regards,

Jason
The shortest distance between two points is no fun -- unless it is about how an operating system should perform.
---
I'm an Advocate and Enthusiast for OS/2 Warp.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5084
  • Karma: +117/-1
    • View Profile
Re: Novice: Compilling FreeBASIC compiler for OS/2 Warp CMD...
« Reply #1 on: August 13, 2024, 09:58:04 pm »
The problem is the cross-compile step, there is no GCC cross compiler for OS/2. Building rtlib itself seems simple enough, though for some stupid reason GCC isn't expanding the wildcard, easy to fix by using the full object names.
Code: [Select]
[H:\tmp\fbc-code]make bootstrap-minimal
gcc -o bootstrap/fbc lib/freebasic/os2-x86/fbrt0.o bootstrap/os2-x86/*.o lib/fre
ebasic/os2-x86/libfb.a
gcc: error: bootstrap/os2-x86/*.o: No such file or directory
make: *** [makefile:1569: bootstrap/fbc] Error 1

Unluckily the next step is to cross compile, with no cross compiler.
Here's the diff of the quick hack I did on git head.

Lars

  • Hero Member
  • *****
  • Posts: 1367
  • Karma: +70/-0
    • View Profile
Re: Novice: Compilling FreeBASIC compiler for OS/2 Warp CMD...
« Reply #2 on: August 13, 2024, 10:28:42 pm »
I understood that fbc on Windows will cross-compile itself to result in an fbc (on Windows) that can then generate the assembler files to build itself which in turn can be assembled with the gnu assembler in OS/2.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5084
  • Karma: +117/-1
    • View Profile
Re: Novice: Compilling FreeBASIC compiler for OS/2 Warp CMD...
« Reply #3 on: August 13, 2024, 11:34:59 pm »
Possibly, I don't have a Windows environment to try it on and libfb.a has a lot of C source as well.