| ... |
... |
@@ -322,37 +322,27 @@ outputForeignStubs logger tmpfs dflags unit_state mod location stubs |
|
322
|
322
|
Just stub_h -> do
|
|
323
|
323
|
OsPath.createDirectoryIfMissing True (OsPath.takeDirectory stub_h)
|
|
324
|
324
|
outputForeignStubs_help (OsPath.unsafeDecodeUtf stub_h) stub_h_output_w
|
|
325
|
|
- ("#include <HsFFI.h>\n" ++ cplusplus_hdr) cplusplus_ftr
|
|
|
325
|
+ "#include <HsFFI.h>\n"
|
|
326
|
326
|
|
|
327
|
327
|
putDumpFileMaybe logger Opt_D_dump_foreign
|
|
328
|
328
|
"Foreign export stubs" FormatC stub_c_output_d
|
|
329
|
329
|
|
|
330
|
330
|
stub_c_file_exists
|
|
331
|
331
|
<- outputForeignStubs_help stub_c stub_c_output_w
|
|
332
|
|
- ("#define IN_STG_CODE 0\n" ++
|
|
333
|
|
- "#include <Rts.h>\n" ++
|
|
334
|
|
- rts_includes ++
|
|
335
|
|
- ffi_includes ++
|
|
336
|
|
- cplusplus_hdr)
|
|
337
|
|
- cplusplus_ftr
|
|
338
|
|
- -- We're adding the default hc_header to the stub file, but this
|
|
339
|
|
- -- isn't really HC code, so we need to define IN_STG_CODE==0 to
|
|
340
|
|
- -- avoid the register variables etc. being enabled.
|
|
|
332
|
+ (rts_includes ++
|
|
|
333
|
+ ffi_includes)
|
|
341
|
334
|
|
|
342
|
335
|
return (stub_h_file_exists, if stub_c_file_exists
|
|
343
|
336
|
then Just stub_c
|
|
344
|
337
|
else Nothing )
|
|
345
|
|
- where
|
|
346
|
|
- cplusplus_hdr = "#if defined(__cplusplus)\nextern \"C\" {\n#endif\n"
|
|
347
|
|
- cplusplus_ftr = "#if defined(__cplusplus)\n}\n#endif\n"
|
|
348
|
338
|
|
|
349
|
339
|
|
|
350
|
340
|
-- It is more than likely that the stubs file will
|
|
351
|
341
|
-- turn out to be empty, in which case no file should be created.
|
|
352
|
|
-outputForeignStubs_help :: FilePath -> String -> String -> String -> IO Bool
|
|
353
|
|
-outputForeignStubs_help _fname "" _header _footer = return False
|
|
354
|
|
-outputForeignStubs_help fname doc_str header footer
|
|
355
|
|
- = do writeFile fname (header ++ doc_str ++ '\n':footer ++ "\n")
|
|
|
342
|
+outputForeignStubs_help :: FilePath -> String -> String -> IO Bool
|
|
|
343
|
+outputForeignStubs_help _fname "" _header = return False
|
|
|
344
|
+outputForeignStubs_help fname doc_str header
|
|
|
345
|
+ = do writeFile fname (header ++ doc_str ++ "\n")
|
|
356
|
346
|
return True
|
|
357
|
347
|
|
|
358
|
348
|
-- -----------------------------------------------------------------------------
|