Merge remote-tracking branch 'origin/master' into newplatform

This commit is contained in:
Manu 2016-08-26 15:27:11 +09:00
Родитель af235f246c ad17919e94
Коммит 73c3f6eb28
2 изменённых файлов: 145 добавлений и 139 удалений

101
tools/np-build-driver.lua Normal file
Просмотреть файл

@ -0,0 +1,101 @@
ffi = require 'ffi'
local SLASH = "/"
if ffi.os == "Windows" then SLASH = "\\" end
-- Code by David Kastrup
require "lfs"
function dirtree(dir)
assert(dir and dir ~= "", "directory parameter is missing or empty")
if string.sub(dir, -1) == SLASH then
dir=string.sub(dir, 1, -2)
end
local function yieldtree(dir)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
entry=dir..SLASH..entry
local attr=lfs.attributes(entry)
coroutine.yield(entry,attr)
if attr.mode == "directory" then
yieldtree(entry)
end
end
end
end
return coroutine.wrap(function() yieldtree(dir) end)
end
function string.ends(String,End)
return End=='' or string.sub(String,-string.len(End))==End
end
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
local exclude_dirs = {}
local exclude_files = {}
local directory = ""
common_flags = "-Wno-macro-redefined -I.."..SLASH.."NativePath -I.."..SLASH.."NativePath"..SLASH.."standard"
objs = {}
cfiles = {}
hfiles = {}
debug = false
platform = "windows"
outputName = "lib"
function table.contains(table, element)
for _, value in pairs(table) do
if string.starts(element, value) then
return true
end
end
return false
end
for i,v in ipairs(arg) do
if v == "debug" then
debug = true
elseif string.starts(v, "-I") then
local includeDir = string.sub(v, 3)
common_flags = common_flags.." -I"..includeDir
elseif string.starts(v, "-D") then
local includeDir = string.sub(v, 3)
common_flags = common_flags.." -D"..includeDir
elseif string.starts(v, "-n") then
local n = string.sub(v, 3)
outputName = n
elseif string.starts(v, "-E") then
local n = string.sub(v, 3)
table.insert(exclude_dirs, n)
elseif string.starts(v, "-e") then
local n = string.sub(v, 3)
table.insert(exclude_files, n)
elseif v == "ios" then
platform = "ios"
elseif v == "linux" then
platform = "linux"
elseif v == "android" then
platform = "android"
elseif v == "macos" then
platform = "macos"
else
directory = v
end
end
for filename, attr in dirtree(directory) do
if table.contains(exclude_dirs, filename) ~= true and table.contains(exclude_files, filename) ~= true then
if (string.ends(filename, ".c") or string.ends(filename, ".cpp")) and attr.mode == "file" and table.contains(exclude_files, filename) ~= true then
table.insert(cfiles, filename)
print("Keeping: "..filename)
end
else
print("Excluding: "..filename)
end
end

Просмотреть файл

