automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

compiling in subdirs, linking in top-level dir


From: Guillaume Rousse
Subject: compiling in subdirs, linking in top-level dir
Date: Thu, 23 Nov 2006 16:11:05 +0100
User-agent: Thunderbird 1.5.0.8 (X11/20061109)

I'm having troubles building a large ocaml library, where code is
divided into subdirectories for maintainance ease, as each of them
relies on optional dependencies.

The final stage (linking) has to be done from the top-level directory,
so as to create a single library. As linking order is strict, I have to
give linker a precise list of files. So far I tried various strategies:

1) compile from subdirs, link from top-level dir
This means recursing in each subdir to compile file:
SUBDIRS = a
if (DEPB)
SUBDIRS += b
endif

This make writing suffix rules easy
.ml.cmo:
        $(OCAMLC) -I ../ $(OCAMLCFLAGS) -c $<

However, I have troubles to compute exact object list order from the
top-level directory...

(Actually, I never tried this strategy with automake, with autoconf
only, but the problem stay the same.

2) compile and link from the top-level dir
I just maintain the list of object file directly:
OCAMLSOURCES = a/a1.ml a/a2.ml
if (DEPB)
OCAMLSOURCES += b/b1.ml b/b2/ml
endif

This make writing linking target easy
lib.cma:
        $(OCAMLMKLIB) -o lib $(OCAMLSOURCES:.ml=.cmo)

However, this make writing compilation suffix rules difficult, as I have
to pass a directory-specific -I flag for each of them:

a/.ml.cmo:
        $(OCAMLC) -I a $(OCAMLCFLAGS) -c $<

b/.ml.cmo:
        $(OCAMLC) -I b $(OCAMLCFLAGS) -c $<

Alternatively, I can produce a single -I flags including all
directories, but it is a bit ugly.

Is there any other choice ?




reply via email to

[Prev in Thread] Current Thread [Next in Thread]