Bigloo compilation

Pierre Weis (weis@pauillac.inria.fr)
Wed, 16 Mar 1994 12:08:13 +0100 (MET)

From: Pierre Weis <weis@pauillac.inria.fr>
Message-Id: <9403161108.AA07387@pauillac.inria.fr>
Subject: Bigloo compilation
To: caml-list@pauillac.inria.fr
Date: Wed, 16 Mar 1994 12:08:13 +0100 (MET)

Although Bigloo is very easy to use, it is not so evident to switch
from regular camlc compilation to Bigloo compilation: you have to
adapt the make files.
This message is intended to help you in this process: it gives you a
very simple way to build a new make file, adapted to the compilation
using Bigloo.

Makefile template:
------------------
We give here a makefile template to build applications using
the Bigloo compiler. It uses a perl script, camloodep, to automatically
find out the depencies between modules. Thus, to build your
application, you have to complete the template by filling the make
variables OBJS and DEST:
OBJS is the exhaustive list of object files used in the application
(remember that this are .o files in bigloo, instead of .zo files when
compiling with camlc).
DEST is the name you want to give to your application.

Then you have to type in the two following shell commands:
1) First
make depend
that completes the makefile (which is supposed to be named Makefile,
and should be writable), with all the dependencies found in the Caml
source files.
2) Second
make
that compiles all your source files and build the target executable program.

Compilation flags for Bigloo:
-----------------------------
Compilation flags SAFECOMPFLAGS and UNSAFECOMPFLAGS are used to tune the
Bigloo compiler.
- UNSAFECOMPFLAGS correspond to the ``-O fast'' option of the camlc
compiler (no bound tests for vector and string accesses and
updates). This is the most optimizing option for Caml compilation
using Bigloo.
- SAFECOMPFLAGS is the safe optimizing option of Bigloo: you can
remove the -O2 flag, the compilation will be a bit faster but the
compiled code runs significantly slower.
Choose the flags appropriate to your case (default flags of the make file
template are safe ones).

******* file Makefile (template) *********
OBJS= # List of object files
DEST= # Target executable program
CAMLC=bigloo
CAMLLINK=$(CAMLC)
CAMLLEX=camllex
CAMLYACC=camlyacc
CAMLDEP=camloodep
RM=/bin/rm -f
LINKFLAGS=-extend caml
SAFECOMPFLAGS=-O2
UNSAFECOMPFLAGS=-unsafe -O2

COMPFLAGS=$(SAFECOMPFLAGS)

all: $(DEST)

$(DEST): $(OBJS)
$(CAMLLINK) -o $(DEST) $(COMPFLAGS) $(OBJS) $(LINKFLAGS)

clean:
$(RM) $(DEST) *.zi *.o *.sci *~ #*#

.SUFFIXES:
.SUFFIXES: .mli .zi .ml .o .c .sci .scm

.mli.zi:
$(CAMLC) $(COMPFLAGS) $<

.ml.o:
$(CAMLC) -A $(COMPFLAGS) $<

depend:
mv Makefile Makefile.bak
(sed -n -e '1,/^### DO NOT DELETE THIS LINE/p' Makefile.bak; \
$(CAMLDEP) *.mli *.ml) > Makefile
rm Makefile.bak

### EVERYTHING THAT GOES BEYOND THIS COMMENT IS GENERATED BY CAMLOODEP
### DO NOT DELETE THIS LINE

******* end of Makefile (template) *********

The camloodep command is a perl script, picked up from the Caml Light
system source code and adapted to Bigloo by Franc,ois Rouaix (you need
the perl programming language, supposed to be installed in directory
/usr/local/bin, to run this program).
******* file camloodep *********
#!/usr/local/bin/perl

# To scan a Caml Light source file, find all references to external modules
# (#open "foo";; or foo__bar), and output the dependencies on standard output.
#
# Usage: camloodep [-I path] <file> ...

while ($#ARGV >= 0) {
$_ = shift(@ARGV);
if (/^-I(.*)$/) {
$dir = $1 ? $1 : shift(@ARGV);
$dir =~ s|/$||;
unshift(@path, $dir);
}
elsif (/(.*)\.mli$/ || /(.*)\.zi$/) {
do scan_source ($_, "$1.zi");
}
elsif (/(.*)\.ml$/ || /(.*)\.o$/) {
do scan_source ($_, "$1.o");
}
else {
die "Don't know what to do with $_";
}
}

sub scan_source {
local ($source_name, $target_name) = @_;
$modname = $target_name;
$modname =~ s|^.*/||;
$modname =~ s|\.z[io]$||;
undef(%imports);
open(SRC, $source_name) || return;
while(<SRC>) {
if (m/#\s*open\s*"([^"]*)"/) {
$imports{$1} = 1;
}
while (m/([a-zA-Z0-9_]+)__/g) {
$imports{$1} = 1;
}
}
close(SRC);
undef(@deps);
if ($target_name =~ m/\.o$/ && -r ($source_name . "i")) {
push(@deps, "$1.zi");
}
foreach $modl (keys(%imports)) {
next if ($modl eq $modname);
if ($dep = do find_path ("$modl.mli")) {
$dep =~ s/\.mli$/.zi/;
push(@deps, $dep);
$dep =~ s/\.zi$/.o/;
push(@deps, $dep);
}
elsif ($dep = do find_path ("$modl.ml")) {
$dep =~ s/\.ml$/.o/;
push(@deps, $dep);
}
}
if ($#deps >= 0) {
print "$target_name: ";
$col = length($target_name) + 2;
foreach $dep (@deps) {
$col += length($dep) + 1;
if ($col >= 77) {
print "\\\n ";
$col = length($dep) + 5;
}
print $dep, " ";
}
print "\n";
}
}

sub find_path {
local ($filename) = @_;
if (-r $filename) {
return $filename;
}
foreach $dir (@path) {
if (-r "$dir/$filename") {
return "$dir/$filename";
}
}
return 0;
}

******* end of camloodep *********

Manuel Serrano & Pierre Weis.