4

Using the wonderful Shake build system, I want to compile a project in a a way which is agnostic to the host operating system.

I have trouble detecting the presence of binaries because they have a different extension across systems (ie: Windows uses .exe).

If I use a need clause to detect whether required binaries are present, how can I check for either Main or Main.exe depending whether the host is Linux or Windows?

kvanbere
  • 3,289
  • 3
  • 27
  • 52

1 Answers1

3

The function you are after is Development.Shake.FilePath.exe, which evalutes to "exe" on Windows and "" on all other platforms. You typically write:

want ["MyExecutable" <.> exe]
"MyExecutable" <.> exe *> \out ->
    cmd "MyCompiler" "-o" [out]

For an example see Examples.Self.Main, which builds Main on Linux and Main.exe on Windows.

The only potential niggle is that all file patterns to the left of *> must be unique. If you define "//*" <.> exe *> ..., then on Windows that will only match executable files (good) but on Linux that will match every file, clashing with all other patterns (bad). The solution is to make executable names distinct in some way, e.g. put them in a special output directory, hardcode the names as "Main" <.> exe etc. Alternatively, you can rely on the fact that only executables have no extension on Linux with:

(\x -> drop 1 (takeExtension x) == exe) ?> \out ->
    ...
Neil Mitchell
  • 9,090
  • 1
  • 27
  • 85