Skip to content

Commit

Permalink
drop old compat code for ocaml < 4.05 (#151)
Browse files Browse the repository at this point in the history
it makes it incompatible with Ubuntu 16.04 that has reached end of life
  • Loading branch information
gautierhattenberger committed Oct 4, 2021
1 parent c6e88cc commit 0bf9275
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 98 deletions.
18 changes: 3 additions & 15 deletions lib/common/ocaml/Makefile
Expand Up @@ -33,27 +33,16 @@ endif


OCAMLBUILD=ocamlbuild -use-ocamlfind
CAMLP4_DEFS ?=

#
# NOTE: due to a bug in older ocamlbuild versions the build-dir can NOT be absolute
# see http://caml.inria.fr/mantis/view.php?id=5503
#
OCAML_VERSION := $(shell ocamlc -version)
OCAML_MAJOR := $(shell echo $(OCAML_VERSION) | cut -f1 -d.)
OCAMLC_MINOR := $(shell echo $(OCAML_VERSION) | cut -f2 -d.)
# using a recent ocaml(build) version >= 4,
# but build-dir MUST NOT contain ..
# so use some magic here to get a normalized absolute path if PPRZLINK_DIR is not set
PPRZLINK_DIR ?= $(realpath $(dir $(lastword $(MAKEFILE_LIST)))/../../..)
BUILDDIR ?= $(PPRZLINK_DIR)/build/ocaml/pprzlink

ifeq ($(shell test $(OCAMLC_MINOR) -ge 2; echo $$?),0)
ifeq ($(shell test $(OCAMLC_MINOR) -ge 4; echo $$?),0)
CAMLP4_DEFS += -DOCAML_V404
endif
endif

INSTALL_FLAGS ?=
# use this option leave ocamlfind ldconf file unchanged
INSTALL_FLAGS += -ldconf ignore
Expand All @@ -62,7 +51,6 @@ ifneq ($(DESTDIR),)
INSTALL_FLAGS += -destdir $(DESTDIR)
endif

PP_OPTS = -pp "camlp4o pa_macro.cmo $(CAMLP4_DEFS)"
# enforce checking a clear type checking between bytes and string
C_OPTS = -cflags -safe-string
INSTALL_FILES = $(shell ls $(BUILDDIR)/*.so $(BUILDDIR)/*.a $(BUILDDIR)/*.mli $(BUILDDIR)/*.cm* $(BUILDDIR)/common/*.mli $(BUILDDIR)/common/*.cm*)
Expand All @@ -73,20 +61,20 @@ all: byte native
byte: _tags META
@echo Build bytecode lib
$(Q)test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
$(Q)$(OCAMLBUILD) $(QUIET) $(PP_OPTS) $(C_OPTS) -build-dir $(BUILDDIR) -I common lib-pprzlink.cma
$(Q)$(OCAMLBUILD) $(QUIET) $(C_OPTS) -build-dir $(BUILDDIR) -I common lib-pprzlink.cma
$(Q)cp META $(BUILDDIR)

# byte with statically linked libs
static: _tags META
@echo Build bytecode lib with static linking
$(Q)test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
$(Q)$(OCAMLBUILD) $(QUIET) $(PP_OPTS) $(C_OPTS) -build-dir $(BUILDDIR) -tag static -I common lib-pprzlink.cma
$(Q)$(OCAMLBUILD) $(QUIET) $(C_OPTS) -build-dir $(BUILDDIR) -tag static -I common lib-pprzlink.cma
$(Q)cp META $(BUILDDIR)

native: _tags META
@echo Build native lib
$(Q)test -d $(BUILDDIR) || mkdir -p $(BUILDDIR)
$(Q)$(OCAMLBUILD) $(QUIET) $(PP_OPTS) $(C_OPTS) -build-dir $(BUILDDIR) -I common lib-pprzlink.cmxa
$(Q)$(OCAMLBUILD) $(QUIET) $(C_OPTS) -build-dir $(BUILDDIR) -I common lib-pprzlink.cmxa
$(Q)cp META $(BUILDDIR)

install: clean_lib byte native META
Expand Down
39 changes: 0 additions & 39 deletions lib/common/ocaml/compatPL.ml

This file was deleted.

27 changes: 0 additions & 27 deletions lib/common/ocaml/compatPL.mli

This file was deleted.

1 change: 0 additions & 1 deletion lib/v1.0/ocaml/lib-pprzlink.mllib
Expand Up @@ -4,4 +4,3 @@ protocol
pprz_transport
pprzlog_transport
xbee_transport
compatPL
6 changes: 3 additions & 3 deletions lib/v1.0/ocaml/pprzLink.ml
Expand Up @@ -245,7 +245,7 @@ let scale_of_units = fun ?auto from_unit to_unit ->
and a = try Some (Xml.attrib u "auto") with _ -> None in
let a = match auto, a with
| Some _, None | None, None -> "" (* No auto conversion *)
| Some t, Some _ | None, Some t -> CompatPL.lowercase_ascii t (* param auto is used before attribute *)
| Some t, Some _ | None, Some t -> String.lowercase_ascii t (* param auto is used before attribute *)
in
if (f = from_unit || a = "display") && (t = to_unit || a = "code") then true else false
) (Xml.children units_xml) in
Expand Down Expand Up @@ -332,14 +332,14 @@ let field_of_xml = fun xml ->
let auc = alt_unit_coef_of_xml xml in
let values = try Str.split pipe_regexp (Xml.attrib xml "values") with _ -> [] in

( CompatPL.lowercase_ascii (xml_attrib xml "name"),
( String.lowercase_ascii (xml_attrib xml "name"),
{ _type = t; fformat = f; alt_unit_coef = auc; enum=values })

let string_of_values = fun vs ->
String.concat " " (List.map (fun (a,v) -> sprintf "%s=%s" a (string_of_value v)) vs)

let assoc = fun a vs ->
try List.assoc (CompatPL.lowercase_ascii a) vs with Not_found ->
try List.assoc (String.lowercase_ascii a) vs with Not_found ->
failwith (sprintf "Attribute '%s' not found in '%s'" a (string_of_values vs))

let float_assoc = fun (a:string) vs ->
Expand Down
1 change: 0 additions & 1 deletion lib/v2.0/ocaml/lib-pprzlink.mllib
Expand Up @@ -4,4 +4,3 @@ protocol
pprz_transport
pprzlog_transport
xbee_transport
compatPL
6 changes: 3 additions & 3 deletions lib/v2.0/ocaml/pprzLink.ml
Expand Up @@ -248,7 +248,7 @@ let scale_of_units = fun ?auto from_unit to_unit ->
and a = try Some (Xml.attrib u "auto") with _ -> None in
let a = match auto, a with
| Some _, None | None, None -> "" (* No auto conversion *)
| Some t, Some _ | None, Some t -> CompatPL.lowercase_ascii t (* param auto is used before attribute *)
| Some t, Some _ | None, Some t -> String.lowercase_ascii t (* param auto is used before attribute *)
in
if (f = from_unit || a = "display") && (t = to_unit || a = "code") then true else false
) (Xml.children units_xml) in
Expand Down Expand Up @@ -335,14 +335,14 @@ let field_of_xml = fun xml ->
let auc = alt_unit_coef_of_xml xml in
let values = try Str.split pipe_regexp (Xml.attrib xml "values") with _ -> [] in

( CompatPL.lowercase_ascii (xml_attrib xml "name"),
( String.lowercase_ascii (xml_attrib xml "name"),
{ _type = t; fformat = f; alt_unit_coef = auc; enum=values })

let string_of_values = fun vs ->
String.concat " " (List.map (fun (a,v) -> sprintf "%s=%s" a (string_of_value v)) vs)

let assoc = fun a vs ->
try List.assoc (CompatPL.lowercase_ascii a) vs with Not_found ->
try List.assoc (String.lowercase_ascii a) vs with Not_found ->
failwith (sprintf "Attribute '%s' not found in '%s'" a (string_of_values vs))

let float_assoc = fun (a:string) vs ->
Expand Down
9 changes: 0 additions & 9 deletions tools/generator/Makefile
Expand Up @@ -28,21 +28,12 @@ OCAMLBUILD=ocamlbuild -use-ocamlfind
#
# NOTE: due to a bug in older ocamlbuild versions the build-dir can NOT be absolute
# see http://caml.inria.fr/mantis/view.php?id=5503
#
OCAML_VERSION := $(shell ocamlc -version)
OCAML_MAJOR := $(shell echo $(OCAML_VERSION) | cut -f1 -d.)
ifeq ($(shell test $(OCAML_MAJOR) -lt 4; echo $$?),0)
# need to use an old buggy ocaml(build) version: dir MUST be relative
OCAML_LIBDIR ?= ../../build/ocaml
BUILDDIR ?= ../../build/ocaml/gen
else
# using a recent ocaml(build) version without THAT particular bug,
# but dir MUST NOT contain ..
# so use some magic here to get a normalized absolute path if PPRZLINK_DIR is not set
PPRZLINK_DIR ?= $(realpath $(dir $(lastword $(MAKEFILE_LIST)))/../..)
OCAML_LIBDIR ?= $(PPRZLINK_DIR)/build/ocaml
BUILDDIR ?= $(PPRZLINK_DIR)/build/ocaml/gen
endif

# FIXME test if pprzlink is installed in the system or try local build
export OCAMLPATH=$(OCAML_LIBDIR)
Expand Down

0 comments on commit 0bf9275

Please sign in to comment.