When building libraries, we need to register them if we use the "build" targets
[ghc-hetmet.git] / mk / paths.mk
1 ################################################################################
2 #
3 #                           paths.mk
4 #
5 #       This file defines Make variables for standard directories
6 #       and file lists
7 #
8 ################################################################################
9
10 ################################################################################
11 #
12 #               Standard variable names
13 #
14 ################################################################################
15 # The fptools mk setup defines a set of standard names which are used
16 # by the standard targets provided by mk. One example of this is the
17 # use of standard names for specifying what files to compile, their
18 # intermediate/object code, and the name of the final
19 # executable. Based on the settings of these variables, the standard
20 # targets will generate/expand rules that automatically compile and
21 # link your program.
22 #
23 # The general rules:
24 #
25 #   SRCS - sources, might be prefixed to indicate what type of source
26 #          they are.
27 #   OBJS - object files (possibly prefixed).
28 #
29 #   PROG - name of final executable
30 #
31 # We attempt to automatically devine the list of sources $(SRCS) to
32 # compile by looking in the current directory (and possibly other
33 # directories which may be specified by setting the $(ALL_DIRS)
34 # variable).  This is complicated by the fact that some files are
35 # derived from other files: eg. .hsc files give rise to -hsc.c and
36 # -hsc.h files, .ly files give rise to .hs files, and .hs files give
37 # rise to .hc files sometimes.
38
39 # So we figure out the sources in three stages: first figure out what
40 # sources we can find (this is $(ALL_SRCS)).  Then figure out all the
41 # "derived" sources (eg. A.hsc generates A.hs and A_hsc.c), and
42 # finally put all these together and remove duplicates (GNU make's
43 # handy sort function does the duplicate removing).
44
45 # HS_SRCS:   list of Haskell modules you want to compile.
46 #             (also use by depend rule).
47 # HS_OBJS:   list of corresponding object files
48 # HS_PROG:   program that is ultimately linked.
49 # HS_IFACES: list of interface files generated
50 #             (caveat: assuming no funny use of -hisuf and that
51 #               file name and module name match)
52
53 ALL_SRCS    = $(wildcard $(patsubst ./%, %,  \
54                    $(patsubst %,%/*.hs,   . $(ALL_DIRS)) \
55                    $(patsubst %,%/*.lhs,  . $(ALL_DIRS)) \
56                    $(patsubst %,%/*.hs-boot,  . $(ALL_DIRS)) \
57                    $(patsubst %,%/*.lhs-boot, . $(ALL_DIRS)) \
58                    $(patsubst %,%/*.y,    . $(ALL_DIRS)) \
59                    $(patsubst %,%/*.ly,   . $(ALL_DIRS)) \
60                    $(patsubst %,%/*.x,    . $(ALL_DIRS)) \
61                    $(patsubst %,%/*.c,    . $(ALL_DIRS)) \
62                    $(patsubst %,%/*.hc,   . $(ALL_DIRS)) \
63                    $(patsubst %,%/*.S,    . $(ALL_DIRS)) \
64                    $(patsubst %,%/*.prl,  . $(ALL_DIRS)) \
65                    $(patsubst %,%/*.lprl, . $(ALL_DIRS)) \
66                    $(patsubst %,%/*.lit,  . $(ALL_DIRS)) \
67                    $(patsubst %,%/*.verb, . $(ALL_DIRS)) \
68                    $(patsubst %,%/*.hsc,  . $(ALL_DIRS)) \
69                    $(patsubst %,%/*.gc,   . $(ALL_DIRS)) \
70                )) $(EXTRA_SRCS)
71
72 # ALL_SRCS is computed once and for all into PRE_SRCS at the top of
73 # target.mk.  Otherwise, we end up re-computing ALL_SRCS every time it
74 # is expanded (it is used in several variables below, and these
75 # variables are used in several others, etc.), which can really slow
76 # down make.
77
78 PRE_HS_SRCS  = $(filter %.hs,  $(PRE_SRCS))
79 PRE_LHS_SRCS = $(filter %.lhs, $(PRE_SRCS))
80
81 PRE_HS_BOOT_SRCS = $(filter %.hs-boot,  $(PRE_SRCS)) \
82                    $(filter %.lhs-boot, $(PRE_SRCS))
83
84 GC_SRCS       = $(filter %.gc,  $(PRE_SRCS))
85 HSC_SRCS      = $(filter %.hsc, $(PRE_SRCS))
86 HAPPY_Y_SRCS  = $(filter %.y,   $(PRE_SRCS))
87 HAPPY_LY_SRCS = $(filter %.ly,   $(PRE_SRCS))
88 HAPPY_SRCS    = $(HAPPY_Y_SRCS) $(HAPPY_LY_SRCS)
89 ALEX_SRCS     = $(filter %.x,   $(PRE_SRCS))
90
91 DERIVED_GC_SRCS       = $(patsubst %.gc, %.hs, $(GC_SRCS)) \
92                         $(patsubst %.gc, %_stub_ffi.c, $(GC_SRCS)) \
93                         $(patsubst %.gc, %_stub_ffi.h, $(GC_SRCS))
94
95 DERIVED_HSC_SRCS      = $(patsubst %.hsc, %.hs, $(HSC_SRCS)) \
96                         $(patsubst %.hsc, %_hsc.c, $(HSC_SRCS)) \
97                         $(patsubst %.hsc, %_hsc.h, $(HSC_SRCS)) \
98                         $(patsubst %.hsc, %.hc, $(HSC_SRCS))
99
100 DERIVED_HAPPY_SRCS    = $(patsubst %.y,   %.hs, $(HAPPY_Y_SRCS)) \
101                         $(patsubst %.ly,  %.hs, $(HAPPY_LY_SRCS))
102
103 DERIVED_ALEX_SRCS     = $(patsubst %.x,   %.hs, $(ALEX_SRCS))
104
105 DERIVED_HC_SRCS       = $(patsubst %.hs,  %.hc, $(PRE_HS_SRCS)) \
106                         $(patsubst %.lhs, %.hc, $(PRE_LHS_SRCS))
107
108 DERIVED_SRCS          = $(DERIVED_GC_SRCS) \
109                         $(DERIVED_HSC_SRCS) \
110                         $(DERIVED_HAPPY_SRCS) \
111                         $(DERIVED_ALEX_SRCS) \
112                         $(DERIVED_HC_SRCS)
113
114 # EXCLUDED_SRCS can be set in the Makefile, otherwise it defaults to empty.
115 EXCLUDED_GC_SRCS       = $(filter %.gc,  $(EXCLUDED_SRCS))
116 EXCLUDED_HSC_SRCS      = $(filter %.hsc, $(EXCLUDED_SRCS))
117 EXCLUDED_HAPPY_Y_SRCS  = $(filter %.y,   $(EXCLUDED_SRCS))
118 EXCLUDED_HAPPY_LY_SRCS = $(filter %.ly,  $(EXCLUDED_SRCS))
119 EXCLUDED_HAPPY_SRCS   = $(EXCLUDED_HAPPY_Y_SRCS) $(EXCLUDED_HAPPY_LY_SRCS)
120 EXCLUDED_ALEX_SRCS    = $(filter %.x,   $(EXCLUDED_SRCS))
121 EXCLUDED_HS_SRCS      = $(filter %.hs,  $(EXCLUDED_SRCS))
122 EXCLUDED_LHS_SRCS     = $(filter %.lhs, $(EXCLUDED_SRCS))
123 EXCLUDED_DERIVED_SRCS = $(patsubst %.hsc, %.hs, $(EXCLUDED_HSC_SRCS)) \
124                         $(patsubst %.hsc, %_hsc.h, $(EXCLUDED_HSC_SRCS)) \
125                         $(patsubst %.hsc, %_hsc.c, $(EXCLUDED_HSC_SRCS)) \
126                         $(patsubst %.hsc, %.hc, $(EXCLUDED_HSC_SRCS)) \
127                         $(patsubst %.gc,  %_stub_ffi.c, $(EXCLUDED_GC_SRCS)) \
128                         $(patsubst %.gc,  %_stub_ffi.h, $(EXCLUDED_GC_SRCS)) \
129                         $(patsubst %.y,   %.hs, $(EXCLUDED_HAPPY_Y_SRCS)) \
130                         $(patsubst %.ly,  %.hs, $(EXCLUDED_HAPPY_LY_SRCS)) \
131                         $(patsubst %.x,   %.hs, $(EXCLUDED_ALEX_SRCS)) \
132                         $(patsubst %.hs,  %.hc, $(EXCLUDED_HS_SRCS)) \
133                         $(patsubst %.lhs, %.hc, $(EXCLUDED_LHS_SRCS)) \
134                         $(patsubst %.hs,  %_stub.c, $(EXCLUDED_HS_SRCS)) \
135                         $(patsubst %.lhs, %_stub.c, $(EXCLUDED_LHS_SRCS))
136
137 # Exclude _hsc.c files; they get built as part of the cbits library,
138 # not part of the main library
139
140 CLOSED_EXCLUDED_SRCS  = $(sort $(EXCLUDED_SRCS) $(EXCLUDED_DERIVED_SRCS))
141
142 SRCS        = $(filter-out $(CLOSED_EXCLUDED_SRCS), \
143                 $(sort $(PRE_SRCS) $(DERIVED_SRCS)))
144
145 HS_SRCS     = $(filter %.lhs %.hs, $(sort $(SRCS) $(BOOT_SRCS)))
146 HS_OBJS     = $(addsuffix .$(way_)o,$(basename $(HS_SRCS)))
147 HS_IFACES   = $(addsuffix .$(way_)hi,$(basename $(HS_SRCS)))
148
149 HI_BOOTS    = $(patsubst %.hs-boot, %.$(way_)hi-boot, \
150               $(patsubst %.lhs-boot, %.$(way_)hi-boot, $(PRE_HS_BOOT_SRCS)))
151
152 O_BOOTS     = $(patsubst %.hs-boot, %.$(way_)o-boot, \
153               $(patsubst %.lhs-boot, %.$(way_)o-boot, $(PRE_HS_BOOT_SRCS)))
154
155 GC_C_OBJS   = $(addsuffix _stub_ffi.$(way_)o,$(basename $(filter %.gc,$(SRCS))))
156 HSC_C_OBJS  = $(addsuffix _hsc.$(way_)o,$(basename $(filter %.hsc,$(SRCS))))
157
158 ifeq "$(BootingFromHc)" "NO"
159 # We don't want to build the _stub.c files ourselves, unless we're
160 # bootstrapping from .hc files.
161 EXCLUDED_C_SRCS = $(patsubst %.lhs, %_stub.c, $(HS_SRCS)) \
162                   $(patsubst %.hs,  %_stub.c, $(HS_SRCS)) \
163                   $(patsubst %.gc, %_stub_ffi.c, $(GC_SRCS)) \
164                   $(patsubst %.gc, %_stub_ffi.h, $(GC_SRCS))
165 endif
166
167 # These are droppings from hsc2hs - ignore them if we see them.
168 EXCLUDED_C_SRCS += $(patsubst %.hsc, %_hsc_make.c, $(HSC_SRCS))
169
170 C_SRCS      = $(filter-out $(EXCLUDED_C_SRCS),$(filter %.c %.S,$(SRCS)))
171 C_OBJS      = $(addsuffix .$(way_)o,$(basename $(C_SRCS)))
172
173 # SCRIPT_SRCS:  list of raw script files (in literate form)
174 # SCRIPT_OBJS:  de-litted scripts
175 SCRIPT_SRCS = $(filter %.lprl,$(SRCS))
176 SCRIPT_OBJS = $(addsuffix .prl,$(basename $(SCRIPT_SRCS)))
177
178 OBJS        = $(HS_OBJS) $(C_OBJS) $(GC_C_OBJS) 
179
180 # The default is for $(LIBOBJS) to be the same as $(OBJS)
181 LIBOBJS     = $(OBJS)
182
183 #
184 # Note that as long as you use the standard variables for setting
185 # which C & Haskell programs you want to work on, you don't have
186 # to set any of the clean variables - the default should do the Right
187 # Thing.
188 #
189
190 #------------------------------------------------------------------
191 #
192 # make depend defaults
193 #
194 # The default set of files for the dependency generators to work on
195 # is just their source equivalents.
196 #
197
198 ifneq "$(BootingFromHc)" "YES"
199 MKDEPENDHS_SRCS=$(HS_SRCS)
200 else
201 MKDEPENDHS_SRCS=
202 endif
203
204 MKDEPENDC_SRCS=$(C_SRCS)
205
206 #------------------------------------------------------------------
207 #
208 # make TAGS defaults
209 #
210 # The default set of files for the TAGS file generators to work on
211 # is just their source equivalents.
212 #
213 TAGS_HS_SRCS=$(HS_SRCS)
214 TAGS_C_SRCS=$(C_SRCS)
215
216 #------------------------------------------------------------------
217 # Clean file make-variables.
218 #
219 # The following three variables are used to control
220 # what gets removed when doing `make clean'
221 #
222 # MOSTLYCLEAN_FILES   object code etc., but not stuff
223 #                     that is slow to recompile and/or stable
224 #
225 # CLEAN_FILES  all files that are created by running make.
226 #
227 # MAINTAINER_CLEAN_FILES also clean out machine-generated files
228 #                        that may require extra tools to create.
229 #
230 #
231 # NOTE: $(SCRIPT_OBJS) is not in MOSTLY_CLEAN_FILES, because in some
232 # places in the tree it appears that we have source files in $(SCRIPT_OBJS).
233 # Specifically glafp-utils/mkdependC/mkdependC.prl and others in driver/ and
234 # possibly others elsewhere in the tree.  ToDo: fix this properly.
235 MOSTLY_CLEAN_FILES += $(HS_OBJS) $(C_OBJS) $(HSC_C_OBJS) $(GC_C_OBJS)
236 CLEAN_FILES        += $(HS_PROG) $(C_PROG) $(SCRIPT_LINK) \
237                       $(PROG) $(LIBRARY) a.out \
238                       $(DERIVED_HSC_SRCS) \
239                       $(DERIVED_GC_SRCS) \
240                       $(patsubst %,%/*.$(way_)hi, . $(ALL_DIRS)) \
241                       $(HI_BOOTS) $(O_BOOTS)
242
243 # we delete *all* the .hi files we can find, rather than just
244 # $(HS_IFACES), because stale interfaces left around by modules which
245 # don't exist any more can screw up the build.
246
247 # Don't clean the .hc files if we're bootstrapping
248 ifneq "$(BootingFromHc)" "YES"
249 CLEAN_FILES += $(DERIVED_HC_SRCS)
250 endif
251
252 DIST_CLEAN_FILES        += .depend* *.hp *.prof
253
254 MAINTAINER_CLEAN_FILES  += $(BOOT_SRCS) $(DERIVED_HAPPY_SRCS) $(DERIVED_ALEX_SRCS)
255
256 #
257 # `Standard' set of files to clean out.
258 #
259 MOSTLY_CLEAN_FILES += \
260  *.CKP *.ln *.BAK *.bak .*.bak *.o core a.out errs ,* *.a .emacs_*  \
261  tags TAGS *.ind *.ilg *.idx *.idx-prev *.aux *.aux-prev *.dvi *.log \
262  *.toc *.lot *.lof *.blg *.cb *_stub.c *_stub.h *.raw_s *.a.list
263
264 #------------------------------------------------------------------
265
266 # Directory in which DLLs are dumped so as not to get picked up by running
267 # programs (e.g. ghc or hsc) that run in the build tree
268
269 DLL_PEN = $(FPTOOLS_TOP)/dll
270
271 #------------------------------------------------------------------
272 #
273 # Stylesheet for HTML generated from DocBook XML
274 #
275
276 FPTOOLS_CSS     = fptools.css
277 FPTOOLS_CSS_ABS = $(FPTOOLS_TOP)/mk/$(FPTOOLS_CSS)