target.mk 35.2 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#################################################################################
#
#			target.mk
#
#		Standard targets for fptools
#
#################################################################################

#
# This file contain three groups of target rules:
#
# 1.  FPtools targets
#	depend*
#	runtests*
#
# 2.  GNU standard targets
#	all*
#	install* uninstall installcheck installdirs
#	clean* distclean* mostlyclean* maintainer-clean*
#	tags*
rrt's avatar
rrt committed
21
#	dvi ps (no info) FPTOOLS adds: pdf rtf html
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#	check
#
# 3. Some of the above targets have a version that
#    recursively invokes that target in sub-directories.
#    This relies on the importing Makefile setting SUBDIRS
#
#    The recursive targets are marked with a * above
#

# 
# 
#


rrt's avatar
rrt committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
##################################################################
#
# 		Recursive stuff
#
# At the top of the file so that recursive makes happen before
# makes in the main directory. This is needed for some targets,
# e.g. when building DLLs in hslibs.
#
##################################################################

# Here are the diabolically clever rules that
# 
# (a) for each "recursive target" <t>
#     propagates "make <t>" to directories in SUBDIRS
#
# (b) when SUBDIRS is empty,
#     for each "multi-way-target" <t>
53
#     calls "make way=w <t>" for each w in $(WAYS)
rrt's avatar
rrt committed
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#
#     This has the effect of making the standard target
#     in each of the specified ways (as well as in the normal way

# Controlling variables
#	WAYS    = extra (beyond the normal way) ways to build things in
# 	SUBDIRS = subdirectories to recurse into

# No ways, so iterate over the SUBDIRS

# note about recursively invoking make: we'd like make to drop all the
# way back to the top level if it fails in any of the
# sub(sub-...)directories.  This is done by setting the -e flag to the
# shell during the loop, which causes an immediate failure if any of
# the shell commands fail.

# One exception: if the user gave the -i or -k flag to make in the
# first place, we'd like to reverse this behaviour.  So we check for
# these flags, and set the -e flag appropriately.  NOTE: watch out for
# the --no-print-directory flag which is passed to recursive
# invocations of make.
#
# NOTE: Truly weird use of exit below to stop the for loop dead in
# its tracks should any of the sub-makes fail. By my reckoning, 
#  "cmd || exit $?" should be equivalent to "cmd"

ifneq "$(SUBDIRS)" ""

82
83
# we override the boot & all targets in the top level Makefile
ifneq "$(NO_ALL_TARGETS)" "YES"
sebc's avatar
sebc committed
84
85
86
ALL_TARGET     = all
BOOT_TARGET    = boot
INSTALL_TARGET = install
87
88
endif

sebc's avatar
sebc committed
89
$(ALL_TARGET) docs runtests $(BOOT_TARGET) TAGS clean distclean mostlyclean maintainer-clean $(INSTALL_TARGET) html ps dvi txt::
rrt's avatar
rrt committed
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
	@echo "------------------------------------------------------------------------"
	@echo "===fptools== Recursively making \`$@' in $(SUBDIRS) ..."
	@echo "PWD = $(shell pwd)"
	@echo "------------------------------------------------------------------------"
# Don't rely on -e working, instead we check exit return codes from sub-makes.
	@case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
	for i in $(SUBDIRS); do \
	  echo "------------------------------------------------------------------------"; \
	  echo "==fptools== $(MAKE) $@ $(MFLAGS);"; \
	  echo " in $(shell pwd)/$$i"; \
	  echo "------------------------------------------------------------------------"; \
	  $(MAKE) --no-print-directory -C $$i $(MFLAGS) $@; \
	  if [ $$? -eq 0 -o $$x_on_err -eq 0 ] ;  then true; else exit 1; fi; \
	done
	@echo "------------------------------------------------------------------------"
	@echo "===fptools== Finished making \`$@' in $(SUBDIRS) ..."
	@echo "PWD = $(shell pwd)"
	@echo "------------------------------------------------------------------------"

endif

#
# Selectively building subdirectories.
#
#
ifneq "$(SUBDIRS)" ""
$(SUBDIRS) ::
	  $(MAKE) -C $@ $(MFLAGS)
endif

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
##################################################################
# 		FPtools standard targets
#
# depend:
#
#  The depend target has to cope with a set of files that may have
#  different ways of computing their dependencies, i.e., a Haskell
#  module's dependencies are computed differently from C files.
#
# Note that we don't compute dependencies automatically, i.e., have the
# .depend file be a target that is dependent on the Haskell+C sources,
# and then have the `depend' target depend on `.depend'. The reason for
# this is that when GNU make is processing the `include .depend' statement
# it records .depend as being a Makefile. Before doing any other processing,
# `make' will try to check to see if the Makefiles are up-to-date. And,
# surprisingly enough, .depend has a rule for it, so if any of the source
# files change, it will be invoked, *regardless* of what target you're making.
#
# So, for now, the dependencies has to be re-computed manually via `make depend'
# whenever a module changes its set of imports. Doing what was outlined above
# is only a small optimisation anyway, it would avoid the recomputation of
# dependencies if the .depend file was newer than any of the source modules.
#
.PHONY: depend

# Compiler produced files that are targets of the source's imports.
MKDEPENDHS_OBJ_SUFFICES=o

depend :: $(MKDEPENDHS_SRCS) $(MKDEPENDC_SRCS)
	@$(RM) .depend
	@touch .depend
ifneq "$(DOC_SRCS)" ""
	$(MKDEPENDLIT) -o .depend $(MKDEPENDLIT_OPTS) $(filter %.lit,$(DOC_SRCS))
endif
ifneq "$(MKDEPENDC_SRCS)" ""
	$(MKDEPENDC) -f .depend $(MKDEPENDC_OPTS) $(foreach way,$(WAYS),-s $(way)) -- $(CC_OPTS) -- $(MKDEPENDC_SRCS) 
endif
ifneq "$(MKDEPENDHS_SRCS)" ""
ken's avatar
ken committed
158
	$(MKDEPENDHS) -M -optdep-f -optdep.depend $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(MKDEPENDHS_OPTS) $(filter-out -split-objs, $(HC_OPTS)) $(MKDEPENDHS_SRCS)
159
160
161
endif


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
##################################################################
# 			boot
#
#  The boot target, at a minimum generates dependency information

.PHONY: boot
boot :: depend


