I have an example for [mpdecimal](http://www.bytereef.org/mpdecimal/index.html) 
(a multi-precision floating point decimal library) in my [nim-mpdecimal 
repo](https://github.com/status-im/nim-decimal/blob/10e41990a753235c681891f2ced2b15b73cd6c11/decimal/decimal_lowlevel.nim#L35-L74):
    
    
    macro compileFilesFromDir(path: static[string], fileNameBody: untyped): 
untyped =
      # Generate the list of compile statement like so:
      # {.compile: "mpdecimal_wrapper/generated/constants.c".}
      # {.compile: "mpdecimal_wrapper/generated/mpdecimal.c".}
      # ...
      #
      # from
      # compileFilesFromDir("mpdecimal_wrapper/generated/"):
      #   "constants.c"
      #   "mpdecimal.c"
      #   ...
      
      result = newStmtList()
      
      for file in fileNameBody:
        assert file.kind == nnkStrLit
        result.add nnkPragma.newTree(
          nnkExprColonExpr.newTree(
            newIdentNode("compile"),
            newLit(path & $file)
          )
        )
    
    # Order is important
    compileFilesFromDir("mpdecimal_wrapper/generated/"):
      "basearith.c"
      "context.c"
      "constants.c"
      "convolute.c"
      "crt.c"
      "mpdecimal.c"
      "mpsignal.c"
      "difradix2.c"
      "fnt.c"
      "fourstep.c"
      "io.c"
      "memory.c"
      "numbertheory.c"
      "sixstep.c"
      "transpose.c"
    
    
    Run

Reply via email to