Makefile structure for the ELKS project

This document describes the intended structure of the Makefiles in the ELKS project, and the standards that should apply to have a completely rational system. It makes a number of assumptions about how the process of compiling ELKS works, and these assumptions are hopefully documented here:

  1. ELKS is not yet able to compile itself, so it has to be compiled under another operating system and ported across. It is not in general possible to use the same compiler to compile ELKS as to compile software designed to run under the other operating system, so there is a need for TWO sets of compilation rules, one for compiling ELKS and another for compiling the tools used in the process of configuring and compiling ELKS.

  2. ELKS is complex enough to require multiple levels of source directories. It is assumed that all actions relating to the files in a given source directory will be documented in the Makefile in that directory.

Based on these assumptions, the following design is offered for a coherent and rational Makefile system:

  1. There will be a file Makefile-rules in the base directory of the ELKS source tree that collects together the standard rules for all subordinate Makefiles.

  2. Each Makefile in the source tree will begin by defining the following variables...

    Variable Definition Values
    ELKSCODE

    States whether the current directory contains code that compiles to become part of the ELKS kernel, or code that compiles to produce tools to be used when configuring or compiling the ELKS kernel.

    YES
    NO
    ELKSDIR

    The relative path from the current directory to the base directory of the ELKS source tree.

    ...and then includes the line...

    include $(ELKSDIR)/Makefile-rules

    ...to generate the standard values and rules. Only AFTER it has done this may any other definitions be made.

    Once this has been done, the following additional variables have been defined and are available for use:

    Variable Definition
    DISTDIR

    The absolute path of the directory to copy files to when making a distribution copy of this directory.

    ELKS_VERSION_CODE

    The current ELKS version encoded as a 32-bit integer.

    INCDIR

    The absolute path of the directory containing the include files to use when compiling ELKS.

    TOPDIR

    The absolute path to the ELKS base directory.

  3. The following rules MUST be defined in each Makefile. Each only needs to deal with appropriate files in its own directory as they are called recursively on each directory containing Makefile files.

    1. cleandir:

      This rule performs any actions required to clean up the files in this directory beyond the standard actions of removing any files named core together with all files with names matching *~ or *.o or *.tmp and finally removing any files named *.s where a matching *.S file exists.

      The above files will be removed automatically and no special action needs to be taken to remove them. Likewise, no special action needs to be taken to remove files in any subdirectories containing a Makefile as this rule is called recursively on all subdirectories.

    2. distdir:

      This rule performs any actions required to create a distribution copy of the files in this directory beyond the standard steps of creating


Copyright © Riley Williams,
Released under the GNU General Public Licence, version 2 only