haskell / c2hs

c2hs is a pre-processor for Haskell FFI bindings to C libraries
http://hackage.haskell.org/package/c2hs
Other
198 stars 50 forks source link

Create `*.chs` files in the output directory when specified. #250

Closed XVilka closed 4 years ago

XVilka commented 4 years ago

I use the following way to produce Haskell bindings:

def gen_haskell_bindings(outdir, path):
    def gen_chs(fname):
        return chs.format(radare2_includedir, fname)

    fname = os.path.splitext(os.path.basename(path))[0]
    cpp_opts = " ".join(r2_includes)
    tmpchs = gen_chs(fname + ".h")
    tmpfname = fname + ".chs"
    tmpf = open(tmpfname, "w")
    tmpf.write(tmpchs)
    print("Writing CHS file: {0}".format(tmpfname))
    cmdline = "c2hs -d trace -d genbind -d ctrav -k -t {0} -C \"{1}\" {2}".format(outdir, cpp_opts, tmpfname)
    # print(cmdline)
    # set PKG_CONFIG_PATH
    pkgenv = set_pkgconfig(radare2_libdir)
    # TODO: Check return code
    call(cmdline, shell=True, env=pkgenv)
    tmpf.close()
    return True

where c2hs -d trace -d genbind -d ctrav -k -t /out/dir -C "..." is the actual command. C2hs creates *.chs files in the current directory while *.chs.h and *.hs files in the output. But it fails to produce meaningful *.hs files because it can't find the *.chs files. Maybe it makes sense to put them in the same output directory as well?

XVilka commented 4 years ago

Sorry, was my mistake.