@@ -559,7 +559,8 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
559559 createDirectoryIfMissingVerbose verbosity True libTargetDir
560560 -- TODO: do we need to put hs-boot files into place for mutually recursive
561561 -- modules?
562- let cObjs = map (`replaceExtension` objExtension) (cSources libBi)
562+ let cLikeFiles = fromNubListR $ toNubListR (cSources libBi) <> toNubListR (cxxSources libBi)
563+ cObjs = map (`replaceExtension` objExtension) cLikeFiles
563564 baseOpts = componentGhcOptions verbosity lbi libBi clbi libTargetDir
564565 vanillaOpts = baseOpts `mappend` mempty {
565566 ghcOptMode = toFlag GhcModeMake ,
@@ -644,6 +645,39 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
644645 else do vanilla; shared
645646 whenProfLib (runGhcProg profOpts)
646647
648+ -- build any C++ sources seperately
649+ unless (not has_code || null (cxxSources libBi)) $ do
650+ info verbosity " Building C++ Sources..."
651+ sequence_
652+ [ do let baseCxxOpts = Internal. componentCxxGhcOptions verbosity implInfo
653+ lbi libBi clbi libTargetDir filename
654+ vanillaCxxOpts = if isGhcDynamic
655+ then baseCxxOpts { ghcOptFPic = toFlag True }
656+ else baseCxxOpts
657+ profCxxOpts = vanillaCxxOpts `mappend` mempty {
658+ ghcOptProfilingMode = toFlag True ,
659+ ghcOptObjSuffix = toFlag " p_o"
660+ }
661+ sharedCxxOpts = vanillaCxxOpts `mappend` mempty {
662+ ghcOptFPic = toFlag True ,
663+ ghcOptDynLinkMode = toFlag GhcDynamicOnly ,
664+ ghcOptObjSuffix = toFlag " dyn_o"
665+ }
666+ odir = fromFlag (ghcOptObjDir vanillaCxxOpts)
667+ createDirectoryIfMissingVerbose verbosity True odir
668+ let runGhcProgIfNeeded cxxOpts = do
669+ needsRecomp <- checkNeedsRecompilation filename cxxOpts
670+ when needsRecomp $ runGhcProg cxxOpts
671+ runGhcProgIfNeeded vanillaCxxOpts
672+ unless forRepl $
673+ whenSharedLib forceSharedLib (runGhcProgIfNeeded sharedCxxOpts)
674+ unless forRepl $ whenProfLib (runGhcProgIfNeeded profCxxOpts)
675+ | filename <- cxxSources libBi]
676+
677+ when has_code . ifReplLib $ do
678+ when (null (allLibModules lib clbi)) $ warn verbosity " No exposed modules"
679+ ifReplLib (runGhcProg replOpts)
680+
647681 -- build any C sources
648682 unless (not has_code || null (cSources libBi)) $ do
649683 info verbosity " Building C Sources..."
@@ -679,17 +713,13 @@ buildOrReplLib forRepl verbosity numJobs pkg_descr lbi lib clbi = do
679713 -- with ghci, but .c files can depend on .h files generated by ghc by ffi
680714 -- exports.
681715
682- when has_code . ifReplLib $ do
683- when (null (allLibModules lib clbi)) $ warn verbosity " No exposed modules"
684- ifReplLib (runGhcProg replOpts)
685-
686716 -- link:
687717 when has_code . unless forRepl $ do
688718 info verbosity " Linking..."
689719 let cProfObjs = map (`replaceExtension` (" p_" ++ objExtension))
690- (cSources libBi)
720+ (cSources libBi ++ cxxSources libBi )
691721 cSharedObjs = map (`replaceExtension` (" dyn_" ++ objExtension))
692- (cSources libBi)
722+ (cSources libBi ++ cxxSources libBi )
693723 compiler_id = compilerId (compiler lbi)
694724 vanillaLibFilePath = libTargetDir </> mkLibName uid
695725 profileLibFilePath = libTargetDir </> mkProfLibName uid
0 commit comments