Skip to content

Commit ccb5a56

Browse files
committed
ocamlyices2: only build the static stub using static libgmp.a.
The library libgmp.a will be searched in system dirs or you can use the flag --with-static-gmp= when running ./configure for setting your own libgmp.a. If no libgmp.a is found, the shared library is used. You can force the use of shared gmp library with --with-shared-gmp. If --with-shared-gmp is not given, the libgmp.a that has been found will be included in the list of installed files. The reason is because if we want to build a shared-gmp-free binary, zarith will sometimes pick the shared library (with -lgmp) over the static lbirary libgmp.a. Including libgmp.a in the distribution of ocamlyices2 is a convenience for creating gmp-shared-free binaries. Why do we prefer using a static version of libgmp.a? =================================================== This is because we build a non-PIC static version of libyices.a. If we wanted to build both static and shared stubs, we should either - build a PIC libyices.a but it would conflict with the non-PIC one - build a shared library libyices.so. For now, I chose to just skip the shared stubs (dllyices2_stubs.so). Also: * turn on -fPIC (in configure.ac) only if non-static gmp * added a way to link statically to libgmp.a (--with-static-gmp) * use -package instead of -I/lib for compiling *.c in ocamlc This option uses the change I made to the build system of libyices. Why? Because I want the possibility of producing binaries that do not need any dll alongside. Guess the host system and pass it to libyices ./configure ========================================================= It is now possible to use ./configure for mingw32 cross-compilation.
1 parent b831a8c commit ccb5a56

10 files changed

+4407
-126
lines changed

Makefile

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all: ext build
1+
all: ext/lib/libyices.a build
22
# Be helpful if not configured
33
Makefile.config: configure
44
@echo Please run ./configure first; exit 1
@@ -25,7 +25,7 @@ CMA_FILE = src/$(LIB_NAME).cma
2525
CMXA_FILE = src/$(LIB_NAME).cmxa
2626
LIB_FILE = src/lib$(LIB_NAME)_stubs.a
2727
A_FILE = src/$(LIB_NAME).a # Generated with the .cmxa
28-
DLL_FILE = src/dll$(LIB_NAME)_stubs.so
28+
DLL_FILE = src/dll$(LIB_NAME)_stubs.$(SO)
2929

3030
ANNOT_FILES = $(ML_SOURCE:%.ml=%.annot)
3131
ifdef BIN_ANNOT
@@ -37,13 +37,21 @@ TESTS_OPT = $(TESTS:%.ml=%.opt)
3737

3838

3939
# Build and install files
40-
41-
BUILD_FILES = $(CMA_FILE) $(DLL_FILE) $(LIB_FILE)
40+
# For now, DLL_FILE is not built because it needs either a PIC libyices.a
41+
# that we could build with --with-pic, or the shared library libyices.so.
42+
# For now, only the static stub is built and linked statically against
43+
# non-PIC libyices.a.
44+
# We also put libgmp.a (if a static libgmp has been found/given) to be sure
45+
# that a static version of libgmp is picked in priority when linking against
46+
# Zarith. To avoid this behaviour, just pass --with-shared-gmp.
47+
BUILD_FILES = $(CMA_FILE) $(LIB_FILE)
4248
INSTALL_FILES = META \
43-
$(CMA_FILE) $(DLL_FILE) $(LIB_FILE)\
49+
$(CMA_FILE) $(LIB_FILE) \
4450
$(MLI_SOURCE) $(CMI_FILES) \
4551
$(ANNOT_FILES) \
46-
src/libyices.a
52+
ext/lib/libyices.a \
53+
$(if $(STATIC_GMP),src/libgmp.a)
54+
4755
ifdef HAVE_OCAMLOPT
4856
BUILD_FILES += $(CMXA_FILE) $(CMXS_FILE) $(A_FILE)
4957
INSTALL_FILES += $(CMXA_FILE) $(CMXS_FILE) $(A_FILE)
@@ -61,13 +69,15 @@ ifdef HAVE_OUNIT
6169
endif
6270

6371
################################################################################
72+
src/libyices.a: ext/lib/libyices.a
73+
cp $^ $@
6474

65-
ext: ext/libyices.a
66-
67-
ext/libyices.a:
68-
$(MAKE) -C ext
69-
src/libyices.a: ext/libyices.a
70-
cp ext/libyices.a src/libyices.a
75+
MAKE_VARIABLES = \
76+
$(if $(STATIC_GMP),STATIC_GMP=$(STATIC_GMP)) \
77+
$(if $(FORCE_SHARED_GMP),FORCE_SHARED_GMP=$(FORCE_SHARED_GMP)) \
78+
HOST=$(HOST)
79+
ext/lib/libyices.a:
80+
$(MAKE) -C ext $(MAKE_VARIABLES)
7181

