The RTS is Haddock-less, tell make about it
[ghc-hetmet.git] / rts / Makefile
1 #-----------------------------------------------------------------------------
2 #
3 #  This is the Makefile for the runtime-system stuff.
4 #  This stuff is written in C (and cannot be written in Haskell).
5 #
6 #  .c  files are vanilla C,
7 #  .hc files are "Haskellized-C", compiled using the C compiler and
8 #      (possibly) the assembly-mangler.  The GHC driver script
9 #      knows how to compile this stuff.
10
11 #-----------------------------------------------------------------------------
12 # Preamble
13
14 TOP=..
15
16 # Set UseGhcForCc: this causes the fptools build system to use a different
17 # set of suffix rules for compiling C code, using $(HC) rather than $(CC)
18 # and prepending "-optc" to $(CC_OPTS).  NB. must be done before including
19 # boilerplate.mk below.
20 UseGhcForCc = YES
21
22 include $(TOP)/mk/boilerplate.mk
23
24 PACKAGE = rts
25
26 HC=$(GHC_INPLACE)
27
28 # -----------------------------------------------------------------------------
29 # RTS ways
30
31 WAYS=$(GhcLibWays) $(GhcRTSWays)
32
33 ifneq "$(findstring debug, $(way))" ""
34 GhcRtsHcOpts=
35 GhcRtsCcOpts=-g -O0
36 endif
37
38 # -----------------------------------------------------------------------------
39
40 # There's nothing for Haddock here...
41 override HADDOCK_DOCS = NO
42
43 # -----------------------------------------------------------------------------
44
45 # Tells the build system not to add various Haskellish options to $(SRC_HC_OPTS)
46 NON_HS_PACKAGE = YES
47
48 # grab sources from these subdirectories
49 ALL_DIRS = hooks parallel sm
50
51 ifeq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
52 ALL_DIRS += win32
53 else
54 ALL_DIRS += posix
55 endif
56
57 ifneq "$(findstring dyn, $(way))" ""
58 DYNAMIC_RTS=YES
59 else
60 DYNAMIC_RTS=NO
61 endif
62
63 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
64 EXCLUDED_SRCS += Main.c
65 # It's not included in the DLL, but we need to compile it up separately.
66
67 all :: Main.$(way_)o
68 INSTALL_LIBS += Main.$(way_)o
69 else
70 EXCLUDED_SRCS += RtsDllMain.c
71 endif
72
73 # This file ends up being empty unless we're building for a powerpc
74 # or darwin system, and it is reported that Solaris ld chokes on it when
75 # building HSrts.o.
76 ifeq "$(findstring $(TargetArch_CPP), powerpc powerpc64)" ""
77 ifeq "$(findstring $(TargetOS_CPP), darwin)" ""
78 EXCLUDED_SRCS += AdjustorAsm.S
79 endif
80 endif
81
82 EXCLUDED_SRCS += parallel/SysMan.c
83
84 # The build system doesn't give us these
85 CMM_SRCS = $(filter-out AutoApply%.cmm, $(wildcard *.cmm)) $(EXTRA_CMM_SRCS)
86 CMM_OBJS = $(patsubst %.cmm,%.$(way_)o, $(CMM_SRCS))
87
88 CLEAN_FILES += $(CMM_OBJS)
89
90 # Override the default $(LIBOBJS) (defaults to $(HS_OBJS))
91 LIBOBJS = $(C_OBJS) $(CMM_OBJS)
92
93 SplitObjs=NO
94
95 H_FILES = $(wildcard ../includes/*.h) $(wildcard *.h)
96
97 #-----------------------------------------------------------------------------
98 # Flags for compiling RTS .c and .hc files
99
100 # gcc provides lots of useful warnings if you ask it.
101 # This is a pretty good list to start with - use a # to comment out
102 # any you don't like.
103 WARNING_OPTS += -Wall
104 WARNING_OPTS += -W
105 WARNING_OPTS += -Wstrict-prototypes 
106 WARNING_OPTS += -Wmissing-prototypes 
107 WARNING_OPTS += -Wmissing-declarations
108 WARNING_OPTS += -Winline
109 WARNING_OPTS += -Waggregate-return
110 #WARNING_OPTS += -Wpointer-arith
111 #WARNING_OPTS += -Wbad-function-cast
112 #WARNING_OPTS += -Wcast-align
113 #WARNING_OPTS += -Wnested-externs
114 #WARNING_OPTS += -Wshadow
115 #WARNING_OPTS += -Wcast-qual
116 #WARNING_OPTS += -Wno-unused 
117 #WARNING_OPTS += -Wredundant-decls 
118 #WARNING_OPTS += -Wconversion
119
120 STANDARD_OPTS += -I../includes -I. -Iparallel -Ism
121 # COMPILING_RTS is only used when building Win32 DLL support.
122 STANDARD_OPTS += -DCOMPILING_RTS
123
124 # HC_OPTS is included in both .c and .cmm compilations, whereas CC_OPTS is
125 # only included in .c compilations.  HC_OPTS included the WAY_* opts, which
126 # must be included in both types of compilations.
127
128 SRC_CC_OPTS += $(WARNING_OPTS)
129 SRC_CC_OPTS += $(STANDARD_OPTS)
130
131 SRC_CC_OPTS += $(GhcRtsCcOpts)
132 SRC_HC_OPTS += $(GhcRtsHcOpts) -package-name rts
133
134 ifneq "$(GhcWithSMP)" "YES"
135 SRC_CC_OPTS += -DNOSMP
136 SRC_HC_OPTS += -optc-DNOSMP
137 endif
138
139 ifneq "$(DYNAMIC_RTS)" "YES"
140 SRC_HC_OPTS += -static
141 else
142 LIB_LD_OPTS += -ignore-package base -ignore-package rts
143 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
144 BASE_VERSION=$(strip $(shell grep version: $(TOP)/libraries/base/base.cabal | cut -f2 -d:))
145 BASE_NAME=HSbase-$(BASE_VERSION)-ghc$(ProjectVersion)$(soext)
146 BASE_DIST_LIB=$(TOP)/libraries/base/dist/build
147 BASE_IMPORT_LIBRARY=$(BASE_DIST_LIB)/lib$(BASE_NAME).a
148 LIB_DEPS=$(BASE_IMPORT_LIBRARY)
149 LIB_LD_OPTS += -L$(BASE_DIST_LIB) -l$(BASE_NAME)
150 # We extract a good bit of information out of the rts package.conf by going via ghc-pkg
151 LIB_LD_OPTS += $(foreach lib,$(shell $(GHC_PKG_INPLACE) field rts extra-libraries | sed -e s/extra-libraries://),"-l$(lib)")
152 LIB_LD_OPTS += $(foreach libdir,$(shell $(GHC_PKG_INPLACE) field rts library-dirs | sed -e s/library-dirs://),"-L$(libdir)")
153 endif
154 endif
155
156 ifeq "$(Windows)" "YES"
157 # On Windows GHC does its own commandline parsing, so we need extra
158 # doublequote protection. Sigh.
159 DQ = \\\"
160 else
161 DQ = \"
162 endif
163
164 # If Main.c is built with optimisation then the SEH exception stuff on
165 # Windows gets confused.
166 # This has to be in HC rather than CC opts, as otherwise there's a
167 # -optc-O2 that comes after it.
168 Main_HC_OPTS += -optc-O0
169
170 RtsMessages_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
171 RtsUtils_CC_OPTS += -DProjectVersion=$(DQ)$(ProjectVersion)$(DQ)
172 RtsUtils_CC_OPTS += -DRtsWay=$(DQ)rts$(_way)$(DQ)
173 RtsUtils_CC_OPTS += -DHostPlatform=$(DQ)$(HOSTPLATFORM)$(DQ)
174 RtsUtils_CC_OPTS += -DBuildPlatform=$(DQ)$(BUILDPLATFORM)$(DQ)
175 RtsUtils_CC_OPTS += -DTargetPlatform=$(DQ)$(TARGETPLATFORM)$(DQ)
176 RtsUtils_CC_OPTS += -DGhcUnregisterised=$(DQ)$(GhcUnregisterised)$(DQ)
177 RtsUtils_CC_OPTS += -DGhcEnableTablesNextToCode=$(DQ)$(GhcEnableTablesNextToCode)$(DQ)
178
179 StgCRun_CC_OPTS += -w
180 Typeable_CC_OPTS += -w
181 RetainerProfile_CC_OPTS += -w
182 sm/Compact_CC_OPTS += -w
183 # On Windows:
184 win32/ConsoleHandler_CC_OPTS += -w
185 win32/ThrIOManager_CC_OPTS += -w
186 win32/Ticker_CC_OPTS += -w
187 Threads_CC_OPTS += -w
188 Capability_CC_OPTS += -w
189 Schedule_CC_OPTS += -w
190 # The above warning supression flags are a temporary kludge.
191 # While working on this module you are encouraged to remove it and fix
192 # any warnings in the module. See
193 #     http://hackage.haskell.org/trac/ghc/wiki/WorkingConventions#Warnings
194 # for details
195
196 ifeq "$(way)" "mp"
197 SRC_HC_OPTS += -I$$PVM_ROOT/include
198 endif
199
200 # If -DDEBUG is in effect, adjust package conf accordingly..
201 ifneq "$(strip $(filter -optc-DDEBUG,$(GhcRtsHcOpts)))" ""
202 PACKAGE_CPP_OPTS += -DDEBUG
203 endif
204
205 ifeq "$(HaveLibMingwEx)" "YES"
206 PACKAGE_CPP_OPTS += -DHAVE_LIBMINGWEX
207 endif
208
209 ifeq "$(GhciWithDebugger)" "YES"
210 STANDARD_OPTS += -DDEBUGGER
211 endif
212
213 ifeq "$(DotnetSupport)" "YES"
214
215
216 # Would like to just use SUBDIRS here, but need to
217 # descend into dotnet/ earlier than that.
218 #
219 all ::
220         $(MAKE) -C dotnet all
221
222 # But use SUBDIRS for other recursive targets.
223 SUBDIRS += dotnet
224
225 LIBOBJS += dotnet/Invoke.o
226 endif
227
228 # Suppress uninitialized variable warnings for GC.c
229 GC_CC_OPTS      += -Wno-uninitialized
230
231 #-----------------------------------------------------------------------------
232 # Include the Front panel code?
233
234 # we need GTK+ for the front panel
235 ifneq "$(GTK_CONFIG)" ""
236 ifeq "$(GhcRtsWithFrontPanel)" "YES"
237 SRC_HC_OPTS             += `$(GTK_CONFIG) --cflags` -optc-DRTS_GTK_FRONTPANEL
238 VisCallbacks_CC_OPTS    += -Wno-unused
239 SRC_MKDEPENDC_OPTS      += `$(GTK_CONFIG) --cflags`
240 else # GhcRtsWithFrontPanel
241 EXCLUDED_SRCS           += $(wildcard Vis*.c)
242 endif
243 else # GTK_CONFIG
244 EXCLUDED_SRCS           += $(wildcard Vis*.c)
245 endif
246
247 #-----------------------------------------------------------------------------
248 # Add PAPI library if needed
249
250 ifeq "$(GhcRtsWithPapi)" "YES"
251 SRC_HC_OPTS             += -optc-DUSE_PAPI
252 PACKAGE_CPP_OPTS        += -DUSE_PAPI
253 endif
254
255 #-----------------------------------------------------------------------------
256 # make depend setup
257
258 SRC_MKDEPENDC_OPTS += -I. -I../includes
259
260 # Hack: we define every way-related option here, so that we get (hopefully)
261 # a superset of the dependencies.  To do this properly, we should generate
262 # a different set of dependencies for each way.  Further hack: PROFILING and
263 # TICKY_TICKY can't be used together, so we omit TICKY_TICKY for now.
264 SRC_MKDEPENDC_OPTS += -DPROFILING -DTHREADED_RTS -DDEBUG
265
266 # -----------------------------------------------------------------------------
267 # The auto-generated apply code
268
269 # We want a slightly different version for the unregisterised way, so we make
270 # AutoApply on a per-way basis (eg. AutoApply_p.cmm).
271
272 ifneq "$(DOING_BIN_DIST)" "YES"
273
274 AUTO_APPLY_CMM = AutoApply$(_way).cmm
275
276 ifneq "$(BootingFromHc)" "YES"
277 $(AUTO_APPLY_CMM): $(GHC_GENAPPLY)
278         @$(RM) $@
279         $(GENAPPLY) $(if $(filter $(way), u debug_u), -u) >$@
280 endif
281
282 EXTRA_CMM_SRCS += $(AUTO_APPLY_CMM)
283
284 CLEAN_FILES += $(AUTO_APPLY_CMM)
285
286 endif
287
288 # -----------------------------------------------------------------------------
289 # Compile GMP only if we don't have it already
290 #
291 # We use GMP's own configuration stuff, because it's all rather hairy
292 # and not worth re-implementing in our Makefile framework.
293
294 CLEAN_FILES += gmp/libgmp.a
295
296 # Need to get the GMP vars in through CPP to package.conf.in, and put
297 # quotes around each element.
298
299 empty =
300 space = $(empty) $(empty)
301 comma = ,
302 PACKAGE_CPP_OPTS += -DGMP_INCLUDE_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_INCLUDE_DIRS))))'
303 PACKAGE_CPP_OPTS += -DGMP_LIB_DIRS='$(subst $(space),$(comma),$(patsubst %,"%",$(strip $(GMP_LIB_DIRS))))'
304
305 ifneq "$(GMP_INCLUDE_DIRS)" ""
306 SRC_HC_OPTS += -I$(GMP_INCLUDE_DIRS)
307 SRC_CC_OPTS += -I$(GMP_INCLUDE_DIRS)
308 SRC_HSC2HS_OPTS += -I$(GMP_INCLUDE_DIRS)
309 endif
310 ifneq "$(GMP_LIB_DIRS)" ""
311 SRC_LD_OPTS += -L$(GMP_LIB_DIRS)
312 endif
313
314 SRC_CC_OPTS += -I../gmp/gmpbuild
315 SRC_HC_OPTS += -I../gmp/gmpbuild
316 SRC_HSC2HS_OPTS += -I../gmp/gmpbuild
317 SRC_LD_OPTS += -L../gmp/gmpbuild
318
319 #-----------------------------------------------------------------------------
320 #
321 # Building the GUM SysMan
322 #
323
324 ifeq "$(way)" "mp"
325 all :: parallel/SysMan
326
327 ifdef solaris2_TARGET_OS
328 __socket_libs = -lsocket -lnsl
329 else
330 __socket_libs =
331 endif
332
333 parallel/SysMan : parallel/SysMan.mp_o parallel/LLComms.mp_o RtsUtils.mp_o RtsFlags.mp_o
334         $(RM) $@
335         gcc -o $@ parallel/SysMan.mp_o parallel/LLComms.mp_o -L$$PVM_ROOT/lib/$$PVM_ARCH -lgpvm3 -lpvm3 $(__socket_libs)
336
337 CLEAN_FILES  += parallel/SysMan.mp_o parallel/SysMan
338 INSTALL_LIBEXECS += parallel/SysMan
339 endif
340
341 #-----------------------------------------------------------------------------
342 # Compiling the cmm files
343
344 # ToDo: should we really include Rts.h here?  Required for GNU_ATTRIBUTE().
345 SRC_HC_OPTS += -I. -\#include HCIncludes.h
346
347 ifeq "$(Windows)" "YES"
348 PrimOps_HC_OPTS += -\#include '<windows.h>' -\#include win32/AsyncIO.h
349 else
350 PrimOps_HC_OPTS += -\#include posix/Itimer.h
351 endif
352
353 # Otherwise the stack-smash handler gets triggered.
354 ifeq "$(TargetOS_CPP)" "openbsd"
355 SRC_HC_OPTS += -optc-fno-stack-protector
356 endif
357
358 # -O3 helps unroll some loops (especially in copy() with a constant argument).
359 sm/Evac_HC_OPTS += -optc-funroll-loops
360
361 # Without this, thread_obj will not be inlined (at least on x86 with GCC 4.1.0)
362 sm/Compact_HC_OPTS += -optc-finline-limit=2500
363
364 # -fno-strict-aliasing is required for the runtime, because we often
365 # use a variety of types to represent closure pointers (StgPtr,
366 # StgClosure, StgMVar, etc.), and without -fno-strict-aliasing gcc is
367 # allowed to assume that these pointers do not alias.  eg. without
368 # this flag we get problems in GC.c:copy() with gcc 3.4.3, the
369 # upd_evacee() assigments get moved before the object copy.
370 SRC_CC_OPTS += -fno-strict-aliasing
371
372 # We *want* type-checking of hand-written cmm.
373 SRC_HC_OPTS += -dcmm-lint 
374
375 ifneq "$(BootingFromHc)" "YES"
376 # .cmm files depend on all the .h files, to a first approximation.
377 %.$(way_)o : %.cmm $(H_FILES)
378         $(HC_PRE_OPTS)
379         $(HC) $(HC_OPTS) -c $< -o $@
380         $(HC_POST_OPTS)
381
382 %.$(way_)hc : %.cmm $(H_FILES)
383         $(HC) $(HC_OPTS) -C $< -o $@
384
385 %.$(way_)s : %.cmm $(H_FILES)
386         $(HC) $(HC_OPTS) -S $< -o $@
387 endif
388
389 #-----------------------------------------------------------------------------
390 #
391 # Files to install
392 #
393 # Just libHSrts is installed uniformly across ways
394 #
395
396 include $(TOP)/mk/target.mk
397
398 ifeq "$(DYNAMIC_RTS) $(HOSTPLATFORM)" "YES i386-unknown-mingw32"
399 $(BASE_IMPORT_LIBRARY): $(LIBRARY).a
400         $(MAKE) -C ../libraries/ make.library.base
401 # just for the timestamps
402         touch $(BASE_IMPORT_LIBRARY)
403 endif
404
405 #-----------------------------------------------------------------------------
406 #
407 # binary-dist
408
409 binary-dist:
410         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/rts
411         $(INSTALL_DIR)                         $(BIN_DIST_DIR)/rts/gmp
412         $(INSTALL_DATA)    Makefile            $(BIN_DIST_DIR)/rts/
413         $(INSTALL_DATA)    package.conf.in     $(BIN_DIST_DIR)/rts/
414 ifneq "$(INSTALL_LIBS)" ""
415         $(INSTALL_DATA)    $(INSTALL_LIBS)     $(BIN_DIST_DIR)/rts/
416 endif
417 ifneq "$(INSTALL_LIBEXECS)" ""
418         $(INSTALL_PROGRAM) $(INSTALL_LIBEXECS) $(BIN_DIST_DIR)/rts/
419 endif