Skip to content

Commit 2317a67

Browse files
committed
Rearrange genPureArgs for hsc2hs without changing semantics
1 parent 500505c commit 2317a67

File tree

1 file changed

+91
-87
lines changed

1 file changed

+91
-87
lines changed

Cabal/src/Distribution/Simple/PreProcess.hs

Lines changed: 91 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -518,101 +518,105 @@ ppHsc2hs bi lbi clbi =
518518
-- directly, or via a response file.
519519
genPureArgs :: Version -> ConfiguredProgram -> String -> String -> [String]
520520
genPureArgs hsc2hsVersion gccProg inFile outFile =
521-
-- Additional gcc options
522-
[ "--cflag=" ++ opt
523-
| opt <-
524-
programDefaultArgs gccProg
525-
++ programOverrideArgs gccProg
526-
]
527-
++ [ "--lflag=" ++ opt
528-
| opt <-
529-
programDefaultArgs gccProg
530-
++ programOverrideArgs gccProg
531-
]
532-
-- OSX frameworks:
533-
++ [ what ++ "=-F" ++ opt
534-
| isOSX
535-
, opt <- nub (concatMap Installed.frameworkDirs pkgs)
536-
, what <- ["--cflag", "--lflag"]
537-
]
538-
++ [ "--lflag=" ++ arg
539-
| isOSX
540-
, opt <- map getSymbolicPath (PD.frameworks bi) ++ concatMap Installed.frameworks pkgs
541-
, arg <- ["-framework", opt]
542-
]
543-
-- Note that on ELF systems, wherever we use -L, we must also use -R
544-
-- because presumably that -L dir is not on the normal path for the
545-
-- system's dynamic linker. This is needed because hsc2hs works by
546-
-- compiling a C program and then running it.
547-
548-
++ ["--cflag=" ++ opt | opt <- platformDefines lbi]
549-
-- Options from the current package:
550-
++ ["--cflag=-I" ++ u dir | dir <- PD.includeDirs bi]
551-
++ [ "--cflag=-I" ++ u (buildDir lbi </> unsafeCoerceSymbolicPath relDir)
552-
| relDir <- mapMaybe symbolicPathRelative_maybe $ PD.includeDirs bi
553-
]
554-
++ [ "--cflag=" ++ opt
555-
| opt <-
556-
PD.ccOptions bi
557-
++ PD.cppOptions bi
558-
-- hsc2hs uses the C ABI
521+
cflags
522+
++ ldflags
523+
++ preccldFlags
524+
++ hsc2hsOptions bi
525+
++ postccldFlags
526+
++ ["-o", outFile, inFile]
527+
where
528+
ldflags =
529+
map ("--lflag=" ++) $
530+
concat
531+
[ programDefaultArgs gccProg ++ programOverrideArgs gccProg
532+
, osxFrameworkDirs
533+
, [ arg
534+
| isOSX
535+
, opt <- map getSymbolicPath (PD.frameworks bi) ++ concatMap Installed.frameworks pkgs
536+
, arg <- ["-framework", opt]
537+
]
538+
, -- Note that on ELF systems, wherever we use -L, we must also use -R
539+
-- because presumably that -L dir is not on the normal path for the
540+
-- system's dynamic linker. This is needed because hsc2hs works by
541+
-- compiling a C program and then running it.
542+
543+
-- Options from the current package:
544+
[ "-L" ++ u opt
545+
| opt <-
546+
if withFullyStaticExe lbi
547+
then PD.extraLibDirsStatic bi
548+
else PD.extraLibDirs bi
549+
]
550+
, [ "-Wl,-R," ++ u opt
551+
| isELF
552+
, opt <-
553+
if withFullyStaticExe lbi
554+
then PD.extraLibDirsStatic bi
555+
else PD.extraLibDirs bi
556+
]
557+
, ["-l" ++ opt | opt <- PD.extraLibs bi]
558+
, PD.ldOptions bi
559+
, -- Options from dependent packages
560+
[ opt
561+
| pkg <- pkgs
562+
, opt <-
563+
["-L" ++ opt | opt <- Installed.libraryDirs pkg]
564+
++ [ "-Wl,-R," ++ opt | isELF, opt <- Installed.libraryDirs pkg
565+
]
566+
++ [ "-l" ++ opt
567+
| opt <-
568+
if withFullyStaticExe lbi
569+
then Installed.extraLibrariesStatic pkg
570+
else Installed.extraLibraries pkg
571+
]
572+
++ Installed.ldOptions pkg
573+
]
574+
]
575+
576+
cflags =
577+
map ("--cflag=" ++) $
578+
concat
579+
[ programDefaultArgs gccProg ++ programOverrideArgs gccProg
580+
, osxFrameworkDirs
581+
, platformDefines lbi
582+
, -- Options from the current package:
583+
["-I" ++ u dir | dir <- PD.includeDirs bi]
584+
, [ "-I" ++ u (buildDir lbi </> unsafeCoerceSymbolicPath relDir)
585+
| relDir <- mapMaybe symbolicPathRelative_maybe $ PD.includeDirs bi
586+
]
587+
588+
, -- hsc2hs uses the C ABI
559589
-- We assume that there are only C sources
560590
-- and C++ functions are exported via a C
561591
-- interface and wrapped in a C source file.
562592
-- Therefore we do not supply C++ flags
563593
-- because there will not be C++ sources.
564594
--
565595
-- DO NOT add PD.cxxOptions unless this changes!
566-
]
567-
++ [ "--cflag=" ++ opt
568-
| opt <-
569-
[ "-I" ++ u (autogenComponentModulesDir lbi clbi)
570-
, "-I" ++ u (autogenPackageModulesDir lbi)
571-
, "-include"
572-
, u $ autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName
596+
PD.ccOptions bi ++ PD.cppOptions bi
597+
598+
,
599+
[ "-I" ++ u (autogenComponentModulesDir lbi clbi)
600+
, "-I" ++ u (autogenPackageModulesDir lbi)
601+
, "-include"
602+
, u $ autogenComponentModulesDir lbi clbi </> makeRelativePathEx cppHeaderName
603+
]
604+
605+
, -- Options from dependent packages
606+
[ opt
607+
| pkg <- pkgs
608+
, opt <-
609+
["-I" ++ opt | opt <- Installed.includeDirs pkg]
610+
++ Installed.ccOptions pkg
611+
]
573612
]
574-
]
575-
++ [ "--lflag=-L" ++ u opt
576-
| opt <-
577-
if withFullyStaticExe lbi
578-
then PD.extraLibDirsStatic bi
579-
else PD.extraLibDirs bi
580-
]
581-
++ [ "--lflag=-Wl,-R," ++ u opt
582-
| isELF
583-
, opt <-
584-
if withFullyStaticExe lbi
585-
then PD.extraLibDirsStatic bi
586-
else PD.extraLibDirs bi
587-
]
588-
++ ["--lflag=-l" ++ opt | opt <- PD.extraLibs bi]
589-
++ ["--lflag=" ++ opt | opt <- PD.ldOptions bi]
590-
-- Options from dependent packages
591-
++ [ "--cflag=" ++ opt
592-
| pkg <- pkgs
593-
, opt <-
594-
["-I" ++ opt | opt <- Installed.includeDirs pkg]
595-
++ Installed.ccOptions pkg
596-
]
597-
++ [ "--lflag=" ++ opt
598-
| pkg <- pkgs
599-
, opt <-
600-
["-L" ++ opt | opt <- Installed.libraryDirs pkg]
601-
++ [ "-Wl,-R," ++ opt | isELF, opt <- Installed.libraryDirs pkg
602-
]
603-
++ [ "-l" ++ opt
604-
| opt <-
605-
if withFullyStaticExe lbi
606-
then Installed.extraLibrariesStatic pkg
607-
else Installed.extraLibraries pkg
608-
]
609-
++ Installed.ldOptions pkg
610-
]
611-
++ preccldFlags
612-
++ hsc2hsOptions bi
613-
++ postccldFlags
614-
++ ["-o", outFile, inFile]
615-
where
613+
614+
osxFrameworkDirs =
615+
[ "-F" ++ opt
616+
| isOSX
617+
, opt <- ordNub (concatMap Installed.frameworkDirs pkgs)
618+
]
619+
616620
-- hsc2hs flag parsing was wrong
617621
-- (see -- https://github.com/haskell/hsc2hs/issues/35)
618622
-- so we need to put -- --cc/--ld *after* hsc2hsOptions,

0 commit comments

Comments
 (0)