@ -1,69 +1,22 @@
ffi = require 'ffi'
-- Special trick to load the parent path of the current script.
local parent_path = string.match(arg[0], "(.-)([^\\/]-%.?([^%.\\/]*))$")
-- Add that path to the list of places where lua will load packages
package.path = package.path .. ";" .. parent_path .. "?.lua"
-- Load the driver package which will take care of the command line arguments and other settings
-- as here we just focus on the code necessary to build our supported platforms
require "np-build-driver"
local SLASH = "/"
if ffi.os == "Windows" then SLASH = "\\" end
-- Code by David Kastrup
require "lfs"
function dirtree(dir)
assert(dir and dir ~= "", "directory parameter is missing or empty")
if string.sub(dir, -1) == SLASH then
dir=string.sub(dir, 1, -2)
end
local function yieldtree(dir)
for entry in lfs.dir(dir) do
if entry ~= "." and entry ~= ".." then
entry=dir..SLASH..entry
local attr=lfs.attributes(entry)
coroutine.yield(entry,attr)
if attr.mode == "directory" then
yieldtree(entry)
end
end
end
end
return coroutine.wrap(function() yieldtree(dir) end)
end
function string.ends(String,End)
return End=='' or string.sub(String,-string.len(End))==End
end
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
local common_flags = "-Wno-macro-redefined -I.."..SLASH.."NativePath -I.."..SLASH.."NativePath"..SLASH.."standard"
local debug_flags = "-O0 -g"
local debug_ms_flags = "-Od"
local release_flags = "-O3"
local release_ms_flags = "-O2"
local objs = {}
local cfiles = {}
local hfiles = {}
local exclude_dirs = {}
local exclude_files = {}
local debug = false
local platform = "windows"
local directory = ""
local outputName = "lib"
local android_ndk_path = os.getenv("ANDROID_NDK_PATH");
--Win dll for checking
function BuildWindows32DLL(cfile)
local flags = ""
if debug then flags = debug_flags else flags = release_flags end
local cmd = "clang -m32 -DNP_WIN32 -Wall -fno-ms-extensions -nobuiltininc -nostdinc++ -target i686-pc-windows-msvc "..common_flags.." "..flags.." -o "..cfile..".o ".." -c "..cfile;
print(cmd)
if os.execute(cmd) == 0 then table.insert(objs, cfile..".o") end
end
@ -90,7 +43,7 @@ function LinkWindows32()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86 && lib /OUT:Windows\\x86\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86 && lib /NOLOGO /OUT:Windows\\x86\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -106,7 +59,7 @@ function LinkWindows64()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x64 && lib /OUT:Windows\\x64\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x64 && lib /NOLOGO /OUT:Windows\\x64\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -124,7 +77,7 @@ function LinkWindowsUWP32()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86 store && lib /OUT:WindowsUWP\\x86\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86 store && lib /NOLOGO /OUT:WindowsUWP\\x86\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -140,7 +93,7 @@ function LinkWindowsUWP64()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x64 store && lib /OUT:WindowsUWP\\x64\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x64 store && lib /NOLOGO /OUT:WindowsUWP\\x64\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -156,7 +109,7 @@ function LinkWindowsUWPARM()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86_arm store && lib /OUT:WindowsUWP\\ARM\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86_arm store && lib /NOLOGO /OUT:WindowsUWP\\ARM\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -167,7 +120,7 @@ function LinkWindows8132()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86 8.1 store && lib /OUT:Windows8.1\\x86\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86 8.1 store && lib /NOLOGO /OUT:Windows8.1\\x86\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -176,7 +129,7 @@ function LinkWindows8164()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x64 8.1 store && lib /OUT:Windows8.1\\x64\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x64 8.1 store && lib /NOLOGO /OUT:Windows8.1\\x64\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -185,7 +138,7 @@ function LinkWindows81ARM()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86_arm 8.1 store && lib /OUT:Windows8.1\\ARM\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall\" x86_arm 8.1 store && lib /NOLOGO /OUT:Windows8.1\\ARM\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -196,7 +149,7 @@ function LinkWindowsWP32()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\WPSDK\\WP80\\vcvarsphoneall\" x86 && lib /OUT:WindowsPhone\\x86\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\WPSDK\\WP80\\vcvarsphoneall\" x86 && lib /NOLOGO /OUT:WindowsPhone\\x86\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -205,7 +158,7 @@ function LinkWindowsWPARM()
for i, o in ipairs(objs) do
objs_str = objs_str..o.." "
end
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\WPSDK\\WP80\\vcvarsphoneall\" x86_arm && lib /OUT:WindowsPhone\\ARM\\"..outputName..".lib "..objs_str
local cmd = "\"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\WPSDK\\WP80\\vcvarsphoneall\" x86_arm && lib /NOLOGO /OUT:WindowsPhone\\ARM\\"..outputName..".lib "..objs_str
os.execute(cmd)
end
@ -441,57 +394,6 @@ function LinkLinuxX86()
os.execute(cmd)
end
function table.contains(table, element)
for _, value in pairs(table) do
if string.starts(element, value) then
return true
end
end
return false
end
for i,v in ipairs(arg) do
if v == "debug" then
debug = true
elseif string.starts(v, "-I") then
local includeDir = string.sub(v, 3)
common_flags = common_flags.." -I"..includeDir
elseif string.starts(v, "-D") then
local includeDir = string.sub(v, 3)
common_flags = common_flags.." -D"..includeDir
elseif string.starts(v, "-n") then
local n = string.sub(v, 3)
outputName = n
elseif string.starts(v, "-E") then
local n = string.sub(v, 3)
table.insert(exclude_dirs, n)
elseif string.starts(v, "-e") then
local n = string.sub(v, 3)
table.insert(exclude_files, n)
elseif v == "ios" then
platform = "ios"
elseif v == "linux" then
platform = "linux"
elseif v == "android" then
platform = "android"
elseif v == "macos" then
platform = "macos"
else
directory = v
end
end
for filename, attr in dirtree(directory) do
print("Processing: "..filename)
if table.contains(exclude_dirs, filename) ~= true and table.contains(exclude_files, filename) ~= true then
if (string.ends(filename, ".c") or string.ends(filename, ".cpp")) and attr.mode == "file" and table.contains(exclude_files, filename) ~= true then
table.insert(cfiles, filename)
end
else
print("Excluding: "..filename)
end
end
if platform == "windows" then
lfs.mkdir("Windows")
lfs.chdir("Windows")
@ -499,27 +401,27 @@ if platform == "windows" then
lfs.mkdir("x86")
lfs.chdir("..")
print ("Building Windows x86 DLL...")
for i,f in ipairs(cfiles) do
BuildWindows32DLL(f)
end
LinkWindows32DLL()
objs = {}
print ("Building Windows x86...")
for i,f in ipairs(cfiles) do
BuildWindows32(f)
end
LinkWindows32()
objs = {}
print ("Building Windows x64...")
for i,f in ipairs(cfiles) do
BuildWindows64(f)
end
LinkWindows64()
objs = {}
lfs.mkdir("WindowsUWP")
lfs.chdir("WindowsUWP")
lfs.mkdir("x64")
@ -527,27 +429,27 @@ if platform == "windows" then
lfs.mkdir("ARM")
lfs.chdir("..")
print ("Building Windows UWP x86...")
for i,f in ipairs(cfiles) do
BuildWindowsUWP32(f)
end
LinkWindowsUWP32()
objs = {}
print ("Building Windows UWP x64...")
for i,f in ipairs(cfiles) do
BuildWindowsUWP64(f)
end
LinkWindowsUWP64()
objs = {}
print ("Building Windows UWP ARM...")
for i,f in ipairs(cfiles) do
BuildWindowsUWPARM(f)
end
LinkWindowsUWPARM()
objs = {}
lfs.mkdir("Windows8.1")
lfs.chdir("Windows8.1")
lfs.mkdir("x64")
@ -555,20 +457,21 @@ if platform == "windows" then
lfs.mkdir("ARM")
lfs.chdir("..")
print ("Building Windows UWP 8.1 x86...")
for i,f in ipairs(cfiles) do
BuildWindowsUWP32(f)
end
LinkWindows8132()
objs = {}
print ("Building Windows UWP 8.1 x64...")
for i,f in ipairs(cfiles) do
BuildWindowsUWP64(f)
end
LinkWindows8164()
objs = {}
print ("Building Windows UWP 8.1 ARM...")
for i,f in ipairs(cfiles) do
BuildWindowsUWPARM(f)
end
@ -577,55 +480,56 @@ if platform == "windows" then
--
objs = {}
lfs.mkdir("WindowsPhone")
lfs.chdir("WindowsPhone")
lfs.mkdir("x86")
lfs.mkdir("ARM")
lfs.chdir("..")
print ("Building Windows Phone x86...")
for i,f in ipairs(cfiles) do
BuildWindowsUWP32(f)
end
LinkWindowsWP32()
objs = {}
print ("Building Windows Phone ARM...")
for i,f in ipairs(cfiles) do
BuildWindowsUWPARM(f)
end
LinkWindowsWPARM()
elseif platform == "ios" then
objs = {}
print ("Building iOS arm7...")
for i,f in ipairs(cfiles) do
BuildIOSArm7(f)
end
LinkIOSArm7()
objs = {}
print ("Building iOS arm7s...")
for i,f in ipairs(cfiles) do
BuildIOSArm7s(f)
end
LinkIOSArm7s()
objs = {}
print ("Building iOS arm64...")
for i,f in ipairs(cfiles) do
BuildIOSArm64(f)
end
LinkIOSArm64()
objs = {}
print ("Building iOS x86...")
for i,f in ipairs(cfiles) do
BuildIOSx86(f)
end
LinkIOSx86()
objs = {}
print ("Building iOS x64...")
for i,f in ipairs(cfiles) do
BuildIOSx64(f)
end
@ -636,14 +540,14 @@ elseif platform == "ios" then
os.execute("lipo "..outputName.."_armv7.a "..outputName.."_armv7s.a "..outputName.."_arm64.a "..outputName.."_i386.a "..outputName.."_x86_64.a -create -output iOS\\"..outputName..".a")
elseif platform == "macos" then
objs = {}
print ("Building macOS x86...")
for i,f in ipairs(cfiles) do
BuildMacOSx86(f)
end
LinkMacOSx86()
objs = {}
print ("Building macOS x64...")
for i,f in ipairs(cfiles) do
BuildMacOSx64(f)
end
@ -660,18 +564,19 @@ elseif platform == "linux" then
lfs.chdir("..")
objs = {}
print ("Building Linux x64...")
for i,f in ipairs(cfiles) do
BuildLinuxX64(f)
end
LinkLinuxX64()
objs = {}
print ("Building Linux x86...")
for i,f in ipairs(cfiles) do
BuildLinuxX86(f)
end
LinkLinuxX86()
elseif platform == "android" then
lfs.mkdir("Android")
lfs.chdir("Android")
@ -683,35 +588,35 @@ elseif platform == "android" then
lfs.chdir("..")
objs = {}
print ("Building Android arm...")
for i,f in ipairs(cfiles) do
BuildAndroidArm(f)
end
LinkAndroidArm()
objs = {}
print ("Building Android arm7...")
for i,f in ipairs(cfiles) do
BuildAndroidArm7(f)
end
LinkAndroidArm7()
objs = {}
print ("Building Android arm64...")
for i,f in ipairs(cfiles) do
BuildAndroidArm64(f)
end
LinkAndroidArm64()
objs = {}
print ("Building Android x86...")
for i,f in ipairs(cfiles) do
BuildAndroidx86(f)
end
LinkAndroidx86()
objs = {}
print ("Building Android x64...")
for i,f in ipairs(cfiles) do
BuildAndroidx64(f)
end