Multiplatform Premake Script

2.3k views Asked by At

I'm the author of Node9, a hosted, hybrid OS that combines Inferno and LuaJIT to create an interactive, distributed development environment. See the project here: https://github.com/jvburnes/node9

I created a basic 4.x premake script to compile all of the dependencies and main source code for OSX, but now people are asking for build configurations for Linux, BSD and Windows. I have the code to do this and I want to create premake configurations to build and run Node9 on these OSs. I'll need to set library and include search paths, compiler names, as well as per-platform defines.

  1. Can anyone point me to a good multi platform premake script?
  2. Do I use "premake gmake" and sense the native platform somehow or do I need to explicitly place the target platform on the command line and refer to that platform in the premake Configuration and Platform sections?
  3. I heard that premake 4.x was legacy and that premake 5.x is the solution going forward. Is it stable and available enough to build for all these platforms?

I know that's a lot of questions, but I want to do this right.

Thanks.

3

There are 3 answers

1
Citron On

I'm not an expert in multiplatform compilation, but here are some things that might help you. First, I strongly advise you to switch to Premake5. It's stable, the community works on it and is quite active, and you have support for modules (Android ? :p) and a lot of cool other features.

As for your questions:

  1. I can't, but basically it should be as simple as something like this:

    solution "multiplatform_solution"
        configurations { "debug", "release", "whatever" }
    
        -- now here, you define your supported platforms
        platforms {
            "win32",
            "win64",
            "macos",
            "linux86",
            "linux64",
            -- etc.
        }
    
        project "some_project"
    
            -- now you can configure some things per platform:
            filter { "platforms:win32" }
                -- some defines, some specific paths to libs, etc.
                -- specific to win 32
                defines { "WIN32" }
            filter { "platforms:macos" }
                -- macos specific configurations
                defines { "you_fool_" } -- yes, it's a troll :p
            -- etc.
    
            -- and configure the rest as usual
    
  2. When you invoke premake gmake you just tell premake to build a makefile for gmake. If you have gmake on Windows, MacOS and Linux, you can use premake gmake for all platforms. It's when you actually build that you just need to specify your configuration and platform. I don't know gmake well enough, but that might look something like this: gmake config=release platform=linux32

  3. As I said, you probably want to update to Premake 5. I think it's stable enough, and in case of problem you can ask questions here :)

0
J. Perkins On

Can anyone point me to a good multi platform premake script?

If you look at a Premake source package, you'll see that it contains multiple makefiles, one for each platform it targets, in directories named like build/gmake.windows and build/gmake.macosx. That's one option.

Another approach is to put it all in one Makefile, like @Citron suggested in his script, and select the desired configuration on the command line at the time you do the build. In that case, your build command should look like:

$ make config=debug_win32

If you run the help target on the Premake generated Makefile it will give you a list of all the valid configuration options:

$ make help

Or, if you don't mind requiring your developers to have Premake installed locally, they can generate a makefile customized for their environment before building. In that case your script might look something like:

solution "MySolution"
   configuration { "Debug", "Release" }

   filter { "system:Windows" }
      -- windows specific stuff

   filter { "system:MacOSX" }
      -- mac specific stuff

   filter { "system:Linux" }
      -- etc.

In this case, running premake5 gmake will create a makefile targeted to the current environment.

1
eris0xff On

This is pretty close. I think a slightly closer answer would be to use filter on the "system:". I think it's the difference between using premake to generate a multiplatform make and using it to build the current platform makefile.

It's the closest answer so far so I'll upvote it.