Added ppflags and noprocess

This commit is contained in:
Ganesh Viswanathan 2017-11-08 02:11:08 -06:00
commit aa11f813f2
3 changed files with 18 additions and 8 deletions

View file

@ -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
```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
```compile``` = file or dir of files of source code to {.compile.} into generated .nim

BIN
nimgen Executable file

Binary file not shown.

View file

@ -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|//|/*).*?$"):
result &= def.captures[0] & "\n"
proc preprocess(file: string): string =
var cmd = "gcc -E " & file
proc preprocess(file, ppflags: string): string =
var cmd = "gcc -E $# $#" % [ppflags, file]
for inc in INCLUDES:
cmd &= " -I " & inc
@ -229,7 +229,7 @@ proc ctags(file: string): string =
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)
if file == "":
return
@ -247,12 +247,12 @@ proc c2nim(fl, outfile, flags: string, recurse, preproc, ctag, define: bool, com
var incls = getincls(file)
for inc in incls:
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
if preproc:
cfile = "temp.c"
writeFile(cfile, preprocess(file))
writeFile(cfile, preprocess(file, ppflags))
elif ctag:
cfile = "temp.c"
writeFile(cfile, ctags(file))
@ -395,7 +395,9 @@ proc runcfg(cfg: string) =
var preproc = false
var ctag = false
var define = false
var noprocess = false
var flags = "--stdcall"
var ppflags = ""
# Save C files in case they have changed
savefile(sfile)
@ -410,11 +412,15 @@ proc runcfg(cfg: string) =
ctag = true
elif act == "defines":
define = true
elif act == "noprocess":
noprocess = true
elif act == "flags":
flags = CONFIG[file][act]
elif act == "ppflags":
ppflags = CONFIG[file][act]
c2nim(file, getnimout(file), flags, recurse, preproc, ctag, define, compile, dynlib)
if not noprocess:
c2nim(file, getnimout(file), flags, ppflags, recurse, preproc, ctag, define, compile, dynlib)
# ###
# Main loop
@ -426,4 +432,4 @@ if paramCount() == 0:
for i in 1..paramCount():
runcfg(paramStr(i))
savefiles()
savefiles()