aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2017-11-08 02:11:08 -0600
committerGanesh Viswanathan <dev@genotrance.com>2017-11-08 02:11:08 -0600
commitaa11f813f22fb7e473248ba0a42cda48f672238e (patch)
tree65b2bf9c9492bb7d6120c75d473cc84c89765163
parentbbe58407cfc9dba26db7a398bb6af3207222843e (diff)
downloadnimgen-aa11f813f22fb7e473248ba0a42cda48f672238e.tar.gz
nimgen-aa11f813f22fb7e473248ba0a42cda48f672238e.zip
Added ppflags and noprocess
-rw-r--r--README.md4
-rwxr-xr-xnimgenbin0 -> 253496 bytes
-rw-r--r--nimgen.nim22
3 files changed, 18 insertions, 8 deletions
diff --git a/README.md b/README.md
index 4f7deea..cc7b8a5 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/nimgen b/nimgen
new file mode 100755
index 0000000..b397c47
--- /dev/null
+++ b/nimgen
Binary files differ
diff --git a/nimgen.nim b/nimgen.nim
index 28ee26e..1ebdcb2 100644
--- a/nimgen.nim
+++ b/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|//|/*).*?$"):
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() \ No newline at end of file
+savefiles()