allow gcc or clang compiler

This commit is contained in:
sonoro1234
2018-10-09 11:03:49 +02:00
parent 073f438467
commit 2759a8ed4d
2 changed files with 21 additions and 19 deletions

View File

@@ -14,8 +14,9 @@
:: set PATH=%PATH%;C:\luaGL;C:\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\mingw32\bin; :: set PATH=%PATH%;C:\luaGL;C:\i686-7.2.0-release-posix-dwarf-rt_v5-rev1\mingw32\bin;
:: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin; :: set PATH=%PATH%;C:\luaGL\sources\luajit-master\luajit-master\bin\mingw32;C:\mingw32\bin;
::process files ::process files
:: arg[1..n] name of implementations to generate :: arg[1] compiler name gcc or clang
luajit ./generator.lua glfw opengl3 opengl2 sdl :: arg[2..n] name of implementations to generate
luajit ./generator.lua "gcc" glfw opengl3 opengl2 sdl
::leave console open ::leave console open
cmd /k cmd /k

View File

@@ -5,27 +5,28 @@
assert(_VERSION=='Lua 5.1',"Must use LuaJIT") assert(_VERSION=='Lua 5.1',"Must use LuaJIT")
assert(bit,"Must use LuaJIT") assert(bit,"Must use LuaJIT")
local script_args = {...} local script_args = {...}
local COMPILER = script_args[1]
--test gcc present --test compiler present
local HAVE_GCC local HAVE_COMPILER
local pipe,err = io.popen("gcc --version","r") local pipe,err = io.popen(COMPILER.." --version","r")
if pipe then if pipe then
local str = pipe:read"*a" local str = pipe:read"*a"
print(str) print(str)
pipe:close() pipe:close()
if str=="" then if str=="" then
HAVE_GCC = false HAVE_COMPILER = false
else else
HAVE_GCC = true HAVE_COMPILER = true
end end
else else
HAVE_GCC = false HAVE_COMPILER = false
print(err) print(err)
end end
print("HAVE_GCC",HAVE_GCC) assert(HAVE_COMPILER,"gcc or clang needed to run script")
print("HAVE_COMPILER",HAVE_COMPILER)
--get implementations --get implementations
local implementations = {} local implementations = {}
for i=1,#script_args do table.insert(implementations,script_args[i]) end for i=2,#script_args do table.insert(implementations,script_args[i]) end
-------------------------------------------------------------------------- --------------------------------------------------------------------------
--this table has the functions to be skipped in generation --this table has the functions to be skipped in generation
@@ -107,7 +108,7 @@ local function filelines(file)
end end
return location_it return location_it
end end
--iterates lines from a gcc -E in a specific location --iterates lines from a gcc/clang -E in a specific location
local function location(file,locpathT) local function location(file,locpathT)
local location_re = '^# (%d+) "([^"]*)"' local location_re = '^# (%d+) "([^"]*)"'
local path_reT = {} local path_reT = {}
@@ -1209,7 +1210,7 @@ local function check_arg_detection(fdefs,typedefs)
print"-----------------end check arg detection-----------------------" print"-----------------end check arg detection-----------------------"
end end
local function get_defines(t) local function get_defines(t)
local pipe,err = io.popen([[gcc -E -dM -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r") local pipe,err = io.popen(COMPILER..[[ -E -dM -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r")
local defines = {} local defines = {}
while true do while true do
local line = pipe:read"*l" local line = pipe:read"*l"
@@ -1298,7 +1299,7 @@ pipe:close()
cimgui_header = cimgui_header:gsub("XXX",imgui_version) cimgui_header = cimgui_header:gsub("XXX",imgui_version)
print("IMGUI_VERSION",imgui_version) print("IMGUI_VERSION",imgui_version)
--get some defines---------------------------- --get some defines----------------------------
if HAVE_GCC then if HAVE_COMPILER then
gdefines = get_defines{"IMGUI_VERSION","FLT_MAX"} gdefines = get_defines{"IMGUI_VERSION","FLT_MAX"}
end end
--first without gcc --first without gcc
@@ -1325,8 +1326,8 @@ cimgui_generation("_nopreprocess",STP,FP)
print"------------------generation with precompiler------------------------" print"------------------generation with precompiler------------------------"
local pFP,pSTP,typedefs_dict2 local pFP,pSTP,typedefs_dict2
if HAVE_GCC then if HAVE_COMPILER then
local pipe,err = io.popen([[gcc -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r") local pipe,err = io.popen(COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ../imgui/imgui.h]],"r")
if not pipe then if not pipe then
error("could not execute gcc "..err) error("could not execute gcc "..err)
@@ -1371,8 +1372,8 @@ if #implementations > 0 then
local source = [[../imgui/examples/imgui_impl_]].. impl .. ".h " local source = [[../imgui/examples/imgui_impl_]].. impl .. ".h "
local locati = [[imgui_impl_]].. impl local locati = [[imgui_impl_]].. impl
local pipe,err local pipe,err
if HAVE_GCC then if HAVE_COMPILER then
pipe,err = io.popen([[gcc -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] ..source,"r") pipe,err = io.popen(COMPILER..[[ -E -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS -DIMGUI_API="" -DIMGUI_IMPL_API="" ]] ..source,"r")
else else
pipe,err = io.open(source,"r") pipe,err = io.open(source,"r")
end end
@@ -1380,7 +1381,7 @@ if #implementations > 0 then
error("could not get file: "..err) error("could not get file: "..err)
end end
local iterator = (HAVE_GCC and location) or filelines local iterator = (HAVE_COMPILER and location) or filelines
for line,locat in iterator(pipe,{locati}) do for line,locat in iterator(pipe,{locati}) do
local line, comment = split_comment(line) local line, comment = split_comment(line)