Lartu / ldpl

COBOL-like programming language that compiles to C++. With serious dinosaurs with neckties and briefcases 🦕💼
https://www.ldpl-lang.org/
Apache License 2.0
158 stars 24 forks source link

Add OS-specific `FLAG` statement #156

Closed xvxx closed 4 years ago

xvxx commented 4 years ago

As per the discussion on lartu/ldpl-ncurses#2, this adds support for an OS-specific version of the FLAG statement:

extension "ldpl-ncurses.cpp"
flag "-O3"
flag linux "-lncursesw"
flag macos "-lncurses"
flag macos "-D_XOPEN_SOURCE_EXTENDED"

This will always pass "-O3" to the compiler (the same as how FLAG works today), but it will check the LDPL compiler's OS to determine whether to pass the additional flags.

The new statement uses the standard C/C++ macros listed at https://sourceforge.net/p/predef/wiki/OperatingSystems/ to detect which OS the user is running. These should be very resilient as they are what "regular" C and C++ programs use to do OS detection. As such, we will probably not need to change the current list but may need to add new entries as new platforms come into being and get supported by LDPL.

(We could also probably cut the list down to just the platforms we support, but, y'know, I wanted to give a shout out to OS/2 and DragonFlyBSD. Maybe PalmOS.)

I didn't add the FLAG DEFAULT "-whatever" functionality because this was simpler, but I could add it if we think it's needed.

Lartu commented 4 years ago

Ok I know at first I said no, but this is a wonderful idea. I would stay in the boundaries of unix-es, though, as the LDPL codebase is not written to handle Windows nor OS/2 nor other more different systems. But hey, we could turn things around and make LDPL compatible with those platforms instead.

That said, I do love this the way it is! Great thing you've got here, thank you very much!

Before merging this into the main codebase, I would like to know how would you feel about putting all BSDs under the same flag. Would that work? I mean, I don't really know how much BSDs differ one from another, but if we used a different flag for each Linux distribution that'd be a mess.

xvxx commented 4 years ago

I would stay in the boundaries of unix-es, though, as the LDPL codebase is not written to handle Windows nor OS/2 nor other more different systems.

:+1: I just removed all the random OSes and kept it to a smaller list of supported system:

I would like to know how would you feel about putting all BSDs under the same flag. Would that work? I mean, I don't really know how much BSDs differ one from another, but if we used a different flag for each Linux distribution that'd be a mess.

I haven't touched BSD since I was a baby dino so I'm not really sure. But I do know that each BSD has its own kernel - they're all forks of each other, and they've all evolved in different directions. So BSD flavors are independent operating systems, whereas Linux flavors all share a kernel.

I think your intuition is right, though. I suggest we:

  1. Say in the README that LDPL officially supports Linux, MacOS, and Android, with experimental support for the web (emscripten) and BSDs.
  2. Group the BSDs into a single FLAG BSD "-blah" statement.
  3. Wait for a BSD enthusiast to join the project and tell us why we're wrong, or right :)

FWIW this has got me interested so I spun up FreeBSD and NetBSD instances on ec2. I was able to build LDPL on FreeBSD and move that binary to NetBSD, and it ran just fine. But I can't say whether that was just luck or there is true compatibility there. I also haven't tested ncurses (lute) or anything yet.

One thing to note is that BSD has its own version of make, so to build LDPL on BSD you'll need to download the gmake package and use that. So, like, our README and build process doesn't work out of the box for BSD, so I'd feel better calling it "experimental" support until someone wants to spend some time making it a nice, tested experience.

Lartu commented 4 years ago

I just removed all the random OSes and kept it to a smaller list of supported system

Wonderful!

I haven't touched BSD since I was a baby dino so I'm not really sure. But I do know that each BSD has its own kernel - they're all forks of each other, and they've all evolved in different directions. So BSD flavors are independent operating systems, whereas Linux flavors all share a kernel.

Haha, baby dino :laughing: :heart: TIL about BSD flavors, I should try one out!

Wait for a BSD enthusiast to join the project and tell us why we're wrong, or right :)

HAHAHA I agree with you :laughing:

FWIW this has got me interested so I spun up FreeBSD and NetBSD instances on ec2. I was able to build LDPL on FreeBSD and move that binary to NetBSD, and it ran just fine. But I can't say whether that was just luck or there is true compatibility there. I also haven't tested ncurses (lute) or anything yet.

Wonderful, thank you for trying that out! I shall try that myself later, too. I don't really think there's going to be much problem with ncurses, but who knows.

One thing to note is that BSD has its own version of make, so to build LDPL on BSD you'll need to > download the gmake package and use that. So, like, our README and build process doesn't work out of the box for BSD, so I'd feel better calling it "experimental" support until someone wants to spend some time making it a nice, tested experience.

Oh, well that's not quite nice. That's it then, let's call it experimental support.

Could you please add this to the readme file and document your new feature on the docs please!

All that said, this is wonderful! You don't cease amaze me, haha! Like always, thank you, thank you for your awesome contributions to the project! :smile: I'm merging this NOW.

xvxx commented 4 years ago

Thank you! I am learning a lot by working with LDPL, it's fun. I'll update the README and the docs when I can, either today or in the next few days.

Lartu commented 4 years ago

Thanks to you! I'm learning a lot by looking at what you do, haha! we'll await your updates, thank you!