-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
327 lines (267 loc) · 9.43 KB
/
Makefile
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
include Makefile.config
PKGNAME = mlgmpidl
PKGVERS = 1.2.15
#---------------------------------------
# Directories
#---------------------------------------
SRCDIR = $(shell pwd)
#
# Installation directory
#
PREFIX = $(MLGMPIDL_PREFIX)
ifeq ($(OCAMLFIND),)
OCAMLCCOPT = -ccopt -L$(MLGMPIDL_PREFIX)
else
SITE-LIB = $(shell $(OCAMLFIND) printconf destdir)
PKG-NAME = gmp
SITE-LIB-PKG = $(SITE-LIB)/$(PKG-NAME)
REQ_PKG = bigarray-compat
OCAMLCCOPT = -ccopt -L$(SITE-LIB)/stublibs -ccopt -L$(SITE-LIB-PKG)
OCAMLC := $(OCAMLFIND) ocamlc -package "$(REQ_PKG)"
OCAMLOPT := $(OCAMLFIND) ocamlopt -package "$(REQ_PKG)"
endif
#---------------------------------------
# CAML part
#---------------------------------------
OCAMLCCOPT += \
-ccopt "$(LDFLAGS)" \
-ccopt -L$(CAML_PREFIX) \
-ccopt -L$(CAMLIDL_PREFIX) \
$(if $(GMP_PREFIX),-ccopt -L$(GMP_PREFIX)/lib) \
$(if $(MPFR_PREFIX),-ccopt -L$(MPFR_PREFIX)/lib) \
LIBS = -lmpfr -lgmp -lcamlidl
OCAMLLDFLAGS = $(OCAMLCCOPT) $(addprefix -cclib ,$(LIBS))
IDLMODULES = mpz mpq mpf mpfr gmp_random
MLMODULES = $(IDLMODULES) mpzf mpqf mpfrf
#---------------------------------------
# C part
#---------------------------------------
ICFLAGS = \
$(CPPFLAGS) \
$(if $(GMP_PREFIX),-I$(GMP_PREFIX)/include) \
$(if $(MPFR_PREFIX),-I$(MPFR_PREFIX)/include) \
-I$(CAML_PREFIX) -I$(CAMLIDL_PREFIX)
LDFLAGS += \
$(if $(GMP_PREFIX),-L$(GMP_PREFIX)/lib) \
$(if $(MPFR_PREFIX),-L$(MPFR_PREFIX)/lib) \
-L$(CAML_PREFIX) -L$(CAML_PREFIX)/stublibs -L$(CAMLIDL_PREFIX) \
$(LIBS)
EXT_DLL ?= .so
CCMODULES = $(IDLMODULES:%=%_caml) gmp_caml
CCLIB = libgmp_caml.a
ifneq ($(ENABLE_PROF),0)
CCLIB += libgmp_caml.p.a
endif
ifneq ($(HAS_SHARED),)
CCLIB += dllgmp_caml$(EXT_DLL)
endif
ifneq ($(HAS_OCAMLOPT),)
MLLIBx = $(MLMODULES:%=%.cmx) gmp.cmxa gmp.a
ifneq ($(ENABLE_PROF),0)
MLLIBx += $(MLMODULES:%=%.p.cmx) gmp.p.cmxa gmp.p.a
endif
ifneq ($(HAS_NATIVE_PLUGINS),)
MLLIBx += gmp.cmxs
endif
endif
FILES_TOINSTALL = \
META \
gmp_caml.h \
$(IDLMODULES:%=%.idl) \
$(MLMODULES:%=%.ml) $(MLMODULES:%=%.mli) \
$(MLMODULES:%=%.cmi) gmp.cma \
$(MLLIBx) \
$(CCLIB)
ifneq ($(HAS_TYPEREX),)
FILES_TOINSTALL += $(MLMODULES:%=%.cmt) $(MLMODULES:%=%.cmti)
endif
#---------------------------------------
# Rules
#---------------------------------------
all: byte opt
byte: $(MLMODULES:%=%.cmi) gmp.cma
opt: $(MLMODULES:%=%.cmx) gmp.cmxa
ifneq ($(ENABLE_PROF),0)
all: prof
prof: $(MLMODULES:%=%.p.cmx) gmp.p.cmxa
endif
ifneq ($(HAS_NATIVE_PLUGINS),)
opt: gmp.cmxs
endif
# Example of compilation command with ocamlfind
%.byte: %.ml
$(OCAMLFIND) ocamlc $(OCAMLFLAGS) -o $@ $*.ml \
-package gmp -linkpkg
%.opt: %.ml
$(OCAMLFIND) ocamlopt -verbose $(OCAMLOPTFLAGS) -o $@ $*.ml \
-package gmp -linkpkg
# without ocamlfind
session.byte: session.ml gmp.cma
$(OCAMLC) -I $(PREFIX)/lib -o $@ bigarray.cma gmp.cma $<
session.opt: session.ml gmp.cmxa
$(OCAMLOPT) -I $(PREFIX)/lib -cclib -L. -o $@ bigarray.cmxa gmp.cmxa $<
# and with noautolink
session2.opt: session.ml
$(OCAMLOPT) -noautolink -I$(SITE-LIB-PKG) -o $@ bigarray.cmxa gmp.cmxa $< \
$(OCAMLLDFLAGS) -cclib "-lbigarray -lgmp_caml"
# CAML gmp
gmp.cma: $(MLMODULES:%=%.cmo) $(CCLIB)
$(OCAMLC) $(OCAMLFLAGS) -a -o $@ $(MLMODULES:%=%.cmo) \
-dllib -lgmp_caml $(OCAMLLDFLAGS)
gmp.cmxa: $(MLMODULES:%=%.cmx) $(CCLIB)
$(OCAMLOPT) $(OCAMLOPTFLAGS) -a -o $@ $(MLMODULES:%=%.cmx) \
-cclib -lgmp_caml $(OCAMLLDFLAGS)
gmp.p.cmxa: $(MLMODULES:%=%.p.cmx) $(CCLIB)
$(OCAMLOPT) -p $(OCAMLOPTFLAGS) -a -o $@ $(MLMODULES:%=%.p.cmx) \
-cclib -lgmp_caml.p $(OCAMLLDFLAGS)
ifneq ($(HAS_NATIVE_PLUGINS),)
gmp.cmxs: gmp.cmxa
$(OCAMLOPT) $(OCAMLOPTFLAGS) -linkall -shared -o $@ -I . $<
endif
# CAML libraries
dll%.p$(EXT_DLL) lib%.p.a: $(CCMODULES:%=%.p.o)
$(OCAMLMKLIB) -oc $*.p $^ $(LDFLAGS) -custom
dll%$(EXT_DLL) lib%.a: $(CCMODULES:%=%.o)
$(OCAMLMKLIB) -oc $* $^ $(LDFLAGS)
.PHONY: META
META:
$(RM) META
echo "description = \"OCaml Interface to GMP and MPFR libraries\"" >META
echo "version = \"$(PKGVERS)\"" >>META
echo "requires = \"$(REQ_PKG)\"" >>META
echo "archive(byte) = \"gmp.cma\"" >>META
echo "archive(byte,plugin) = \"gmp.cma\"" >>META
echo "plugin(byte) = \"gmp.cma\"" >>META
echo "archive(native) = \"gmp.cmxa\"" >>META
echo "archive(native,plugin) = \"gmp.cmxs\"" >>META
echo "plugin(native) = \"gmp.cmxs\"" >>META
ifneq ($(ENABLE_PROF),0)
echo "archive(native,gprof) = \"gmp.p.cmxa\"" >>META
endif
ifeq ($(OCAMLFIND),)
install:
$(INSTALLd) $(MLGMPIDL_PREFIX)/include
$(INSTALLd) $(MLGMPIDL_PREFIX)/lib
$(INSTALL) gmp_caml.h $(MLGMPIDL_PREFIX)/include
$(INSTALL) \
$(IDLMODULES:%=%.idl) \
$(MLMODULES:%=%.ml) $(MLMODULES:%=%.mli) \
$(MLMODULES:%=%.cmi) gmp.cma \
$(MLLIBx) $(CCLIB) \
$(MLGMPIDL_PREFIX)/lib
uninstall:
(cd $(MLGMPIDL_PREFIX)/include; $(RM) gmp_caml.h)
(cd $(MLGMPIDL_PREFIX)/lib; $(RM) \
$(IDLMODULES:%=%.idl) \
$(MLMODULES:%=%.ml) $(MLMODULES:%=%.mli) \
$(MLMODULES:%=%.cmi) gmp.cma \
$(MLLIBx) $(CCLIB) libgmp*caml.a libgmp*caml$(EXT_DLL))
(cd $(MLGMPIDLPREFIX)/bin; $(RM) gmprun gmptop)
else
install: $(FILES_TOINSTALL)
$(OCAMLFIND) remove $(PKG-NAME)
$(OCAMLFIND) install $(PKG-NAME) $^
uninstall:
$(OCAMLFIND) remove $(PKG-NAME)
endif
clean:
$(RM) -r tmp html
$(RM) gmprun gmptop
$(RM) *.aux *.bbl *.ilg *.idx *.ind *.out *.blg *.dvi *.log *.toc *.ps *.html *.pdf
$(RM) *.o *.a *.cm[ioxat] *.cmti *.cmx[as] *.annot lib*$(EXT_DLL) dll*$(EXT_DLL) session.byte session.opt session.opt2 tmp/* html/*
$(RM) ocamldoc.[cefkimoptv]* ocamldoc.sty
$(RM) $(IDLMODULES:%=%.ml) $(IDLMODULES:%=%.mli) $(IDLMODULES:%=%_caml.c) META
distclean: clean
$(RM) Makefile.config
PKG = $(PKGNAME)-$(PKGVERS)
PKGFILES = $(IDLMODULES:%=%.idl) mpfrf.ml mpqf.ml mpzf.ml session.ml introduction.mli mpfrf.mli mpqf.mli mpzf.mli Changes configure COPYING gmp_caml.c gmp_caml.h Makefile mlgmpidl.tex README perlscript_caml.pl perlscript_c.pl META
dist: $(IDLMODULES:%=%.idl) mpfrf.ml mpqf.ml mpzf.ml session.ml introduction.mli mpfrf.mli mpqf.mli mpzf.mli Changes configure COPYING gmp_caml.c gmp_caml.h Makefile mlgmpidl.tex README perlscript_caml.pl perlscript_c.pl META
mkdir -p $(PKG)
cp $(PKGFILES) $(PKG)
tar zcvf $(PKG).tgz $(PKG)
$(RM) -r $(PKG)
#---------------------------------------
# TEX and HTML rules
#---------------------------------------
.PHONY: html mlgmpidl.dvi
mlgmpidl.pdf: mlgmpidl.dvi
$(DVIPDF) mlgmpidl.dvi
mlgmpidl.dvi: introduction.mli $(MLMODULES:%=%.mli)
$(OCAMLDOC) \
-latextitle 1,chapter -latextitle 2,section -latextitle 3,subsection -latextitle 4,subsubsection -latextitle 5,paragraph -latextitle 6,subparagraph -noheader -notrailer -latex -o ocamldoc.tex $^
$(LATEX) mlgmpidl
$(MAKEINDEX) mlgmpidl
$(LATEX) mlgmpidl
$(LATEX) mlgmpidl
html: $(MLMODULES:%=%.mli)
mkdir -p html
$(OCAMLDOC) $(OCAMLINC) -html -d html -colorize-code $^
doc: byte html mlgmpidl.pdf
homepage: html mlgmpidl.pdf
hyperlatex index
scp -r index.html html mlgmpidl.pdf \
salgado:/home/wwwpop-art/people/bjeannet/mlxxxidl-forge/mlgmpidl
ssh salgado chmod -R ugoa+rx /home/wwwpop-art/people/bjeannet/mlxxxidl-forge/mlgmpidl
#--------------------------------------------------------------
# IMPLICIT RULES AND DEPENDENCIES
#--------------------------------------------------------------
.SUFFIXES: .tex .fig .c .h .o .ml .mli .cmi .cmo .cmx .idl _debug.o _prof.o _caml.c
#-----------------------------------
# IDL
#-----------------------------------
$(IDLMODULES:%=%.mli): %.mli: %.ml
$(IDLMODULES:%=%_caml.c): %_caml.c: %.ml
# Generate for each %.idl: %i.ml, %i.mli, %_caml.c
$(IDLMODULES:%=%.ml): %.ml: %.idl perlscript_c.pl perlscript_caml.pl
tmpdir=$$(mktemp -d tmp.XXXXXX); \
trap "$(RM) -r $${tmpdir};" EXIT QUIT INT; \
{ cp $*.idl $${tmpdir}/$*.idl; \
$(CAMLIDL) -no-include \
-D MPFR_VERSION_MAJOR=$(MPFR_VERSION_MAJOR) \
-prepro cpp $${tmpdir}/$*.idl && \
$(PERL) perlscript_c.pl < $${tmpdir}/$*_stubs.c >$*_caml.c && \
$(PERL) perlscript_caml.pl < $${tmpdir}/$*.ml >$*.ml && \
$(PERL) perlscript_caml.pl < $${tmpdir}/$*.mli >$*.mli; }
#-----------------------------------
# C
#-----------------------------------
%.o: %.c gmp_caml.h
$(OCAMLOPT) $(addprefix -ccopt ,$(CFLAGS_DEBUG) $(ICFLAGS)) -g -c -o $@ $<
%.p.o: %.c gmp_caml.h
$(OCAMLOPT) $(addprefix -ccopt ,$(CFLAGS_PROF) $(ICFLAGS)) -ccopt -o -ccopt $@ -c $<
#-----------------------------------
# CAML
#-----------------------------------
%.cmi: %.mli
$(OCAMLC) $(OCAMLFLAGS) -c $<
%.cmo: %.ml %.cmi
$(OCAMLC) $(OCAMLFLAGS) -c $<
$(MLMODULES:%=%.cmx): %.cmx: %.ml %.cmi
$(OCAMLOPT) $(OCAMLOPTFLAGS) -c $<
$(MLMODULES:%=%.p.cmx): %.p.cmx: %.ml %.cmi
$(OCAMLOPT) -p $(OCAMLOPTFLAGS) $(OCAMLINC) -c -o $@ $<
#-----------------------------------
# Dependencies
#-----------------------------------
# Workaround to avoid an infinite loop when generating dependences
# within Docker
ifneq ($(filter Makefile.depend,$(MAKECMDGOALS)),)
Makefile.depend: $(MLMODULES:%=%.mli) $(MLMODULES:%=%.ml)
$(OCAMLDEP) -one-line $+ | \
$(SED) -e '/\.cm[ox]/ { p; s/\.cmx/.p.cmx/; }' > $@
else
-include Makefile.depend
endif
#-----------------------------------
# OPAM Packaging
#-----------------------------------
# see `https://github.com/nberth/opam-dist'
ifneq ($(OPAM_DIST_DIR),)
OPAM_DIR = opam
OPAM_FILES = descr opam
MLSRCS = $(filter-out $(IDLMODULES),$(MLMODULES))
DIST_FILES = *.idl *.c *.h *.tex $(MLSRCS:%=%.ml) $(MLSRCS:%=%.mli) \
Changes README COPYING Makefile Makefile.config.* perlscript_* \
session.ml introduction.mli configure Makefile.depend
-include $(OPAM_DIST_DIR)/opam-dist.mk
endif