Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix building on architectures where ocamlopt is not available
  • Loading branch information
hillu authored and rwmjones committed Feb 28, 2014
1 parent a4be423 commit f75142c
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 32 deletions.
18 changes: 17 additions & 1 deletion builder/Makefile.am
Expand Up @@ -68,7 +68,7 @@ noinst_DATA =
if HAVE_OCAML

# Note this list must be in dependency order.
OBJECTS = \
deps = \
$(top_builddir)/mllib/libdir.cmx \
$(top_builddir)/mllib/common_gettext.cmx \
$(top_builddir)/mllib/common_utils.cmx \
Expand Down Expand Up @@ -109,6 +109,12 @@ OBJECTS = \
cmdline.cmx \
builder.cmx

if HAVE_OCAMLOPT
OBJECTS = $(deps)
else
OBJECTS = $(patsubst %.cmx,%.cmo,$(deps))
endif

bin_SCRIPTS = virt-builder

# -I $(top_builddir)/src/.libs is a hack which forces corresponding -L
Expand All @@ -134,12 +140,22 @@ OCAMLCLIBS = \
-pthread -lpthread \
-lncurses -lcrypt

if HAVE_OCAMLOPT
virt-builder: $(OBJECTS)
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
mlguestfs.cmxa -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
$(OCAML_GCOV_LDFLAGS) \
-o $@
else
virt-builder: $(OBJECTS)
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \
mlguestfs.cma -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
-custom \
$(OCAML_GCOV_LDFLAGS) \
-o $@
endif

.mli.cmi:
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Expand Up @@ -1026,6 +1026,8 @@ AS_IF([test "x$enable_ocaml" != "xno"],[
])
AM_CONDITIONAL([HAVE_OCAML],
[test "x$OCAMLC" != "xno" && test "x$OCAMLFIND" != "xno"])
AM_CONDITIONAL([HAVE_OCAMLOPT],
[test "x$OCAMLOPT" != "xno" && test "x$OCAMLFIND" != "xno"])
AM_CONDITIONAL([HAVE_OCAMLDOC],
[test "x$OCAMLDOC" != "xno"])

Expand Down
60 changes: 41 additions & 19 deletions mllib/Makefile.am
Expand Up @@ -69,6 +69,25 @@ if HAVE_OCAML
# - We're not actually building a functioning program here, we're just
# linking everything together to check all the modules build OK.
# - This list must be in dependency order.
ocaml_modules = config \
libdir \
common_gettext \
common_utils \
urandom \
random_seed \
hostname \
timezone \
firstboot \
perl_edit \
tTY \
fsync \
progress \
uRI \
crypt \
password \
mkdtemp \
planner

OBJECTS = \
$(top_builddir)/fish/guestfish-progress.o \
$(top_builddir)/fish/guestfish-uri.o \
Expand All @@ -77,25 +96,13 @@ OBJECTS = \
progress-c.o \
uri-c.o \
crypt-c.o \
mkdtemp-c.o \
config.cmx \
libdir.cmx \
common_gettext.cmx \
common_utils.cmx \
urandom.cmx \
random_seed.cmx \
hostname.cmx \
timezone.cmx \
firstboot.cmx \
perl_edit.cmx \
tTY.cmx \
fsync.cmx \
progress.cmx \
uRI.cmx \
crypt.cmx \
password.cmx \
mkdtemp.cmx \
planner.cmx
mkdtemp-c.o

if HAVE_OCAMLOPT
OBJECTS += $(patsubst %,%.cmx,$(ocaml_modules))
else
OBJECTS += $(patsubst %,%.cmo,$(ocaml_modules))
endif

noinst_SCRIPTS = dummy

Expand All @@ -116,11 +123,20 @@ OCAMLCLIBS = \
-L../gnulib/lib/.libs -lgnu

dummy: $(OBJECTS)
if HAVE_OCAMLOPT
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
mlguestfs.cmxa -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
$(OCAML_GCOV_LDFLAGS) \
-o $@
else
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \
mlguestfs.cma -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
-custom \
$(OCAML_GCOV_LDFLAGS) \
-o $@
endif

.mli.cmi:
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
Expand Down Expand Up @@ -153,9 +169,15 @@ DEFAULT_INCLUDES = \

check_SCRIPTS = common_utils_tests

