In this exercise you will get to know two tools that are used especially in the open source world. The first is a build management system make
of which many implementations exist. On linux systems gnumake
is most common. Have a look at gnumake's manual
if you have trouble writing Makefiles on pure intuition (or lack a vast number of monkeys).
The other tool that will be introduced is subversion
, a version control system. It has a centralized distribution system with one repository at the center. There are many different implementations for subversion. Apart from the very useful plugins for eclipse
and visual studio
, there is a very nice point and click interface for microsoft windows called tortoise
The university runs a subversion server. You can use this facility by asking one of the staff to create an account and a repository for you. When logged in at the university you can use the subversion website
to manage and view repositories.
Subversion is documented pretty well in the manual
and it also never hurts to have a look at svn's own build in help (type
in a console).
This assignment will be performed on linux, but it will suffice to log onto a linux machine using putty
. You should be able to run make, flex, bison and svn in the console. Next download this repository package
and unpack it (I will assume it's located at
). Normally a repository would be at a server, but svn also supports direct file access.
Leave the repository alone, you should not alter any files within the repository's directory structure. Checkout a working copy of the repository with the following command:
svn checkout file://$REPO
Alternativaly use tortoise
: right-click in a directory in explorer and use the first item in the context menu named
. The rest is up to you.
Example: suppose you downloaded the repository-zip file to ~/repositories:
Then go back to another directory to checkout a working copy:
svn checkout file://$REPO
You have now the source code of a small interpreter. It already has a build script which uses bash. You can compile it by running
and try it with
./interpreter < test-03.lam
. The output should be
The actual purpose of the program is not very important, though. More
important are the following facts about the implementation:
- The program consists of several C source files and header files such as
- The parser is implemented using the Bison parser generator which translates a Bison parser specificition (
parser.y) into a C-language parser corresponding to the specified grammar.
- Likewise, the lexical analyser (lexer) is implemented using the Flex lexer generator. The lexer is specified in
The current build script is not very easy to maintain and it will recompile all source files every time it is called. Compiling big programs can take a lot of time, so we should try to recompile as few files as possible.
Your job is to write a Makefile that will take care of this. It should at least have the following targets:
clean which removes all files created by the compilation process
interpreter which compiles the entire program and recompiles only the necessary parts if something has changed, this should be the default target
Furthermore you should introduce pattern rules for the lexer and parser files. Make already has some pattern rules for
files, but it uses the deprecated lex and yacc.
Since finding all the dependencies is probably not your favourite kind of work, you can use a tool called makedepend that does this for you. Have a look at the man page to get more information.
If you've finished the makefile, commit your changes to the repository.
Fiddling with subversion
Checkout a new working copy in a different directory and try change the same file in different working copies. After committing in both working copies, the file sometimes can be merged automatically. Sometimes conflicts (merge errors) will arise. Describe when they arise and when subversion will automatically merge them. Describe how to create both a successful merge and a conflict.
Handing in the Exercise
Zip the repository (not your working copy!) which should now include the new makefile, make sure it still works after creating the conflicts. You can answer the question about subversions conflicts in a readme file.
This exercise is based heavily on a previous exercise
- 27 Sep 2006