diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2017-11-14 22:34:12 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2017-11-14 22:34:12 -0600 |
| commit | e5eb693d2e6b12bd3cc22a586c77fff840a2a0bf (patch) | |
| tree | 1350ed8a18f90a6d477c2f1f753fc8d9c953ae89 | |
| parent | a02cbbeebaf2c56850e6a6d1507063bf068ae0cb (diff) | |
| download | nimgen-e5eb693d2e6b12bd3cc22a586c77fff840a2a0bf.tar.gz nimgen-e5eb693d2e6b12bd3cc22a586c77fff840a2a0bf.zip | |
- Recurse only quoted in #includev0.1.0
- Unique header/dynlib naming
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | nimgen.nim | 27 |
2 files changed, 19 insertions, 10 deletions
@@ -40,6 +40,8 @@ _[n.global]_ output = name of the Nimble project once installed, also location to place generated .nim files +quotes = pick up any headers included using "" (and not <> which is typically used for standard headers) [default: true] + filter = string to identify and recurse into library .h files in #include statements and exclude standard headers _[n.include]_ @@ -13,6 +13,7 @@ var DONE: seq[string] = @[] var CONFIG: Config var FILTER = "" +var QUOTES = true var OUTPUT = "" var INCLUDES: seq[string] = @[] var EXCLUDES: seq[string] = @[] @@ -165,9 +166,9 @@ proc getincls(file: string): seq[string] = result = @[] withFile(file): for f in content.findIter(re"(?m)^\s*#\s*include\s+(.*?)$"): - var inc = f.captures[0].replace(re"""[<>"]""", "").strip() - if FILTER in inc and (not exclude(inc)): - result.add(inc) + var inc = f.captures[0].strip() + if ((QUOTES and inc.contains("\"")) or (FILTER != "" and FILTER in inc)) and (not exclude(inc)): + result.add(inc.replace(re"""[<>"]""", "").strip()) result = result.deduplicate() @@ -266,18 +267,20 @@ proc c2nim(fl, outfile, flags, ppflags: string, recurse, preproc, ctag, define: for inc in INCLUDES: passC &= ("""{.passC: "-I\"" & gorge("nimble path $#").strip() & "/$#\"".}""" % [OUTPUT, inc]) & "\n" + let fname = file.splitFile().name if dynlib.len() != 0: let win = "when defined(Windows):\n" let lin = "when defined(Linux):\n" let osx = "when defined(MacOSX):\n" var winlib, linlib, osxlib: string = "" for dl in dynlib: + let lib = " const dynlib$# = \"$#\"\n" % [fname, dl] if dl.splitFile().ext == ".dll": - winlib &= " const dynlib$# = \"$#\"\n" % [OUTPUT, dl] + winlib &= lib if dl.splitFile().ext == ".so": - linlib &= " const dynlib$# = \"$#\"\n" % [OUTPUT, dl] + linlib &= lib if dl.splitFile().ext == ".dylib": - osxlib &= " const dynlib$# = \"$#\"\n" % [OUTPUT, dl] + osxlib &= lib if winlib != "": outlib &= win & winlib & "\n" @@ -287,10 +290,10 @@ proc c2nim(fl, outfile, flags, ppflags: string, recurse, preproc, ctag, define: outlib &= osx & osxlib & "\n" if outlib != "": - extflags &= " --dynlib:dynlib$#" % OUTPUT + extflags &= " --dynlib:dynlib$#" % fname else: - passC &= "const header$# = \"$#\"\n" % [OUTPUT, fl] - extflags = "--header:header$#" % OUTPUT + passC &= "const header$# = \"$#\"\n" % [fname, fl] + extflags = "--header:header$#" % fname # Run c2nim on generated file var cmd = "c2nim $# $# --out:$# $#" % [flags, extflags, outfile, cfile] @@ -342,7 +345,10 @@ proc runcfg(cfg: string) = OUTPUT = CONFIG["n.global"]["output"] if CONFIG["n.global"].hasKey("filter"): FILTER = CONFIG["n.global"]["filter"] - + if CONFIG["n.global"].hasKey("quotes"): + if CONFIG["n.global"]["quotes"] == "false": + QUOTES = false + if CONFIG.hasKey("n.include"): for inc in CONFIG["n.include"].keys(): INCLUDES.add(inc) @@ -364,6 +370,7 @@ proc runcfg(cfg: string) = for act in CONFIG[file].keys(): action = act.replace(re"\..*", "") if action == "create": + createDir(file.splitPath().head) writeFile(file, CONFIG[file][act]) elif action in @["prepend", "append", "replace", "compile", "dynlib"] and sfile != "": if action == "prepend": |
