You have probably already found out that compiling, packing, and
signing of Place Users can become a little tedious, repeated every
time you change any tiny bit in the source code. In order to make
life easier you can write a shell script that cares for all the
necessary steps. This solution has a drawback: A shell script will
usually try to recompile everything although you only changed one
class. This takes too much time when your projects become larger.
Here make may be quite
a handy tool. It checks the timestamps and only calls the compiler
for modified files.
How do I write a makefile for a Place User? We show you for the case of the HelloWorld agent:
| Makefile |
|---|
# Caution: --> must be replaced by a TAB sign all: HelloWorld.spu clean: -->rm -f *.class *.spu rebuild: clean all HelloWorld.class: HelloWorld.java -->javac -classpath $(CLASSPATH):. HelloWorld.java HelloWorld.spu: HelloWorld.class -->rm -f HelloWorld.spu -->secadmin /home/user/ametas/places/first/config crspu HelloWorld -->secadmin /home/user/ametas/places/first/config addsig HelloWorld -privk /home/user/ametas/id/user.idy |
This makefile must be stored in the same directory as the
HelloWorld agent. To execute it, change to this directory
(here e.g. $AMETAS_HOME/agents)
and call the program make:
cd $AMETAS_HOME/agents make |
All dependencies and target files behind
HelloWorld.spu)
will be updated if necessary. To remove all classes and SPU
containers in the current directory you use
make clean
This processes the clean rule, resulting in some rm command executions. The rebuild rule at first deletes all automatically generated files (clean) and then recompiles all files (all):
make rebuild
A short explanation of make
make processes makefiles containing
rules which define dependencies between
files of a project. A rule consists of a target and zero or
more dependencies. Thus, the
rule HelloWorld.class: HelloWorld.java (from the above makefile)
declares that the file HelloWorld.class
(the target) depends on the file HelloWorld.java.
That means that HelloWorld.class
must always be rebuild whenever HelloWorld.java
has changed (has a newer timestamp than HelloWorld.class).
The way how to create HelloWorld.class
is displayed in the next line. In this example the Java compiler is
started on the Java file. Each command that appears in a rule must
be preceded by a tabulator, not by a blank! Otherwise
it will not be executed. Note that we used -->
in the example to symbolize TABs; you have to hit your TAB key
instead.
Rules may contain several commands. You find an example with the
rule for HelloWorld.spu: HelloWorld.class. When you call
make without arguments, it looks for a file named
Makefile or makefile in the
current working directory and tries the first rule (here all).
This leads to the following actions:
make analyzes the rule for the target all
and finds out that it depends on HelloWorld.spu.
HelloWorld.spu, this rule is now
analyzed in order to create HelloWorld.spu.
HelloWorld.spu rule says that the target depends on
HelloWorld.class. Now a rule is searched for this file.
HelloWorld.class depends on HelloWorld.java,
but HelloWorld.java does not offer further rules.
When HelloWorld.class either does not exist or is older than
HelloWorld.java, the command defined by this rule will be executed
in order to create or update HelloWorld.class.
make now turns back to the rule for HelloWorld.spu.
If the file HelloWorld.class was recreated, it is now younger
than HelloWorld.spu, and the commands to create HelloWorld.spu
are executed in order to update HelloWorld.spu. The SPU is removed
at first, then created and signed. This rule consists of three commands:
The first one remove the outdated SPU file; the second recreates the SPU;
the third one signs it. The third command is pretty long and therefore split
in two parts. You need to add a backslash behind every line that is
continued by the next line.
Ask yourself what happens when HelloWorld.class is younger than
HelloWorld.java and HelloWorld.spu does not exist.
For more details on make and Makefiles please
refer to their documentation which is normally part of every Unix
distribution.
| Please note that in order to automatically sign your container, you must provide your passphrase in plaintext. This is a high security risk. If you include your passphrase in the makefile you should ensure that other people do not have read permission on it! |