if HAVE_OCAMLOPT
common_utils_tests: common_gettext.cmx common_utils.cmx common_utils_tests.cmx
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
mlguestfs.cmxa -linkpkg $^ -cclib -lncurses -o $@
else
common_utils_tests: common_gettext.cmo common_utils.cmo common_utils_tests.cmo
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \
mlguestfs.cma -linkpkg $^ -cclib -lncurses -o $@
endif

TESTS_ENVIRONMENT = $(top_builddir)/run --test

Expand Down
28 changes: 19 additions & 9 deletions ocaml/Makefile.am
Expand Up @@ -40,7 +40,10 @@ if HAVE_OCAML
OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX
OCAMLOPTFLAGS = $(OCAMLCFLAGS)

noinst_DATA = mlguestfs.cma mlguestfs.cmxa META
noinst_DATA = mlguestfs.cma META
if HAVE_OCAMLOPT
noinst_DATA += mlguestfs.cmxa
endif

# Build the C part into a library, so that automake handles the C
# compilation step for us. Note that we don't directly use this
Expand All @@ -51,18 +54,15 @@ noinst_LIBRARIES = libguestfsocaml.a
# 'libmlguestfs.a' and if run at the same time, they will stomp on or
# corrupt each others copy. Hence we have to serialize the calls.

CLEANFILES += stamp-mlguestfs

mlguestfs.cma mlguestfs.cmxa: stamp-mlguestfs

stamp-mlguestfs: libguestfsocaml.a guestfs.cmo guestfs.cmx
mlguestfs.cma: libguestfsocaml.a guestfs.cmo
$(OCAMLMKLIB) -o mlguestfs \
$(libguestfsocaml_a_OBJECTS) guestfs.cmo \
-L$(top_builddir)/src/.libs -lguestfs

mlguestfs.cmxa: libguestfsocaml.a guestfs.cmx
$(OCAMLMKLIB) -o mlguestfs \
$(libguestfsocaml_a_OBJECTS) guestfs.cmx \
-L$(top_builddir)/src/.libs -lguestfs
touch $@

libguestfsocaml_a_CPPFLAGS = \
-DGUESTFS_PRIVATE=1 \
Expand Down Expand Up @@ -121,11 +121,17 @@ test_progs_opt += \
t/guestfs_430_progress_messages.opt
endif

test_progs_all = $(test_progs_bc) $(test_progs_opt)
test_progs_all = $(test_progs_bc)
if HAVE_OCAMLOPT
test_progs_all += $(test_progs_opt)
endif

TESTS = run-bindtests $(test_progs_all)

noinst_DATA += bindtests.bc bindtests.opt $(test_progs_all)
noinst_DATA += bindtests.bc $(test_progs_all)
if HAVE_OCAMLOPT
noinst_DATA += bindtests.opt
endif

%.bc: %.cmo mlguestfs.cma
$(top_builddir)/libtool -dlopen $(top_builddir)/src/.libs/libguestfs.la --mode=execute \
Expand Down Expand Up @@ -178,3 +184,7 @@ install-data-hook:
CLEANFILES += $(noinst_DATA)

endif

# Tell version 3.79 and up of GNU make to not build goals in this
# directory in parallel.
.NOTPARALLEL:
13 changes: 13 additions & 0 deletions ocaml/examples/Makefile.am
Expand Up @@ -49,12 +49,25 @@ noinst_SCRIPTS = create_disk inspect_vm

OCAMLFINDFLAGS = -cclib -L$(top_builddir)/src/.libs

if HAVE_OCAMLOPT
create_disk: create_disk.ml
$(OCAMLFIND) ocamlopt $(OCAMLFINDFLAGS) -package unix -linkpkg \
-warn-error A -I .. mlguestfs.cmxa $< -o $@

inspect_vm: inspect_vm.ml
$(OCAMLFIND) ocamlopt $(OCAMLFINDFLAGS) -package unix -linkpkg \
-warn-error A -I .. mlguestfs.cmxa $< -o $@
else

# This avoids:
# Error: Error on dynamically loaded library: ../dllmlguestfs.so: libguestfs.so.0: cannot open shared object file: No such file or directory
create_disk: create_disk.ml
$(top_builddir)/run $(OCAMLFIND) ocamlc $(OCAMLFINDFLAGS) -package unix -linkpkg \
-warn-error A -I .. mlguestfs.cma $< -o $@

inspect_vm: inspect_vm.ml
$(top_builddir)/run $(OCAMLFIND) ocamlc $(OCAMLFINDFLAGS) -package unix -linkpkg \
-warn-error A -I .. mlguestfs.cma $< -o $@
endif

