[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2007-03-30 (16:27) |
From: | Aleksey Nogin <nogin@m...> |
Subject: | Re: Example OMakefile to package OCaml code as a C library |
On 28.03.2007 01:40, Joel Reymont wrote: > Does anyone have an example OMakefile that can be used to package OCaml > code as a C library? > > This is along the lines of what I'm trying to accomplish: > > ocamlopt -output-obj -o fibcaml.o fib.ml > ocamlopt -c fibwrap.c > cp /usr/local/lib/ocaml/libasmrun.a libfib.a > ar r libfib.a fibcaml.o fibwrap.o > Joel, The above seems relatively straightforward. I would imagine that you can give ocamlopt a list of .cmx files instead of the .ml files (this should make things more modular and incremental). So you just do something like: ----------- LIB = fib CFILES = fibwrap MLFILES = fib OCAMLLIB = $(dir $"$(shell $(OCAMLC) -where)") $(LIB)caml$(EXT_OBJ): $(addsuffix .cmx, $(MLFILES)) $(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) -output-obj -o $@ $(OCamlLinkSort $+) OBJS = $(addsuffix $(EXT_OBJ), $(LIB)caml $(CFILES)) lib$(LIB)$(EXT_LIB): $(OCAMLLIB)/libasmrun$(EXT_LIB) $(OBJS) cp -f $< $@ ar q $@ $(OBJS) ---------- The above can also be easily made into a function that can be reused: ---------- OCAMLLIB = $(dir $"$(shell $(OCAMLC) -where)") MakeWrapLib(LIB, MLFILES, CFILES) = $(LIB)caml$(EXT_OBJ): $(addsuffix .cmx, $(MLFILES)) $(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) -output-obj -o $@ $(OCamlLinkSort $+) OBJS = $(addsuffix $(EXT_OBJ), $(LIB)caml $(CFILES)) lib$(LIB)$(EXT_LIB): $(OCAMLLIB)/libasmrun$(EXT_LIB) $(OBJS) cp -f $< $@ ar q $@ $(OBJS) return lib$(LIB)$(EXT_LIB) MakeWrapLib(fib, fib, fibwrap) ---------- Aleksey