Commit 199f3888 authored by Simon Marlow's avatar Simon Marlow
Browse files

Parse the ghc --info values using a Haskell program, and cache the results

Should improve startup time of make in the testsuite, and it is
simpler.
parent 5ff65d76
...@@ -21,4 +21,4 @@ endif ...@@ -21,4 +21,4 @@ endif
clean distclean maintainer-clean: clean distclean maintainer-clean:
$(MAKE) -C $(TOP)/timeout $@ $(MAKE) -C $(TOP)/timeout $@
$(RM) -f mk/*.o mk/*.hi mk/ghc-config mk/ghc-config.exe mk/ghcconfig*.mk
...@@ -35,26 +35,6 @@ endif ...@@ -35,26 +35,6 @@ endif
$(call canonicalise,$1) $(call canonicalise,$1)
endef endef
define get-ghc-rts-field # $1 = result variable, $2 = field name
$1 := $$(shell '$$(TEST_HC)' +RTS --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
endef
define get-ghc-field # $1 = result variable, $2 = field name
$1 := $$(shell '$$(TEST_HC)' --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
endef
define get-ghc-feature-bool # $1 = result variable, $2 = field name
SHELL_RES := $$(shell '$$(TEST_HC)' --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
$1 := $$(strip \
$$(if $$(SHELL_RES), \
$$(if $$(subst YES,,$$(SHELL_RES)), \
$$(if $$(subst NO,,$$(SHELL_RES)), \
$$(warning ghc info field not YES or NO: $2: $$(SHELL_RES)), \
NO), \
YES), \
$$(warning ghc info field not found: $2)))
endef
ifeq "$(TEST_HC)" "" ifeq "$(TEST_HC)" ""
STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1) STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1)
...@@ -136,9 +116,6 @@ ifeq "$(shell test -x '$(HPC)' && echo exists)" "" ...@@ -136,9 +116,6 @@ ifeq "$(shell test -x '$(HPC)' && echo exists)" ""
$(error Cannot find hpc: $(HPC)) $(error Cannot find hpc: $(HPC))
endif endif
$(eval $(call get-ghc-field,GhcRTSWays,RTS ways))
$(eval $(call get-ghc-field,AR,ar command))
ifeq "$(AR)" "" ifeq "$(AR)" ""
AR = ar AR = ar
endif endif
...@@ -151,7 +128,25 @@ CP = cp ...@@ -151,7 +128,25 @@ CP = cp
RM = rm -f RM = rm -f
PYTHON = python PYTHON = python
$(eval $(call get-ghc-rts-field,HostOS,Host OS)) # -----------------------------------------------------------------------------
# configuration of TEST_HC
# ghc-config.hs is a short Haskell program that runs ghc --info, parses
# the results, and emits a little .mk file with make bindings for the values.
# This way we cache the results for different values of $(TEST_HC)
$(TOP_ABS)/mk/ghc-config : $(TOP_ABS)/mk/ghc-config.hs
"$(TEST_HC)" --make -o $@ $<
ghc-config-mk = $(TOP_ABS)/mk/ghcconfig$(subst /,_,$(subst \,_,$(TEST_HC))).mk
$(ghc-config-mk) : $(TOP_ABS)/mk/ghc-config
$(TOP_ABS)/mk/ghc-config $(TEST_HC) >$@
include $(ghc-config-mk)
# -----------------------------------------------------------------------------
ifeq "$(HostOS)" "mingw32" ifeq "$(HostOS)" "mingw32"
WINDOWS = YES WINDOWS = YES
else else
......
import System.Environment
import System.Process
main = do
[ghc] <- getArgs
info <- readProcess ghc ["+RTS", "--info"] ""
let fields = read info :: [(String,String)]
getGhcField fields "HostOS" "Host OS"
getGhcField fields "WORDSIZE" "Word size"
getGhcField fields "TARGETPLATFORM" "Target platform"
getGhcField fields "TargetOS_CPP" "Target OS"
getGhcField fields "TargetARCH_CPP" "Target architecture"
info <- readProcess ghc ["--info"] ""
let fields = read info :: [(String,String)]
getGhcField fields "GhcStage" "Stage"
getGhcField fields "GhcWithNativeCodeGen" "Have native code generator"
getGhcField fields "GhcWithInterpreter" "Have interpreter"
getGhcField fields "GhcUnregisterised" "Unregisterised"
getGhcField fields "GhcWithSMP" "Support SMP"
getGhcField fields "GhcRTSWays" "RTS ways"
getGhcField fields "AR" "ar command"
getGhcField :: [(String,String)] -> String -> String -> IO ()
getGhcField fields mkvar key = do
case lookup key fields of
Nothing -> fail ("No field: " ++ key)
Just val -> putStrLn (mkvar ++ '=':val)
...@@ -31,10 +31,6 @@ TEST_HC_OPTS = -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user- ...@@ -31,10 +31,6 @@ TEST_HC_OPTS = -fforce-recomp -dcore-lint -dcmm-lint -dno-debug-output -no-user-
RUNTEST_OPTS = RUNTEST_OPTS =
$(eval $(call get-ghc-rts-field,WORDSIZE,Word size))
$(eval $(call get-ghc-rts-field,TARGETPLATFORM,Target platform))
$(eval $(call get-ghc-rts-field,TargetOS_CPP,Target OS))
$(eval $(call get-ghc-rts-field,TargetARCH_CPP,Target architecture))
ifeq "$(filter $(TargetOS_CPP), cygwin32 mingw32)" "" ifeq "$(filter $(TargetOS_CPP), cygwin32 mingw32)" ""
exeext = exeext =
else else
...@@ -43,7 +39,6 @@ endif ...@@ -43,7 +39,6 @@ endif
RUNTEST_OPTS += -e ghc_compiler_always_flags="'$(TEST_HC_OPTS)'" RUNTEST_OPTS += -e ghc_compiler_always_flags="'$(TEST_HC_OPTS)'"
$(eval $(call get-ghc-feature-bool,GhcWithNativeCodeGen,Have native code generator))
ifeq "$(GhcWithNativeCodeGen)" "YES" ifeq "$(GhcWithNativeCodeGen)" "YES"
RUNTEST_OPTS += -e ghc_with_native_codegen=1 RUNTEST_OPTS += -e ghc_with_native_codegen=1
else else
...@@ -71,8 +66,6 @@ else ...@@ -71,8 +66,6 @@ else
RUNTEST_OPTS += -e ghc_with_dynamic_rts=0 RUNTEST_OPTS += -e ghc_with_dynamic_rts=0
endif endif
$(eval $(call get-ghc-field,GhcStage,Stage))
$(eval $(call get-ghc-feature-bool,GhcWithInterpreter,Have interpreter))
ifeq "$(GhcWithInterpreter)" "NO" ifeq "$(GhcWithInterpreter)" "NO"
RUNTEST_OPTS += -e ghc_with_interpreter=0 RUNTEST_OPTS += -e ghc_with_interpreter=0
else ifeq "$(GhcStage)" "1" else ifeq "$(GhcStage)" "1"
...@@ -81,14 +74,12 @@ else ...@@ -81,14 +74,12 @@ else
RUNTEST_OPTS += -e ghc_with_interpreter=1 RUNTEST_OPTS += -e ghc_with_interpreter=1
endif endif
$(eval $(call get-ghc-feature-bool,GhcUnregisterised,Unregisterised))
ifeq "$(GhcUnregisterised)" "YES" ifeq "$(GhcUnregisterised)" "YES"
RUNTEST_OPTS += -e ghc_unregisterised=1 RUNTEST_OPTS += -e ghc_unregisterised=1
else else
RUNTEST_OPTS += -e ghc_unregisterised=0 RUNTEST_OPTS += -e ghc_unregisterised=0
endif endif
$(eval $(call get-ghc-feature-bool,GhcWithSMP,Support SMP))
ifeq "$(GhcWithSMP)" "YES" ifeq "$(GhcWithSMP)" "YES"
RUNTEST_OPTS += -e ghc_with_smp=1 RUNTEST_OPTS += -e ghc_with_smp=1
else else
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment