forked from polazarus/ocamlyices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.in
276 lines (207 loc) · 7.35 KB
/
Makefile.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
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
# Copyright (c) 2012, Mickaël Delahaye <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
# OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
PACKAGE_NAME = @PACKAGE_NAME@
PACKAGE_VERSION = @PACKAGE_VERSION@
PACKAGE_TARNAME = @PACKAGE_TARNAME@
SHELL = /bin/sh
prefix = @prefix@
bindir = @bindir@
datarootdir = @datarootdir@
datadir = @datadir@
docdir = @docdir@
exec_prefix = @exec_prefix@
libdir = @libdir@
sharedstatedir = @sharedstatedir@
YICES_C_H = $(prefix)/include/yices_c.h
YICESL_C_H = $(prefix)/include/yicesl_c.h
# Ocaml library directories for linking
OCAMLLIB = @OCAMLLIB@
OCAMLINC = $(addprefix -I, $(OCAMLLIB))
# Ocaml library directory where to install this package
OCAMLDESTDIR = @OCAMLDESTDIR@
# Input
CAMLIDL_SOURCE = yices yicesl
# Output
OUTPUT = $(PACKAGE_NAME)
OUTPUT_BYTECODE = $(OUTPUT).cma
OUTPUT_NATIVE = $(OUTPUT).cmxa
OUTPUT_NATIVE_LIB = $(OUTPUT).a
OUTPUT_O = $(OUTPUT).o
OUTPUT_LIB_NAME = $(OUTPUT)
OUTPUT_LIB = lib$(OUTPUT).a
OUTPUT_DLL = dll$(OUTPUT).so
META = META
# Tools
CAMLIDL = @CAMLIDL@
OCAMLC = @OCAMLC@
OCAMLOPT = @OCAMLOPT@
OCAMLDOC = @OCAMLDOC@
OCAMLFIND = @OCAMLFIND@
CC = @CC@
CFLAGS = -O2 -fPIC $(OCAMLINC)
AR = ar
INSTALL = install
INSTALL_PROGRAM = $(INSTALL)
INSTALL_DATA = $(INSTALL) -m 644
INCREMENTAL_LINKER = $(CC) $(CFLAGS) -r -nostdlib
#INCREMENTAL_LINKER = $(LD) -r
# Parameters: PARTIAL_LINKING and CUSTOM (for using custom bytecode compilation)
CUSTOM = @CUSTOM@
PARTIAL_LINKING = @PARTIAL_LINKING@
STATIC_YICES = @STATIC_YICES_WITH_GMP@
# Library dependencies #########################################################
# Libraries to use with 'ocamlopt' or 'ocamlc -custom'
CCLIBS = stdc++ yices
ifneq ($(PARTIAL_LINKING),yes)
CCLIBS += camlidl
endif
# Partial linking library
PLLIBS = camlidl # no dependency to camlidl for Ocamlyices users
# Libraries to build the shared library dll*.so (used only when CUSTOM=no)
DL_STATIC_LIBS = camlidl
ifeq ($(STATIC_YICES),yes)
DL_STATIC_LIBS += yices
DL_SHARED_LIBS = stdc++
else
DL_SHARED_LIBS = yices
endif
# Names of Camlidl-related files ###############################################
CAMLIDL_IDL = $(CAMLIDL_SOURCE:=.idl)
CAMLIDL_ML = $(CAMLIDL_SOURCE:=.ml)
CAMLIDL_MLI = $(CAMLIDL_SOURCE:=.mli)
CAMLIDL_STUBS_C = $(CAMLIDL_SOURCE:=_stubs.c)
CAMLIDL_GENERATED = $(CAMLIDL_ML) $(CAMLIDL_MLI) $(CAMLIDL_STUBS_C)
CAMLIDL_STUBS_O = $(CAMLIDL_STUBS_C:.c=.o)
CAMLIDL_CMI = $(CAMLIDL_MLI:.mli=.cmi)
CAMLIDL_CMO = $(CAMLIDL_ML:.ml=.cmo)
CAMLIDL_CMX = $(CAMLIDL_ML:.ml=.cmx)
################################################################################
prefix_lib = $(filter /%,$(1)) $(filter -l%,$(1)) $(patsubst %,-l%,$(filter-out /%,$(filter-out -l%,$(1))))
.PHONY: all byte native camlidl patches clean distclean mrproper install uninstall
all: camlidl byte native $(META)
byte: $(CAMLIDL_CMI) $(OUTPUT_BYTECODE)
native: $(CAMLIDL_CMI) $(OUTPUT_NATIVE)
camlidl : $(CAMLIDL_ML) $(CAMLIDL_MLI) $(CAMLIDL_STUBS_C)
# Generic compilation ##########################################################
%.ml %.mli %_stubs.c : %.idl %.hdr
$(CAMLIDL) $<
sed -e '/^and yicesl\?_\(log_file_\)\?error/ d' \
-e '/^and srec_p/ d' \
-e '/^and\s\+yices_type_ptr = yices_type$$/ d' \
-e 's/yices_type_ptr/yices_type/g' \
-e 's/ yices_type/ typ/g' \
-e 's/srec_p/string/g' \
-e 's/\([ (.]\)yicesl\?_/\1/g' \
-i $(<:.idl=.mli) -i $(<:.idl=.ml)
sed -e '/^and var_decl_iterator$$/ d' \
-e '/^and scalar_\(int\|name\)\b/ d' \
-e 's/scalar_name/string/g' \
-e 's/scalar_int/int/g' \
-i $(<:.idl=.mli)
sed '1r $(<:.idl=.hdr)' -i $(<:.idl=.mli)
%.cmi: %.mli
$(OCAMLC) -c $< -o $@
%.cmo: %.ml
$(OCAMLC) -c $< -o $@
%.cmx: %.ml
$(OCAMLOPT) -c $< -o $@
# Generic dependencies #########################################################
$(CAMLIDL_CMO): %.cmo: %.cmi
$(CAMLIDL_CMX): %.cmx: %.cmi
%_stubs.o : %.h
# Other dependencies ###########################################################
yices.ml: yicesl.ml
yices.cmi: yicesl.cmi
yicesl.cmo: yicesl.cmi
yicesl.cmx: yicesl.cmi
yices.cmo: yicesl.cmi yices.cmi
yices.cmx: yicesl.cmx yices.cmi
# C compilation and linking ####################################################
.SUFFIXES:
.SUFFIXES: .c .o
$(OUTPUT_LIB): $(CAMLIDL_STUBS_O)
ifeq ($(PARTIAL_LINKING),no)
$(AR) crs $@ $^
else
# Partial linking for efficiency
# For ld, libraries must be after last
$(INCREMENTAL_LINKER) $(OCAMLLIB:%=-L%) $^ $(call prefix_lib,$(PLLIBS)) \
-o $(OUTPUT_O)
$(AR) crs $@ $(OUTPUT_O)
endif
ifeq ($(CUSTOM),yes)
$(OUTPUT_BYTECODE): $(CAMLIDL_CMO) $(OUTPUT_LIB)
$(OCAMLC) -a -custom -o $@ -cclib -l$(OUTPUT_LIB:lib%.a=%) \
$(addprefix -cclib ,$(call prefix_lib, $(CCLIBS))) $(CAMLIDL_CMO)
else
$(OUTPUT_DLL): $(CAMLIDL_STUBS_O)
$(CC) $(CFLAGS) -shared $(OCAMLLIB:%=-L%) $^ \
-Wl,-Bstatic $(call prefix_lib,$(DL_STATIC_LIBS)) \
-Wl,-Bdynamic $(call prefix_lib,$(DL_SHARED_LIBS)) \
-o $@
$(OUTPUT_BYTECODE): $(CAMLIDL_CMO) $(OUTPUT_DLL)
$(OCAMLC) -a -o $@ -dllib -l$(OUTPUT_DLL:dll%.so=%) $(CAMLIDL_CMO)
endif
$(OUTPUT_NATIVE): $(CAMLIDL_CMX) $(OUTPUT_LIB)
$(OCAMLOPT) -a -o $@ $(CAMLIDL_CMX) -cclib -l$(OUTPUT_LIB_NAME) \
$(addprefix -cclib ,$(call prefix_lib, $(CCLIBS)))
# Meta #########################################################################
$(META): $(META).in
@$(RM) $@
sed -e 's|__NATIVE__|$(OUTPUT_NATIVE)|g' \
-e 's|__BYTECODE__|$(OUTPUT_BYTECODE)|g' \
-e 's|__VERSION__|$(PACKAGE_VERSION)|g' $< > $@
@chmod -f a-w $@
# Doc ##########################################################################
ifneq ($(OCAMLDOC),)
doc: doc/html/index.html
doc/html/index.html: *.mli
@mkdir -p $(dir $@)
$(OCAMLDOC) -html $^ -d $(dir $@)
@touch $@
endif
# Cleaning #####################################################################
clean:
$(RM) *.cmo *.cmi *.cmx *.a *.o $(CAMLIDL_GENERATED)
distclean mrproper: clean
$(RM) *.cma *.cmxa *.a *.so $(META)
# Install ######################################################################
INSTALLABLE = $(CAMLIDL_CMI) $(OUTPUT_LIB) $(OUTPUT_NATIVE_LIB) \
$(OUTPUT_BYTECODE) $(OUTPUT_NATIVE) $(META)
ifeq ($(CUSTOM),no)
INSTALLABLE_DLL = $(OUTPUT_DLL)
endif
ifneq ($(OCAMLFIND),)
install:
$(OCAMLFIND) install $(PACKAGE_NAME) $(INSTALLABLE) -dll $(INSTALLABLE_DLL)
uninstall:
$(OCAMLFIND) remove $(PACKAGE_NAME)
else
install:
$(INSTALL_DATA) -d $(OCAMLDESTDIR)/$(PACKAGE_NAME)
$(INSTALL_DATA) -t $(OCAMLDESTDIR)/$(PACKAGE_NAME) $(INSTALLABLE)
ifneq ($(strip $(INSTALLABLE_DLL)),)
$(INSTALL_DATA) -t $(OCAMLDESTDIR)/stublibs $(INSTALLABLE_DLL)
endif
uninstall:
$(RM) -r $(OCAMLDESTDIR)/$(PACKAGE_NAME) \
$(INSTALLABLE_DLL:%=$(OCAMLDESTDIR)/stublibs/%)
endif
# Makefile and configure #######################################################
Makefile: Makefile.in config.status
./config.status
config.status: configure
./config.status --recheck
configure: configure.ac
autoconf