stevedonovan / Lake

A Lua-based Build Tool
MIT License
134 stars 17 forks source link

Field of needs as function #21

Closed moteus closed 11 years ago

moteus commented 11 years ago

If we use static libraries then we have to use specific static library depend on copile options: For example for zlib i use

lake.define_need('zlib-static-md', function()
  return {
    incdir = J(ZLIB_DIR, 'include');
    libdir = J(ZLIB_DIR, 'static');
    libs   = {'zlib_vc10_md'};
  }
end)

lake.define_need('zlib-static-mt', function()
  return {
    incdir = J(ZLIB_DIR, 'include');
    libdir = J(ZLIB_DIR, 'static');
    libs   = {'zlib_vc10_mt'};
  }
end)

ZLIB_NEED = IF(DYNAMIC, 'zlib-static-md', 'zlib-static-mt')

But if need.lib is function we can define need as:

lake.define_need('zlib-static', function()
  return {
    incdir = J(ZLIB_DIR, 'include');
    libdir = J(ZLIB_DIR, 'static');
    libs   = function(target)
      local lib = 'zlib'
      if MSVC then
        lib = lib .. 
          '_vc' .. MSVC_VER ..                      -- version 
          IF(target.dynamic,'_md', '_mt')    -- depend on targed
      end
      lib = lib .. IF(DEBUG, '_d', '')
      return lib
    end
  }
end)
stevedonovan commented 11 years ago

The version now up does allow any of these fields to be functions, but they will be passed the original arguments to program or shared, etc. Resolution of needs comes early, so there's no way I can pass you a target, sorry. But you can check args.dynamic, should work.

moteus commented 11 years ago

I don't think is good solution. May be should wait add this feature until we can pass target object. For now I can write needs generator and select one of them in lakefile. And what about compiler version. For MSVC i write:

execute_wrapper('cl',nil, function(status, code, f)
  if not status then return end
  local str = f:read("*l")
  if not str then return end
  local major, minor, rev, build = string.match(str, "[Cc]ompiler [Vv]ersion%s+(%d+)[.](%d+)[.](%d+)[.](%d+)")
  if not(major and minor and rev and build) then return end
  MSVC_MAJOR = tonumber(major)
  MSVC_MINOR = tonumber(minor)
  MSVC_REV   = tonumber(rev)
  MSVC_BUILD = tonumber(build)
  MSVC_VER   = ({
    [15] = 9;
    [16] = 10;
    [17] = 12;
  })[MSVC_MAJOR]
end)
stevedonovan commented 11 years ago

On Fri, Jan 25, 2013 at 11:37 AM, moteus notifications@github.com wrote:

May be should wait add this feature until we can pass target object.

Well, it's technically hard to pass the target, since the target has not been created yet. Let me think about this.

What specifically do you need that can only come from the target? You do have access to args, and args.dynamic will be available (I will check this)

Another way of saying this is that needs are not dependent on targets

And what about compiler version. For MSVC i write:

OK, that looks like useful code - we already have more than 3.000 lines, another 15 will not make big difference ;)

stevedonovan commented 11 years ago

On Fri, Jan 25, 2013 at 11:47 AM, steve donovan steve.j.donovan@gmail.com wrote:

OK, that looks like useful code - we already have more than 3.000 lines, another 15 will not make big difference ;)

Easy enough - but I see the third number is much larger - is that not the build number, followed by the revision?

moteus commented 11 years ago

If we have several targets with difference static/dinamic options. I have project with 5 dll and 1 exe. And one of dll always use static runtime. May be we can use objects as needs. so we can crate just need generator and register them in lake.

SQLITE3_NEED = lake.need('sqlite3', {dynamic=true})
moteus commented 11 years ago

Easy enough - but I see the third number is much larger - is that not the build number, followed by the revision?

I dont know. I use only MSCV_MAJOR.

moteus commented 11 years ago

added lake.compiler_version()

What if MSVC will contain MS Visual Studio Version 8,9,10? Or add new constatnt MSVC_VER.