summaryrefslogtreecommitdiff
path: root/libraries/Makefile.common
blob: 8fe1462d642b07ac59c8a2bc4fc5c53184ec311b (plain)
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
# This Makefile.common is used only in an nhc98 build of the libraries.
# It is included from each package's individual Makefile.nhc98.
# We assume the following definitions have already been made in
# the importing Makefile.
#
# THISPKG = e.g. mypkg
# SEARCH  = e.g. -P../IO -P../PreludeIO -package base
# SRCS    = all .hs .gc and .c files
#
# EXTRA_H_FLAGS = e.g. -prelude
# EXTRA_C_FLAGS = e.g. -I../Binary
include ../Makefile.inc

# nasty hack - replace flags for ghc, nhc98, with hbc specific ones
ifeq "hbc" "${BUILDCOMP}"
EXTRA_H_FLAGS := ${EXTRA_HBC_FLAGS}
endif

DIRS     = $(shell ${LOCAL}pkgdirlist ${THISPKG})

OBJDIR   = ${BUILDDIR}/${OBJ}/libraries/${THISPKG}
OBJDIRS  = $(patsubst %, ${OBJDIR}/%, ${DIRS})
FINALLIB = ${DST}/libHS${THISPKG}.$A
INCDIRS  = ${INCDIR}/packages/${THISPKG} \
	   $(patsubst %, ${INCDIR}/packages/${THISPKG}/%, ${DIRS})
.SUFFIXES: .hi .hs .lhs .o .gc .c .hc .p.o .p.c .z.o .z.c .hsc

SRCS_HS  = $(filter %.hs, ${SRCS})
SRCS_LHS = $(filter %.lhs,${SRCS})
SRCS_GC  = $(filter %.gc, ${SRCS})
SRCS_HSC = $(filter %.hsc,${SRCS})
SRCS_C   = $(filter %.c,  ${SRCS})
SRCS_HASK= $(SRCS_HS) $(SRCS_LHS) $(SRCS_GC) $(SRCS_HSC)

OBJS_HS  = $(patsubst %.hs, ${OBJDIR}/%.$O, ${SRCS_HS})
OBJS_LHS = $(patsubst %.lhs,${OBJDIR}/%.$O, ${SRCS_LHS})
OBJS_GC  = $(patsubst %.gc, ${OBJDIR}/%.$O, ${SRCS_GC})
OBJS_HSC = $(patsubst %.hsc,${OBJDIR}/%.$O, ${SRCS_HSC})
OBJS_C   = $(patsubst %.c,  ${OBJDIR}/%.$O, ${SRCS_C})
OBJS_HASK= ${OBJS_HS} ${OBJS_LHS} ${OBJS_GC} ${OBJS_HSC}
OBJS     = $(OBJS_HASK) $(OBJS_C)

CFILES_HS  = $(patsubst %.hs, %.$C,  ${SRCS_HS})
CFILES_LHS = $(patsubst %.lhs,%.$C,  ${SRCS_LHS})
CFILES_GC  = $(patsubst %.gc, %.$C,  ${SRCS_GC})
CFILES_XS  = $(patsubst %.gc, %_.$C, ${SRCS_GC}) \
             $(patsubst %.gc, %_.hs, ${SRCS_GC})
CFILES_HSC = $(patsubst %.hsc,%.$C,  ${SRCS_HSC})
CFILES_GEN = ${CFILES_HS} ${CFILES_LHS} ${CFILES_GC} ${CFILES_HSC}

ifeq "p" "${PROFILING}"
HC += -p
endif
 
ifeq "z" "${TPROF}"
HC += -z
endif

all: ${OBJDIR} ${OBJDIRS} ${INCDIRS} extra ${OBJS} ${FINALLIB}
extra:
cfiles: extracfiles ${CFILES_GEN}
extracfiles:
fromC: ${OBJDIR} ${OBJS_C} ${OBJDIRS}
	$(HC) -c -d $(OBJDIR) $(EXTRA_C_FLAGS) ${SEARCH} ${CFILES_GEN}
	echo $(OBJS) | xargs ar cr ${FINALLIB}
objdir: ${OBJDIR} ${OBJDIRS} ${INCDIRS}
${OBJDIR} ${OBJDIRS} ${INCDIRS}:
	mkdir -p $@
${FINALLIB}: ${OBJS}
	echo $(OBJS) | xargs ar cr $@
cleanhi:
	-rm -f $(patsubst %, %/*.hi, ${DIRS})
cleanC: cleanExtraC
	-rm -f ${CFILES_GEN} ${CFILES_XS}
clean:	cleanhi
	-rm -f $(patsubst %, ${OBJDIR}/%/*.$O, ${DIRS})
	-rm -f $(patsubst %.gc, %_.hs, $(filter %.gc, $(SRCS)))
	-rm -f $(patsubst %.gc, %_.$C,  $(filter %.gc, $(SRCS)))
cleanExtraC:

# general build rules for making objects from Haskell files
$(OBJS_HASK): #$(OBJDIR) $(OBJDIRS) $(SRCS_HASK)
	$(LOCAL)hmake -hc=$(HC) -hidir $(INCDIR)/packages/$(THISPKG) \
		$(SEARCH) $(EXTRA_H_FLAGS) -d$(OBJDIR) \
		$(SRCS_HASK)
${OBJS_HS}: ${OBJDIR}/%.$O : %.hs
${OBJS_LHS}: ${OBJDIR}/%.$O : %.lhs
${OBJS_GC}: ${OBJDIR}/%.$O : %.gc
${OBJS_HSC}: ${OBJDIR}/%.$O : %.hsc

# general build rule for making objects from C files
${OBJS_C}: ${OBJDIR}/%.$O : cbits/%.c
	$(CC) -c -I$(INCDIR) $(ENDIAN) $(filter -I%, ${SEARCH}) \
		$(EXTRA_C_FLAGS) -o $@ $<

# general build rules for making bootstrap C files from Haskell files
$(CFILES_GEN):
	$(LOCAL)hmake -hc=$(HC) -C -hidir $(INCDIR)/packages/$(THISPKG) \
		$(SEARCH) $(EXTRA_H_FLAGS) \
		$(SRCS_HASK)
${CFILES_HS}: %.$C : %.hs
${CFILES_LHS}: %.$C : %.lhs
${CFILES_GC}: %.$C : %.gc
${CFILES_HSC}: %.$C : %.hsc

# hack to get round mutual recursion between libraries
HIFILES = $(patsubst %.hs,../${THISLIB}/%.${HISUFFIX},$(filter %.hs, ${SRCS}))
${HIFILES}: ../${THISLIB}/%.${HISUFFIX} : %.hs
	$(HC) -c $(PART_FLAGS) -o /dev/null $<

# The importing Makefile may now define extra individual dependencies
#    e.g.
# ${OBJDIR}/Function.$O: Function.hs ${OBJDIR}/Other.$O
#
# and C-files dependencies likewise
#    e.g.
# AlignBin.c:    BinHandle.c