##################################################################
# 		GNU Standard targets
#
#	Every Makefile should define the following targets
# 
# `all'
#      Compile the entire program. This should be the default target.
rrt's avatar
rrt committed
178
#      This target need not rebuild any documentation files
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# 
# `install'
#      Compile the program and copy the executables, libraries, and so on
#      to the file names where they should reside for actual use. If
#      there is a simple test to verify that a program is properly
#      installed, this target should run that test.
# 
#      The commands should create all the directories in which files are
#      to be installed, if they don't already exist. This includes the
#      directories specified as the values of the variables prefix and
#      exec_prefix , as well as all subdirectories that are needed. One
#      way to do this is by means of an installdirs target as described
#      below.
# 
#      Use `-' before any command for installing a man page, so that make
#      will ignore any errors.  This is in case there are systems that
#      don't have the Unix man page documentation system installed.
# 
# `uninstall'
#      Delete all the installed files that the `install' target would
#      create (but not the noninstalled files such as `make all' would
#      create).
# 
# `clean'
# 
#      Delete all files from the current directory that are normally
#      created by building the program.  Don't delete the files that
#      record the configuration. Also preserve files that could be made
#      by building, but normally aren't because the distribution comes
#      with them.
# 
#      Delete `.dvi' files here if they are not part of the
#      distribution.
# 
# `distclean'
#      Delete all files from the current directory that are created by
#      configuring or building the program. If you have unpacked the
#      source and built the program without creating any other files,
#      `make distclean' should leave only the files that were in the
#      distribution.
# 
# `mostlyclean'
#      Like `clean', but may refrain from deleting a few files that
#      people normally don't want to recompile. For example, the
#      `mostlyclean' target for GCC does not delete `libgcc.a', because
#      recompiling it is rarely necessary and takes a lot of time.
# 
# `maintainer-clean'
#      Delete everything from the current directory that can be
#      reconstructed with this Makefile.  This typically includes
#      everything deleted by distclean , plus more: C source files
rrt's avatar
rrt committed
230
#      produced by Bison, tags tables, and so on.
231
232
233
234
235
236
237
238
239
240
# 
#      One exception, however: `make maintainer-clean' should not delete
#      `configure' even if `configure' can be remade using a rule in the
#      Makefile. More generally, `make maintainer-clean' should not delete
#      anything that needs to exist in order to run `configure' and then
#      begin to build the program.
# 
# `TAGS'
#      Update a tags table for this program.
# 
rrt's avatar
rrt committed
241
242
243
244
# `dvi' `ps' `pdf' `html' `pdf'
#      Generate DVI/PS/PDF files for LaTeX/DocBook docs. Not everything is
#      supported everywhere, but the intention is to standardise on DocBook
#      producing all formats.
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#
# `check'
#      Perform self-tests (if any). The user must build the program
#      before running the tests, but need not install the program; you
#      should write the self-tests so that they work when the program is
#      built but not installed.
# 
# The following targets are suggested as conventional names, for programs
# in which they are useful.
# 
# installcheck
#      Perform installation tests (if any). The user must build and
#      install the program before running the tests. You should not
#      assume that `$(bindir)' is in the search path.
# 
# installdirs
#      It's useful to add a target named `installdirs' to create the
#      directories where files are installed, and their parent
#      directories. There is a script called `mkinstalldirs' which is
#      convenient for this; find it in the Texinfo package.
sof's avatar
sof committed
265
266
#      (FPTOOLS: we use a close relative of the suggested script, situated
#       in glafp-utils/mkdirhier -- SOF)
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295




###########################################
#
#	Targets: "all"
#
###########################################

# For each of these variables that is defined
# we generate one "all" rule and one rule for the variable itself:
#
#	HS_PROG		Haskell program
#	C_PROG		C program
#	LIBRARY		Library
#	SCRIPT_PROG	Script (e.g. Perl script)
#
# For details of exactly what rule is generated, see the
# relevant section below

.PHONY: all

#----------------------------------------
#	Haskell programs

ifneq "$(HS_PROG)" ""
all :: $(HS_PROG)

296
ifneq "$(BootingFromHc)" "YES"
297
$(HS_PROG) :: $(HS_OBJS)
298
299
300
301
302
303
	$(HC) -o $@ $(HC_OPTS) $(LD_OPTS) $(HS_OBJS)
else
# see bootstrp.mk
$(HS_PROG) :: $(HS_OBJS)
	$(CC) -o $@ $(HC_BOOT_CC_OPTS) $(HC_BOOT_LD_OPTS) $(HS_OBJS) $(HC_BOOT_LIBS)
endif
rrt's avatar
rrt committed
304

305
# for building a Haskell program, we add FptoolsHcOpts
rrt's avatar
rrt committed
306
SRC_HC_OPTS += $(FptoolsHcOpts)
rrt's avatar
rrt committed
307
endif
rrt's avatar
rrt committed
308

309
310
311
#----------------------------------------
#	C programs

rrt's avatar
rrt committed
312
313
314
ifneq "$(C_PROG)" ""
all :: $(C_PROG)

315
316
317
318
319
320
$(C_PROG) :: $(C_OBJS)
	$(CC) -o $@ $(CC_OPTS) $(LD_OPTS) $(C_OBJS) $(LIBS)
endif


#----------------------------------------
321
#	Building HsLibs libraries.
322
323
#
# Inputs:
rrt's avatar
rrt committed
324
#   $(PACKAGE) is the name of the library to build
325
326
327
328
#   $(IS_CBITS_LIB) should be "YES" for a "cbits" library
#
# Outputs:
#   $(LIBRARY)		the name of the library.a
rrt's avatar
rrt committed
329
#   $(GHIC_LIBRARY)	the name of the library.o (for GHCi)
330
331
332
333
334
335
#   $(LIBOBJS)		objects to put in library
#   $(STUBOBJS)		more objects to put in library
# 
# $(LIBOBJS) is set to $(HS_OBJS) or $(C_OBJS) depending
# on whether or not it's a "cbits" library.  But you can
# override this by setting $(LIBOBJS) yourself
336

rrt's avatar
rrt committed
337
ifneq "$(PACKAGE)" ""
338

339
340
341
342
# add syslib dependencies and current package name
SRC_HC_OPTS += -package-name $(PACKAGE)
SRC_HC_OPTS += $(patsubst %, -package %, $(PACKAGE_DEPS))

