174 lines | 5723 chars
1 | #************************************************************************** |
2 | #* * |
3 | #* OCaml * |
4 | #* * |
5 | #* Xavier Leroy, projet Cristal, INRIA Rocquencourt * |
6 | #* * |
7 | #* Copyright 1999 Institut National de Recherche en Informatique et * |
8 | #* en Automatique. * |
9 | #* * |
10 | #* All rights reserved. This file is distributed under the terms of * |
11 | #* the GNU Lesser General Public License version 2.1, with the * |
12 | #* special exception on linking described in the file LICENSE. * |
13 | #* * |
14 | #************************************************************************** |
15 | |
16 | ROOTDIR=../.. |
17 | |
18 | include $(ROOTDIR)/Makefile.config |
19 | include $(ROOTDIR)/Makefile.common |
20 | include $(ROOTDIR)/Makefile.best_binaries |
21 | |
22 | OC_CFLAGS += $(SHAREDLIB_CFLAGS) |
23 | |
24 | OC_CPPFLAGS += -I$(ROOTDIR)/runtime |
25 | |
26 | NATIVE_CPPFLAGS = \ |
27 | -DNATIVE_CODE -DTARGET_$(ARCH) -DMODEL_$(MODEL) -DSYS_$(SYSTEM) |
28 | |
29 | CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun |
30 | |
31 | LIBS = -nostdlib -I $(ROOTDIR)/stdlib -I $(ROOTDIR)/otherlibs/$(UNIXLIB) |
32 | |
33 | CAMLC=$(BEST_OCAMLC) $(LIBS) |
34 | CAMLOPT=$(BEST_OCAMLOPT) $(LIBS) |
35 | |
36 | MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib |
37 | COMPFLAGS=-w +33..39 -warn-error A -g -bin-annot -safe-string |
38 | ifeq "$(FLAMBDA)" "true" |
39 | OPTCOMPFLAGS=-O3 |
40 | else |
41 | OPTCOMPFLAGS= |
42 | endif |
43 | |
44 | LIBNAME=threads |
45 | |
46 | ifeq "$(UNIX_OR_WIN32)" "unix" |
47 | HEADER = st_posix.h |
48 | else # Windows |
49 | HEADER = st_win32.h |
50 | endif |
51 | |
52 | # Note: the header on which object files produced from st_stubs.c |
53 | # should actually depend is known for sure only at compile-time. |
54 | # That's why this dependency is handled in the Makefile directly |
55 | # and removed from the output of the C compiler during make depend |
56 | |
57 | BYTECODE_C_OBJS=st_stubs_b.$(O) |
58 | NATIVECODE_C_OBJS=st_stubs_n.$(O) |
59 | |
60 | THREADS_SOURCES = thread.ml mutex.ml condition.ml event.ml threadUnix.ml |
61 | |
62 | THREADS_BCOBJS = $(THREADS_SOURCES:.ml=.cmo) |
63 | THREADS_NCOBJS = $(THREADS_SOURCES:.ml=.cmx) |
64 | |
65 | MLIFILES=thread.mli mutex.mli condition.mli event.mli threadUnix.mli |
66 | CMIFILES=$(MLIFILES:.mli=.cmi) |
67 | |
68 | all: lib$(LIBNAME).$(A) $(LIBNAME).cma $(CMIFILES) |
69 | |
70 | allopt: lib$(LIBNAME)nat.$(A) $(LIBNAME).cmxa $(CMIFILES) |
71 | |
72 | lib$(LIBNAME).$(A): $(BYTECODE_C_OBJS) |
73 | $(MKLIB_CMD) -o $(LIBNAME) $(BYTECODE_C_OBJS) $(PTHREAD_LINK) |
74 | |
75 | lib$(LIBNAME)nat.$(A): $(NATIVECODE_C_OBJS) |
76 | $(MKLIB_CMD) -o $(LIBNAME)nat $^ |
77 | |
78 | $(LIBNAME).cma: $(THREADS_BCOBJS) |
79 | ifeq "$(UNIX_OR_WIN32)" "unix" |
80 | $(MKLIB) -o $(LIBNAME) -ocamlc '$(CAMLC)' -cclib -lunix -linkall \ |
81 | $(PTHREAD_CAML_LINK) $^ |
82 | # TODO: Figure out why -cclib -lunix is used here. |
83 | # It may be because of the threadsUnix module which is deprecated. |
84 | # It may hence be good to figure out whether this module shouldn't be |
85 | # removed, and then -cclib -lunix arguments. |
86 | else # Windows |
87 | $(MKLIB) -o $(LIBNAME) -ocamlc "$(CAMLC)" -linkall \ |
88 | $(PTHREAD_CAML_LINK) $^ |
89 | endif |
90 | |
91 | # See remark above: force static linking of libthreadsnat.a |
92 | $(LIBNAME).cmxa: $(THREADS_NCOBJS) |
93 | $(CAMLOPT) -linkall -a -cclib -lthreadsnat $(PTHREAD_CAML_LINK) -o $@ $^ |
94 | |
95 | # Note: I removed "-cclib -lunix" from the line above. |
96 | # Indeed, if we link threads.cmxa, then we must also link unix.cmxa, |
97 | # which itself will pass -lunix to the C linker. It seems more |
98 | # modular to me this way. -- Alain |
99 | |
100 | # The following lines produce two object files st_stubs_b.$(O) and |
101 | # st_stubs_n.$(O) from the same source file st_stubs.c (it is compiled |
102 | # twice, each time with different options). |
103 | |
104 | st_stubs_n.$(O): OC_CPPFLAGS += $(NATIVE_CPPFLAGS) |
105 | |
106 | st_stubs_b.$(O): st_stubs.c $(HEADER) |
107 | $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $< |
108 | |
109 | st_stubs_n.$(O): st_stubs.c $(HEADER) |
110 | $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $< |
111 | |
112 | partialclean: |
113 | rm -f *.cm* |
114 | |
115 | clean: partialclean |
116 | rm -f dllthreads*$(EXT_DLL) *.$(A) *.$(O) |
117 | |
118 | INSTALL_THREADSLIBDIR=$(INSTALL_LIBDIR)/$(LIBNAME) |
119 | |
120 | install: |
121 | if test -f dllthreads$(EXT_DLL); then \ |
122 | $(INSTALL_PROG) \ |
123 | dllthreads$(EXT_DLL) "$(INSTALL_STUBLIBDIR)/dllthreads$(EXT_DLL)"; \ |
124 | fi |
125 | $(INSTALL_DATA) libthreads.$(A) "$(INSTALL_LIBDIR)" |
126 | cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreads.$(A) |
127 | mkdir -p "$(INSTALL_THREADSLIBDIR)" |
128 | $(INSTALL_DATA) \ |
129 | $(CMIFILES) threads.cma \ |
130 | "$(INSTALL_THREADSLIBDIR)" |
131 | ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true" |
132 | $(INSTALL_DATA) \ |
133 | $(CMIFILES:.cmi=.cmti) \ |
134 | "$(INSTALL_THREADSLIBDIR)" |
135 | $(INSTALL_DATA) $(MLIFILES) "$(INSTALL_THREADSLIBDIR)" |
136 | endif |
137 | $(INSTALL_DATA) threads.h "$(INSTALL_LIBDIR)/caml" |
138 | |
139 | installopt: |
140 | $(INSTALL_DATA) libthreadsnat.$(A) "$(INSTALL_LIBDIR)" |
141 | cd "$(INSTALL_LIBDIR)"; $(RANLIB) libthreadsnat.$(A) |
142 | $(INSTALL_DATA) \ |
143 | $(THREADS_NCOBJS) threads.cmxa threads.$(A) \ |
144 | "$(INSTALL_THREADSLIBDIR)" |
145 | cd "$(INSTALL_THREADSLIBDIR)" && $(RANLIB) threads.$(A) |
146 | |
147 | .SUFFIXES: .ml .mli .cmo .cmi .cmx |
148 | |
149 | .mli.cmi: |
150 | $(CAMLC) -c $(COMPFLAGS) $< |
151 | |
152 | .ml.cmo: |
153 | $(CAMLC) -c $(COMPFLAGS) $< |
154 | |
155 | .ml.cmx: |
156 | $(CAMLOPT) -c $(COMPFLAGS) $(OPTCOMPFLAGS) $< |
157 | |
158 | .PHONY: depend |
159 | ifeq "$(TOOLCHAIN)" "msvc" |
160 | depend: |
161 | $(error Dependencies cannot be regenerated using the MSVC ports) |
162 | else |
163 | depend: |
164 | $(CC) -MM $(OC_CPPFLAGS) st_stubs.c \ |
165 | | sed -e 's/st_stubs\.o/st_stubs_b.$$(O)/' \ |
166 | -e 's/ st_\(posix\|win32\)\.h//g' > .depend |
167 | $(CC) -MM $(OC_CPPFLAGS) $(NATIVE_CPPFLAGS) \ |
168 | st_stubs.c | sed -e 's/st_stubs\.o/st_stubs_n.$$(O)/' \ |
169 | -e 's/ st_\(posix\|win32\)\.h//g' >> .depend |
170 | $(CAMLRUN) $(ROOTDIR)/boot/ocamlc -depend -slash *.mli *.ml >> .depend |
171 | endif |
172 | |
173 | include .depend |
174 |