endif
18 changes: 17 additions & 1 deletion resize/Makefile.am
Expand Up @@ -31,7 +31,7 @@ SOURCES = \
if HAVE_OCAML

# Note this list must be in dependency order.
OBJECTS = \
deps = \
$(top_builddir)/mllib/tty-c.o \
$(top_builddir)/mllib/tTY.cmx \
$(top_builddir)/mllib/fsync-c.o \
Expand All @@ -47,6 +47,12 @@ OBJECTS = \
$(top_builddir)/mllib/config.cmx \
resize.cmx

if HAVE_OCAMLOPT
OBJECTS = $(deps)
else
OBJECTS = $(patsubst %.cmx,%.cmo,$(deps))
endif

bin_SCRIPTS = virt-resize

# -I $(top_builddir)/src/.libs is a hack which forces corresponding -L
Expand All @@ -69,12 +75,22 @@ OCAMLCLIBS = \
-L../src/.libs -lutils \
-L../gnulib/lib/.libs -lgnu

if HAVE_OCAMLOPT
virt-resize: $(OBJECTS)
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
mlguestfs.cmxa -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
$(OCAML_GCOV_LDFLAGS) \
-o $@
else
virt-resize: $(OBJECTS)
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \
mlguestfs.cma -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
-custom \
$(OCAML_GCOV_LDFLAGS) \
-o $@
endif

.mli.cmi:
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
Expand Down
18 changes: 17 additions & 1 deletion sparsify/Makefile.am
Expand Up @@ -32,7 +32,7 @@ SOURCES = \
if HAVE_OCAML

# Note this list must be in dependency order.
OBJECTS = \
deps = \
$(top_builddir)/fish/guestfish-progress.o \
$(top_builddir)/mllib/tty-c.o \
$(top_builddir)/mllib/progress-c.o \
Expand All @@ -44,6 +44,12 @@ OBJECTS = \
statvfs-c.o \
sparsify.cmx

if HAVE_OCAMLOPT
OBJECTS = $(deps)
else
OBJECTS = $(patsubst %.cmx,%.cmo,$(deps))
endif

bin_SCRIPTS = virt-sparsify

# -I $(top_builddir)/src/.libs is a hack which forces corresponding -L
Expand All @@ -61,12 +67,22 @@ endif
OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX $(OCAMLPACKAGES)
OCAMLOPTFLAGS = $(OCAMLCFLAGS)

if HAVE_OCAMLOPT
virt-sparsify: $(OBJECTS)
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
mlguestfs.cmxa -linkpkg $^ \
-cclib -lncurses \
$(OCAML_GCOV_LDFLAGS) \
-o $@
else
virt-sparsify: $(OBJECTS)
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \
mlguestfs.cma -linkpkg $^ \
-cclib -lncurses \
-custom \
$(OCAML_GCOV_LDFLAGS) \
-o $@
endif

.mli.cmi:
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
Expand Down
18 changes: 17 additions & 1 deletion sysprep/Makefile.am
Expand Up @@ -85,7 +85,7 @@ SOURCES = \
if HAVE_OCAML

# Note this list must be in dependency order.
OBJECTS = \
deps = \
$(top_builddir)/mllib/common_gettext.cmx \
$(top_builddir)/mllib/common_utils.cmx \
$(top_builddir)/fish/guestfish-uri.o \
Expand All @@ -106,6 +106,12 @@ OBJECTS = \
$(patsubst %,sysprep_operation_%.cmx,$(operations)) \
main.cmx

if HAVE_OCAMLOPT
OBJECTS = $(deps)
else
OBJECTS = $(patsubst %.cmx,%.cmo,$(deps))
endif

bin_SCRIPTS = virt-sysprep

# -I $(top_builddir)/src/.libs is a hack which forces corresponding -L
Expand All @@ -128,12 +134,22 @@ OCAMLCLIBS = \
-L../src/.libs -lutils \
-L../gnulib/lib/.libs -lgnu

if HAVE_OCAMLOPT
virt-sysprep: $(OBJECTS)
$(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) \
mlguestfs.cmxa -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
$(OCAML_GCOV_LDFLAGS) \
-o $@
else
virt-sysprep: $(OBJECTS)
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) \
mlguestfs.cma -linkpkg $^ \
-cclib '$(OCAMLCLIBS)' \
-custom \
$(OCAML_GCOV_LDFLAGS) \
-o $@
endif

.mli.cmi:
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
Expand Down

0 comments on commit f75142c

Please sign in to comment.