From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=UPPERCASE_25_50 autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 8A145BC69 for ; Fri, 30 Mar 2007 18:27:25 +0200 (CEST) Received: from hub.hrl.com (hub.hrl.com [208.179.241.200]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l2UGROAQ008167 for ; Fri, 30 Mar 2007 18:27:25 +0200 Received: from [192.27.172.110] (dangle.hrl.com [192.27.172.110]) by hpux03.hrl.com (iPlanet Messaging Server 5.2 HotFix 2.10 (built Dec 26 2005)) with ESMTP id <0JFQ0039Y5PNBK@hpux03.hrl.com> for caml-list@inria.fr; Fri, 30 Mar 2007 09:27:23 -0700 (PDT) Date: Fri, 30 Mar 2007 09:27:23 -0700 From: Aleksey Nogin Subject: Re: Example OMakefile to package OCaml code as a C library In-reply-to: To: Joel Reymont Cc: Caml List , omake@metaprl.org Reply-To: omake@metaprl.org, Caml List Message-id: <460D3A6B.8040006@metaprl.org> Organization: MetaPRL/Mojave Research Group MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT User-Agent: Thunderbird 1.5.0.10 (X11/20070301) References: X-Miltered: at concorde with ID 460D3A6C.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 ocaml:01 ocamlopt:01 -output-obj:01 ocamlopt:01 usr:01 lib:01 libasmrun:01 cmx:01 modular:01 lib:01 ocamllib:01 ocamlc:01 -where:01 cmx:01 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