forked from haskell/cabal
/
GHCMakefile.in
154 lines (119 loc) · 4.18 KB
/
GHCMakefile.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
82
83
84
85
86
87
88
89
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
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
# -----------------------------------------------------------------------------
# Makefile template starts here.
GHC_OPTS += -i$(odir)
# For adding options on the command-line
GHC_OPTS += $(EXTRA_HC_OPTS)
WAY_p_OPTS = -prof
ifneq "$(way)" ""
way_ := $(way)_
_way := _$(way)
GHC_OPTS += $(WAY_$(way)_OPTS)
GHC_OPTS += -hisuf $(way_)hi -hcsuf $(way_)hc -osuf $(osuf)
endif
osuf = $(way_)o
hisuf = $(way_)hi
HS_OBJS = $(patsubst %,$(odir)/%.$(osuf),$(subst .,/,$(modules)))
HS_IFS = $(patsubst %,$(odir)/%.$(hisuf),$(subst .,/,$(modules)))
C_OBJS = $(patsubst %.c,$(odir)/%.$(osuf),$(C_SRCS))
LIB = $(odir)/libHS$(package)$(_way).a
RM = rm -f
# Optionally include local customizations:
-include Makefile.local
# Rules follow:
MKSTUBOBJS = find $(odir) -name "*_stub.$(osuf)" -print
# HACK ^^^ we tried to use $(wildcard), but apparently it fails due to
# make using cached directory contents, or something.
all :: .depend $(LIB)
.depend : $(MAKEFILE)
$(GHC) -M -optdep-f -optdep.depend $(foreach way,$(WAYS),-optdep-s -optdep$(way)) $(foreach obj,$(MKDEPENDHS_OBJ_SUFFICES),-osuf $(obj)) $(filter-out -split-objs, $(GHC_OPTS)) $(modules)
for dir in $(sort $(foreach mod,$(HS_OBJS) $(C_OBJS),$(dir $(mod)))); do \
if test ! -d $$dir; then mkdir -p $$dir; fi \
done
include .depend
ifneq "$(filter -split-objs, $(GHC_OPTS))" ""
$(LIB) : $(HS_OBJS) $(C_OBJS)
@$(RM) $@
(echo $(C_OBJS) `$(MKSTUBOBJS)`; find $(patsubst %.$(osuf),%_split,$(HS_OBJS)) -name '*.$(way_)o' -print) | xargs -s 30000 $(AR) q $(EXTRA_AR_ARGS) $@
else
$(LIB) : $(HS_OBJS) $(C_OBJS)
@$(RM) $@
echo $(C_OBJS) $(HS_OBJS) `$(MKSTUBOBJS)` | xargs -s 30000 $(AR) q $(EXTRA_AR_ARGS) $@
endif
ifneq "$(GHCI_LIB)" ""
ifeq "$(way)" ""
all :: $(GHCI_LIB)
$(GHCI_LIB) : $(HS_OBJS) $(C_OBJS)
@$(RM) $@
$(LD) -r -x -o $@ $(EXTRA_LD_OPTS) $(HS_OBJS) `$(MKSTUBOBJS)` $(C_OBJS)
endif
endif
# suffix rules
ifneq "$(odir)" ""
odir_ = $(odir)/
else
odir_ =
endif
$(odir_)%.$(osuf) : $(srcdir)/%.hs
$(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(hisuf)
$(odir_)%.$(osuf) : $(srcdir)/%.lhs
$(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(hisuf)
# The .hs files might be in $(odir) if they were preprocessed
$(odir_)%.$(osuf) : $(odir_)%.hs
$(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(hisuf)
$(odir_)%.$(osuf) : $(odir_)%.lhs
$(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(hisuf)
$(odir_)%.$(osuf) : $(srcdir)/%.c
@$(RM) $@
$(GHC) $(GHC_CC_OPTS) -c $< -o $@
$(odir_)%.$(osuf) : $(srcdir)/%.$(way_)s
@$(RM) $@
$(GHC) $(GHC_CC_OPTS) -c $< -o $@
$(odir_)%.$(osuf) : $(srcdir)/%.S
@$(RM) $@
$(GHC) $(GHC_CC_OPTS) -c $< -o $@
$(odir_)%.$(way_)s : $(srcdir)/%.c
@$(RM) $@
$(GHC) $(GHC_CC_OPTS) -S $< -o $@
$(odir_)%.$(osuf)-boot : $(srcdir)/%.hs-boot
$(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi-boot
$(odir_)%.$(osuf)-boot : $(srcdir)/%.lhs-boot
$(GHC) $(GHC_OPTS) -c $< -o $@ -ohi $(basename $@).$(way_)hi-boot
%.$(hisuf) : %.$(osuf)
@if [ ! -f $@ ] ; then \
echo Panic! $< exists, but $@ does not.; \
exit 1; \
else exit 0 ; \
fi
%.$(way_)hi-boot : %.$(osuf)-boot
@if [ ! -f $@ ] ; then \
echo Panic! $< exists, but $@ does not.; \
exit 1; \
else exit 0 ; \
fi
$(odir_)%.$(hisuf) : %.$(way_)hc
@if [ ! -f $@ ] ; then \
echo Panic! $< exists, but $@ does not.; \
exit 1; \
else exit 0 ; \
fi
show:
@echo '$(VALUE)="$($(VALUE))"'
clean ::
$(RM) $(HS_OBJS) $(C_OBJS) $(LIB) $(GHCI_LIB) $(HS_IFS) .depend
$(RM) -rf $(wildcard $(patsubst %.$(osuf), %_split, $(HS_OBJS)))
$(RM) $(wildcard $(patsubst %.$(osuf), %.o-boot, $(HS_OBJS)))
$(RM) $(wildcard $(patsubst %.$(osuf), %.hi-boot, $(HS_OBJS)))
$(RM) $(wildcard $(patsubst %.$(osuf), %_stub.o, $(HS_OBJS)))
ifneq "$(strip $(WAYS))" ""
ifeq "$(way)" ""
all clean ::
# 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 "== $(MAKE) way=$$i -f $(MAKEFILE) $@;"; \
$(MAKE) way=$$i -f $(MAKEFILE) --no-print-directory $(MFLAGS) $@ ; \
if [ $$? -eq 0 ] ; then true; else exit $$x_on_err; fi; \
done
@echo "== Finished recursively making \`$@' for ways: $(WAYS) ..."
endif
endif