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 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 57D37BC69 for ; Wed, 28 Mar 2007 23:01:44 +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 l2SL1fux003638 for ; Wed, 28 Mar 2007 23:01:43 +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 <0JFM00DG7T2R39@hpux03.hrl.com> for caml-list@inria.fr; Wed, 28 Mar 2007 14:01:40 -0700 (PDT) Date: Wed, 28 Mar 2007 14:01:39 -0700 From: Aleksey Nogin Subject: Re: [Caml-list] Can this OMakefile be simplified? In-reply-to: <755EDEB6-46CF-4212-8D37-2F83E62550E2@gmail.com> To: Joel Reymont Cc: Caml List , omake@metaprl.org Reply-To: Caml List , omake@metaprl.org Message-id: <460AD7B3.9020900@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: <755EDEB6-46CF-4212-8D37-2F83E62550E2@gmail.com> X-Miltered: at concorde with ID 460AD7B5.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; bindings:01 ocaml:01 bindings:01 mangling:01 cmo:01 cmx:01 cmifiles:01 cmi:01 lib:01 cmxa:01 lib:01 stubs:01 ocamlfind:01 ocamlcflags:01 ocaml:01 On 28.03.2007 01:28, Joel Reymont wrote: > I found this OMakefile in the sqlite3 bindings for OCaml. I'm trying to > package my translator as a set of C bindings and I wonder if this > Omakefile can be made simpler. [...] > ########################################### > > SubstVersion(output, input) = > # should use fsubst, but it doesn't seem to be > # working properly in 0.9.2. > $(output) : $(input) > sed "s%@VERSION@%$(VERSION)%g" < $< > $@ I wonder what the problem was here - I would imagine it is fixed now. In any case, a lot of this version mangling stuff is probably specific to how the sqlite3 build environment is set up. A lot of the code below can be simplified using some of the features of the more recent versions of OMake. > ########################################### > OCamlLibraryExt(name, files, cfiles) = > OFILES = $(addsuffix $(EXT_OBJ), $(cfiles)) > CMOFILES = $(addsuffix .cmo, $(files)) > CMXFILES = $(addsuffix .cmx, $(files)) > CMIFILES = $(addsuffix .cmi, $(files)) > CLIB = $(file $(name)$(EXT_LIB)) > BYTELIB = $(file $(name).cma) > NATIVELIB = $(file $(name).cmxa) > STUBLIB = lib$(name)_stubs > # Create C library to contain all the object files... > StaticCLibrary($(STUBLIB), $(cfiles)) > # Link commands > # TODO: Doesn't work with ddls... > $(BYTELIB): $(CMOFILES) $(STUBLIB)$(EXT_LIB) > $(OCAMLFIND) $(OCAMLLINK) $(OCAMLFLAGS) $(OCAMLCFLAGS) \ > $(OCAML_LIB_FLAGS) -a -custom -cclib -l$(name)_stubs \ > -o $@ $(OCamlLinkSort $(CMOFILES)) > > $(NATIVELIB) $(CLIB): $(CMXFILES) $(STUBLIB)$(EXT_LIB) > $(OCAMLFIND) $(OCAMLOPTLINK) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) \ > $(OCAML_LIB_FLAGS) -a -cclib -l$(name)_stubs -o \ > $(NATIVELIB) $(OCamlLinkSort $(CMXFILES)) > > # Add to targets > if $(NATIVE_ENABLED) > library: $(NATIVELIB) > > if $(BYTE_ENABLED) > library: $(BYTELIB) The above can be significantly simplified, using something like the code below (untested). OCamlLibraryExt(name, files, cfiles) = STUBLIB = lib$(name)_stubs STUBLIB_BIN = $(StaticCLibrary $(STUBLIB), $(cfiles)) OCAMLCFLAGS += -custom OCAML_LIB_FLAGS += -cclib -l$(STUBLIB) LIB_FILES = $(OCamlLibrary $(name), $(files)) $(LIB_FILES): $(STUBLIB_BIN) library: $(LIB_FILES) return $(LIB_FILES) The "return" line is option - it is only needed if somebody wants to know with files just got their build rules defined (can be very helpful, as the usage of the StaticCLibrary and OCamlLibrary functions above demonstrates). > # Program with tag for executables > OCamlProgramExt(tag, name, sources) = > OCamlProgram($(name), $(sources)) > > if $(NATIVE_ENABLED) > $(tag) : $(name).opt > > if $(BYTE_ENABLED) > $(tag) : $(name).run The above is IMO unnecessary. The function can be defined as OCamlProgramExt(tag, name, sources) = $(tag): $(OCamlProgram $(name), $(sources)) but it is better to simply inline the corresponding code. > OCAMLLIBDIR = $(shell ocamlfind printconf stdlib) OCAMLLIBDIR = $(shell $(OCAMLC) -where) might be a slightly better idea (it's nice not to rely on having ocamlfind installed). Aleksey