Added ppflags and noprocess
This commit is contained in:
parent
bbe58407cf
commit
aa11f813f2
3 changed files with 18 additions and 8 deletions
|
|
@ -68,6 +68,10 @@ The following keys apply to library source code and help with generating the .ni
|
||||||
|
|
||||||
```flags``` = flags to pass to the c2nim process in "quotes" [default: --stdcall]. --cdecl, --assumedef, --assumendef may be useful
|
```flags``` = flags to pass to the c2nim process in "quotes" [default: --stdcall]. --cdecl, --assumedef, --assumendef may be useful
|
||||||
|
|
||||||
|
```ppflags``` = flags to pass to the preprocessor [default: ""]. -D for gcc and others may be useful
|
||||||
|
|
||||||
|
```noprocess``` = do not process this source file with c2nim [default: false] - this is useful if a file only needs to be manipulated
|
||||||
|
|
||||||
Multiple entries for the all following keys are possible by appending any .string to the key. E.g. dynlib.win, compile.dir
|
Multiple entries for the all following keys are possible by appending any .string to the key. E.g. dynlib.win, compile.dir
|
||||||
|
|
||||||
```compile``` = file or dir of files of source code to {.compile.} into generated .nim
|
```compile``` = file or dir of files of source code to {.compile.} into generated .nim
|
||||||
|
|
|
||||||
BIN
nimgen
Executable file
BIN
nimgen
Executable file
Binary file not shown.
22
nimgen.nim
22
nimgen.nim
|
|
@ -182,8 +182,8 @@ proc getdefines(file: string): string =
|
||||||
for def in FILES[file].findIter(re"(?m)^(\s*#\s*define\s+[\w\d_]+\s+[\d.x]+)(?:\r|//|/*).*?$"):
|
for def in FILES[file].findIter(re"(?m)^(\s*#\s*define\s+[\w\d_]+\s+[\d.x]+)(?:\r|//|/*).*?$"):
|
||||||
result &= def.captures[0] & "\n"
|
result &= def.captures[0] & "\n"
|
||||||
|
|
||||||
proc preprocess(file: string): string =
|
proc preprocess(file, ppflags: string): string =
|
||||||
var cmd = "gcc -E " & file
|
var cmd = "gcc -E $# $#" % [ppflags, file]
|
||||||
for inc in INCLUDES:
|
for inc in INCLUDES:
|
||||||
cmd &= " -I " & inc
|
cmd &= " -I " & inc
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ proc ctags(file: string): string =
|
||||||
|
|
||||||
return fdata
|
return fdata
|
||||||
|
|
||||||
proc c2nim(fl, outfile, flags: string, recurse, preproc, ctag, define: bool, compile, dynlib: seq[string] = @[]) =
|
proc c2nim(fl, outfile, flags, ppflags: string, recurse, preproc, ctag, define: bool, compile, dynlib: seq[string] = @[]) =
|
||||||
var file = search(fl)
|
var file = search(fl)
|
||||||
if file == "":
|
if file == "":
|
||||||
return
|
return
|
||||||
|
|
@ -247,12 +247,12 @@ proc c2nim(fl, outfile, flags: string, recurse, preproc, ctag, define: bool, com
|
||||||
var incls = getincls(file)
|
var incls = getincls(file)
|
||||||
for inc in incls:
|
for inc in incls:
|
||||||
incout &= "import " & inc.splitFile().name & "\n"
|
incout &= "import " & inc.splitFile().name & "\n"
|
||||||
c2nim(inc, getnimout(inc), flags, recurse, preproc, ctag, define)
|
c2nim(inc, getnimout(inc), flags, ppflags, recurse, preproc, ctag, define, compile, dynlib)
|
||||||
|
|
||||||
var cfile = file
|
var cfile = file
|
||||||
if preproc:
|
if preproc:
|
||||||
cfile = "temp.c"
|
cfile = "temp.c"
|
||||||
writeFile(cfile, preprocess(file))
|
writeFile(cfile, preprocess(file, ppflags))
|
||||||
elif ctag:
|
elif ctag:
|
||||||
cfile = "temp.c"
|
cfile = "temp.c"
|
||||||
writeFile(cfile, ctags(file))
|
writeFile(cfile, ctags(file))
|
||||||
|
|
@ -395,7 +395,9 @@ proc runcfg(cfg: string) =
|
||||||
var preproc = false
|
var preproc = false
|
||||||
var ctag = false
|
var ctag = false
|
||||||
var define = false
|
var define = false
|
||||||
|
var noprocess = false
|
||||||
var flags = "--stdcall"
|
var flags = "--stdcall"
|
||||||
|
var ppflags = ""
|
||||||
|
|
||||||
# Save C files in case they have changed
|
# Save C files in case they have changed
|
||||||
savefile(sfile)
|
savefile(sfile)
|
||||||
|
|
@ -410,11 +412,15 @@ proc runcfg(cfg: string) =
|
||||||
ctag = true
|
ctag = true
|
||||||
elif act == "defines":
|
elif act == "defines":
|
||||||
define = true
|
define = true
|
||||||
|
elif act == "noprocess":
|
||||||
|
noprocess = true
|
||||||
elif act == "flags":
|
elif act == "flags":
|
||||||
flags = CONFIG[file][act]
|
flags = CONFIG[file][act]
|
||||||
|
elif act == "ppflags":
|
||||||
|
ppflags = CONFIG[file][act]
|
||||||
|
|
||||||
|
if not noprocess:
|
||||||
c2nim(file, getnimout(file), flags, recurse, preproc, ctag, define, compile, dynlib)
|
c2nim(file, getnimout(file), flags, ppflags, recurse, preproc, ctag, define, compile, dynlib)
|
||||||
|
|
||||||
# ###
|
# ###
|
||||||
# Main loop
|
# Main loop
|
||||||
|
|
@ -426,4 +432,4 @@ if paramCount() == 0:
|
||||||
for i in 1..paramCount():
|
for i in 1..paramCount():
|
||||||
runcfg(paramStr(i))
|
runcfg(paramStr(i))
|
||||||
|
|
||||||
savefiles()
|
savefiles()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue