Default to 'ghc' rather than '$(HC)' for BOOT_HC
[nofib.git] / mk / boilerplate.mk
1 #################################################################################
2 #
3 # nofib/mk/boilerplate.mk
4 #
5 # Boilerplate Makefile for an fptools project
6 #
7 #################################################################################
8
9 # Begin by slurping in the boilerplate from one level up,
10 # with standard TOP-mangling
11 # Remember, TOP is the top level of the innermost level
12
13 default : all
14
15 show:
16 @echo '$(VALUE)="$($(VALUE))"'
17
18 RM = rm -f
19 SIZE = size
20 STRIP = strip
21 PERL = /usr/bin/perl
22 CONTEXT_DIFF = diff -U 1
23 DEFAULT_TMPDIR = /tmp
24 EXECUTABLE_FILE = chmod +x
25
26 # Benchmarks controls which set of tests should be run
27 # You can run one or more of
28 # imaginary
29 # spectral
30 # real
31 # parallel
32 # gc
33 # smp
34 # fibon
35 NoFibSubDirs = imaginary spectral real shootout
36
37 # Haskell compiler options for nofib
38 NoFibHcOpts = -O2
39
40 # Number of times to run each program
41 NoFibRuns = 5
42
43 # -----------------------------------------------------------------
44 # Everything after this point
45 # augments or overrides previously set variables.
46 # (these files are optional, so `make' won't fret if it
47 # cannot get to them).
48 # -----------------------------------------------------------------
49
50 SRC_HC_OPTS += $(NoFibHcOpts) -Rghc-timing
51
52 ifeq "$(WithNofibHc)" ""
53
54 STAGE1_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage1)
55 STAGE2_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage2)
56 STAGE3_GHC := $(abspath $(TOP)/../inplace/bin/ghc-stage3)
57
58 ifneq "$(wildcard $(STAGE1_GHC) $(STAGE1_GHC).exe)" ""
59
60 ifeq "$(BINDIST)" "YES"
61 HC := $(abspath $(TOP)/../)/bindisttest/install dir/bin/ghc
62 else ifeq "$(stage)" "1"
63 HC := $(STAGE1_GHC)
64 else ifeq "$(stage)" "3"
65 HC := $(STAGE3_GHC)
66 else
67 # use stage2 by default
68 HC := $(STAGE2_GHC)
69 endif
70
71 else
72 HC := $(shell which ghc)
73 endif
74
75 else
76
77 # We want to support both "ghc" and "/usr/bin/ghc" as values of WithNofibHc
78 # passed in by the user, but
79 # which ghc == /usr/bin/ghc
80 # which /usr/bin/ghc == /usr/bin/ghc
81 # so on unix-like platforms we can just always 'which' it.
82 # However, on cygwin, we can't just use which:
83 # $ which c:/ghc/ghc-7.4.1/bin/ghc.exe
84 # which: no ghc.exe in (./c:/ghc/ghc-7.4.1/bin)
85 # so we start off by using realpath, and if that succeeds then we use
86 # that value. Otherwise we fall back on 'which'.
87 HC_REALPATH := $(realpath $(WithNofibHc))
88 ifeq "$(HC_REALPATH)" ""
89 HC := $(shell which '$(WithNofibHc)')
90 else
91 HC := $(HC_REALPATH)
92 endif
93
94 endif
95
96 MKDEPENDHS := $(HC) # ToDo: wrong, if $(HC) isn't GHC.
97
98 # We need a GHC that can build nofib-analyse. $(HC) will often be a
99 # freshly built compiler, without the necessary packages installed,
100 # so it isn't a good bet. Just using plain 'ghc' seems like our best
101 # bet to find a suitable compiler.
102 ifeq "$(BOOT_HC)" ""
103 BOOT_HC = ghc
104 endif
105
106 # We want to support both "ghc" and "/usr/bin/ghc" as values of BOOT_HC
107 # passed in by the user, but
108 # which ghc == /usr/bin/ghc
109 # which /usr/bin/ghc == /usr/bin/ghc
110 # so on unix-like platforms we can just always 'which' it.
111 # However, on cygwin, we can't just use which:
112 # $ which c:/ghc/ghc-7.4.1/bin/ghc.exe
113 # which: no ghc.exe in (./c:/ghc/ghc-7.4.1/bin)
114 # so we start off by using realpath, and if that succeeds then we use
115 # that value. Otherwise we fall back on 'which'.
116 #
117 # Note also that we need to use 'override' in order to override a
118 # value given on the commandline.
119 BOOT_HC_REALPATH := $(realpath $(BOOT_HC))
120 ifeq "$(BOOT_HC_REALPATH)" ""
121 override BOOT_HC := $(shell which '$(BOOT_HC)')
122 else
123 override BOOT_HC := $(BOOT_HC_REALPATH)
124 endif
125
126 ifeq "$(BOOT_HC)" ""
127 $(error Could not find BOOT_HC)
128 endif
129
130 define get-ghc-rts-field # $1 = result variable, $2 = field name
131 $1 := $$(shell '$$(HC)' +RTS --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
132 endef
133
134 define get-ghc-field # $1 = result variable, $2 = field name
135 $1 := $$(shell '$$(HC)' --info | grep '^ .("$2",' | tr -d '\r' | sed -e 's/.*", *"//' -e 's/")$$$$//')
136 endef
137
138 $(eval $(call get-ghc-rts-field,HC_VERSION,GHC version))
139 $(eval $(call get-ghc-field,SplitObjs,Object splitting supported))
140 $(eval $(call get-ghc-field,CC,C compiler command))
141
142 define ghc-ge # $1 = major version, $2 = minor version
143 HC_VERSION_GE_$1_$2 := $$(shell if [ `echo $$(HC_VERSION) | sed 's/\..*//'` -gt $1 ]; then echo YES; else if [ `echo $$(HC_VERSION) | sed 's/\..*//'` -ge $1 ] && [ `echo $$(HC_VERSION) | sed -e 's/[^.]*\.//' -e 's/\..*//'` -ge $2 ]; then echo YES; else echo NO; fi; fi)
144 endef
145
146 $(eval $(call ghc-ge,6,13))
147
148 RUNTEST = $(TOP)/runstdtest/runstdtest
149
150 include $(TOP)/mk/ghc-paths.mk
151 include $(TOP)/mk/ghc-opts.mk
152 include $(TOP)/mk/paths.mk
153 include $(TOP)/mk/opts.mk
154
155 -include .depend