343
344
ifeq "$(IS_CBITS_LIB)" "YES"
_cbits := _cbits
rrt's avatar
rrt committed
345
346
STUBOBJS += $(HSC_C_OBJS)
# Add _hsc.c files to the cbits library
ken's avatar
ken committed
347
C_SRCS += $(wildcard ../*_hsc.c)
rrt's avatar
rrt committed
348
# Make .hsc.h include files from the directory above visible
sof's avatar
sof committed
349
350
# (and the cbits/ library too).
SRC_CC_OPTS += -I.. -I.
351
352
endif

rrt's avatar
rrt committed
353
354
LIBRARY      = libHS$(PACKAGE)$(_cbits)$(_way).a
GHCI_LIBRARY = HS$(PACKAGE)$(_cbits)$(_way).o
355
356
357
358
359

ifneq "$(IS_CBITS_LIB)" "YES"
WAYS=$(GhcLibWays)
endif

360
ifeq "$(LIBOBJS)" ""
361
  ifeq "$(IS_CBITS_LIB)" "YES"
362
  LIBOBJS = $(C_OBJS)
363
364
  else
  LIBOBJS = $(HS_OBJS)
365
366
  endif
endif
367

368
369
SRC_CC_OPTS += -I$(GHC_INCLUDE_DIR) -I$(GHC_RUNTIME_DIR)

370
ifeq "$(IS_CBITS_LIB)" "YES"
371
override datadir:=$(libdir)/include
rrt's avatar
rrt committed
372
INSTALL_DATAS += Hs$(shell perl -e 'print ucfirst "$(PACKAGE)"').h
373
374
else
SRC_CC_OPTS += -Icbits
375
endif
376

rrt's avatar
rrt committed
377
endif # PACKAGE
378
379
380

#----------------------------------------
#	Libraries/archives
381
#
ken's avatar
ken committed
382
# Build $(LIBRARY) from $(LIBOBJS)+$(STUBOBJS)
383
384
385
386
387
388
389
#
# Inputs:
#   $(LIBOBJS)
#   $(STUBOBJS)
#
# Outputs:
#   Rule to build $(LIBRARY)
390

391
392
393
394
395
ifneq "$(LIBRARY)" ""
all :: $(LIBRARY)

define BUILD_LIB
$(RM) $@
396
$(AR) $(AR_OPTS) $@ $(STUBOBJS) $(LIBOBJS)
397
398
399
400
401
402
403
404
405
406
407
$(RANLIB) $@
endef

#
# For Haskell object files, we might have chosen to split
# up the object files. Test for whether the library being
# built is consisting of Haskell files by (hackily) checking
# whether HS_SRCS is empty or not.
#

ifneq "$(HS_SRCS)" ""
rrt's avatar
rrt committed
408
ifeq "$(SplitObjs)" "YES"
409

410
411
412
# can't split objs in way 'u', so we disable it here
ifneq "$(way)" "u"

413
414
SRC_HC_OPTS += -split-objs

ken's avatar
ken committed
415
ifeq "$(ArSupportsInput)" ""
416
417
define BUILD_LIB
$(RM) $@
418
(echo $(STUBOBJS); $(FIND) $(patsubst %.$(way_)o,%,$(LIBOBJS)) -name '*.$(way_)o') | xargs ar q $@
419
420
$(RANLIB) $@
endef
ken's avatar
ken committed
421
422
423
424
425
426
427
428
429
430
else
define BUILD_LIB
$(RM) $@
echo $(STUBOBJS) > $@.list
$(FIND) $(patsubst %.$(way_)o,%,$(LIBOBJS)) -name '*.$(way_)o' >> $@.list
$(AR) $(AR_OPTS) $@ $(ArSupportsInput) $@.list
$(RM) $@.list
$(RANLIB) $@
endef
endif
431
432
433

# Extra stuff for compiling Haskell files with $(SplitObjs):

434
435
436
437
438
439
440
HC_SPLIT_PRE = \
    $(RM) $@; if [ ! -d $(basename $@) ]; then mkdir $(basename $@); else \
    $(FIND) $(basename $@) -name '*.$(way_)o' | xargs $(RM) __rm_food; fi
ifeq "$(GhcWithInterpreter)" "YES"
HC_SPLIT_POST = ld -r -x -o $@ $(basename $@)/*.$(way_)o
else
HC_SPLIT_POST = touch $@
441
endif # GhcWithInterpreter == YES
442

443
444
SRC_HC_PRE_OPTS  += $(HC_SPLIT_PRE);
SRC_HC_POST_OPTS += $(HC_SPLIT_POST);
445

446
447
448
449
450
451
#
# If (Haskell) object files are split, cleaning up 
# consist of descending into the directories where
# the myriads of object files have been put.
#

452
extraclean ::
453
454
	$(FIND) $(patsubst %.$(way_)o,%,$(HS_OBJS)) -name '*.$(way_)o' -print | xargs $(RM) __rm_food
	-rmdir $(patsubst %.$(way_)o,%,$(HS_OBJS)) > /dev/null 2>&1
455

456
endif # $(way) == u
457
endif # $(SplitObjs)
458
endif # $(HS_SRCS)
459

460
461
462
463
#
# Remove local symbols from library objects if requested.
#

464
ifeq "$(StripLibraries)" "YES"
rrt's avatar
rrt committed
465
ifeq "$(SplitObjs)" "YES"
466
467
468
469
470
471
472
SRC_HC_POST_OPTS += \
  for i in $(basename $@)/*; do \
	ld -r -x -o $$i.tmp $$i; \
	$(MV) $$i.tmp $$i; \
  done
else
SRC_HC_POST_OPTS += \
473
  ld -r -x -o $@.tmp $@; $(MV) $@.tmp $@
474
475
endif # SplitObjs
endif # StripLibraries
476

477
$(LIBRARY) :: $(STUBOBJS) $(LIBOBJS)
478
	$(BUILD_LIB)
479
endif # LIBRARY = ""
480

481
482
483
#--------------------------------------------------------------
#	Build dynamically-linkable libraries for GHCi
#
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# Build $(GHCI_LIBRARY) from $(LIBOBJS)+$(STUBOBJS)
#
# Why?  GHCi can only link .o files (at the moment), not .a files
# so we have to build libFoo.o as well as libFoo.a
#
# Furthermore, GHCi currently never loads 
# profiling libraries (or other non-std ways)
#
# Inputs:
#   $(GHCI_LIBRARY)
#
# Outputs:
#   Rule to build $(GHCI_LIBRARY)

498
499

ifneq "$(GHCI_LIBRARY)" ""
500
ifeq "$(way)" ""
501
502
ifeq "$(GhcWithInterpreter)" "YES"

503
504
505
506

INSTALL_LIBS += $(GHCI_LIBRARY)
CLEAN_FILES += $(GHCI_LIBRARY)

507
508
all :: $(GHCI_LIBRARY)

509
ifneq "$(GHCI_LIBRARY)" "HSstd.o"
510
511
512
513
# An annoying gotcha is that the Prelude is a bit special,
# for reasons described in ghc/lib/std/Makefile.
# So we only put in this standard rule for packages other than std
# The rule for the Prelude is in ghc/lib/std/Makefile
514
# We check for GHCI_LIBRARY being HSstd.o rather than
rrt's avatar
rrt committed
515
# PACKAGE being std, because we want to still use the boilerplate rule 
516
# for cbits.
517
518
$(GHCI_LIBRARY) :: $(LIBOBJS)
	ld -r -x -o $@ $(LIBOBJS) $(STUBOBJS)
519
520
endif

521
522
523
endif # GhcWithInterpreter
endif # way
endif # GHCI_LIBRARY
524
525


sof's avatar
sof committed
526
527
528
#----------------------------------------
#	Building Win32 DLLs
#
529
530

ifeq "$(DLLized)" "YES"
rrt's avatar
rrt committed
531
SRC_CC_OPTS += -DDLLized
532

rrt's avatar
rrt committed
533
ifneq "$(PACKAGE)" ""
534

rrt's avatar
rrt committed
535
SRC_BLD_DLL_OPTS += --export-all --output-def=HS$(PACKAGE)$(_cbits)$(_way).def DllVersionInfo.$(way_)o
rrt's avatar
rrt committed
536
537

ifneq "$(PACKAGE) $(IS_CBITS_LIB)" "std YES"
rrt's avatar
rrt committed
538
ifneq "$(PACKAGE)" "rts"
539
540
SRC_BLD_DLL_OPTS += -lHSstd_cbits_imp -L$(GHC_LIB_DIR)/std/cbits
SRC_BLD_DLL_OPTS += -lHSrts_$(way_)imp -L$(GHC_RUNTIME_DIR)
rrt's avatar
rrt committed
541
ifneq "$(PACKAGE)" "std"
542
543
544
545
546
  ifeq "$(IS_CBITS_LIB)" ""
  SRC_BLD_DLL_OPTS += -lHSstd_$(way_)imp -L$(GHC_LIB_DIR)/std 
  endif
endif
endif
rrt's avatar
rrt committed
547
548
endif

549
550
SRC_BLD_DLL_OPTS += -lgmp -L. -L$(GHC_RUNTIME_DIR)/gmp
ifeq "$(IS_CBITS_LIB)" ""
rrt's avatar
rrt committed
551
552
SRC_BLD_DLL_OPTS += $(patsubst %,-lHS%_$(way_)imp, $(PACKAGE_DEPS))
SRC_BLD_DLL_OPTS += $(patsubst %,-L../%, $(PACKAGE_DEPS))
553
554
endif
ifneq "$(HAS_CBITS)" ""
rrt's avatar
rrt committed
555
SRC_BLD_DLL_OPTS += -lHS$(PACKAGE)_cbits_imp -Lcbits
556
557
558
endif
SRC_BLD_DLL_OPTS += -lwsock32 -lwinmm

rrt's avatar
rrt committed
559
endif # PACKAGE != ""
560
561
562
563
564
565

SplitObjs = NO 

ifneq "$(LIBRARY)" ""

all :: DllVersionInfo.$(way_)o
sof's avatar
sof committed
566
567

ifeq "$(DLL_NAME)" ""
568
DLL_NAME = $(patsubst %.a,%.dll,$(subst lib,,$(LIBRARY)))
sof's avatar
sof committed
569
570
endif

rrt's avatar
rrt committed
571
ifneq "$(DLL_NAME)" ""
rrt's avatar
rrt committed
572
DLL_NAME := $(DLL_PEN)/$(DLL_NAME)
rrt's avatar
rrt committed
573
endif
rrt's avatar
rrt committed
574

sof's avatar
sof committed
575
576
all :: $(DLL_NAME)

sof's avatar
sof committed
577
ifeq "$(DLL_IMPLIB_NAME)" ""
578
DLL_IMPLIB_NAME = $(patsubst %.a,%_imp.a,$(LIBRARY))
sof's avatar
sof committed
579
580
endif

sof's avatar
sof committed
581
$(DLL_NAME) :: $(LIBRARY)
rrt's avatar
rrt committed
582
	$(BLD_DLL) --output-lib $(DLL_IMPLIB_NAME) -o $(DLL_NAME) $(LIBRARY) $(BLD_DLL_OPTS)
583
584
585
endif # LIBRARY != ""

endif # DLLized
sof's avatar
sof committed
586

sof's avatar
sof committed
587
588
589
590
591
592
#
# Version information is baked into a DLL by having the DLL include DllVersionInfo.o.
# The version info contains two user tweakables: DLL_VERSION and DLL_VERSION_NAME.
# (both are given sensible defaults though.)
#
# Note: this will not work as expected with Cygwin B20.1; you need a more recent
593
#       version of binutils (to pick up windres bugfixes.)
sof's avatar
sof committed
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622

ifndef DLL_VERSION
DLL_VERSION=$(ProjectVersion)
endif

ifndef DLL_VERSION_NAME
DLL_VERSION_NAME="http://www.haskell.org/ghc"
endif

ifndef DLL_DESCRIPTION
DLL_DESCRIPTION="A GHC-compiled DLL"
endif

ifndef EXE_VERSION
EXE_VERSION=$(ProjectVersion)
endif

ifndef EXE_VERSION_NAME
EXE_VERSION_NAME="http://www.haskell.org/ghc"
endif

ifndef EXE_DESCRIPTION
EXE_DESCRIPTION="A GHC-compiled binary"
endif

#
# Little bit of lo-fi mangling to get at the right set of settings depending
# on whether we're generating the VERSIONINFO for a DLL or EXE
# 
623
DLL_OR_EXE=$(subst VersionInfo.$(way_)rc,,$@)
sof's avatar
sof committed
624
625
626
627
628
VERSION_FT=$(subst Dll, 0x2L, $(subst Exe, 0x1L, $(DLL_OR_EXE)))
VERSION_RES_NAME=$(subst Exe,$(EXE_VERSION_NAME), $(subst Dll, $(DLL_VERSION_NAME),$(DLL_OR_EXE)))
VERSION_RES=$(subst Exe,$(EXE_VERSION), $(subst Dll, $(DLL_VERSION),$(DLL_OR_EXE)))
VERSION_DESC=$(subst Exe,$(EXE_DESCRIPTION), $(subst Dll, $(DLL_DESCRIPTION),$(DLL_OR_EXE)))

629
630
DllVersionInfo.$(way_)rc ExeVersionInfo.$(way_)rc:
	$(RM) DllVersionInfo.$(way_)rc
sof's avatar
sof committed
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
	echo "1 VERSIONINFO"  		    > $@
	echo "FILEVERSION 1,0,0,1"         >> $@
	echo "PRODUCTVERSION 1,0,0,1"      >> $@
	echo "FILEFLAGSMASK 0x3fL"         >> $@
	echo "FILEOS 0x4L"                 >> $@
	echo "FILETYPE $(VERSION_FT)"      >> $@
	echo "FILESUBTYPE 0x0L"            >> $@
	echo "BEGIN"                       >> $@
	echo " BLOCK \"StringFileInfo\""   >> $@
	echo " BEGIN"                      >> $@
	echo "  BLOCK \"040904B0\""        >> $@
	echo "  BEGIN"                     >> $@
	echo "   VALUE \"CompanyName\", \"$(VERSION_RES_NAME)\\0\"" >> $@
	echo "   VALUE \"FileVersion\", \"$(VERSION_RES)\\0\"" >> $@
	echo "   VALUE \"ProductVersion\", \"$(VERSION_RES)\\0\"" >> $@
	echo "   VALUE \"FileDescription\", \"$(VERSION_DESC)\\0\"" >> $@
	echo "  END" >> $@
	echo " END" >> $@
	echo " BLOCK \"VarFileInfo\""  >> $@
	echo " BEGIN" >> $@
	echo "  VALUE \"Translation\", 0x0409, 1200" >> $@
	echo " END" >> $@
	echo "END" >> $@

655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
#----------------------------------------
#	Script programs

ifneq "$(SCRIPT_PROG)" ""

# To produce a fully functional script, you may
# have to add some configuration variables at the top of 
# the script, i.e., the compiler driver needs to know
# the path to various utils in the build tree for instance.
#
# To have the build rule for the script automatically do this
# for you, set the variable SCRIPT_SUBST_VARS to the list of
# variables you need to put in.

#
# SCRIPT_SUBST creates a string of echo commands that
# will when evaluated append the (perl)variable name and its value 
# to the target it is used for, i.e.,
#
#    A=foo
#    B=bar
#    SCRIPT_SUBST_VARS = A B
#    SCRIPT_SUBST=echo "$""A=\"foo\";" >> $@; echo "$""B=\"bar\";" >> $@
#
#    so if you have a rule like the following
#    
#     foo:
#         @(RM) $@
#         @(TOUCH) $@
#         @eval $(SCRIPT_SUBST)
#
#    `make foo' would create a file `foo' containing the following
#
#    % cat foo
#    $A=foo;
#    $B=bar;
#    %
#
# ToDo: make this work for shell scripts (drop the initial $).
#
695
696
697
ifeq "$(INTERP)" "$(SHELL)"
SCRIPT_SUBST=$(foreach val,$(SCRIPT_SUBST_VARS),"echo \"$(val)=\\\"$($(val))\\\";\" >> $@;")
else
698
SCRIPT_SUBST=$(foreach val,$(SCRIPT_SUBST_VARS),"echo \"$$\"\"$(val)=\\\"$($(val))\\\";\" >> $@;")
699
endif
700
701
702

all :: $(SCRIPT_PROG)

703
$(SCRIPT_PROG) : $(SCRIPT_OBJS)
704
705
	$(RM) $@
	@echo Creating $@...
sof's avatar
sof committed
706
ifeq "$(INTERP)" "perl"
sof's avatar
sof committed
707
	echo "#! "$(PERL) > $@
sof's avatar
sof committed
708
else
709
710
711
712
713
ifneq "$(INTERP)" ""
	@echo "#!"$(INTERP) > $@
else
	@touch $@
endif
sof's avatar
sof committed
714
endif
715
716
717
ifneq "$(SCRIPT_PREFIX_FILES)" ""
	@cat $(SCRIPT_PREFIX_FILES) >> $@
endif
718
ifneq "$(SCRIPT_SUBST)" ""
719
	@eval $(SCRIPT_SUBST) 
720
endif
721
722
	@cat $(SCRIPT_OBJS) >> $@
	@chmod a+x $@
sof's avatar
sof committed
723
	@echo Done.
724
725
endif

726
727
# ---------------------------------------------------------------------------
# Symbolic links
728

729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# links to programs: we sometimes install a program as
# <name>-<version> with a link from <name> to the real program.

ifneq "$(LINK)" ""

all :: $(LINK)

CLEAN_FILES += $(LINK)

ifeq "$(LINK_TARGET)" ""
ifneq "$(SCRIPT_PROG)" ""
LINK_TARGET = $(SCRIPT_PROG)
else
ifneq "$(HS_PROG)" ""
LINK_TARGET = $(HS_PROG)
else
ifneq "$(C_PROG)" ""
LINK_TARGET = $(C_PROG)
else
LINK_TARGET = dunno
endif
endif
endif
endif
753

sof's avatar
sof committed
754
#
755
# Don't want to overwrite $(LINK)s that aren't symbolic
756
# links. Testing for symbolic links is problematic to do in
sof's avatar
sof committed
757
758
759
# a portable fashion using a /bin/sh test, so we simply rely
# on perl.
#
760
761
762
763
764
$(LINK) : $(LINK_TARGET)
	@if ( $(PERL) -e '$$fn="$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
	   echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK)"; \
	   $(RM) $(LINK); \
	   $(LN_S) $(LINK_TARGET) $(LINK); \
sof's avatar
sof committed
765
	 else \
766
767
768
769
770
771
772
773
774
775
	   echo "Creating a symbolic link from $(LINK_TARGET) to $(LINK) failed: \`$(LINK)' already exists"; \
	   echo "Perhaps remove \`$(LINK)' manually?"; \
	   exit 1; \
	 fi;


#
# install links to script drivers.
#
install ::
chak's avatar
chak committed
776
	@$(INSTALL_DIR) $(bindir)
777
778
779
780
781
782
783
	@if ( $(PERL) -e '$$fn="$(bindir)/$(LINK)"; exit ((! -f $$fn || -l $$fn) ? 0 : 1);' ); then \
	   echo "Creating a symbol link from $(LINK_TARGET) to $(LINK) in $(bindir)"; \
	   $(RM) $(bindir)/$(LINK); \
	   $(LN_S) $(LINK_TARGET) $(bindir)/$(LINK); \
	 else \
	   echo "Creating a symbol link from $(LINK_TARGET) to $(LINK) in $(bindir) failed: \`$(bindir)/$(LINK)' already exists"; \
	   echo "Perhaps remove \`$(bindir)/$(LINK)' manually?"; \
sof's avatar
sof committed
784
785
	   exit 1; \
	 fi;
786

787
endif # LINK 
788

sof's avatar
sof committed
789

790
791
792
793
794
795
796
797
798
###########################################
#
#	Targets: install install-strip uninstall
#
###########################################

# For each of these variables that is defined, you
# get one install rule
#
sof's avatar
sof committed
799
800
801
802
803
804
#	INSTALL_PROGS 	     executable programs in $(bindir)
#	INSTALL_SCRIPTS	     executable scripts in $(bindir)
#	INSTALL_LIBS	     platform-dependent libraries in $(libdir) (ranlib'ed)
#	INSTALL_LIB_SCRIPTS  platform-dependent scripts   in $(libdir)
#	INSTALL_LIBEXECS     platform-dependent execs in $(libdir)
#	INSTALL_DATAS	     platform-independent files in $(datadir)
805
806
807
808
809
810
811
812
#
# If the installation directory variable is undefined, the install rule simply
# emits a suitable error message.
#
# Remember, too, that the installation directory variables ($(bindir) and
# friends can be overridden from their original settings in mk/config.mk.in
# || mk/build.mk
#
sof's avatar
sof committed
813
814
815
816
817
818
819
.PHONY: install installdirs install-strip install-dirs uninstall install-docs show-install

show-install :
	@echo "bindir = $(bindir)"
	@echo "libdir = $(libdir)"
	@echo "libexecdir = $(libexecdir)  # by default, same as libdir"
	@echo "datadir = $(datadir)  # unused for ghc project"
820
821
822
823
824

#
# Sometimes useful to separate out the creation of install directories 
# from the installation itself.
#
sof's avatar
sof committed
825
install-dirs ::
sof's avatar
sof committed
826
827
828
829
	@$(INSTALL_DIR) $(bindir)
	@$(INSTALL_DIR) $(libdir)
	@$(INSTALL_DIR) $(libexecdir)
	@$(INSTALL_DIR) $(datadir)
830
831

# Better do this first...
sof's avatar
sof committed
832
833
834
# but we won't for the moment, do it on-demand from
# within the various install targets instead.
#install:: install-dirs
835

836
837
838
839
840
841
842
843
844
845
# Install libraries automatically
ifneq "$(LIBRARY)" ""
INSTALL_LIBS  += $(LIBRARY)
ifeq "$(DLLized)" "YES"
INSTALL_PROGS += $(DLL_NAME)
INSTALL_LIBS += $(patsubst %.a,%_imp.a, $(LIBRARY))
endif
INSTALL_DATAS += $(HS_IFACES)
endif

846
ifneq "$(INSTALL_PROGS)" ""
sof's avatar
sof committed
847
848
849
850
851
852
853
854
855
856
857

#
# Here's an interesting one - when using the win32 version
# of install (provided via the cygwin toolkit), we have to
# supply the .exe suffix, *if* there's no other suffix.
#
# The rule below does this by ferreting out the suffix of each
# entry in the INSTALL_PROGS list. If there's no suffix, use
# $(exeext).
# 
# This is bit of a pain to express since GNU make doesn't have
858
859
# something like $(if ...), but possible using $(subst ...)
# [Aside: I added support for $(if ...) to my local copy of GNU
sof's avatar
sof committed
860
# make at one stage, perhaps I should propagate the patch to
861
# the GNU make maintainers...] 
sof's avatar
sof committed
862
863
864
#
INSTALL_PROGS := $(foreach p, $(INSTALL_PROGS), $(addsuffix $(subst _,,$(subst __,$(exeext),_$(suffix $(p))_)), $(basename $(p))))

865
install:: $(INSTALL_PROGS)
sof's avatar
sof committed
866
	@$(INSTALL_DIR) $(bindir)
sof's avatar
sof committed
867
	@for i in $(INSTALL_PROGS); do \
sof's avatar
sof committed
868
		    echo $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(bindir); \
sof's avatar
sof committed
869
		    $(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(bindir) ;  \
sof's avatar
sof committed
870
	done
sof's avatar
sof committed
871
872
endif

sof's avatar
sof committed
873
874
875
876
#
# Just like INSTALL_PROGS, but prefix with install sites bin/lib/data and
# install without stripping.
#
sof's avatar
sof committed
877
878
ifneq "$(INSTALL_SCRIPTS)" ""
install:: $(INSTALL_SCRIPTS)
sof's avatar
sof committed
879
	@$(INSTALL_DIR) $(bindir)
sof's avatar
sof committed
880
	for i in $(INSTALL_SCRIPTS); do \
881
		$(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(bindir); \
sof's avatar
sof committed
882
883
884
885
886
	done
endif

ifneq "$(INSTALL_LIB_SCRIPTS)" ""
install:: $(INSTALL_LIB_SCRIPTS)
sof's avatar
sof committed
887
	@$(INSTALL_DIR) $(libdir)
888
	for i in $(INSTALL_LIB_SCRIPTS); do \
889
		$(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(libdir); \
sof's avatar
sof committed
890
	done
sof's avatar
sof committed
891
endif
892

893
894
ifneq "$(INSTALL_LIBEXEC_SCRIPTS)" ""
install:: $(INSTALL_LIBEXEC_SCRIPTS)
sof's avatar
sof committed
895
	@$(INSTALL_DIR) $(libexecdir)
896
	for i in $(INSTALL_LIBEXEC_SCRIPTS); do \
897
		$(INSTALL_SCRIPT) $(INSTALL_OPTS) $$i $(libexecdir); \
898
899
900
	done
endif

901
902
ifneq "$(INSTALL_LIBS)" ""
install:: $(INSTALL_LIBS)
sof's avatar
sof committed
903
	@$(INSTALL_DIR) $(libdir)
sof's avatar
sof committed
904
	for i in $(INSTALL_LIBS); do \
sof's avatar
sof committed
905
906
907
		case $$i in \
		  *.a) \
		    $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(libdir); \
908
		    $(RANLIB) $(libdir)/`basename $$i` ;; \
sof's avatar
sof committed
909
910
		  *.dll) \
		    $(INSTALL_DATA) -s $(INSTALL_OPTS) $$i $(libdir) ;; \
sof's avatar
sof committed
911
912
913
		  *) \
		    $(INSTALL_DATA) $(INSTALL_OPTS) $$i $(libdir); \
		esac; \
sof's avatar
sof committed
914
	done
915
916
917
endif

ifneq "$(INSTALL_LIBEXECS)" ""
sof's avatar
sof committed
918
919
920
921
922
923
#
# See above comment next to defn of INSTALL_PROGS for what
# the purpose of this one-liner is.
# 
INSTALL_LIBEXECS := $(foreach p, $(INSTALL_LIBEXECS), $(addsuffix $(subst _,,$(subst __,$(exeext),_$(suffix $(p))_)), $(basename $(p))))

924
install:: $(INSTALL_LIBEXECS)
sof's avatar
sof committed
925
	@$(INSTALL_DIR) $(libexecdir)
sof's avatar
sof committed
926
	-for i in $(INSTALL_LIBEXECS); do \
sof's avatar
sof committed
927
		$(INSTALL_PROGRAM) $(INSTALL_BIN_OPTS) $$i $(libexecdir); \
sof's avatar
sof committed
928
	done
929
930
931
932
endif

ifneq "$(INSTALL_DATAS)" ""
install:: $(INSTALL_DATAS)
sof's avatar
sof committed
933
	@$(INSTALL_DIR) $(datadir)
sof's avatar
sof committed
934
935
936
	for i in $(INSTALL_DATAS); do \
		$(INSTALL_DATA) $(INSTALL_OPTS) $$i $(datadir); \
	done
937
938
endif

939
940
941
942
943
944
945
946
ifneq "$(INSTALL_INCLUDES)" ""
install:: $(INSTALL_INCLUDES)
	@$(INSTALL_DIR) $(includedir)
	for i in $(INSTALL_INCLUDES); do \
		$(INSTALL_DATA) $(INSTALL_OPTS) $$i $(includedir); \
	done
endif

947
948
949
950
#
# Use with care..
#
uninstall:: 
sof's avatar
sof committed
951
952
	@for i in $(INSTALL_PROGS) "" ; do			\
	  if test "$$i"; then 					\
953
954
		echo rm -f $(bindir)/`basename $$i`;		\
		rm -f $(bindir)/`basename $$i`;			\
sof's avatar
sof committed
955
	  fi; 							\
956
	done
sof's avatar
sof committed
957
958
	@for i in $(INSTALL_LIBS) ""; do			\
	  if test "$$i"; then 					\
959
960
		echo rm -f $(libdir)/`basename $$i`;		\
		rm -f $(libdir)/`basename $$i`;			\
sof's avatar
sof committed
961
	  fi;							\
962
	done
sof's avatar
sof committed
963
964
	@for i in $(INSTALL_LIBEXECS) ""; do			\
	  if test "$$i"; then 					\
965
966
		echo rm -f $(libexecdir)/`basename $$i`;	\
		rm -f $(libexecdir)/`basename $$i`;		\
sof's avatar
sof committed
967
	  fi;							\
968
	done
sof's avatar
sof committed
969
970
	@for i in $(INSTALL_DATAS) ""; do			\
	  if test "$$i"; then 					\
971
972
		echo rm -f $(datadir)/`basename $$i`;		\
		rm -f $(datadir)/`basename $$i`;		\
sof's avatar
sof committed
973
	  fi;							\
974
975
976
977
978
979
980
981
982
983
	done

#
# install-strip is from the GNU Makefile standard.
#
ifneq "$(way)" ""
install-strip::
	@$(MAKE) EXTRA_INSTALL_OPTS='-s' install                                	
endif

984
##############################################################################
985
#
rrt's avatar
rrt committed
986
#	Targets: check tags show
987
#
988
##############################################################################
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005

#------------------------------------------------------------
# 			Check

.PHONY: check

check:: $(TESTS)
	@for i in $(filter-out %.lhs .hs, $(TESTS)) ''; do	\
	  if (test -f "$$i"); then 		\
	    echo Running: `basename $$i` ;	\
	    cd test; `basename $$i` ;		\
	  fi;					\
	done;

#------------------------------------------------------------
# 			Tags

sof's avatar
sof committed
1006
.PHONY: TAGS tags
1007

sof's avatar
sof committed
1008
tags TAGS:: $(TAGS_HS_SRCS) $(TAGS_C_SRCS)
1009
1010
	@$(RM) TAGS
	@touch TAGS
sof's avatar
sof committed
1011
ifneq "$(TAGS_HS_SRCS)" ""
sof's avatar
sof committed
1012
	$(HSTAGS) $(HSTAGS_OPTS) -- $(TAGS_HS_SRCS)
1013
endif
sof's avatar
sof committed
1014
ifneq "$(TAGS_C_SRCS)" ""
sof's avatar
sof committed
1015
	etags -a $(TAGS_C_SRCS)
1016
endif
sof's avatar
sof committed
1017
	@( DEREFFED=`ls -l Makefile | sed -e 's/.*-> \(.*\)/\1/g'` && $(RM) `dirname $$DEREFFED`/TAGS && $(CP) TAGS `dirname $$DEREFFED` ) 2>/dev/null || echo TAGS file generated, perhaps copy over to source tree?
1018
1019
1020
1021
1022
1023
1024
1025

#------------------------------------------------------------
# 			Makefile debugging
# to see the effective value used for a Makefile variable, do
#  make show VALUE=MY_VALUE
#

show:
1026
	@echo '$(VALUE)="$($(VALUE))"'
1027

1028
################################################################################
1029
#
1030
1031
1032
1033
#			SGML Documentation
#
################################################################################

1034
.PHONY: dvi ps html pdf rtf
1035

1036
1037
1038
1039
1040
ifneq "$(SGML_DOC)" ""

# multi-file SGML document: main document name is specified in $(SGML_DOC),
# sub-documents (.sgml files) listed in $(SGML_SRCS).

1041
ifeq "$(SGML_SRCS)" ""
1042
SGML_SRCS = $(wildcard *.sgml)
1043
endif
1044

chak's avatar
chak committed
1045
1046
1047
1048
1049
1050
SGML_TEX  = $(addsuffix .tex,$(SGML_DOC))
SGML_DVI  = $(addsuffix .dvi,$(SGML_DOC))
SGML_PS   = $(addsuffix .ps,$(SGML_DOC))
SGML_PDF  = $(addsuffix .pdf,$(SGML_DOC))
SGML_RTF  = $(addsuffix .rtf,$(SGML_DOC))
SGML_HTML = $(addsuffix .html,$(SGML_DOC))
1051
# HTML output goes in a subdirectory on its own.
chak's avatar
chak committed
1052
SGML_TEXT = $(addsuffix .txt,$(SGML_DOC))
1053

sof's avatar
sof committed
1054
$(SGML_DVI) $(SGML_PS) $(SGML_HTML) $(SGML_TEXT) $(SGML_PDF) :: $(SGML_SRCS)
1055

1056
1057
dvi  :: $(SGML_DVI)
ps   :: $(SGML_PS)
1058
1059
1060
pdf  :: $(SGML_PDF)
rtf  :: $(SGML_RTF)
html :: $(SGML_HTML)
1061
txt  :: $(SGML_TEXT)
1062

1063
CLEAN_FILES += $(SGML_TEXT) $(SGML_TEX) $(SGML_PS) $(SGML_DVI) $(SGML_PDF) $(SGML_RTF) $(SGML_HTML) $(SGML_DOC)-*.html
1064
# can't use $(SGML_SRCS) here, it was maybe used elsewhere
1065

1066
extraclean ::
1067
1068
	$(RM) -rf DBTOHTML_OUTPUT_*
	$(RM) -rf *.junk/
1069
	$(RM) -rf $(SGML_DOC)
1070
endif
1071

1072
##############################################################################
1073
1074
1075
#
#	Targets: clean
#
1076
##############################################################################
1077

1078
1079
1080
1081
# we have to be careful about recursion here; since all the clean
# targets are recursive, we don't want to make eg. distclean depend on
# clean because that would result in far too many recursive calls.

1082
.PHONY: mostlyclean clean distclean maintainer-clean
1083
1084
1085
1086

mostlyclean::
	rm -f $(MOSTLY_CLEAN_FILES)

1087
1088
# extraclean is used for adding actions to the clean target.
extraclean::
1089

1090
1091
1092
1093
1094
clean:: extraclean
	rm -f $(MOSTLY_CLEAN_FILES) $(CLEAN_FILES)

distclean:: extraclean
	rm -f $(MOSTLY_CLEAN_FILES) $(CLEAN_FILES) $(DIST_CLEAN_FILES)
1095

1096
maintainer-clean:: extraclean
1097
1098
	@echo 'This command is intended for maintainers to use; it'
	@echo 'deletes files that may need special tools to rebuild.'
1099
	rm -f $(MOSTLY_CLEAN_FILES) $(CLEAN_FILES) $(DIST_CLEAN_FILES) $(MAINTAINER_CLEAN_FILES)
1100

1101
################################################################################
1102
1103
1104
#
#			Way management
#
1105
################################################################################
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142

# Here is the ingenious jiggery pokery that allows you to build multiple versions
# of a program in a single build tree.
#
# The ways setup requires the following variables to be set:
#
# Expects:	$(WAYS)			the possible "way" strings to one of 
#					which $(way) will be set


# So how does $(way) ever get set to anything?  Answer, we recursively
# invoke make, setting $(way) on the command line.
# When do we do this recursion?  Answer: whenever the programmer
# asks make to make a target that involves a way suffix.
# We must remember *not* to recurse again; but that's easy: we
# just see if $(way) is set:

ifeq "$(way)" ""

# If $(WAYS) = p mc, then WAY_TARGETS expands to
#	%.p_lhs %.p_hs %.p_o ... %.mc_lhs %.p_hs ...
# and OTHER_WAY_TARGETS to
#	%_p.a %_p %_mc.a %_mc
# where the suffixes are from $(SUFFIXES)
#
# We have to treat libraries and "other" targets differently, 
# because their names are of the form
#	libHS_p.a and Foo_p
# whereas everything else has names of the form
#	Foo.p_o

FPTOOLS_SUFFIXES := o hi hc

WAY_TARGETS     = $(foreach way,$(WAYS),$(foreach suffix, $(FPTOOLS_SUFFIXES), %.$(way)_$(suffix)))
LIB_WAY_TARGETS = $(foreach way,$(WAYS),%_$(way).a %_$(way))

# $@ will be something like Foo.p_o
sof's avatar
sof committed
1143
1144
1145
1146
1147
# $(suffix $@)     returns .p_o
# $(subst .,.p_o)  returns p_o
# $(subst _,.,p_o) returns p.o   (clever)
# $(basename p.o)  returns p
# 
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
$(WAY_TARGETS) :
	$(MAKE) way=$(basename $(subst _,.,$(subst .,,$(suffix $@)))) $@

# $(@F) will be something like libHS_p.a, or Foo_p
# $(basename $(@F)) will be libHS_p, or Foo_p
# The sed script extracts the "p" part.

$(LIB_WAY_TARGETS) :
	$(MAKE) $(MFLAGS) $@ way=$(subst .,,$(suffix $(subst _,.,$(basename $@))))

endif	# if way
1159

1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
# -------------------------------------------------------------------------
# Object and interface files have suffixes tagged with their ways

ifneq "$(way)" ""
SRC_HC_OPTS += -hisuf $(way_)hi -hcsuf $(way_)hc -osuf $(way_)o
endif

# -------------------------------------------------------------------------
# Rules to invoke the current target recursively for each way

1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
ifneq "$(WAYS)" ""
ifeq "$(way)" ""

# NB: the targets exclude 
#	boot runtests
# since these are way-independent
all docs TAGS clean distclean mostlyclean maintainer-clean install ::
	@echo "------------------------------------------------------------------------"
	@echo "===fptools== Recursively making \`$@' for ways: $(WAYS) ..."
	@echo "PWD = $(shell pwd)"
	@echo "------------------------------------------------------------------------"
# Don't rely on -e working, instead we check exit return codes from sub-makes.
	@case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
	for i in $(WAYS) ; do \
	  echo "------------------------------------------------------------------------"; \
	  echo "==fptools== $(MAKE) way=$$i $@;"; \
	  echo "PWD = $(shell pwd)"; \
	  echo "------------------------------------------------------------------------"; \
	  $(MAKE) way=$$i --no-print-directory $(MFLAGS) $@ ; \
	  if [ $$? -eq 0 ] ; then true; else exit $$x_on_err; fi; \
	done
	@echo "------------------------------------------------------------------------"
	@echo "===fptools== Finished recursively making \`$@' for ways: $(WAYS) ..."
	@echo "PWD = $(shell pwd)"
	@echo "------------------------------------------------------------------------"

endif
endif