@@ -131,18 +131,19 @@ buildMakeActions outputDir filePathMap usePrefix =
131131 writeTextFile (supportDir </> "map_key.hh") $ B.unpack $(embedFile "pcc/include/map_key.hh")
132132 writeTextFile (supportDir </> "hash.hh") $ B.unpack $(embedFile "pcc/include/hash.hh")
133133
134− when (requiresForeign m) $ do
135− let inputPath = dropExtension $ getInputFile mn
136− hfile = addExtension inputPath "hh"
137− sfile = addExtension inputPath "cc"
138− hfileExists <- textFileExists hfile
139− when (not hfileExists) (throwError . P.errorMessage $ P.MissingFFIModule mn)
140− text <- readTextFile hfile
134+ let inputPath = dropExtension $ getInputFile mn
135+ hfile = addExtension inputPath "hh"
136+ sfile = addExtension inputPath "cc"
137+ hfileExists <- textFileExists hfile
138+ when (hfileExists || requiresForeign m) $ do
139+ text <- if hfileExists
140+ then readTextFile hfile
141+ else pure []
141142 writeTextFile (addExtension (fileBase ++ "_ffi") "hh") text
142− sfileExists <- textFileExists sfile
143− when (sfileExists) $ do
144− text' <- readTextFile sfile
145− writeTextFile (addExtension (fileBase ++ "_ffi") "cc") text'
143+ sfileExists <- textFileExists sfile
144+ when (sfileExists) $ do
145+ text' <- readTextFile sfile
146+ writeTextFile (addExtension (fileBase ++ "_ffi") "cc") text'
146147
147148 requiresForeign :: CF.Module a -> Bool
148149 requiresForeign = not . null . CF.moduleForeign