* Can this OMakefile be simplified?
@ 2007-03-28 8:28 Joel Reymont
2007-03-28 21:01 ` [Caml-list] " Aleksey Nogin
0 siblings, 1 reply; 2+ messages in thread
From: Joel Reymont @ 2007-03-28 8:28 UTC (permalink / raw)
To: Caml List
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.
Any suggestions? Pointers to simpler Omakefiles for other C bindings?
Thanks in advance, Joel
###########################################
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" < $< > $@
###########################################
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)
# Program with tag for executables
OCamlProgramExt(tag, name, sources) =
OCamlProgram($(name), $(sources))
if $(NATIVE_ENABLED)
$(tag) : $(name).opt
if $(BYTE_ENABLED)
$(tag) : $(name).run
###############################
.PHONY : library examples install dist
VERSION = $(nth 0, $(rev $(split -, $(dir .))))
OCAMLFLAGS = -w A
OCAMLPPFLAGS = -pp camlp4r
OCAMLDEPFLAGS = -pp camlp4r
BYTE_ENABLED = true
NATIVE_ENABLED = true
OCAMLLIBDIR = $(shell ocamlfind printconf stdlib)
CFLAGS = -Wall -Werror -I $(OCAMLLIBDIR)
PKG = $(basename $(absname $(dir .)))
# Targets in subdirectories...
.SUBDIRS: lib examples
# Targets:
.DEFAULT: library examples
# Distribution:
dist : .DEFAULT
tar -C $(dir ..) -c -j -f $(dir ..)/$(PKG).tar.bz2 \
$(addprefix $(PKG)/, $(shell bzr inventory --kind file))
--
http://wagerlabs.com/
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Can this OMakefile be simplified?
2007-03-28 8:28 Can this OMakefile be simplified? Joel Reymont
@ 2007-03-28 21:01 ` Aleksey Nogin
0 siblings, 0 replies; 2+ messages in thread
From: Aleksey Nogin @ 2007-03-28 21:01 UTC (permalink / raw)
To: Joel Reymont; +Cc: Caml List, omake
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-03-28 21:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-28 8:28 Can this OMakefile be simplified? Joel Reymont
2007-03-28 21:01 ` [Caml-list] " Aleksey Nogin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox