Proposal for Premake project templating

edited September 2015 in General discussions
This post is split off from: https://forum.orx-project.org/discussion/8234 Proposal #2.

Premake is a brilliant tool for making projects on all operating systems and IDEs. It would be of great benefit to beginners to have everything down to one command + options to build without fuss.

I would propose we start with a folder structure template in the bitbucket repo. This could either be:
    1. orx/code/demo 2. orx/tutorial

Either could serve as a template for developer's own projects. A build folder will exist there as well as a premake4.lua file.

In the same folder will exist two script files:
    1. buildproject.sh 2. buildproject.bat (and accompanying powershell script)

One is for linux/mac and the other for windows.

Command usage would be:

buildproject <SolutionName> <ProjectName> <IDE>

Example: buildproject mySolution myProject codelite
Another: buildproject MyGame alienInvadersProject gmake

The sequence of tasks the script would preform would be:
    1. Search and replace strings in the premake4.lua file with the values in parameters 1 and 2. 2. Save a new temporary premake4-configured.lua file. 3. Execute premake from inside orx/extern/premake against the new lua file and pass along param3, the IDE value. 4. Copy in the orx/lib libraries and report to the user if they do not exist yet. 5. Copy in the includes.

Done. The user can then copy this entire project folder out as the basis for their own project - complete with the configured solution and project names.

Below is a test script I have done for the .lua configuration part using powershell on windows. The linux script will be more straight forward:
param($p1, $p2, $p3, $p4)

(Get-Content $p1) | 
ForEach-Object { $_ -replace "-- Solution: orx", "-- Solution: $p3" } | 
ForEach-Object { $_ -replace 'solution "Tutorial"', "solution ""$p3""" } | 
ForEach-Object { $_ -replace "-- Project: 01_Object", "-- Project: $p4" } | 
ForEach-Object { $_ -replace 'project "01_Object"', "project ""$p4""" } | 
ForEach-Object { $_ -replace 'files {"../src/01_Object.c"}', 'files {"../**.cpp", "../include/**.h"}' } | 
Set-Content $p2

The advantage of this solution is that it requires no other thirdparty libraries or scripting languages except what is standard on most machines (ie bash or powershell/msdos batch).

Comments

  • edited September 2015
    Here is a complete working sample for windows:
    param(
    	[string] $solutionName = $(Read-Host 'What do you want to call your Solution file?'), 
    	[string] $projectName = $(Read-Host 'What do you want to call your Project?'),
    	[string] $projectType = $(Read-Host 'What project type do you want to make? (codeblocks, codelite, gmake, vs2002, vs2003, vs2005, vs2008, vs2010, vs2012, vs2013, xcode3, xcode4 or android) ')
    	)
    
    If ($projectType -eq "android"){
    	 Write-Host "Go and create something with gradle here." -foreground Green
    } else {
    
    	#1. Replace items in premake.lua with user specified solution and project names. Output to a new file.
    	(Get-Content ".premake4.lua") | 
    	ForEach-Object { $_ -replace "-- Solution: orx", "-- Solution: $solutionName" } | 
    	ForEach-Object { $_ -replace 'solution "Tutorial"', "solution ""$solutionName""" } | 
    	ForEach-Object { $_ -replace "-- Project: 01_Object", "-- Project: $projectName" } | 
    	ForEach-Object { $_ -replace 'project "01_Object"', "project ""$projectName""" } | 
    	ForEach-Object { $_ -replace 'files {"../src/01_Object.c"}', 'files {"../**.cpp", "../include/**.h"}' } | 
    	Set-Content ".premake4-configured.lua"
    
    	#2. Execute premake and build based on the user's parameters
    	Start-Process -FilePath "....externpremakeinwindowspremake4.exe" -ArgumentList "--file=premake4-configured.lua $projectType" -Wait 
    	Write-Host "$projectType project has has been build. Please check the build folder." -foreground Green
    
    }
    

    Currenty builds using premake for windows. Either supply parameters or it will prompt you for each with a question if you don't supply anything.

    If "android" is a supplied parameter, it hits the android stub for now. Potentially, this could go off and execute gradle scripts to build something simple for android beginners, or those curious to try their project on an android device.
  • jimjim
    edited September 2015
    Hey,
    This looks good, so this can generate project files for which platforms in its current state?
  • edited September 2015
    Currently anything premake can do:

    codeblocks, codelite, gmake, vs2002, vs2003, vs2005, vs2008, vs2010, vs2012, vs2013, xcode3, xcode4

    Codelite and gmake can be for windows, linux or mac.
  • edited September 2015
    Oh, so premake doesn't support eclipse CDT? I was considering moving to premake to be closer to the rest of the community but lack of eclipse project support is a show stopper for me.

    I'm starting to feel that my taste in development tools is too misaligned with the orx community for me to be able to contribute via a project template :(
  • edited September 2015
    As a side note, premake support extensions for such a case. Adding Eclipse+CDT shouldn't be much of a problem, if you so desire.
    Ubisoft did add support for Android+Android Studio to it, but of course it's not something I was allowed to use elsewhere. :)

    I used Eclipsed+CDT for a few years before dropping it around 2008, when it got worse and worse in term of stability and performance, but I'm sure they've fixed all those issues by now.
  • jimjim
    edited September 2015
    Hehe I doubt anyone uses xcode 3 or 4 :p I guess premake could generate project up to xcode6? Also that xcode project is a mac project not ios project right? Then we can look into premake-ios just to generate ios project if possible.

    I never liked eclipse tbh.

    Update: I found this premake fork which happens to support xcode4 ios, also android ndk project not sure if that's eclipse, might wanna look into it. https://github.com/soundsrc/premake-stable
Sign In or Register to comment.