146 lines | 4258 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 | # Common Makefile for otherlibs |
17 | |
18 | ROOTDIR=../.. |
19 | include $(ROOTDIR)/Makefile.config |
20 | include $(ROOTDIR)/Makefile.common |
21 | include $(ROOTDIR)/Makefile.best_binaries |
22 | |
23 | CAMLRUN ?= $(ROOTDIR)/boot/ocamlrun |
24 | |
25 | CAMLC := $(BEST_OCAMLC) -nostdlib -I $(ROOTDIR)/stdlib |
26 | CAMLOPT := $(BEST_OCAMLOPT) -nostdlib -I $(ROOTDIR)/stdlib |
27 | |
28 | OC_CFLAGS += $(SHAREDLIB_CFLAGS) $(EXTRACFLAGS) |
29 | OC_CPPFLAGS += -I$(ROOTDIR)/runtime |
30 | |
31 | # Compilation options |
32 | COMPFLAGS=-absname -w +a-4-9-41-42-44-45-48 -warn-error A -bin-annot -g \ |
33 | -safe-string -strict-sequence -strict-formats $(EXTRACAMLFLAGS) |
34 | ifeq "$(FLAMBDA)" "true" |
35 | OPTCOMPFLAGS=-O3 |
36 | else |
37 | OPTCOMPFLAGS= |
38 | endif |
39 | ifeq "$(FUNCTION_SECTIONS)" "true" |
40 | OPTCOMPFLAGS += -function-sections |
41 | endif |
42 | MKLIB=$(CAMLRUN) $(ROOTDIR)/tools/ocamlmklib |
43 | |
44 | # Variables that must be defined by individual libraries: |
45 | # LIBNAME |
46 | # CAMLOBJS |
47 | |
48 | # Variables that can be defined by individual libraries, |
49 | # but have sensible default values: |
50 | COBJS ?= |
51 | EXTRACFLAGS ?= |
52 | EXTRACAMLFLAGS ?= |
53 | LINKOPTS ?= |
54 | LDOPTS ?= |
55 | HEADERS ?= |
56 | CMIFILES ?= $(CAMLOBJS:.cmo=.cmi) |
57 | CAMLOBJS_NAT ?= $(CAMLOBJS:.cmo=.cmx) |
58 | CLIBNAME ?= $(LIBNAME) |
59 | |
60 | ifeq "$(COBJS)" "" |
61 | STUBSLIB= |
62 | else |
63 | STUBSLIB=lib$(CLIBNAME).$(A) |
64 | endif |
65 | |
66 | .PHONY: all allopt opt.opt # allopt and opt.opt are synonyms |
67 | all: $(STUBSLIB) $(LIBNAME).cma $(CMIFILES) |
68 | |
69 | allopt: $(STUBSLIB) $(LIBNAME).cmxa $(LIBNAME).$(CMXS) $(CMIFILES) |
70 | opt.opt: allopt |
71 | |
72 | $(LIBNAME).cma: $(CAMLOBJS) |
73 | ifeq "$(COBJS)" "" |
74 | $(CAMLC) -o $@ -a -linkall $(CAMLOBJS) $(LINKOPTS) |
75 | else |
76 | $(MKLIB) -o $(LIBNAME) -oc $(CLIBNAME) -ocamlc '$(CAMLC)' -linkall \ |
77 | $(CAMLOBJS) $(LINKOPTS) |
78 | endif |
79 | |
80 | $(LIBNAME).cmxa: $(CAMLOBJS_NAT) |
81 | ifeq "$(COBJS)" "" |
82 | $(CAMLOPT) -o $@ -a -linkall $(CAMLOBJS_NAT) $(LINKOPTS) |
83 | else |
84 | $(MKLIB) -o $(LIBNAME) -oc $(CLIBNAME) -ocamlopt '$(CAMLOPT)' -linkall \ |
85 | $(CAMLOBJS_NAT) $(LINKOPTS) |
86 | endif |
87 | |
88 | $(LIBNAME).cmxs: $(LIBNAME).cmxa $(STUBSLIB) |
89 | $(CAMLOPT_CMD) -shared -o $(LIBNAME).cmxs -I . $(LIBNAME).cmxa |
90 | |
91 | lib$(CLIBNAME).$(A): $(COBJS) |
92 | $(MKLIB_CMD) -oc $(CLIBNAME) $(COBJS) $(LDOPTS) |
93 | |
94 | install:: |
95 | if test -f dll$(CLIBNAME)$(EXT_DLL); then \ |
96 | $(INSTALL_PROG) \ |
97 | dll$(CLIBNAME)$(EXT_DLL) \ |
98 | "$(INSTALL_STUBLIBDIR)/"; \ |
99 | fi |
100 | ifneq "$(STUBSLIB)" "" |
101 | $(INSTALL_DATA) $(STUBSLIB) "$(INSTALL_LIBDIR)/" |
102 | cd "$(INSTALL_LIBDIR)"; $(RANLIB) lib$(CLIBNAME).$(A) |
103 | endif |
104 | |
105 | $(INSTALL_DATA) \ |
106 | $(LIBNAME).cma $(CMIFILES) \ |
107 | "$(INSTALL_LIBDIR)/" |
108 | ifeq "$(INSTALL_SOURCE_ARTIFACTS)" "true" |
109 | $(INSTALL_DATA) \ |
110 | $(CMIFILES:.cmi=.mli) \ |
111 | $(CMIFILES:.cmi=.cmti) \ |
112 | "$(INSTALL_LIBDIR)/" |
113 | endif |
114 | if test -n "$(HEADERS)"; then \ |
115 | $(INSTALL_DATA) $(HEADERS) "$(INSTALL_LIBDIR)/caml/"; \ |
116 | fi |
117 | |
118 | installopt: |
119 | $(INSTALL_DATA) \ |
120 | $(CAMLOBJS_NAT) $(LIBNAME).cmxa $(LIBNAME).$(A) \ |
121 | "$(INSTALL_LIBDIR)/" |
122 | cd "$(INSTALL_LIBDIR)"; $(RANLIB) $(LIBNAME).a |
123 | if test -f $(LIBNAME).cmxs; then \ |
124 | $(INSTALL_PROG) $(LIBNAME).cmxs "$(INSTALL_LIBDIR)/"; \ |
125 | fi |
126 | |
127 | partialclean: |
128 | rm -f *.cm* |
129 | |
130 | clean:: partialclean |
131 | rm -f *.dll *.so *.a *.lib *.o *.obj |
132 | |
133 | .SUFFIXES: .ml .mli .cmi .cmo .cmx .$(O) |
134 | |
135 | .mli.cmi: |
136 | $(CAMLC) -c $(COMPFLAGS) $< |
137 | |
138 | .ml.cmo: |
139 | $(CAMLC) -c $(COMPFLAGS) $< |
140 | |
141 | .ml.cmx: |
142 | $(CAMLOPT) -c $(COMPFLAGS) $(OPTCOMPFLAGS) $< |
143 | |
144 | .c.$(O): |
145 | $(CC) -c $(OC_CFLAGS) $(OC_CPPFLAGS) $(OUTPUTOBJ)$@ $< |
146 |