Introduction

While packaging an application you will discover that debian/rules file is one of the most importants maintainer scripts required for a perfect package's build. This file it's simply a makefile, and learning make structures, variables and constructions can help you to understand how to modify and learn maintainer scripts like debian/rules too. Rules file can be invoked by saying its name instead of launching make itself, thanks to the starting line at the top of the file: #!/usr/bin/make -f.

A simple rule is made on a simple structure based on targets, dependencies and commands. Here is what a simple rule looks like:

config.status: bar 
foo

Add here commands to configure the package.
./configure 

In our case:

  1. target is "config.status"

  2. dependencies are represented by "bar"

  3. foo and ./configure are the commands that will be executed, in this case, to configure the package.

The lines with the colon " : " in them are called dependency lines. They determine whether the target has to be rebuilt. The Left side of the colon is identified as the target itself of the dependency. Right side of the colon got the sources needed to make the target. A dependency line says, for example, that the target depends on a source file or a to another target as in the previous example. Until configure target is launched, config.status is not able to work as it depends directly from configure target specified above. When this has been verified, rules file keep checking the next space under this target where the developer will place every command is needed to build/configure/clean the package.

The Makefile rules for building and installation can also use compilers and related programs by running them via make variables so that the developer can substitute them with other alternatives:

ar bison cc flex install ld ldconfig lex 
make makeinfo ranlib texi2dvi yacc 

Those programs can be called by using these variables while writing the makefile:

$(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX) 
$(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)