Add flag allowing convenient disabling of terminfo support
authorBen Gamari <bgamari.foss@gmail.com>
Tue, 28 Feb 2017 14:27:04 +0000 (09:27 -0500)
committerBen Gamari <ben@smart-cactus.org>
Tue, 28 Feb 2017 15:56:07 +0000 (10:56 -0500)
This is a common thing that users who cross-compile must fight against.
It turns out that it's pretty straightforward to make is convenient.

Test Plan: Cross compile without a target `ncurses` available

Reviewers: danharaj, hvr, erikd, austin, rwbarton

Subscribers: rwbarton, thomie, snowleopard

Differential Revision: https://phabricator.haskell.org/D3177

compiler/ghc.mk
ghc.mk
mk/config.mk.in
mk/flavours/bench-cross.mk
mk/flavours/perf-cross.mk
mk/flavours/quick-cross.mk
utils/ghc-pkg/Main.hs
utils/ghc-pkg/ghc-pkg.cabal
utils/ghc-pkg/ghc.mk

index ce41eca..36603a4 100644 (file)
@@ -361,6 +361,10 @@ compiler_CONFIGURE_OPTS += --ghc-option=-DNOSMP
 compiler_CONFIGURE_OPTS += --ghc-option=-optc-DNOSMP
 endif
 
+ifeq "$(WITH_TERMINFO)" "NO"
+compiler_stage2_CONFIGURE_OPTS += --flags=-terminfo
+endif
+
 # Careful optimisation of the parser: we don't want to throw everything
 # at it, because that takes too long and doesn't buy much, but we do want
 # to inline certain key external functions, so we instruct GHC not to
diff --git a/ghc.mk b/ghc.mk
index b2888c0..578e031 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -431,9 +431,7 @@ else # CLEANING
 # compiler already has installed (or up-to-date enough).
 
 PACKAGES_STAGE0 = binary Cabal/Cabal hpc ghc-boot-th ghc-boot hoopl transformers template-haskell ghci
-ifeq "$(Windows_Host)" "NO"
 PACKAGES_STAGE0 += terminfo
-endif
 
 PACKAGES_STAGE1 += ghc-prim
 PACKAGES_STAGE1 += $(INTEGER_LIBRARY)
@@ -469,7 +467,7 @@ ifeq "$(HADDOCK_DOCS)" "YES"
 PACKAGES_STAGE1 += xhtml
 endif
 
-ifeq "$(Windows_Target)" "NO"
+ifeq "$(WITH_TERMINFO)" "YES"
 PACKAGES_STAGE1 += terminfo
 endif
 PACKAGES_STAGE1 += haskeline
index b90aca3..0fad90c 100644 (file)
@@ -100,6 +100,15 @@ GhcDynamic=NO
 # GhcProfiled=YES means compile a profiled stage-2 compiler
 GhcProfiled=NO
 
+# WITH_TERMINFO can be used to disable terminfo support throughout the compiler
+# and its tools. This is handy in the case of cross-compilation, where we may
+# not have an ncurses build for the target.
+ifeq "$(Windows_Target)" "NO"
+WITH_TERMINFO=YES
+else
+WITH_TERMINFO=NO
+endif
+
 ifeq "$(findstring $(TargetOS_CPP),linux freebsd dragonfly openbsd netbsd solaris2 kfreebsdgnu haiku linux-android)" ""
 TargetElf = NO
 else
index 15b359e..90344fc 100644 (file)
@@ -8,6 +8,7 @@ HADDOCK_DOCS       = NO
 BUILD_SPHINX_HTML  = NO
 BUILD_SPHINX_PDF   = NO
 BUILD_MAN          = NO
+WITH_TERMINFO      = NO
 
 INTEGER_LIBRARY      = integer-simple
 Stage1Only           = YES
index 669b51a..f202642 100644 (file)
@@ -8,6 +8,7 @@ HADDOCK_DOCS       = NO
 BUILD_SPHINX_HTML  = NO
 BUILD_SPHINX_PDF   = NO
 BUILD_MAN          = NO
+WITH_TERMINFO      = NO
 
 INTEGER_LIBRARY      = integer-simple
 Stage1Only           = YES
index 92347ca..b886a8d 100644 (file)
@@ -8,6 +8,7 @@ HADDOCK_DOCS       = NO
 BUILD_SPHINX_HTML  = NO
 BUILD_SPHINX_PDF   = NO
 BUILD_MAN          = NO
+WITH_TERMINFO      = NO
 
 INTEGER_LIBRARY      = integer-simple
 Stage1Only           = YES
index 44960ca..dd49180 100644 (file)
@@ -9,6 +9,14 @@
 {-# LANGUAGE TupleSections #-}
 {-# LANGUAGE ScopedTypeVariables #-}
 {-# OPTIONS_GHC -fno-warn-orphans #-}
+
+-- We never want to link against terminfo while bootstrapping.
+#ifdef BOOTSTRAPPING
+#ifdef WITH_TERMINFO
+#undef WITH_TERMINFO
+#endif
+#endif
+
 -----------------------------------------------------------------------------
 --
 -- (c) The University of Glasgow 2004-2009.
@@ -80,7 +88,7 @@ import System.Posix hiding (fdToHandle)
 import qualified System.Info(os)
 #endif
 
-#if !defined(mingw32_HOST_OS) && !defined(BOOTSTRAPPING)
+#ifdef WITH_TERMINFO
 import System.Console.Terminfo as Terminfo
 #endif
 
@@ -1429,7 +1437,7 @@ listPackages verbosity my_flags mPackageName mModuleName = do
 
   if simple_output then show_simple stack else do
 
-#if defined(mingw32_HOST_OS) || defined(BOOTSTRAPPING)
+#ifndef WITH_TERMINFO
     mapM_ show_normal stack
 #else
     let
index 3511e36..8776cb9 100644 (file)
@@ -15,6 +15,11 @@ Category: Development
 build-type: Simple
 cabal-version: >=1.10
 
+Flag terminfo
+    Description: Build GHC with terminfo support on non-Windows platforms.
+    Default: True
+    Manual: False
+
 Executable ghc-pkg
     Default-Language: Haskell2010
     Main-Is: Main.hs
@@ -30,8 +35,10 @@ Executable ghc-pkg
                    binary,
                    ghc-boot,
                    bytestring
+    if !os(windows) && flag(terminfo)
+        Build-Depends: terminfo
+        Cpp-Options: -DWITH_TERMINFO
     if !os(windows)
-        Build-Depends: unix,
-                       terminfo
+        Build-Depends: unix
     if os(windows)
         c-sources: CRT_noglob.c
index f7d97de..002c812 100644 (file)
@@ -57,6 +57,10 @@ utils/ghc-pkg_dist_INSTALL = YES
 utils/ghc-pkg_dist_INSTALL_SHELL_WRAPPER_NAME = ghc-pkg-$(ProjectVersion)
 endif
 
+ifeq "$(WITH_TERMINFO)" "NO"
+utils/ghc-pkg_dist-install_CONFIGURE_OPTS += -f-terminfo
+endif
+
 $(eval $(call build-prog,utils/ghc-pkg,dist,0))
 
 $(ghc-pkg_INPLACE) : | $(INPLACE_PACKAGE_CONF)/.