Open source software needs to be distributed. This chapter gives a simple example of how you can upload your files and make it easy for others to download and install your program.
To make it easy for others to obtain the latest version of your program, you give them a recipe. That is all they need. In the recipe you describe how to download the files and compile the program. Here is an example:
1 ORIGIN = ftp://ftp.mysite.org/pub/theprog 2 3 :recipe {fetch = $ORIGIN/main.aap} 4 5 SOURCE = main.c 6 version.c 7 HEADER = common.h 8 TARGET = theprog 9 10 :attr {fetch = $ORIGIN/%file%} $SOURCE $HEADER |
The first line specifies the location where all the files can be found. It is good idea to specify this only once. If you would use the text all over the recipe it is more difficult to read and it would be more work when the URL changes.
Line 3 specifies where this recipe can be obtained. After obtaining this recipe once, it can be updated with a simple command:
% aap refresh
Aap: Updating recipe "main.aap"
Aap: Attempting download of "ftp://ftp.mysite.org/pub/theprog/main.aap"
Aap: Downloaded "ftp://ftp.mysite.org/pub/theprog/main.aap" to "/home/mool/.aap/cache/98092140.aap"
Aap: Copied file from cache: "main.aap"
%
The messages from Aap are a bit verbose. This is just in case the downloading is very slow, you will have some idea of what is going on.
Lines 5 to 8 define the source and target files. This is not different from the examples that were used to compile a program.
The last line specifies where the files can be fetched from. This is done by giving the source and header files the fetch attribute. The :attr command does not cause the files to be fetched yet. When a file is used somewhere and it has a fetch attribute, then it is fetched. Thus files that are not used will not be fetched.
A user of your program stores this recipe as "main.aap" and runs aap without arguments. What will happen is:
Dependencies will be created from SOURCE and TARGET to build "theprog" from "main.c" and "version.c".
The target "theprog" depends on "main.c" and "version.c". Since these files do not exist and they do have a fetch attribute, they are fetched.
The "main.c" file is inspected for dependencies. It includes the "common.h" file, which is automatically added to the list of dependencies. Since "common.h" does not exist and has a fetch attribute, it is fetched as well.
Now that all the files are present they are compiled and linked into "theprog".
You need to upload the files mentioned in the recipe above. This needs to be repeated each time one of the files changes. This is essentially the same as publishing a web site. This recipe will do the work:
:include main.aap TARGET = URL = scp://user@ftp.mysite.org//pub/theprog/%file% :attr {publish = $URL} $SOURCE $HEADER main.aap all: publish |
Write this recipe as "publish.aap" and execute it with aap -f publish.aap. There is no need to specify the target to be build, since the last line specifies that the default target "all" depends on "publish" and the "publish" target publishes all files with a publish attribute.
In the first line the :include command is used to include the recipe "main.aap". This works like the contents of "main.aap" was present in place of the :include command. The "main.aap" recipe defines SOURCE and HEADER. Including this avoids having to list the source files again. But the "main.aap" recipe also defined TARGET, which would trigger the default rule to build a program. We don't want that here, therefore TARGET is made empty after including "main.aap".