8.5 Functors at Abstract URIs

If my compiled functor is stored in file /home/denys/oz-kurs/Greet.ozf then I must also import it from this file, i. e. explicitly using this pathname, and my programs will not work for you when you download them to your computer. Hardwiring filenames is a bad idea. A much better idea is to use an abstract name rather than a specific concrete one, for example:

x-ozlib://oz-kurs/examples/Greet.ozf

Such an abstract name is called a URI (Uniform Resource Identifier), and the mapping from URI to specific files (or URLs) is performed automatically by the Mozart resolver. We will not go into the details of the resolver, but rather, we will show you how to take advantage of it by installing packages and by developing your own projects as packages.

All the Mozart system modules use URIs of the form x-oz://.... For the modules developed in this course, we will use URIs of the form x-ozlib://oz-kurs/....

8.5.1 A Simple Makefile

Let us turn our greeting library into a package. To this end, we need to provide ozmake with a description of our package. Such a description is called a makefile and is conventionally stored in a file called makefile.oz. This contains a record describing the package. For our greeting library we write the following makefile:

makefile(
   lib   : [ 'Greet.ozf' ]
   uri   : 'x-ozlib://oz-kurs/examples' 
   mogul : 'mogul:/oz-kurs/denys/greet' 
   )

The lib feature lists the compiled functors provided by the package. The uri feature gives the base URI for our libraries: thus our Greet.ozf functor will be available at URI:

x-ozlib://oz-kurs/examples/Greet.ozf

The mogul feature uniquely identifies this package. Why do we need both feature uri and mogul? Because it is often useful to have several packages that install libraries under the same URI: feature mogul indentifies the package, while feature uri gives the namespace for its libraries. Now, simply invoking:

ozmake

consults the makefile and builds Greet.ozf if necessary, but more importantly:

ozmake --install

installs our package so that the greeting module can be imported from the URI mentioned above. Let's try this command now:

% ozmake --install
ozc -c Greet.oz -o Greet.ozf
mkdir /home/denys/.oz/cache/x-ozlib/oz-kurs
mkdir /home/denys/.oz/cache/x-ozlib/oz-kurs/examples
cp Greet.ozf /home/denys/.oz/cache/x-ozlib/oz-kurs/examples/Greet.ozf

ozmake echoes the commands1 that it executes. Here, it compiled Greet.oz to produce Greet.ozf, then created the directories to install the libraries in my personal Oz area (each user has their own), and finally copied Greet.ozf to its final destination as an installed library. You too can install this package and we all can use the greeting library it provides by importing it from the same abstract URI:

declare [M]={Module.link ['x-ozlib://oz-kurs/examples/Greet.ozf']}
{M.greet}


1. actually ozmake echoes an idealization of the commands that it executes. This idealization shows the Unix commands that would typically be executed to obtain the desired effect. The actual implementation is designed to be portable across platforms: in particular, it needs to work on Windows.

Denys Duchier, Claire Gardent and Joachim Niehren
Version 1.3.99 (20050412)