7282
debug: CFLAGS += -DDEBUG
7383
debug: build
@@ -96,16 +106,26 @@ src/types.o: src/types.c src/config.h src/types.h src/terms.h src/misc.h
96106
# -custom will simply integrate the ocamlrun.a in the library. With -custom,
97107
# the resulting library will be forced to be a static library (.a).
98108
%.o: %.c
99-
$(OCAMLFIND) ocamlc -g -custom -c $< -ccopt '-std=c99 -fPIC $(CFLAGS) -I$(OCAML_LIBDIR) -I$(ZARITH_LIBDIR) -Iext -Isrc'
109+
$(OCAMLFIND) ocamlc $(PACKAGES) -g -custom -c $< -ccopt '-std=c99 $(CFLAGS) -Iext/include -Isrc $(CPPFLAGS)'
100110
mv $(notdir $@) $@
101111

112+
ifneq ($(STATIC_GMP),)
113+
src/libgmp.a: $(STATIC_GMP)
114+
cp $^ $@
115+
$(LIB_FILE) $(DLL_FILE): | src/libgmp.a
116+
endif
117+
102118
# Compile libyices2_stubs.a and dllyices2_stubs.so.
103119
# NOTE: If I use the flag -Lext for finding the library -lyices, the resulting
104120
# library will complain about -Lext being useless.
105121
# To avoid that, we ocamlmklib in the same dir as libyices.a and use -L. (which
106122
# should not output any warning when building with the yices2 package).
107-
src/lib$(LIB_NAME)_stubs.a src/dll$(LIB_NAME)_stubs.so: $(OBJECTS) | src/libyices.a
108-
cd $(dir $@) && $(OCAMLFIND) ocamlmklib -o $(LIB_NAME)_stubs $(notdir $^) $(LDFLAGS) $(LIBS) -L.
123+
#
124+
# The preprocessor variable -DNOYICES_DLL allows to disable the linking to a dll
125+
# and thus you can link to a static libyices.a instead of libyices.dll.a/libyices.a.
126+
# -custom = only produce static libyices_stubs.a, not the shared dllyices_stubs.so.
127+
$(LIB_FILE) $(DLL_FILE): $(OBJECTS) | src/libyices.a
128+
cd src && $(OCAMLFIND) ocamlmklib -o $(LIB_NAME)_stubs $(notdir $^) $(LDFLAGS) $(LIBS) -custom -lyices -L. -ccopt -DNOYICES_DLL
109129

110130
src/%.cmi: src/%.mli
111131
$(OCAMLFIND) ocamlc $(PACKAGES) -I src -annot $(BIN_ANNOT) -c -o $@ $<
@@ -116,17 +136,17 @@ src/%.cmx: src/%.ml
116136

117137
# Library compilation ##########################################################
118138

119-
%$(LIB_NAME).cma: %$(LIB_NAME).cmo | %lib$(LIB_NAME)_stubs.a %dll$(LIB_NAME)_stubs.so
139+
%$(LIB_NAME).cma: %$(LIB_NAME).cmo | %lib$(LIB_NAME)_stubs.a %dll$(LIB_NAME)_stubs.$(SO)
120140
$(OCAMLFIND) ocamlc -a \
121-
-cclib '-l$(LIB_NAME)_stubs -lyices -lgmp $(LDFLAGS) $(LIBS)' \
141+
-cclib '-l$(LIB_NAME)_stubs -lyices $(LDFLAGS) $(LIBS)' \
122142
-custom $^ -o $@
123143

124144
%$(LIB_NAME).cmxa %$(LIB_NAME).a: %$(LIB_NAME).cmx | %lib$(LIB_NAME)_stubs.a
125145
$(OCAMLFIND) ocamlopt -a \
126-
-cclib '-l$(LIB_NAME)_stubs -lyices -lgmp $(LDFLAGS) $(LIBS)' \
146+
-cclib '-l$(LIB_NAME)_stubs -lyices $(LDFLAGS) $(LIBS)' \
127147
$^ -o $@
128148

129-
%$(LIB_NAME).cmxs %$(LIB_NAME).so: %$(LIB_NAME).cmxa %$(LIB_NAME).cmx | %dll$(LIB_NAME)_stubs.so
149+
%$(LIB_NAME).cmxs %$(LIB_NAME).$(SO): %$(LIB_NAME).cmxa %$(LIB_NAME).cmx | %dll$(LIB_NAME)_stubs.$(SO)
130150
$(OCAMLFIND) ocamlopt -shared -I $(dir $@) $^ -o $@
131151

132152
# Documentation ################################################################

Makefile.config.in

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,16 @@ CC = @CC@
1818

1919
# Configuration
2020
CFLAGS = @CFLAGS@
21-
LIBS = -lyices @LIBS@
21+
LIBS = @LIBS@
22+
23+
CPPFLAGS = @CPPFLAGS@
24+
CFLAGS = @CFLAGS@
25+
LDFLAGS = @LDFLAGS@
26+
27+
HOST_OS = @host_os@
28+
HOST = @host@
29+
HOST_CPU = @host_cpu@
30+
31+
SO = @SO@
32+
STATIC_GMP = @STATIC_GMP@
33+
FORCE_SHARED_GMP = @FORCE_SHARED_GMP@

0 commit comments

Comments
 (0)